a6f0f0a1cb
A draft starting with ! shows a Shell mode indicator and runs through chat_shell_run instead of being sent to the agent; the chat's actions menu gains Run command. Each run is a terminal-style card among the turns with live output, Stop, its exit status, Copy output and Send to agent.
104 lines
3.4 KiB
Dart
104 lines
3.4 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/chat/domain/chat_commands.dart';
|
|
import 'package:pipelines_app/features/chat/shell/chat_shell_command.dart';
|
|
import 'package:pipelines_app/features/chat/shell/chat_shell_run.dart';
|
|
|
|
ChatShellRun _run(String id, int started, {String status = 'running'}) =>
|
|
ChatShellRun(
|
|
id: id,
|
|
command: 'ls',
|
|
directory: '/w',
|
|
status: status,
|
|
startedAt: started,
|
|
);
|
|
|
|
void main() {
|
|
test('a leading ! (after blanks) is shell mode and names the command', () {
|
|
expect(chatDraftIsShell('!ls -la'), isTrue);
|
|
expect(chatDraftIsShell(' ! git status'), isTrue);
|
|
expect(chatDraftIsShell('say !hi'), isFalse);
|
|
expect(chatDraftIsShell('/help'), isFalse);
|
|
expect(chatShellCommandOf(' ! git status '), 'git status');
|
|
expect(chatShellCommandOf('!'), '');
|
|
expect(chatShellCommandOf('hello'), isNull);
|
|
});
|
|
|
|
test('/help lists the shell hint after the commands', () {
|
|
expect(chatCommandHelpText().split('\n').last, chatShellHelpLine);
|
|
});
|
|
|
|
test('runs are placed among timed rows by start time', () {
|
|
final rows = [
|
|
{
|
|
'kind': 'user',
|
|
'key': 'u1',
|
|
'message': {'created_at': 100},
|
|
},
|
|
{'kind': 'assistant', 'key': 'a1', 'created_at': 200},
|
|
{'kind': 'user', 'key': 'local', 'message': <String, dynamic>{}},
|
|
{'kind': 'assistant', 'key': 'a2', 'created_at': 400},
|
|
];
|
|
final merged = withChatShellRunRows(rows, [
|
|
_run('late', 500),
|
|
_run('early', 150),
|
|
_run('mid', 300),
|
|
]);
|
|
expect(merged.map((row) => row['key']), [
|
|
'u1',
|
|
'chat-shell-run-early',
|
|
'a1',
|
|
'local',
|
|
'chat-shell-run-mid',
|
|
'a2',
|
|
'chat-shell-run-late',
|
|
]);
|
|
expect(withChatShellRunRows(rows, const []), same(rows));
|
|
});
|
|
|
|
test('status words follow the recorded outcome', () {
|
|
ChatShellRun ended(String status, {int? code, String signal = ''}) =>
|
|
ChatShellRun(
|
|
id: 'r',
|
|
command: 'x',
|
|
directory: '/',
|
|
status: status,
|
|
startedAt: 1,
|
|
exitCode: code,
|
|
signal: signal,
|
|
);
|
|
expect(ended('exited', code: 0).state, ChatShellRunState.succeeded);
|
|
expect(chatShellStatusLabel(ended('exited', code: 2)), 'Exit 2');
|
|
expect(ended('exited', code: 2).state, ChatShellRunState.failed);
|
|
expect(
|
|
chatShellStatusLabel(ended('exited', signal: 'killed')),
|
|
'Killed (killed)',
|
|
);
|
|
expect(chatShellStatusLabel(ended('stopped')), 'Stopped');
|
|
expect(chatShellStatusLabel(ended('interrupted')), 'Interrupted');
|
|
expect(chatShellDuration(250), '250 ms');
|
|
expect(chatShellDuration(1500), '1.5 s');
|
|
expect(chatShellDuration(125000), '2m 5s');
|
|
});
|
|
|
|
test('live chunks join only when contiguous and mark a gap otherwise', () {
|
|
var run = _run('r', 1);
|
|
run = run.withChunk('abc', 0, 3).withChunk('def', 3, 6);
|
|
expect(run.output, 'abcdef');
|
|
expect(run.truncated, isFalse);
|
|
expect(run.withChunk('abc', 0, 3).output, 'abcdef', reason: 'a repeat');
|
|
final gapped = run.withChunk('xyz', 10, 13);
|
|
expect(gapped.output, 'xyz');
|
|
expect(gapped.truncated, isTrue);
|
|
final read = ChatShellRun.fromJson({
|
|
'id': 'r',
|
|
'status': 'exited',
|
|
'exit_code': 0,
|
|
'output': 'tail',
|
|
'output_start': 6,
|
|
'output_bytes': 10,
|
|
})!;
|
|
expect(read.truncated, isTrue);
|
|
expect(read.withChunk('more', 10, 14).output, 'tailmore');
|
|
});
|
|
}
|