From a6a765cd4454be00b550c1dced4743e49aafbaa8 Mon Sep 17 00:00:00 2001 From: Ayaan Gazali Date: Sun, 23 Aug 2026 21:22:05 -0700 Subject: [PATCH] test(scripts): wait for the e2e state path file to have content (#128403) * test(scripts): wait for the e2e state path file to have content waitForFile returned as soon as the path file existed. The child creates that file and writes it in separate syscalls, so the reader could observe it empty, read "" as the state dir, and fail the existence assertion on a path that was never written. That surfaces as "expected false to be true" under CI load. Wait for non-empty content instead. * test(scripts): make the state path publication race deterministic The suite previously published the path in one write, so it passed with either readiness predicate and protected nothing. Publish the empty file first and delay the real write, which is the window a real writer leaves open, so the case fails on the existence-only check and passes on the content-aware one. * test(scripts): publish e2e state paths atomically --------- Co-authored-by: Peter Steinberger --- test/scripts/e2e-temp-state-dir.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/scripts/e2e-temp-state-dir.test.ts b/test/scripts/e2e-temp-state-dir.test.ts index 00df9994ae09..e75b4b2b75ac 100644 --- a/test/scripts/e2e-temp-state-dir.test.ts +++ b/test/scripts/e2e-temp-state-dir.test.ts @@ -98,14 +98,16 @@ describe("E2E temp state dirs", () => { const helperUrl = pathToFileURL(path.resolve("scripts/e2e/lib/temp-state-dir.ts")).href; writeFileSync( scriptPath, - `import { writeFileSync } from "node:fs"; + `import { renameSync, writeFileSync } from "node:fs"; import { createE2eStateDir } from ${JSON.stringify(helperUrl)}; const state = await createE2eStateDir("openclaw-e2e-temp-state-signal-", { OPENCLAW_STATE_DIR: "", }); state.registerExitCleanup(); -writeFileSync(${JSON.stringify(statePathFile)}, state.stateDir); +// Publish atomically so the polling parent cannot observe an empty state-path file. +writeFileSync(${JSON.stringify(`${statePathFile}.tmp`)}, state.stateDir); +renameSync(${JSON.stringify(`${statePathFile}.tmp`)}, ${JSON.stringify(statePathFile)}); setInterval(() => {}, 1000); `, );