import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/ui/adaptive/segmented_bar_overflow.dart'; import 'chat_shell_fixtures.dart'; /// A desktop keyboard, where Enter sends. final _desktop = TargetPlatformVariant.only(TargetPlatform.linux); void main() { late ShellGateway gateway; setUp(() => gateway = ShellGateway()); tearDown(() => gateway.close()); final field = find.byKey(const Key('chat-composer-field')); final shellMode = find.byKey(const Key('chat-composer-shell-mode')); testWidgets('a leading ! shows Shell mode and runs instead of sending', ( tester, ) async { await tester.pumpWidget(shellThread(gateway)); await tester.pump(); await tester.enterText(field, 'hello'); await tester.pump(); expect(shellMode, findsNothing); await tester.enterText(field, '!git status'); await tester.pump(); expect(shellMode, findsOneWidget); expect(find.text('Shell'), findsOneWidget); expect(find.byTooltip('Run command'), findsOneWidget); await tester.sendKeyEvent(LogicalKeyboardKey.enter); await tester.pump(); await tester.pump(); expect(gateway.bodies('chat_shell_run').single['command'], 'git status'); expect(gateway.calls.where((c) => c.type == 'chat_prompt'), isEmpty); expect(shellMode, findsNothing, reason: 'the draft was consumed'); // The started run is drawn as a card at once. expect(find.text('\$ git status'), findsOneWidget); }, variant: _desktop); testWidgets('a refused command keeps the draft and says why', (tester) async { gateway.refusal = 'this chat already runs 4 commands'; await tester.pumpWidget(shellThread(gateway)); await tester.pump(); await tester.enterText(field, '!sleep 9'); await tester.pump(); await tester.tap(find.byKey(const Key('chat-composer-primary'))); await tester.pump(); await tester.pump(); expect(find.textContaining('already runs 4 commands'), findsOneWidget); expect(shellMode, findsOneWidget); expect(gateway.calls.where((c) => c.type == 'chat_prompt'), isEmpty); }); testWidgets('a bare ! asks for a command and sends nothing', (tester) async { await tester.pumpWidget(shellThread(gateway)); await tester.pump(); await tester.enterText(field, '!'); await tester.pump(); await tester.tap(find.byKey(const Key('chat-composer-primary'))); await tester.pump(); expect(find.text('Type a command after !.'), findsOneWidget); expect(gateway.bodies('chat_shell_run'), isEmpty); }); testWidgets('Run command… in the actions menu runs the typed command', ( tester, ) async { await tester.pumpWidget(shellThread(gateway)); await tester.pump(); await tester.tap(find.byKey(segmentedMoreKey).hitTestable().first); await tester.pumpAndSettle(); await tester.tap(find.text('Run command…')); await tester.pumpAndSettle(); await tester.enterText( find.byKey(const Key('chat-shell-run-field')), ' ls -la ', ); await tester.tap(find.byKey(const Key('chat-shell-run-confirm'))); // The running card's indicator never settles; let the dialog close. await tester.pump(); await tester.pump(const Duration(seconds: 1)); expect(gateway.bodies('chat_shell_run').single['command'], 'ls -la'); expect(find.text('\$ ls -la'), findsOneWidget); }); }