From c0eac5fc8b4f15d43ccd1615095b3e549f805c6e Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 22 Oct 2026 12:14:26 +0100 Subject: [PATCH] fix(app): keep chat attachment send analysis clean Remove the redundant dart:typed_data import so integrated analysis is clean, restore immediate composer focus on send, and cover operation-id reuse for refused attachment retries plus duplicate-name removal. --- .../chat/conversation/chat_composer_bar.dart | 4 +- .../chat_composer_attachment_send_test.dart | 61 ++++++++++++++++++- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/app/lib/features/chat/conversation/chat_composer_bar.dart b/app/lib/features/chat/conversation/chat_composer_bar.dart index c2c5a484..00f41864 100644 --- a/app/lib/features/chat/conversation/chat_composer_bar.dart +++ b/app/lib/features/chat/conversation/chat_composer_bar.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:typed_data'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -130,6 +129,8 @@ class _ChatComposerBarState extends State { setState(() => _attachmentError = error.message); return; } + // Keep the caret in the field while the prompt is in flight, as before. + _focus.requestFocus(); final accepted = await composer.send(attachments: parts); if (!mounted) return; if (accepted) { @@ -138,7 +139,6 @@ class _ChatComposerBarState extends State { _attachmentError = null; }); } - _focus.requestFocus(); } /// Adds the operator's explicit selection through the host seam. A dismissed 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 0a2b7295..3aaed834 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 @@ -39,14 +39,16 @@ void main() { group('ChatComposerController.send', () { late FakeComposerGateway gateway; late ChatComposerController controller; + var operationSeq = 0; setUp(() { + operationSeq = 0; gateway = FakeComposerGateway(); controller = ChatComposerController( gateway, 's', drafts: MemoryChatDraftStore(), - newOperationId: () => 'op/1', + newOperationId: () => 'op/${operationSeq += 1}', ); }); @@ -79,6 +81,32 @@ void main() { expect(controller.draft, ''); }, ); + + test('a refused prompt reuses its id only for matching parts', () async { + gateway.prompt = (_, _) async => throw StateError('response lost'); + final first = _wireParts([ + _file('notes.txt', [1]), + ]); + final second = _wireParts([ + _file('notes.txt', [2]), + ]); + await controller.setDraft('hello'); + + await controller.send(attachments: first); + await controller.send(attachments: second); + await controller.send( + attachments: _wireParts([ + _file('notes.txt', [2]), + ]), + ); + + expect(gateway.promptBodies.map((body) => body['operation_id']), [ + 'op/1', + 'op/2', + 'op/2', + ]); + expect(controller.draft, 'hello'); + }); }); group('ChatComposerBar send', () { @@ -160,6 +188,37 @@ void main() { }, ); + testWidgets('removing one duplicate name sends the other file', ( + tester, + ) async { + // Same name, type and size, so only position tells the two picks apart. + final files = [ + _file('notes.txt', utf8.encode('aaaaa')), + _file('notes.txt', utf8.encode('bbbbb')), + ]; + await pumpBar(tester, _FakePicker([files]).picker); + + await pickFiles(tester); + expect(find.text('notes.txt'), findsNWidgets(2)); + + await tester.tap( + find.descendant( + of: find.byKey(const ValueKey('chat-composer-attachment-1')), + matching: find.byTooltip('Remove notes.txt'), + ), + ); + await tester.pump(); + expect(find.text('notes.txt'), findsOneWidget); + + await typeAndSend(tester, 'hello'); + + expect( + gateway.promptBodies.single['attachments'], + _wireParts([files[0]]), + ); + expect(find.byKey(const Key('chat-composer-attachments')), findsNothing); + }); + testWidgets('a refusal restores the exact draft and keeps the chips', ( tester, ) async {