merge(app): land chat-slash

This commit is contained in:
2026-10-22 16:15:50 +01:00
6 changed files with 1059 additions and 13 deletions
@@ -0,0 +1,414 @@
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);
});
}
@@ -0,0 +1,93 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/domain/chat_commands.dart';
void main() {
test('records the web command list verbatim and in order', () {
expect(chatCommands.map((command) => command.name), [
'new',
'close',
'rename',
'stop',
'help',
]);
expect(chatCommands.map((command) => command.usage), [
'/new',
'/close',
'/rename <title>',
'/stop',
'/help',
]);
expect(chatCommands.map((command) => command.summary), [
'Start a fresh session in this directory',
'Finish this session for every client, keeping its history',
'Rename this session on this device',
'Stop the turn that is running',
'List every command',
]);
expect(
chatCommands.where((command) => command.takesArgument).map((c) => c.name),
['rename'],
);
});
test('a bare slash offers every recorded command', () {
expect(chatCommandSuggestions('/'), chatCommands);
expect(chatCommandSuggestions(' /'), chatCommands);
});
test('the name prefix filters case-insensitively', () {
expect(chatCommandSuggestions('/n').map((command) => command.name), [
'new',
]);
expect(chatCommandSuggestions('/re').map((command) => command.name), [
'rename',
]);
expect(chatCommandSuggestions('/CL').map((command) => command.name), [
'close',
]);
expect(chatCommandSuggestions('/s').map((command) => command.name), [
'stop',
]);
});
test('an argument, plain text or an unknown word offers nothing', () {
expect(chatCommandSuggestions('/close '), isEmpty);
expect(chatCommandSuggestions('/rename My chat'), isEmpty);
expect(chatCommandSuggestions('/zzz'), isEmpty);
expect(chatCommandSuggestions('hello'), isEmpty);
expect(chatCommandSuggestions(''), isEmpty);
});
test('the query is only the single slash word', () {
expect(chatCommandQuery('/Help'), 'help');
expect(chatCommandQuery(' /He'), 'he');
expect(chatCommandQuery('/help '), isNull);
expect(chatCommandQuery('help'), isNull);
});
test('the slash word carries any argument and is null without a slash', () {
expect(chatCommandWord('/close'), '/close');
expect(chatCommandWord(' /close now'), '/close');
expect(chatCommandWord('/rename My chat'), '/rename');
expect(chatCommandWord('plain'), isNull);
expect(chatCommandWord('/'), '/');
expect(chatCommandNamed('/CLOSE'), chatCommands[1]);
expect(chatCommandNamed('/close'), chatCommands[1]);
expect(chatCommandNamed('/rename My chat'), chatCommands[2]);
expect(chatCommandNamed('/zzz'), isNull);
expect(chatCommandNamed('/close now'), chatCommands[1]);
expect(chatCommandNamed('plain'), isNull);
});
test('the parsed reports keep the web client words', () {
expect(
chatUnknownCommandReport('/nope'),
'“/nope” is not a command, so nothing was sent to the agent. '
'Send it as a message, or cancel.',
);
expect(
chatCommandUnavailableReport('/close'),
'“/close” is not available yet, so nothing was sent to the agent.',
);
});
}