63babc597a
A leading slash opens the recorded command palette above the composer, filtered by name prefix and driven by Up/Down, Enter, tap and Escape. Slash drafts never reach the prompt path: a recorded command reports locally that its action is not implemented yet, and an unknown word takes the web client's no-send report with an explicit Send as message offer. Enter and the primary control share that route. Adds the chat commands domain vocabulary, the palette widget, composer wiring and regression tests; notes/C9-commands.md records behaviour and the remaining command-action gap.
415 lines
13 KiB
Dart
415 lines
13 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'chat_composer_bar_fixtures.dart';
|
|
|
|
void main() {
|
|
late ComposerBarGateway gateway;
|
|
late int sequence;
|
|
|
|
String nextOperation() => 'op/${++sequence}';
|
|
|
|
setUp(() {
|
|
gateway = ComposerBarGateway()..page = fixtureTurn();
|
|
sequence = 0;
|
|
});
|
|
|
|
tearDown(() => gateway.close());
|
|
|
|
Future<void> pumpComposer(
|
|
WidgetTester tester, {
|
|
bool cupertino = false,
|
|
}) async {
|
|
await tester.pumpWidget(
|
|
composerThread(
|
|
gateway,
|
|
cupertino: cupertino,
|
|
newOperationId: nextOperation,
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
Finder palette() => find.byKey(const Key('chat-command-palette'));
|
|
Finder row(String name) => find.byKey(ValueKey<String>('chat-command-$name'));
|
|
|
|
testWidgets('a leading slash opens the filtered recorded command palette', (
|
|
tester,
|
|
) async {
|
|
await pumpComposer(tester);
|
|
|
|
await tester.enterText(find.byKey(const Key('chat-composer-field')), '/');
|
|
await tester.pump();
|
|
|
|
expect(palette(), findsOneWidget);
|
|
for (final name in ['new', 'close', 'rename', 'stop', 'help']) {
|
|
expect(row(name), findsOneWidget);
|
|
}
|
|
expect(find.text('/new'), findsOneWidget);
|
|
expect(
|
|
find.text('Start a fresh session in this directory'),
|
|
findsOneWidget,
|
|
);
|
|
|
|
await tester.enterText(find.byKey(const Key('chat-composer-field')), '/cl');
|
|
await tester.pump();
|
|
|
|
expect(row('close'), findsOneWidget);
|
|
expect(row('new'), findsNothing);
|
|
expect(row('rename'), findsNothing);
|
|
expect(row('stop'), findsNothing);
|
|
expect(row('help'), findsNothing);
|
|
|
|
// Recognition is case-insensitive, and an argument or plain text hides it.
|
|
await tester.enterText(find.byKey(const Key('chat-composer-field')), '/CL');
|
|
await tester.pump();
|
|
expect(row('close'), findsOneWidget);
|
|
|
|
await tester.enterText(
|
|
find.byKey(const Key('chat-composer-field')),
|
|
'/close now',
|
|
);
|
|
await tester.pump();
|
|
expect(palette(), findsNothing);
|
|
|
|
await tester.enterText(
|
|
find.byKey(const Key('chat-composer-field')),
|
|
'plain text',
|
|
);
|
|
await tester.pump();
|
|
expect(palette(), findsNothing);
|
|
});
|
|
|
|
testWidgets('Escape closes the palette until the draft is edited again', (
|
|
tester,
|
|
) async {
|
|
await pumpComposer(tester);
|
|
final field = find.byKey(const Key('chat-composer-field'));
|
|
|
|
await tester.enterText(field, '/he');
|
|
await tester.pump();
|
|
expect(palette(), findsOneWidget);
|
|
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
|
await tester.pump();
|
|
|
|
expect(palette(), findsNothing);
|
|
expect(fieldText(tester), '/he');
|
|
expect(gateway.promptBodies, isEmpty);
|
|
|
|
await tester.enterText(field, '/hel');
|
|
await tester.pump();
|
|
expect(palette(), findsOneWidget);
|
|
|
|
// Editing reopens even when the operator returns to the exact word that
|
|
// was dismissed: the closure follows the edit, not the text.
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
|
await tester.pump();
|
|
await tester.enterText(field, '/h');
|
|
await tester.pump();
|
|
expect(palette(), findsOneWidget);
|
|
await tester.enterText(field, '/he');
|
|
await tester.pump();
|
|
expect(palette(), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('an unknown command reports locally and never prompts', (
|
|
tester,
|
|
) async {
|
|
await pumpComposer(tester);
|
|
final field = find.byKey(const Key('chat-composer-field'));
|
|
|
|
await tester.enterText(field, '/nope');
|
|
await tester.pump();
|
|
expect(palette(), findsNothing);
|
|
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(gateway.promptBodies, isEmpty);
|
|
expect(fieldText(tester), '');
|
|
expect(
|
|
find.text(
|
|
'“/nope” is not a command, so nothing was sent to the agent. '
|
|
'Send it as a message, or cancel.',
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.text('Send as message'), findsOneWidget);
|
|
expect(find.text('Cancel'), findsOneWidget);
|
|
|
|
// The primary Send control takes the same command path, never the prompt.
|
|
await tester.enterText(field, '/also unknown');
|
|
await tester.pump();
|
|
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(gateway.promptBodies, isEmpty);
|
|
expect(fieldText(tester), '');
|
|
expect(
|
|
find.text(
|
|
'“/also” is not a command, so nothing was sent to the agent. '
|
|
'Send it as a message, or cancel.',
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
|
|
await tester.tap(find.byKey(const Key('chat-command-cancel')));
|
|
await tester.pump();
|
|
|
|
expect(find.byKey(const Key('chat-composer-command-notice')), findsNothing);
|
|
expect(gateway.promptBodies, isEmpty);
|
|
});
|
|
|
|
testWidgets('Send as message is the only route an unknown command takes', (
|
|
tester,
|
|
) async {
|
|
await pumpComposer(tester);
|
|
final field = find.byKey(const Key('chat-composer-field'));
|
|
|
|
await tester.enterText(field, '/nope');
|
|
await tester.pump();
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pumpAndSettle();
|
|
expect(gateway.promptBodies, isEmpty);
|
|
|
|
await tester.tap(find.byKey(const Key('chat-command-send-as-message')));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(gateway.promptBodies.single['text'], '/nope');
|
|
expect(fieldText(tester), '');
|
|
expect(find.byKey(const Key('chat-composer-command-notice')), findsNothing);
|
|
});
|
|
|
|
testWidgets('a completed command never becomes a prompt', (tester) async {
|
|
await pumpComposer(tester);
|
|
final field = find.byKey(const Key('chat-composer-field'));
|
|
|
|
await tester.enterText(field, '/cl');
|
|
await tester.pump();
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(fieldText(tester), '/close');
|
|
expect(palette(), findsNothing);
|
|
expect(gateway.promptBodies, isEmpty);
|
|
|
|
// A second Enter re-reports the command instead of sending it.
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(gateway.promptBodies, isEmpty);
|
|
expect(fieldText(tester), '/close');
|
|
expect(
|
|
find.text(
|
|
'“/close” is not available yet, so nothing was sent to the agent.',
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
|
|
// The primary control and the explicit send shortcut take the same path.
|
|
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
|
await tester.pumpAndSettle();
|
|
expect(gateway.promptBodies, isEmpty);
|
|
expect(fieldText(tester), '/close');
|
|
|
|
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(gateway.promptBodies, isEmpty);
|
|
expect(fieldText(tester), '/close');
|
|
|
|
// An argument does not make the slash draft sendable either.
|
|
await tester.enterText(field, '/close now');
|
|
await tester.pump();
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(gateway.promptBodies, isEmpty);
|
|
expect(fieldText(tester), '/close now');
|
|
});
|
|
|
|
testWidgets('a command picked from the palette is never sent either', (
|
|
tester,
|
|
) async {
|
|
await pumpComposer(tester);
|
|
final field = find.byKey(const Key('chat-composer-field'));
|
|
|
|
await tester.enterText(field, '/h');
|
|
await tester.pump();
|
|
await tester.tap(row('help'));
|
|
await tester.pumpAndSettle();
|
|
expect(fieldText(tester), '/help');
|
|
|
|
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(gateway.promptBodies, isEmpty);
|
|
expect(fieldText(tester), '/help');
|
|
expect(
|
|
find.text(
|
|
'“/help” is not available yet, so nothing was sent to the agent.',
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
});
|
|
|
|
testWidgets('a row completes the command and never prompts', (tester) async {
|
|
await pumpComposer(tester);
|
|
final field = find.byKey(const Key('chat-composer-field'));
|
|
|
|
await tester.enterText(field, '/cl');
|
|
await tester.pump();
|
|
await tester.tap(row('close'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(fieldText(tester), '/close');
|
|
expect(palette(), findsNothing);
|
|
expect(gateway.promptBodies, isEmpty);
|
|
});
|
|
|
|
testWidgets('Up/Down move the highlight and Enter completes it', (
|
|
tester,
|
|
) async {
|
|
await pumpComposer(tester);
|
|
final field = find.byKey(const Key('chat-composer-field'));
|
|
|
|
await tester.enterText(field, '/');
|
|
await tester.pump();
|
|
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
|
|
await tester.pump();
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(fieldText(tester), '/close');
|
|
expect(palette(), findsNothing);
|
|
expect(gateway.promptBodies, isEmpty);
|
|
});
|
|
|
|
testWidgets('ArrowUp wraps the highlight to the last command', (
|
|
tester,
|
|
) async {
|
|
await pumpComposer(tester);
|
|
final field = find.byKey(const Key('chat-composer-field'));
|
|
|
|
await tester.enterText(field, '/');
|
|
await tester.pump();
|
|
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
|
|
await tester.pump();
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(fieldText(tester), '/help');
|
|
expect(palette(), findsNothing);
|
|
expect(gateway.promptBodies, isEmpty);
|
|
});
|
|
|
|
testWidgets('the highlight resets when the filtered list shrinks', (
|
|
tester,
|
|
) async {
|
|
await pumpComposer(tester);
|
|
final field = find.byKey(const Key('chat-composer-field'));
|
|
|
|
await tester.enterText(field, '/');
|
|
await tester.pump();
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
|
|
await tester.pump();
|
|
|
|
// `/r` leaves one row, so the stale third index drops back to the first;
|
|
// widening to `/` must not restore it.
|
|
await tester.enterText(field, '/r');
|
|
await tester.pump();
|
|
await tester.enterText(field, '/');
|
|
await tester.pump();
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(fieldText(tester), '/new');
|
|
expect(palette(), findsNothing);
|
|
expect(gateway.promptBodies, isEmpty);
|
|
});
|
|
|
|
testWidgets(
|
|
'the Cupertino host reports an unknown command with its controls',
|
|
(tester) async {
|
|
await pumpComposer(tester, cupertino: true);
|
|
final field = find.byKey(const Key('chat-composer-field'));
|
|
|
|
await tester.enterText(field, '/nope');
|
|
await tester.pump();
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(tester.takeException(), isNull);
|
|
expect(gateway.promptBodies, isEmpty);
|
|
|
|
await tester.tap(find.byKey(const Key('chat-command-send-as-message')));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(gateway.promptBodies.single['text'], '/nope');
|
|
expect(fieldText(tester), '');
|
|
},
|
|
);
|
|
|
|
testWidgets('Escape dismisses the local command report', (tester) async {
|
|
await pumpComposer(tester);
|
|
final field = find.byKey(const Key('chat-composer-field'));
|
|
|
|
await tester.enterText(field, '/nope');
|
|
await tester.pump();
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
find.byKey(const Key('chat-composer-command-notice')),
|
|
findsOneWidget,
|
|
);
|
|
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
|
await tester.pump();
|
|
|
|
expect(find.byKey(const Key('chat-composer-command-notice')), findsNothing);
|
|
expect(gateway.promptBodies, isEmpty);
|
|
});
|
|
|
|
testWidgets('the Cupertino host shows the same palette', (tester) async {
|
|
await pumpComposer(tester, cupertino: true);
|
|
final field = find.byKey(const Key('chat-composer-field'));
|
|
|
|
await tester.enterText(field, '/re');
|
|
await tester.pump();
|
|
|
|
expect(palette(), findsOneWidget);
|
|
expect(row('rename'), findsOneWidget);
|
|
expect(find.text('/rename'), findsOneWidget);
|
|
expect(find.text('Rename this session on this device'), findsOneWidget);
|
|
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
|
await tester.pump();
|
|
expect(palette(), findsNothing);
|
|
});
|
|
|
|
testWidgets('the palette fits a 320px phone at 2x text', (tester) async {
|
|
tester.view.physicalSize = const Size(640, 1200);
|
|
tester.view.devicePixelRatio = 2;
|
|
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
|
|
|
await pumpComposer(tester, cupertino: true);
|
|
await tester.enterText(find.byKey(const Key('chat-composer-field')), '/');
|
|
await tester.pump();
|
|
|
|
expect(tester.takeException(), isNull);
|
|
expect(palette(), findsOneWidget);
|
|
expect(row('new'), findsOneWidget);
|
|
expect(row('help'), findsOneWidget);
|
|
});
|
|
}
|