fix(app): keep Send available while a chat turn runs

This commit is contained in:
2026-10-24 01:57:46 +01:00
parent 7f88f14a52
commit 91854148dd
3 changed files with 146 additions and 34 deletions
@@ -1,4 +1,7 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
@@ -18,34 +21,35 @@ void main() {
tearDown(() => gateway.close());
testWidgets('Stop replaces Send while running and interrupts this session', (
tester,
) async {
await tester.pumpWidget(
composerThread(gateway, newOperationId: nextOperation),
);
await tester.pumpAndSettle();
expect(find.byTooltip(chatSendLabel), findsOneWidget);
testWidgets(
'Stop stays beside Send while running and interrupts this session',
(tester) async {
await tester.pumpWidget(
composerThread(gateway, newOperationId: nextOperation),
);
await tester.pumpAndSettle();
expect(find.byTooltip(chatSendLabel), findsOneWidget);
gateway.emitEvent(chatStepFrame('running'));
await tester.pump();
await tester.pump();
gateway.emitEvent(chatStepFrame('running'));
await tester.pump();
await tester.pump();
expect(find.byTooltip(chatSendLabel), findsNothing);
expect(find.byTooltip(chatStopLabel), findsOneWidget);
final button = tester.widget<IconButton>(
find.byKey(const Key('chat-composer-primary')),
);
final scheme = Theme.of(
tester.element(find.byKey(const Key('chat-composer-primary'))),
).colorScheme;
expect(button.style?.backgroundColor?.resolve({}), scheme.error);
expect(find.byTooltip(chatSendLabel), findsOneWidget);
expect(find.byTooltip(chatStopLabel), findsOneWidget);
final button = tester.widget<IconButton>(
find.byKey(const Key('chat-composer-stop')),
);
final scheme = Theme.of(
tester.element(find.byKey(const Key('chat-composer-stop'))),
).colorScheme;
expect(button.style?.backgroundColor?.resolve({}), scheme.error);
await tester.tap(find.byKey(const Key('chat-composer-primary')));
await tester.pumpAndSettle();
expect(gateway.interruptBodies.single, {'session_id': 's'});
expect(gateway.promptBodies, isEmpty);
});
await tester.tap(find.byKey(const Key('chat-composer-stop')));
await tester.pumpAndSettle();
expect(gateway.interruptBodies.single, {'session_id': 's'});
expect(gateway.promptBodies, isEmpty);
},
);
testWidgets('the queued notice is a polite line and clears on a frame', (
tester,
@@ -108,6 +112,83 @@ void main() {
});
for (final cupertino in [false, true]) {
testWidgets(
'running send waits only for its acknowledgement and keeps newer draft '
'(${cupertino ? 'cupertino' : 'material'})',
(tester) async {
final reply = Completer<Map<String, dynamic>>();
gateway.prompt = (_, _) => reply.future;
await tester.pumpWidget(
composerThread(
gateway,
cupertino: cupertino,
newOperationId: nextOperation,
),
);
await tester.pumpAndSettle();
gateway.emitEvent(chatStepFrame('running'));
await tester.pump();
await tester.pump();
final field = find.byKey(const Key('chat-composer-field'));
await tester.enterText(field, 'Queue this');
await tester.pump();
await tester.tap(find.byKey(const Key('chat-composer-primary')));
await tester.pump();
await tester.enterText(field, 'Newer draft');
await tester.pump();
// Keyboard submit shares the sending guard: no duplicate in flight.
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pump();
expect(gateway.promptBodies, hasLength(1));
reply.complete({'chat_queued': true});
await tester.pumpAndSettle();
expect(fieldText(tester), 'Newer draft');
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
expect(gateway.interruptBodies, isEmpty);
},
);
testWidgets('send follow-ups during a running turn without interrupting '
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
gateway.prompt = (_, _) async => {'chat_queued': true};
await tester.pumpWidget(
composerThread(
gateway,
cupertino: cupertino,
newOperationId: nextOperation,
),
);
await tester.pumpAndSettle();
gateway.emitEvent(chatStepFrame('running'));
await tester.pump();
await tester.pump();
for (final text in ['First follow-up', 'Second follow-up']) {
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
text,
);
await tester.pump();
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-composer-primary')));
await tester.pumpAndSettle();
expect(fieldText(tester), '');
expect(find.text(chatQueuedNotice), findsOneWidget);
}
expect(gateway.promptBodies.map((body) => body['text']), [
'First follow-up',
'Second follow-up',
]);
expect(gateway.promptBodies.map((body) => body['operation_id']), [
'op/1',
'op/2',
]);
expect(gateway.interruptBodies, isEmpty);
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
});
testWidgets('the composer wraps at 320 logical px with 2x text '
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
tester.view.physicalSize = const Size(640, 1200);
@@ -140,9 +221,14 @@ void main() {
);
await tester.pump();
gateway.emitEvent(chatStepFrame('running'));
await tester.pump();
await tester.pump();
expect(tester.takeException(), isNull);
expect(find.byKey(const Key('chat-composer')), findsOneWidget);
expect(find.byKey(const Key('chat-composer-primary')), findsOneWidget);
expect(find.byKey(const Key('chat-composer-stop')), findsOneWidget);
});
}
}