diff --git a/app/lib/features/chat/conversation/chat_thread_view.dart b/app/lib/features/chat/conversation/chat_thread_view.dart index bd79e64a..9cc482b1 100644 --- a/app/lib/features/chat/conversation/chat_thread_view.dart +++ b/app/lib/features/chat/conversation/chat_thread_view.dart @@ -8,6 +8,7 @@ import '../../../core/api_gateway.dart'; import '../data/chat_repository.dart'; import '../domain/chat_activity_detail.dart'; import '../domain/chat_notice.dart'; +import '../domain/chat_attachment_picker.dart'; import '../domain/chat_transcript.dart'; import '../ui/sessions/chat_adaptive.dart'; import '../ui/sessions/session_actions.dart'; @@ -47,6 +48,7 @@ class ChatThreadView extends StatefulWidget { this.syncToken = 0, this.drafts, this.newOperationId, + this.attachmentPicker, this.scrollPositions, this.initialNotice, this.onCreatedSession, @@ -94,6 +96,9 @@ class ChatThreadView extends StatefulWidget { /// Test/fixture seam for deterministic operation ids. final String Function()? newOperationId; + /// Host picker seam for the thread's composer. + final ChatAttachmentPicker? attachmentPicker; + /// The destination's per-conversation scroll store. The screen supplies one /// that outlives this view, so a conversation opened again returns to where /// the operator left it. Null keeps the view stateless across visits. @@ -198,6 +203,13 @@ class _ChatThreadViewState extends State { 'native_message_id': send.nativeMessageId, 'parts': [ {'type': 'text', 'text': send.text}, + for (final attachment in send.attachments) + { + 'type': 'file', + 'name': attachment['name'], + 'uri': attachment['name'], + 'mime': attachment['mime'], + }, ], }); }); @@ -850,6 +862,7 @@ class _ChatThreadViewState extends State { composer: _composer, running: _controller.running, commands: _commandActions(), + picker: widget.attachmentPicker, ), ], ); diff --git a/app/test/features/chat/conversation/chat_composer_attachment_send_test.dart b/app/test/features/chat/conversation/chat_composer_attachment_send_test.dart index 3aaed834..f59b2fc5 100644 --- a/app/test/features/chat/conversation/chat_composer_attachment_send_test.dart +++ b/app/test/features/chat/conversation/chat_composer_attachment_send_test.dart @@ -8,7 +8,9 @@ import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart'; import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart'; import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart'; +import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart'; import 'package:pipelines_app/features/chat/domain/chat_attachment_picker.dart'; +import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart'; import 'chat_composer_bar_fixtures.dart'; import 'chat_composer_fixtures.dart'; @@ -188,6 +190,74 @@ void main() { }, ); + testWidgets('optimistic sent files render and are replaced by history', ( + tester, + ) async { + final files = [ + _file('screen.png', [0, 1, 2], mime: 'image/png'), + _file('notes.txt', utf8.encode('hello')), + ]; + final picker = _FakePicker([files]).picker; + var syncToken = 0; + Widget thread() => materialHost( + ChatThreadView( + gateway: gateway, + sessionId: 's', + onBack: () {}, + syncToken: syncToken, + drafts: MemoryChatDraftStore(), + newOperationId: () => 'op/1', + attachmentPicker: picker, + ), + ); + await tester.pumpWidget(thread()); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(const Key('chat-composer-attach'))); + await tester.pumpAndSettle(); + await typeAndSend(tester, 'hello'); + expect(find.text('screen.png'), findsOneWidget); + expect(find.text('notes.txt'), findsOneWidget); + expect(find.textContaining('data'), findsNothing); + + gateway.page = { + 'chat_history': { + 'messages': [ + { + 'id': 'msg_op1', + 'role': 'user', + 'operation_id': 'op/1', + 'parts': [ + {'type': 'text', 'text': 'hello'}, + {'type': 'file', 'name': 'screen.png', 'uri': 'screen.png'}, + {'type': 'file', 'name': 'notes.txt', 'uri': 'notes.txt'}, + ], + }, + ], + 'next_cursor': '', + 'has_more': false, + }, + }; + syncToken++; + await tester.pumpWidget(thread()); + await tester.pumpAndSettle(); + expect(find.text('screen.png'), findsOneWidget); + expect(find.text('notes.txt'), findsOneWidget); + expect(find.byType(ChatMessageView), findsOneWidget); + }); + + testWidgets('text-only optimistic turn has no file part', (tester) async { + await tester.pumpWidget( + composerThread(gateway, newOperationId: () => 'op/text'), + ); + await tester.pumpAndSettle(); + await typeAndSend(tester, 'plain text'); + + expect(find.text('plain text'), findsOneWidget); + expect(find.byType(ChatMessageView), findsOneWidget); + expect(find.text('screen.png'), findsNothing); + expect(find.text('notes.txt'), findsNothing); + }); + testWidgets('removing one duplicate name sends the other file', ( tester, ) async {