5c3248a48d
Show Expand only when output can overflow and drop the final newline from the drawn output. The full-app probe lists shell runs with ?shell=1 so the cards, Shell mode and Run command dialog can be captured in Chrome.
186 lines
5.0 KiB
Dart
186 lines
5.0 KiB
Dart
// Operator shell commands for the full-app probe (`?shell=1`, with
|
|
// `?chats=N`): every fixture chat lists four recorded runs (succeeded, failed,
|
|
// stopped and one still running), and chat_shell_run/stop/share answer as the
|
|
// server does, with the frames that follow.
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
|
|
bool _enabled = false;
|
|
DateTime _base = DateTime.now();
|
|
|
|
void configureChatShellFixture(Map<String, String> params) {
|
|
_enabled = params['shell'] == '1';
|
|
_base = DateTime.now().subtract(const Duration(minutes: 3));
|
|
}
|
|
|
|
int _at(int seconds) =>
|
|
_base.add(Duration(seconds: seconds)).millisecondsSinceEpoch;
|
|
|
|
String _session(JsonMap request) {
|
|
final body = request['chat_shell_run_request'] ?? request['chat_query'];
|
|
return body is Map ? '${body['session_id'] ?? ''}' : '';
|
|
}
|
|
|
|
JsonMap _run(
|
|
String session,
|
|
String id,
|
|
String command,
|
|
int started, {
|
|
String status = 'exited',
|
|
int? exitCode,
|
|
int duration = 0,
|
|
String output = '',
|
|
}) => {
|
|
'id': id,
|
|
'session_id': session,
|
|
'command': command,
|
|
'directory': '/Users/operator/src/pipelines',
|
|
'status': status,
|
|
'exit_code': ?exitCode,
|
|
'started_at': _at(started),
|
|
if (status != 'running') 'ended_at': _at(started) + duration,
|
|
'duration_ms': duration,
|
|
'output': output,
|
|
'output_bytes': output.length,
|
|
};
|
|
|
|
List<JsonMap> _runs(String session) => [
|
|
_run(
|
|
session,
|
|
'run_status',
|
|
'git status --short',
|
|
0,
|
|
exitCode: 0,
|
|
duration: 84,
|
|
output:
|
|
' M app/lib/features/chat/shell/chat_shell_run_card.dart\n'
|
|
'?? app/notes/chat-shell-commands.md\n',
|
|
),
|
|
_run(
|
|
session,
|
|
'run_tests',
|
|
'go test ./internal/server -run ChatShell',
|
|
20,
|
|
exitCode: 1,
|
|
duration: 4210,
|
|
output:
|
|
'${[for (final name in _tests) '=== RUN TestChatShell$name\n--- PASS: TestChatShell$name (0.0${name.length % 9}s)\n'].join()}'
|
|
'--- FAIL: TestChatShellStopInterruptsTheGroup (0.21s)\n'
|
|
' chat_shell_run_test.go:112: stopped record = {Status:exited}\n'
|
|
'FAIL\n'
|
|
'FAIL\tgit.a-wan.net/alan/pipelines/internal/server\t0.611s\n'
|
|
'FAIL\n',
|
|
),
|
|
_run(
|
|
session,
|
|
'run_watch',
|
|
'tail -f /var/log/system.log',
|
|
40,
|
|
status: 'stopped',
|
|
duration: 15200,
|
|
output: 'Nov 9 15:58:01 host kernel[0]: wake reason: EC.LidOpen\n',
|
|
),
|
|
_run(
|
|
session,
|
|
'run_build',
|
|
'flutter build web --target tool/search_selection_probe_entry.dart',
|
|
60,
|
|
status: 'running',
|
|
output:
|
|
'Compiling lib/main.dart for the Web...\n'
|
|
'Font asset "CupertinoIcons.ttf" was tree-shaken.\n',
|
|
),
|
|
];
|
|
|
|
JsonMap? chatShellReply(JsonMap request) {
|
|
if (!_enabled) return null;
|
|
final id = request['id'];
|
|
final session = _session(request);
|
|
final body = request['chat_shell_run_request'];
|
|
final runId = body is Map ? '${body['run_id'] ?? ''}' : '';
|
|
switch ('${request['type']}') {
|
|
case 'chat_shell_runs':
|
|
return {
|
|
'id': id,
|
|
'type': 'chat_shell_runs',
|
|
'chat_shell_runs': _runs(session),
|
|
};
|
|
case 'chat_shell_run':
|
|
return {
|
|
'id': id,
|
|
'type': 'chat_shell_run',
|
|
'chat_shell_run': _run(
|
|
session,
|
|
'run_new',
|
|
body is Map ? '${body['command'] ?? ''}' : '',
|
|
180,
|
|
status: 'running',
|
|
),
|
|
};
|
|
case 'chat_shell_stop':
|
|
return {'id': id, 'type': 'chat_shell_stop'};
|
|
case 'chat_shell_run_output':
|
|
return {
|
|
'id': id,
|
|
'type': 'chat_shell_run_output',
|
|
'chat_shell_run': _runs(session).firstWhere(
|
|
(run) => run['id'] == runId,
|
|
orElse: () => _runs(session).first,
|
|
),
|
|
};
|
|
case 'chat_shell_share':
|
|
return {'id': id, 'type': 'chat_prompt'};
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// The frames the server pushes after a run starts or is stopped.
|
|
List<JsonMap> chatShellFollowUps(JsonMap request) {
|
|
if (!_enabled) return const [];
|
|
final session = _session(request);
|
|
JsonMap frame(JsonMap body) => {
|
|
'type': 'chat_shell_run_event',
|
|
'chat_shell_run_event': {'session_id': session, ...body},
|
|
};
|
|
switch ('${request['type']}') {
|
|
case 'chat_shell_run':
|
|
const text = 'hello from the fixture shell\n';
|
|
final body = request['chat_shell_run_request'];
|
|
return [
|
|
frame({
|
|
'run_id': 'run_new',
|
|
'output': text,
|
|
'offset': 0,
|
|
'end': text.length,
|
|
}),
|
|
frame({
|
|
'run_id': 'run_new',
|
|
'run': _run(
|
|
session,
|
|
'run_new',
|
|
body is Map ? '${body['command'] ?? ''}' : '',
|
|
180,
|
|
exitCode: 0,
|
|
duration: 37,
|
|
),
|
|
}),
|
|
];
|
|
case 'chat_shell_stop':
|
|
final run = _runs(session).last
|
|
..['status'] = 'stopped'
|
|
..['duration_ms'] = 9100;
|
|
return [
|
|
frame({'run_id': run['id'], 'run': run}),
|
|
];
|
|
}
|
|
return const [];
|
|
}
|
|
|
|
const _tests = [
|
|
'RunStreamsToEveryWatcherAndPersists',
|
|
'RunLimitsAndRefusals',
|
|
'ShareQueuesAnOrdinaryPrompt',
|
|
'RetainsBoundedTail',
|
|
'ShutdownAndRestartInterrupt',
|
|
'OutputKeepsCharactersWhole',
|
|
];
|