diff --git a/packages/paperclip-runner/scripts/materialize-kimi-distribution.test.mjs b/packages/paperclip-runner/scripts/materialize-kimi-distribution.test.mjs index a3adb002918..0bd816430a9 100644 --- a/packages/paperclip-runner/scripts/materialize-kimi-distribution.test.mjs +++ b/packages/paperclip-runner/scripts/materialize-kimi-distribution.test.mjs @@ -39,12 +39,14 @@ test("distribution build admits network settings without provider keys or Node i test("setup cancellation physically stops an in-flight owned child", { timeout: 5_000 }, async t => { const { root } = await fixture(t), pidFile = join(root, "pid"); const controller = new AbortController(); - const result = runKimiBuildCommand(process.execPath, ["-e", "require('node:fs').writeFileSync(process.argv[1],String(process.pid));setInterval(()=>{},1000)", pidFile], { env: {}, timeout: 3_000 }, undefined, controller.signal).then(() => null, error => error); - let pid; + const result = runKimiBuildCommand(process.execPath, ["-e", "const f=require('node:fs');f.writeFileSync(process.argv[1]+'.tmp',String(process.pid));f.renameSync(process.argv[1]+'.tmp',process.argv[1]);setInterval(()=>{},1000)", pidFile], { env: {}, timeout: 3_000 }, undefined, controller.signal).then(() => null, error => error); + let pid, settled = false; + void result.then(() => { settled = true; }); try { - for (let attempt = 0; attempt < 100; attempt++) { - try { pid = Number(await readFile(pidFile, "utf8")); break; } - catch (error) { if (error.code !== "ENOENT") throw error; await delay(10); } + while (!settled && !(Number.isSafeInteger(pid) && pid > 0)) { + try { pid = Number(await readFile(pidFile, "utf8")); } + catch (error) { if (error.code !== "ENOENT") throw error; } + await delay(10); } assert.ok(Number.isSafeInteger(pid) && pid > 0, "The real child did not start"); controller.abort(); diff --git a/packages/paperclip-runner/scripts/provision-kimi-package.test.mjs b/packages/paperclip-runner/scripts/provision-kimi-package.test.mjs index acd9f190df9..e9ae78dfa81 100644 --- a/packages/paperclip-runner/scripts/provision-kimi-package.test.mjs +++ b/packages/paperclip-runner/scripts/provision-kimi-package.test.mjs @@ -54,7 +54,7 @@ test("installed Kimi setup is self-contained, rejects corrupt assets and cancels let stderr = ""; cancelled.stderr.on("data", chunk => { stderr = (stderr + chunk).slice(-4096); }); const kill = setTimeout(() => cancelled.kill("SIGKILL"), 5_000); try { - for (let attempt = 0; attempt < 100; attempt++) { + while (cancelled.exitCode === null && cancelled.signalCode === null) { try { if (await readFile(ready, "utf8") === "ready") break; } catch (error) { if (error.code !== "ENOENT") throw error; } await delay(10); diff --git a/packages/paperclip-runner/scripts/stage-runner-binary.test.mjs b/packages/paperclip-runner/scripts/stage-runner-binary.test.mjs index e262d64a213..2127a9d1842 100644 --- a/packages/paperclip-runner/scripts/stage-runner-binary.test.mjs +++ b/packages/paperclip-runner/scripts/stage-runner-binary.test.mjs @@ -86,8 +86,8 @@ test("release metadata rejects incompatible native, harness and protocol contrac async function withOwnedChildren(root, action) { const owned = []; - const start = (command, args) => { - const child = spawn(command, args, { env: { PATH: "/usr/bin:/bin" }, stdio: "ignore" }); + const start = (command, args, argv0) => { + const child = spawn(command, args, { argv0, env: { PATH: "/usr/bin:/bin" }, stdio: "ignore" }); // close follows both exit and spawn error. A failed second spawn must not // interrupt retirement of the first still-running executable. const closed = new Promise(resolve => child.once("close", resolve)); @@ -115,7 +115,7 @@ test("atomically publishes while the previous executable is running", { skip: pr await withOwnedChildren(root, async start => { await stageRunnerBinary("/bin/sleep", destination); const previous = await stat(destination); - const old = start(destination, ["30"]); + const old = start(destination, ["30"], "sleep"); await old.spawned; await stageRunnerBinary("/bin/sleep", destination); const published = await stat(destination); @@ -124,7 +124,7 @@ test("atomically publishes while the previous executable is running", { skip: pr assert.equal(old.child.exitCode, null); assert.equal(old.child.signalCode, null); assert.deepEqual(await readdir(root), ["paperclip-runnerd"]); - const next = start(destination, ["0"]); + const next = start(destination, ["0"], "sleep"); await next.spawned; await next.closed; assert.equal(next.child.exitCode, 0); }); @@ -150,7 +150,7 @@ test("a source rebuild selects fresh dev bytes while preserving release binaries await mkdir(path.dirname(source), { recursive: true }); await writeFile(source, "fn main() {}\n"); await mkdir(path.dirname(built), { recursive: true }); - await copyHostFixture("/bin/echo", built); + await copyHostFixture("/bin/sh", built); const previousBuild = path.join(root, "previous-build"); await copyHostFixture("/bin/sleep", previousBuild); await stageRunnerBinary(previousBuild, hostTarget); @@ -178,7 +178,7 @@ test("a source rebuild selects fresh dev bytes while preserving release binaries const manifestPath = path.join(binaryRoot, "release-manifest.json"); const manifest = JSON.stringify({ schema: "paperclip.runner.release-binaries.v1", sourceRevision: "a".repeat(40), platforms }); await writeFile(manifestPath, manifest); - const old = start(hostTarget, ["30"]); + const old = start(hostTarget, ["30"], "sleep"); await old.spawned; const requirement = { repoRoot: root, nativeRunnerRequired: true }; assert.equal(paperclipRunnerBinaryNeedsBuild(requirement), true); @@ -198,7 +198,7 @@ test("a source rebuild selects fresh dev bytes while preserving release binaries assert.equal(paperclipRunnerBinaryNeedsBuild(requirement), false); assert.equal(old.child.exitCode, null); assert.equal(old.child.signalCode, null); - const next = start(selected.binary, ["rebuilt"]); + const next = start(selected.binary, ["-c", "exit 0"]); await next.spawned; await next.closed; assert.equal(next.child.exitCode, 0); });