diff --git a/src/process/exec.test.ts b/src/process/exec.test.ts index e62611112b3..d8d621abc56 100644 --- a/src/process/exec.test.ts +++ b/src/process/exec.test.ts @@ -25,7 +25,7 @@ describe("runCommandWithTimeout", () => { 'process.stdout.write((process.env.OPENCLAW_BASE_ENV ?? "") + "|" + (process.env.OPENCLAW_TEST_ENV ?? ""))', ], { - timeoutMs: 120, + timeoutMs: 80, env: { OPENCLAW_TEST_ENV: "ok" }, }, ); @@ -38,10 +38,10 @@ describe("runCommandWithTimeout", () => { it("kills command when no output timeout elapses", async () => { const result = await runCommandWithTimeout( - [process.execPath, "-e", "setTimeout(() => {}, 20)"], + [process.execPath, "-e", "setTimeout(() => {}, 10)"], { - timeoutMs: 80, - noOutputTimeoutMs: 8, + timeoutMs: 30, + noOutputTimeoutMs: 4, }, ); @@ -82,9 +82,9 @@ describe("runCommandWithTimeout", () => { it("reports global timeout termination when overall timeout elapses", async () => { const result = await runCommandWithTimeout( - [process.execPath, "-e", "setTimeout(() => {}, 12)"], + [process.execPath, "-e", "setTimeout(() => {}, 10)"], { - timeoutMs: 6, + timeoutMs: 4, }, ); diff --git a/src/process/supervisor/supervisor.test.ts b/src/process/supervisor/supervisor.test.ts index c2317e8d39f..dec725e1501 100644 --- a/src/process/supervisor/supervisor.test.ts +++ b/src/process/supervisor/supervisor.test.ts @@ -4,7 +4,13 @@ import { createProcessSupervisor } from "./supervisor.js"; type ProcessSupervisor = ReturnType; type SpawnOptions = Parameters[0]; type ChildSpawnOptions = Omit, "backendId" | "mode">; -const OUTPUT_DELAY_MS = 3; + +function createWriteStdoutArgv(output: string): string[] { + if (process.platform === "win32") { + return [process.execPath, "-e", `process.stdout.write(${JSON.stringify(output)})`]; + } + return ["/usr/bin/printf", "%s", output]; +} async function spawnChild(supervisor: ProcessSupervisor, options: ChildSpawnOptions) { return supervisor.spawn({ @@ -19,12 +25,7 @@ describe("process supervisor", () => { const supervisor = createProcessSupervisor(); const run = await spawnChild(supervisor, { sessionId: "s1", - // Delay stdout slightly so listeners are attached even on heavily loaded runners. - argv: [ - process.execPath, - "-e", - `setTimeout(() => process.stdout.write("ok"), ${OUTPUT_DELAY_MS})`, - ], + argv: createWriteStdoutArgv("ok"), timeoutMs: 1_000, stdinMode: "pipe-closed", }); @@ -63,12 +64,7 @@ describe("process supervisor", () => { sessionId: "s1", scopeKey: "scope:a", replaceExistingScope: true, - // Small delay makes stdout capture deterministic by giving listeners time to attach. - argv: [ - process.execPath, - "-e", - `setTimeout(() => process.stdout.write("new"), ${OUTPUT_DELAY_MS})`, - ], + argv: createWriteStdoutArgv("new"), timeoutMs: 1_000, stdinMode: "pipe-closed", }); @@ -98,12 +94,7 @@ describe("process supervisor", () => { let streamed = ""; const run = await spawnChild(supervisor, { sessionId: "s-capture", - // Avoid race where child exits before stdout listeners are attached. - argv: [ - process.execPath, - "-e", - `setTimeout(() => process.stdout.write("streamed"), ${OUTPUT_DELAY_MS})`, - ], + argv: createWriteStdoutArgv("streamed"), timeoutMs: 1_000, stdinMode: "pipe-closed", captureOutput: false,