Files
pipelines/app/test/features/chat/shell/chat_shell_dismiss_test.dart
alan 8e98651db6 Remove Cupertino chat shell branches
Keep the Material-only chat shell path while preserving public Cupertino parameters for callers. Narrow matching tests to the supported Material host.
2026-11-11 04:41:58 +00:00

142 lines
4.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/shell/chat_shell_runs_controller.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar_overflow.dart';
import 'chat_shell_fixtures.dart';
void main() {
late ShellGateway gateway;
setUp(() => gateway = ShellGateway());
tearDown(() => gateway.close());
Finder card() => find.bySemanticsIdentifier('chat-shell-run-card');
final dismiss = find.byKey(const Key('chat-shell-run-dismiss'));
final notice = find.byKey(const Key('chat-shell-undo-notice'));
JsonMap finished(String id, {String command = 'true'}) => shellRecord(
id,
command: command,
status: 'exited',
exitCode: 0,
output: 'out $id\n',
durationMs: 50,
);
testWidgets('Dismiss removes a finished card without a notice', (
tester,
) async {
gateway.runs = [finished('run_done'), shellRecord('run_live')];
await tester.pumpWidget(shellThread(gateway));
await tester.pump();
expect(card(), findsNWidgets(2));
// Only the finished card offers Dismiss; a running one must stop first.
expect(dismiss, findsOneWidget);
expect(find.byTooltip('Dismiss'), findsOneWidget);
await tester.tap(dismiss);
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
expect(gateway.bodies('chat_shell_dismiss').single['run_ids'], [
'run_done',
]);
expect(card(), findsOneWidget);
expect(find.text('\$ true'), findsNothing);
expect(notice, findsNothing);
expect(find.text('Command dismissed'), findsNothing);
expect(find.text('Undo'), findsNothing);
});
testWidgets('a refused dismissal brings the card back with the reason', (
tester,
) async {
gateway.runs = [finished('run_done')];
gateway.dismissRefusal = 'the store is read-only';
await tester.pumpWidget(shellThread(gateway));
await tester.pump();
await tester.tap(dismiss);
await tester.pump();
expect(card(), findsOneWidget);
expect(find.byKey(const Key('chat-shell-run-error')), findsOneWidget);
expect(find.textContaining('the store is read-only'), findsOneWidget);
expect(notice, findsNothing);
});
testWidgets('the More menu has no Dismiss all without a finished run', (
tester,
) async {
gateway.runs = [shellRecord('run_live')];
await tester.pumpWidget(shellThread(gateway));
await tester.pump();
await tester.tap(find.byKey(segmentedMoreKey).hitTestable().first);
await tester.pump(const Duration(milliseconds: 500));
expect(find.text('Run command…'), findsOneWidget);
expect(find.text('Dismiss all finished commands'), findsNothing);
});
testWidgets('Dismiss all finished commands leaves running ones', (
tester,
) async {
gateway.runs = [shellRecord('run_live'), shellRecord('run_a')];
await tester.pumpWidget(shellThread(gateway));
await tester.pump();
// Finishing runs offers the entry.
gateway.runs = [
finished('run_a'),
finished('run_b', command: 'ls'),
shellRecord('run_live'),
];
gateway.emitRun(finished('run_a'));
gateway.emitRun(finished('run_b', command: 'ls'));
await tester.pump();
await tester.tap(find.byKey(segmentedMoreKey).hitTestable().first);
await tester.pump(const Duration(milliseconds: 500));
await tester.tap(find.text('Dismiss all finished commands'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(gateway.bodies('chat_shell_dismiss').single['run_ids'], [
'run_a',
'run_b',
]);
expect(card(), findsOneWidget);
expect(find.text('2 commands dismissed'), findsNothing);
expect(find.text('Undo'), findsNothing);
});
testWidgets('another client dismissing a run removes its card here', (
tester,
) async {
gateway.runs = [finished('run_done')];
await tester.pumpWidget(shellThread(gateway));
await tester.pump();
expect(card(), findsOneWidget);
gateway.emitDismissed('run_done');
await tester.pump();
expect(card(), findsNothing);
// A restore there brings it back here too, output read back.
gateway.emitRun(finished('run_done'));
await tester.pump();
await tester.pump();
expect(card(), findsOneWidget);
expect(gateway.calls.where((c) => c.type == 'chat_shell_runs').length, 2);
});
test('a readback drops runs dismissed while this copy was away', () async {
gateway.runs = [finished('run_a'), finished('run_b')];
final controller = ChatShellRunsController(gateway, 's');
addTearDown(controller.dispose);
await pumpEventQueue();
expect(controller.runs.map((r) => r.id), ['run_a', 'run_b']);
gateway.runs = [finished('run_b')];
gateway.dismissed = ['run_a'];
await controller.refresh();
expect(controller.runs.map((r) => r.id), ['run_b']);
expect(controller.finishedIds, ['run_b']);
});
}