Files
pipelines/app/test/features/chat/domain/chat_commands_test.dart
T
alan 63babc597a feat(app): offer the chat slash command palette
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.
2026-10-22 15:47:46 +01:00

94 lines
3.1 KiB
Dart

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.',
);
});
}