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.
This commit is contained in:
@@ -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<ChatComposerBar> {
|
||||
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<ChatComposerBar> {
|
||||
_attachmentError = null;
|
||||
});
|
||||
}
|
||||
_focus.requestFocus();
|
||||
}
|
||||
|
||||
/// Adds the operator's explicit selection through the host seam. A dismissed
|
||||
|
||||
@@ -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<String>('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 {
|
||||
|
||||
Reference in New Issue
Block a user