Files
pipelines/app/test/features/chat/domain/chat_commands_test.dart
T
alan 01040a7b12 Stop the replaced session on /new for every harness
/new already released the old native session through the chat-close
release path, but two gaps let the replaced session stay alive, and the
client told the operator it could still be resumed in a terminal:

- Claude Code: ReleaseSession only closed a host this server was
  attached to. A host registered for the session but not attached (a
  failed reattach, or one left by an earlier server) kept running. It is
  now asked to close over its socket and killed as a fallback.
- Codex: ReleaseSession only interrupted an active turn. It now also
  sends thread/unsubscribe so the App Server unloads the thread; a later
  prompt reloads it through the existing "thread not found" resume path.
- The /new notice now says the previous session was stopped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 18:10:41 +00:00

109 lines
3.7 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',
'stop_tasks',
'help',
]);
expect(chatCommands.map((command) => command.usage), [
'/new',
'/close',
'/rename <title>',
'/stop',
'/stop_tasks',
'/help',
]);
expect(chatCommands.map((command) => command.summary), [
'Clear the context: continue this chat in a fresh session',
'Finish this session for every client, keeping its history',
'Rename this session',
'Stop the turn that is running',
'Stop all background tasks in this chat',
'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',
'stop_tasks',
]);
});
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.',
);
});
test('the /new notice says the replaced session was stopped', () {
// The server releases the old harness session before it answers, so the
// notice must not suggest it is still running or resumable.
expect(
chatNewSessionNotice,
'New session started. The agent no longer sees the earlier '
'conversation; the previous session was stopped.',
);
expect(chatNewSessionNotice, isNot(contains('resume')));
});
}