diff --git a/apps/app/test/image.test.ts b/apps/app/test/image.test.ts index 169a1a0e02..b2b7a01dc4 100644 --- a/apps/app/test/image.test.ts +++ b/apps/app/test/image.test.ts @@ -848,8 +848,8 @@ describe("Build a candidate and sign it (spec/release/index.md, \"Story: Build a }), [row])); const read = () => stateOf(JSON.parse(readFileSync(path, "utf8"))); const save = (state: Record) => write(directory, "github.json", state); - writeFileSync(join(directory, "gh"), `#!/usr/bin/env python3 -import hashlib,json,os,sys + writeFileSync(join(directory, "gh"), `#!/usr/bin/env -S python3 -S +import json,os,sys from pathlib import Path from urllib.parse import urlsplit file=Path(os.environ["GH_FIXTURE"]) @@ -869,6 +869,7 @@ if a[:2]==["api","graphql"]: totalCount=state.get("releaseIndexTotal",len(rows)),nodes=page,pageInfo=dict(hasNextPage=i+1 { const send = (frame: ToBox | Link, n?: number) => { if (child.stdin.writable) child.stdin.write(encode(frame, n)); }; const hello = (seen: number) => send({ t: "hello", seen, client }); const frames = () => lines.filter((line): line is Numbered => "frame" in line); + let acknowledging = acknowledge; // Like the client: acknowledge what arrived, often enough to keep the lease. - const ping = setInterval(() => { if (acknowledge && lines.some(isAck)) send({ t: "ack", n: frames().at(-1)?.n ?? 0 }); }, 200); + const ping = setInterval(() => { if (acknowledging && lines.some(isAck)) send({ t: "ack", n: frames().at(-1)?.n ?? 0 }); }, 200); + /** From now on the link acknowledges nothing, as a client that dies before it takes what comes next. */ + const fallSilent = () => { acknowledging = false; }; const closed = new Promise((resolve) => child.on("close", () => { clearInterval(ping); resolve(); })); const find = (t: T) => frames().find((line) => line.frame.t === t); - return { child, client, lines, send, hello, frames, find, closed }; + return { child, client, lines, send, hello, frames, find, closed, fallSilent }; } /** A first link that starts `request` as `runId` and, like the client, acknowledges the run. */ @@ -822,9 +825,10 @@ describe("run links", () => { const first = await startRun(home, "img-1", request); await until(() => (fs.existsSync(path.join(worktree, ".spec-cache", entry)) ? true : undefined), "the check to write its result"); expect(seal("k")).toEqual({ facts: null, busy: 1 }); + // Its client never collects it: the result waits on the saved box, and would in a copy. + first.fallSilent(); fs.writeFileSync(path.join(worktree, "go"), ""); const exit = await until(() => first.find("exit"), "the exit frame"); - // Its client never collects it: the result waits on the saved box, and would in a copy. first.child.kill("SIGKILL"); await until(() => (owned(home, "img-1") ? undefined : true), "the check's owner to leave"); const second = await finish(home, "img-2", { ...request, key: "k2", worktree: path.join(home, "wt2"), argv: ["sh", "-c", `test -f .spec-cache/${entry}`] });