Merge pull request #1410 from pikasTech/fix/1373-node-host-script-stdin

fix: stream node host scripts over stdin
This commit is contained in:
Lyon
2026-07-01 19:58:43 +08:00
committed by GitHub
2 changed files with 51 additions and 1 deletions
@@ -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<CommandResult> {
return { command, cwd, exitCode: 0, stdout: "", stderr: "", signal: null, timedOut: false };
},
commandOk(): boolean {
return true;
},
async runCommandToFiles(): Promise<number> {
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`);
});
+1 -1
View File
@@ -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 {