feat(chat): ChatGPT-style transcript and composer

Agent replies sit on the page without a bubble and get a copy control;
the operator's turn is a neutral rounded bubble; the composer is one
filled pill with +, a borderless field and a round Send, and its
placeholder names the chat's folder. Also fixes two picker tests left
stale by the native picker.
This commit is contained in:
2026-10-30 15:56:39 +00:00
parent 962b358af0
commit 027c2f800e
11 changed files with 461 additions and 154 deletions
@@ -207,7 +207,10 @@ void main() {
testWidgets('the attach control is disabled without a host picker', (
tester,
) async {
await pumpBar(tester);
await pumpBar(
tester,
picker: const ChatAttachmentPicker.unsupported('No picker here.'),
);
final attach = tester.widget<IconButton>(
find.byKey(const Key('chat-composer-attach')),
@@ -76,10 +76,12 @@ Widget composerThread(
ChatDraftStore? drafts,
String Function()? newOperationId,
VoidCallback? onBack,
JsonMap? session,
}) {
final thread = ChatThreadView(
gateway: gateway,
sessionId: 's',
session: session,
syncToken: syncToken,
onBack: onBack ?? () {},
drafts: drafts ?? MemoryChatDraftStore(),
@@ -30,4 +30,47 @@ void main() {
expect(paragraph.overflow, TextOverflow.ellipsis);
}
});
test('the placeholder names the chat\'s folder when it has one', () {
expect(chatComposerPlaceholderFor('/Users/ada/repos/tank'), 'Work on tank');
expect(
chatComposerPlaceholderFor('/Users/ada/repos/tank/'),
'Work on tank',
);
expect(chatComposerPlaceholderFor(r'C:\\work\\tank'), 'Work on tank');
expect(chatComposerPlaceholderFor(' '), chatComposerPlaceholder);
expect(chatComposerPlaceholderFor('/'), chatComposerPlaceholder);
});
for (final cupertino in [false, true]) {
testWidgets('the composer is one pill holding attach, field and Send '
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
final gateway = ComposerBarGateway();
addTearDown(gateway.close);
await tester.pumpWidget(
composerThread(
gateway,
cupertino: cupertino,
session: const {'id': 's', 'directory': '/Users/ada/repos/tank'},
),
);
await tester.pumpAndSettle();
final pill = find.byKey(const Key('chat-composer-pill'));
for (final key in [
'chat-composer-attach',
'chat-composer-field',
'chat-composer-primary',
]) {
expect(
find.descendant(of: pill, matching: find.byKey(Key(key))),
findsOneWidget,
);
}
expect(
find.descendant(of: pill, matching: find.text('Work on tank')),
findsOneWidget,
);
});
}
}
@@ -3,6 +3,7 @@ import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/domain/chat_attachment_draft.dart';
import 'package:pipelines_app/features/chat/domain/chat_attachment_picker.dart';
import 'package:pipelines_app/features/chat/domain/chat_attachment_picker_stub.dart';
void main() {
test('passes the chosen names, MIME types and bytes through', () async {
@@ -58,8 +59,12 @@ void main() {
expect(opened, 1);
});
test('the host picker reports its unsupported capability honestly', () async {
final picker = hostChatAttachmentPicker;
// The test VM is a dart:io host, which now has the native picker, so the
// unsupported path is exercised through the stub's own picker.
test('an unsupported host picker reports its capability honestly', () async {
const picker = ChatAttachmentPicker.unsupported(
chatAttachmentUnsupportedMessage,
);
expect(picker.isSupported, isFalse);
await expectLater(
@@ -0,0 +1,118 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
JsonMap _row(JsonMap message) => transcriptRows([message]).single;
final JsonMap _answer = _row({
'id': 'a1',
'role': 'assistant',
'parts': [
{'type': 'reasoning', 'text': 'Thinking it over'},
{'type': 'text', 'text': 'First paragraph.'},
{'type': 'text', 'text': 'Second paragraph.'},
],
});
final JsonMap _question = _row({
'id': 'u1',
'role': 'user',
'parts': [
{'type': 'text', 'text': 'Please prepare the system'},
],
});
Widget _host(List<JsonMap> rows, {bool cupertino = false}) {
final body = ListView(
children: [for (final row in rows) ChatMessageView(row: row)],
);
if (cupertino) {
return CupertinoApp(home: CupertinoPageScaffold(child: body));
}
return MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: Scaffold(body: body),
);
}
void main() {
for (final cupertino in [false, true]) {
final style = cupertino ? 'cupertino' : 'material';
testWidgets('only the operator turn is a bubble ($style)', (tester) async {
await tester.pumpWidget(
_host([_question, _answer], cupertino: cupertino),
);
Finder bubbleAround(String text) => find.ancestor(
of: find.text(text),
matching: find.byType(ChatUserBubble),
);
expect(bubbleAround('Please prepare the system'), findsOneWidget);
expect(bubbleAround('First paragraph.'), findsNothing);
expect(
find.ancestor(
of: find.text('First paragraph.'),
matching: find.byType(ChatAgentSurface),
),
findsOneWidget,
);
});
testWidgets('a finished reply copies its answer text ($style)', (
tester,
) async {
final copied = <String>[];
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
(call) async {
if (call.method == 'Clipboard.setData') {
copied.add('${(call.arguments as Map)['text']}');
}
return null;
},
);
addTearDown(
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
null,
),
);
await tester.pumpWidget(
_host([_question, _answer], cupertino: cupertino),
);
// The operator's own turn has nothing to copy beneath it.
expect(find.byKey(const Key('chat-message-copy')), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-message-copy')));
await tester.pump();
expect(copied, ['First paragraph.\n\nSecond paragraph.']);
final done = cupertino ? CupertinoIcons.checkmark : Icons.check;
final copy = cupertino ? CupertinoIcons.doc_on_doc : Icons.copy_outlined;
expect(find.byIcon(done), findsOneWidget);
await tester.pump(const Duration(seconds: 2));
expect(find.byIcon(copy), findsOneWidget);
expect(find.byIcon(done), findsNothing);
});
}
testWidgets('a streaming or text-less reply offers no copy', (tester) async {
final streaming = {..._answer, 'streaming': true};
final reasoningOnly = _row({
'id': 'a2',
'role': 'assistant',
'parts': [
{'type': 'reasoning', 'text': 'Only thinking'},
],
});
await tester.pumpWidget(_host([streaming, reasoningOnly]));
expect(find.byKey(const Key('chat-message-copy')), findsNothing);
});
}