Dismiss finished shell command cards with Undo
Finished command cards get a Dismiss button and the chat's More menu a Dismiss all finished commands entry. Dismissal applies to every client of the chat; a SnackBar (Material) or transient notice (Cupertino) offers Undo for 5 s. Running commands cannot be dismissed until they end.
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
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,
|
||||
);
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('$host: Dismiss removes a finished card and Undo restores it', (
|
||||
tester,
|
||||
) async {
|
||||
gateway.runs = [finished('run_done'), shellRecord('run_live')];
|
||||
await tester.pumpWidget(shellThread(gateway, cupertino: cupertino));
|
||||
await tester.pump();
|
||||
|
||||
expect(card(), findsNWidgets(2));
|
||||
// Only the finished card offers Dismiss; a running one must stop first.
|
||||
expect(dismiss, findsOneWidget);
|
||||
expect(
|
||||
cupertino
|
||||
? find.bySemanticsLabel('Dismiss')
|
||||
: 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, findsOneWidget);
|
||||
expect(find.text('Command dismissed'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Undo'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
expect(gateway.bodies('chat_shell_restore').single['run_ids'], [
|
||||
'run_done',
|
||||
]);
|
||||
expect(card(), findsNWidgets(2));
|
||||
expect(find.text('\$ true'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('$host: the Undo notice goes away after five seconds', (
|
||||
tester,
|
||||
) async {
|
||||
gateway.runs = [finished('run_done')];
|
||||
await tester.pumpWidget(shellThread(gateway, cupertino: cupertino));
|
||||
await tester.pump();
|
||||
await tester.tap(dismiss);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
expect(notice, findsOneWidget);
|
||||
await tester.pump(const Duration(seconds: 5));
|
||||
await tester.pumpAndSettle();
|
||||
expect(notice, findsNothing);
|
||||
expect(card(), findsNothing);
|
||||
expect(gateway.bodies('chat_shell_restore'), isEmpty);
|
||||
});
|
||||
}
|
||||
|
||||
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'), findsOneWidget);
|
||||
// Let the SnackBar finish entering.
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
await tester.tap(find.text('Undo'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
expect(card(), findsNWidgets(3));
|
||||
});
|
||||
|
||||
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);
|
||||
// Its Undo there restores it 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']);
|
||||
});
|
||||
}
|
||||
@@ -18,6 +18,13 @@ class ShellGateway implements ApiGateway {
|
||||
List<JsonMap> runs = const [];
|
||||
String? refusal;
|
||||
|
||||
/// Tombstone ids the `chat_shell_runs` readback reports.
|
||||
List<String> dismissed = const [];
|
||||
|
||||
/// The refusal of `chat_shell_dismiss` / `chat_shell_restore`, when set.
|
||||
String? dismissRefusal;
|
||||
String? restoreRefusal;
|
||||
|
||||
/// The reply to a `chat_shell_run_output` that resumes from an offset.
|
||||
JsonMap? resumeReply;
|
||||
int _serial = 0;
|
||||
@@ -42,7 +49,19 @@ class ShellGateway implements ApiGateway {
|
||||
case 'chat_messages':
|
||||
return chatPage(const []);
|
||||
case 'chat_shell_runs':
|
||||
return {'chat_shell_runs': runs};
|
||||
return {'chat_shell_runs': runs, 'chat_shell_dismissed': dismissed};
|
||||
case 'chat_shell_dismiss':
|
||||
if (dismissRefusal != null) throw StateError(dismissRefusal!);
|
||||
return {'chat_shell_dismissed': body['run_ids']};
|
||||
case 'chat_shell_restore':
|
||||
if (restoreRefusal != null) throw StateError(restoreRefusal!);
|
||||
final ids = (body['run_ids'] as List).toSet();
|
||||
return {
|
||||
'chat_shell_runs': [
|
||||
for (final run in runs)
|
||||
if (ids.contains(run['id'])) run,
|
||||
],
|
||||
};
|
||||
case 'chat_shell_run':
|
||||
if (refusal != null) throw StateError(refusal!);
|
||||
return {
|
||||
@@ -82,6 +101,15 @@ class ShellGateway implements ApiGateway {
|
||||
},
|
||||
});
|
||||
|
||||
void emitDismissed(String id) => _frames.add({
|
||||
'type': 'chat_shell_run_event',
|
||||
'chat_shell_run_event': {
|
||||
'session_id': 's',
|
||||
'run_id': id,
|
||||
'dismissed': true,
|
||||
},
|
||||
});
|
||||
|
||||
void close() => _frames.close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user