From 60ae8129ecc3ecd74969595e9184bcc96b2d5d0f Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 1 Jul 2026 11:57:56 +0000 Subject: [PATCH] fix: stream node host scripts over stdin --- scripts/src/hwlab-node/runtime-common.test.ts | 50 +++++++++++++++++++ scripts/src/hwlab-node/runtime-common.ts | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 scripts/src/hwlab-node/runtime-common.test.ts diff --git a/scripts/src/hwlab-node/runtime-common.test.ts b/scripts/src/hwlab-node/runtime-common.test.ts new file mode 100644 index 00000000..13d97c3f --- /dev/null +++ b/scripts/src/hwlab-node/runtime-common.test.ts @@ -0,0 +1,50 @@ +import assert from "node:assert/strict"; +import { beforeEach, mock, test } from "bun:test"; + +import type { CommandResult } from "../command"; + +interface RunCommandCall { + command: string[]; + cwd: string; + options: { timeoutMs?: number; env?: NodeJS.ProcessEnv; input?: string }; +} + +const runCommandCalls: RunCommandCall[] = []; + +mock.module("../command", () => ({ + runCommand(command: string[], cwd: string, options: RunCommandCall["options"] = {}): CommandResult { + runCommandCalls.push({ command, cwd, options }); + return { command, cwd, exitCode: 0, stdout: "", stderr: "", signal: null, timedOut: false }; + }, + async runCommandObserved(command: string[], cwd: string): Promise { + return { command, cwd, exitCode: 0, stdout: "", stderr: "", signal: null, timedOut: false }; + }, + commandOk(): boolean { + return true; + }, + async runCommandToFiles(): Promise { + return 0; + }, + tailFile(): string { + return ""; + }, +})); + +const { runNodeHostScript } = await import("./runtime-common"); + +beforeEach(() => { + runCommandCalls.length = 0; +}); + +test("node host scripts are sent through trans stdin instead of inline argv", () => { + const script = "printf render-ok\\n"; + + runNodeHostScript({ nodeRoute: "JD01" } as never, script, 55); + + assert.equal(runCommandCalls.length, 1); + const call = runCommandCalls[0]!; + assert.deepEqual(call.command.slice(-2), ["JD01", "sh"]); + assert.equal(call.command.includes("--"), false); + assert.equal(call.options.timeoutMs, 55_000); + assert.equal(call.options.input, `${script}\n`); +}); diff --git a/scripts/src/hwlab-node/runtime-common.ts b/scripts/src/hwlab-node/runtime-common.ts index a503b99f..01d91743 100644 --- a/scripts/src/hwlab-node/runtime-common.ts +++ b/scripts/src/hwlab-node/runtime-common.ts @@ -220,7 +220,7 @@ export function transPath(): string { } export function runNodeHostScript(spec: HwlabRuntimeLaneSpec, script: string, timeoutSeconds: number, input = ""): CommandResult { - return runCommand([transPath(), spec.nodeRoute, "sh", "--", script], repoRoot, { input, timeoutMs: timeoutSeconds * 1000 }); + return runCommand([transPath(), spec.nodeRoute, "sh"], repoRoot, { input: `${script}\n${input}`, timeoutMs: timeoutSeconds * 1000 }); } export function runNodeHostScriptAsync(spec: HwlabRuntimeLaneSpec, script: string, timeoutSeconds: number, label: string): CommandResult {