Merge branch 'worktree-agent-a26df8b0059ab1b12'
This commit is contained in:
@@ -1,17 +1,30 @@
|
||||
// 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.
|
||||
// `?chats=N`): every fixture chat lists four recorded terminal runs
|
||||
// (succeeded, failed, stopped and an interactive login still waiting for a
|
||||
// token), and chat_shell_run/stop/share/input answer as the server does, with
|
||||
// the frames that follow. The login prompt hides what is typed, as a real
|
||||
// terminal's password prompt does, and finishes on Enter.
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
bool _enabled = false;
|
||||
DateTime _base = DateTime.now();
|
||||
int _loginEnd = utf8.encode(_loginPrompt).length;
|
||||
int _tokenLength = 0;
|
||||
|
||||
void configureChatShellFixture(Map<String, String> params) {
|
||||
_enabled = params['shell'] == '1';
|
||||
_base = DateTime.now().subtract(const Duration(minutes: 3));
|
||||
_loginEnd = utf8.encode(_loginPrompt).length;
|
||||
}
|
||||
|
||||
const String _loginPrompt =
|
||||
'\x1b[1m!\x1b[0m First copy your one-time code: \x1b[1;33mA1B2-C3D4\x1b[0m\r\n'
|
||||
'Open this URL to continue in your web browser: '
|
||||
'\x1b[4mhttps://github.com/login/device\x1b[0m\r\n'
|
||||
'\x1b[32m?\x1b[0m \x1b[1mPaste an authentication token\x1b[0m: ';
|
||||
|
||||
int _at(int seconds) =>
|
||||
_base.add(Duration(seconds: seconds)).millisecondsSinceEpoch;
|
||||
|
||||
@@ -30,6 +43,9 @@ JsonMap _run(
|
||||
int duration = 0,
|
||||
String output = '',
|
||||
}) => {
|
||||
'terminal': true,
|
||||
'cols': 100,
|
||||
'rows': 30,
|
||||
'id': id,
|
||||
'session_id': session,
|
||||
'command': command,
|
||||
@@ -40,7 +56,7 @@ JsonMap _run(
|
||||
if (status != 'running') 'ended_at': _at(started) + duration,
|
||||
'duration_ms': duration,
|
||||
'output': output,
|
||||
'output_bytes': output.length,
|
||||
'output_bytes': utf8.encode(output).length,
|
||||
};
|
||||
|
||||
List<JsonMap> _runs(String session) => [
|
||||
@@ -52,8 +68,8 @@ List<JsonMap> _runs(String session) => [
|
||||
exitCode: 0,
|
||||
duration: 84,
|
||||
output:
|
||||
' M app/lib/features/chat/shell/chat_shell_run_card.dart\n'
|
||||
'?? app/notes/chat-shell-commands.md\n',
|
||||
' \x1b[31mM\x1b[0m app/lib/features/chat/shell/chat_shell_run_card.dart\r\n'
|
||||
'\x1b[31m??\x1b[0m app/notes/chat-shell-commands.md\r\n',
|
||||
),
|
||||
_run(
|
||||
session,
|
||||
@@ -63,12 +79,12 @@ List<JsonMap> _runs(String session) => [
|
||||
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',
|
||||
'${[for (final name in _tests) '=== RUN TestChatShell$name\r\n\x1b[32m--- PASS\x1b[0m: TestChatShell$name (0.0${name.length % 9}s)\r\n'].join()}'
|
||||
'\x1b[1;31m--- FAIL\x1b[0m: TestChatShellStopInterruptsTheGroup (0.21s)\r\n'
|
||||
' chat_shell_run_test.go:112: stopped record = {Status:exited}\r\n'
|
||||
'\x1b[31mFAIL\x1b[0m\r\n'
|
||||
'\x1b[31mFAIL\x1b[0m\tgit.a-wan.net/alan/pipelines/internal/server\t0.611s\r\n'
|
||||
'\x1b[31mFAIL\x1b[0m\r\n',
|
||||
),
|
||||
_run(
|
||||
session,
|
||||
@@ -77,17 +93,15 @@ List<JsonMap> _runs(String session) => [
|
||||
40,
|
||||
status: 'stopped',
|
||||
duration: 15200,
|
||||
output: 'Nov 9 15:58:01 host kernel[0]: wake reason: EC.LidOpen\n',
|
||||
output: 'Nov 9 15:58:01 host kernel[0]: wake reason: EC.LidOpen\r\n^C',
|
||||
),
|
||||
_run(
|
||||
session,
|
||||
'run_build',
|
||||
'flutter build web --target tool/search_selection_probe_entry.dart',
|
||||
'run_login',
|
||||
'gh auth login --hostname github.com',
|
||||
60,
|
||||
status: 'running',
|
||||
output:
|
||||
'Compiling lib/main.dart for the Web...\n'
|
||||
'Font asset "CupertinoIcons.ttf" was tree-shaken.\n',
|
||||
output: _loginPrompt,
|
||||
),
|
||||
];
|
||||
|
||||
@@ -129,6 +143,10 @@ JsonMap? chatShellReply(JsonMap request) {
|
||||
};
|
||||
case 'chat_shell_share':
|
||||
return {'id': id, 'type': 'chat_prompt'};
|
||||
case 'chat_shell_input':
|
||||
return {'id': id, 'type': 'chat_shell_input'};
|
||||
case 'chat_shell_resize':
|
||||
return {'id': id, 'type': 'chat_shell_resize'};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -171,6 +189,37 @@ List<JsonMap> chatShellFollowUps(JsonMap request) {
|
||||
return [
|
||||
frame({'run_id': run['id'], 'run': run}),
|
||||
];
|
||||
case 'chat_shell_input':
|
||||
// The token prompt does not echo; Enter completes the login.
|
||||
final body = request['chat_shell_run_request'];
|
||||
final data = body is Map ? '${body['data'] ?? ''}' : '';
|
||||
_tokenLength += data.replaceAll('\r', '').length;
|
||||
if (!data.contains('\r')) return const [];
|
||||
final done =
|
||||
'\r\n\x1b[2m(received a $_tokenLength-character token)\x1b[0m\r\n'
|
||||
'\x1b[32m\u2713\x1b[0m Configured git protocol\r\n'
|
||||
'\x1b[32m\u2713\x1b[0m Logged in as \x1b[1moperator\x1b[0m\r\n';
|
||||
final start = _loginEnd;
|
||||
_loginEnd += utf8.encode(done).length;
|
||||
return [
|
||||
frame({
|
||||
'run_id': 'run_login',
|
||||
'output': done,
|
||||
'offset': start,
|
||||
'end': _loginEnd,
|
||||
}),
|
||||
frame({
|
||||
'run_id': 'run_login',
|
||||
'run': _run(
|
||||
session,
|
||||
'run_login',
|
||||
'gh auth login --hostname github.com',
|
||||
60,
|
||||
exitCode: 0,
|
||||
duration: 48200,
|
||||
)..['output_bytes'] = _loginEnd,
|
||||
}),
|
||||
];
|
||||
}
|
||||
return const [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user