Merge pull request #614 from pikasTech/fix/web-observe-command-table-20260621
fix: render web observe command as table
This commit is contained in:
@@ -7179,7 +7179,7 @@ function webObserveShort(value: string, maxLength: number): string {
|
||||
return `${value.slice(0, maxLength - 1)}~`;
|
||||
}
|
||||
|
||||
function runNodeWebProbeObserveCommand(options: NodeWebProbeObserveOptions, spec: HwlabRuntimeLaneSpec, stopCommand: boolean): Record<string, unknown> {
|
||||
function runNodeWebProbeObserveCommand(options: NodeWebProbeObserveOptions, spec: HwlabRuntimeLaneSpec, stopCommand: boolean): Record<string, unknown> | RenderedCliResult {
|
||||
const type = options.commandType ?? (stopCommand ? "stop" : null);
|
||||
if (type === null) throw new Error("web-probe observe command requires --type");
|
||||
const commandId = `cmd-${Date.now().toString(36)}-${randomBytes(3).toString("hex")}`;
|
||||
@@ -7211,7 +7211,7 @@ function runNodeWebProbeObserveCommand(options: NodeWebProbeObserveOptions, spec
|
||||
"if [ -f \"$state_dir/pid\" ]; then kill \"$(cat \"$state_dir/pid\")\" >/dev/null 2>&1 || true; fi",
|
||||
"printf '{\"ok\":true,\"forced\":true,\"stateDir\":\"%s\"}\\n' \"$state_dir\"",
|
||||
].join("\n"), 55);
|
||||
return {
|
||||
return withWebObserveCommandRendered({
|
||||
ok: killResult.exitCode === 0,
|
||||
status: killResult.exitCode === 0 ? "forced-stop-requested" : "blocked",
|
||||
command: webObserveCommandLabel("stop", options),
|
||||
@@ -7224,9 +7224,9 @@ function runNodeWebProbeObserveCommand(options: NodeWebProbeObserveOptions, spec
|
||||
gracefulResult: compactCommandResult(result),
|
||||
forceResult: compactCommandResult(killResult),
|
||||
valuesRedacted: true,
|
||||
};
|
||||
});
|
||||
}
|
||||
return {
|
||||
return withWebObserveCommandRendered({
|
||||
ok: result.exitCode === 0 && commandResult?.ok !== false,
|
||||
status: result.exitCode === 0 ? (options.waitMs > 0 ? "completed-or-queued" : "queued") : "blocked",
|
||||
command: webObserveCommandLabel(stopCommand ? "stop" : "command", options),
|
||||
@@ -7239,9 +7239,46 @@ function runNodeWebProbeObserveCommand(options: NodeWebProbeObserveOptions, spec
|
||||
observer: commandResult,
|
||||
result: compactCommandResult(result),
|
||||
valuesRedacted: true,
|
||||
});
|
||||
}
|
||||
|
||||
function withWebObserveCommandRendered(value: Record<string, unknown>): RenderedCliResult {
|
||||
return {
|
||||
ok: value.ok !== false,
|
||||
command: typeof value.command === "string" ? value.command : "hwlab nodes web-probe observe command",
|
||||
contentType: "text/plain",
|
||||
renderedText: renderWebObserveCommandTable(value),
|
||||
};
|
||||
}
|
||||
|
||||
function renderWebObserveCommandTable(value: Record<string, unknown>): string {
|
||||
const observerCommand = record(value.observerCommand);
|
||||
const observer = record(value.observer);
|
||||
const result = record(observer?.result);
|
||||
const id = webObserveText(value.id);
|
||||
const lines = [
|
||||
`hwlab nodes web-probe observe command (${webObserveText(value.status)})`,
|
||||
"",
|
||||
webObserveTable(["OBSERVER", "COMMAND", "TYPE", "STATUS", "TEXT_BYTES", "TEXT_HASH", "DETAIL"], [[
|
||||
id,
|
||||
webObserveText(value.commandId),
|
||||
webObserveText(observerCommand?.type),
|
||||
webObserveText(observer?.ok === false ? "failed" : observer?.completedAt !== undefined ? "completed" : value.status),
|
||||
webObserveText(observerCommand?.textBytes),
|
||||
webObserveShort(webObserveText(observerCommand?.textHash), 24),
|
||||
webObserveShort(webObserveText(result?.mark ?? result?.currentUrl ?? observer?.error ?? observer?.queued), 80),
|
||||
]]),
|
||||
"",
|
||||
"Next:",
|
||||
` bun scripts/cli.ts hwlab nodes web-probe observe status ${id}`,
|
||||
` bun scripts/cli.ts hwlab nodes web-probe observe analyze ${id}`,
|
||||
"",
|
||||
"Disclosure:",
|
||||
" default view is a bounded command result; use observe status/analyze for sampled state.",
|
||||
];
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function runNodeWebProbeObserveCollect(options: NodeWebProbeObserveOptions, spec: HwlabRuntimeLaneSpec): Record<string, unknown> {
|
||||
const script = [
|
||||
"set -eu",
|
||||
|
||||
Reference in New Issue
Block a user