From 9b6ca0d718bdedfa3528f228ae6124f04ec4fe52 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 16 Nov 2026 12:15:31 +0000 Subject: [PATCH] test(ci): edit only after the first watch run finishes in the watch-rerun case (#4081) The watch-rerun case edited the watched files as soon as the first run printed its marker line, while that run was still finishing. On main run 43858822733 no rerun followed within ten seconds. Wait for the run's own summary before editing, so the edit cannot land inside it. Failure labels that report output were built when the wait began, so the annotation showed only what had arrived before it. Build them when the wait ends. Refs #4081 Co-Authored-By: Claude Opus 5.5 --- tests/test-invocation-lifetime.test.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test-invocation-lifetime.test.ts b/tests/test-invocation-lifetime.test.ts index cca5d4d0e8..26d5754837 100644 --- a/tests/test-invocation-lifetime.test.ts +++ b/tests/test-invocation-lifetime.test.ts @@ -5,10 +5,12 @@ import { consumerProbe, invocationFixture } from "./helpers/test-invocation-fixt const roots: string[] = []; afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }); }); function fixture() { const value = invocationFixture(); roots.push(value.root); return value; } -async function until(check: () => boolean, label: string) { +// A label that reports output is a function, read when the wait ends: built at +// the call, it would show only what had arrived before the wait began. +async function until(check: () => boolean, label: string | (() => string)) { const end = Date.now() + 10_000; while (!check() && Date.now() < end) await Bun.sleep(10); - expect(check(), label).toBe(true); + expect(check(), typeof label === "string" ? label : label()).toBe(true); } // A child publishes every file this suite polls for and then reads by writing a // temporary file and renaming it into place. writeFileSync creates the file @@ -81,7 +83,7 @@ const out=openSync("tmp/survivor.log","w");const child=spawn(process.execPath,[" survivor = readPid(join(root, "tmp/survivor-pid"), "SURVIVOR_PID_PUBLISHED"); const result = await running.done; expect(result.code).not.toBe(0); writeFileSync(join(root, "tmp/owner-died"), "release"); - await until(() => existsSync(join(root, "tmp/survivor-done")), "SURVIVOR_ACTUAL_FALLBACK: " + (existsSync(join(root, "tmp/survivor.log")) ? readFileSync(join(root, "tmp/survivor.log"), "utf8") : "")); + await until(() => existsSync(join(root, "tmp/survivor-done")), () => "SURVIVOR_ACTUAL_FALLBACK: " + (existsSync(join(root, "tmp/survivor.log")) ? readFileSync(join(root, "tmp/survivor.log"), "utf8") : "")); expect(readFileSync(join(root, "tmp/survivor-done"), "utf8")).toBe("done"); } finally { running.child.kill(); await running.done; @@ -176,10 +178,13 @@ for (const entry of ["wrapper", "direct"] as const) test(`${entry} watch reruns const child=Bun.spawn([process.execPath,...${JSON.stringify(args)}],{stdout:"inherit",stderr:"inherit"});const end=Date.now()+15000;while(!existsSync("tmp/stop-watch")&&Date.now() running.output().includes("WATCH_CONSUMER 1"), "FIRST_WATCH_CONSUMER: " + running.output()); + // Edit only after the first watch run has finished. Bun prints the summary + // after the file's teardown, so the edit cannot land inside that run, and + // the rerun it starts is the only one this test waits for. + await until(() => /WATCH_CONSUMER 1[\s\S]*Ran 1 test across 1 file/.test(running.output()), () => "FIRST_WATCH_RUN_COMPLETE: " + running.output()); write("expected", "2"); write("packages/ithaca/src/index.ts", "export const cargo = 2;\n"); write("watched.test.ts", watched + "\n// Odysseus prepares another voyage.\n"); - await until(() => running.output().includes("WATCH_CONSUMER 2"), "SECOND_WATCH_CONSUMER: " + running.output()); + await until(() => running.output().includes("WATCH_CONSUMER 2"), () => "SECOND_WATCH_CONSUMER: " + running.output()); write("tmp/stop-watch", "stop"); const result = await running.done; expect(result.code, result.output).toBe(0); expect(result.output).not.toContain("(fail)"); } finally { write("tmp/stop-watch", "stop"); running.child.kill(); await running.done; }