diff --git a/scripts/src/hwlab-node-impl.ts b/scripts/src/hwlab-node-impl.ts index 120e4d83..34a092b4 100644 --- a/scripts/src/hwlab-node-impl.ts +++ b/scripts/src/hwlab-node-impl.ts @@ -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 { +function runNodeWebProbeObserveCommand(options: NodeWebProbeObserveOptions, spec: HwlabRuntimeLaneSpec, stopCommand: boolean): Record | 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): 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 { + 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 { const script = [ "set -eu",