fix(cli): stop the preflight cancel test reading a pid file mid-write (#4077)

The test polled a pid file written by `echo $$ > path`, whose shell
redirection creates (truncates) the file before the echo writes to
it. A read landing in that window parsed an empty string to 0, which
satisfied "not undefined" and exited the wait loop early, failing
the next assertion with "expected 0 to be greater than 0" — the
exact shape of the intermittent CI failure. The loop now only
accepts a parsed value that's a positive integer, reproduced with a
busy-wait harness that hit the empty-file race in most iterations
and confirmed clean after the fix.
This commit is contained in:
Miguel Ángel
2026-09-18 09:46:12 -04:00
committed by GitHub
parent de9206e0f8
commit a7cc1d2cff
+6 -2
View File
@@ -88,10 +88,14 @@ describe("runEnvironmentChecks", () => {
const deadline = Date.now() + 2_000;
while (probePid === undefined && Date.now() < deadline) {
try {
probePid = Number(readFileSync(pidPath, "utf8").trim());
// Shell `>` redirection creates (truncates) the file before `echo $$`
// writes to it — a read can land on that empty window and parse to 0.
const pid = Number(readFileSync(pidPath, "utf8").trim());
if (Number.isInteger(pid) && pid > 0) probePid = pid;
} catch {
await new Promise((resolve) => setTimeout(resolve, 10));
// pid file not created yet
}
if (probePid === undefined) await new Promise((resolve) => setTimeout(resolve, 10));
}
expect(probePid).toBeGreaterThan(0);