fix: de-flake hook-bus observe-hook test (JSON EOF race) - #168
Merged
Conversation
The "emit() fires observe hooks without blocking the caller" test waited on waitForFile(), which only checked existsSync. The observe-hook command (`cat > marker`) CREATES the file empty and writes the JSON asynchronously, so under load the read raced the write and hit an empty/partial file — "JSON Parse error: Unexpected EOF" at hook-bus.test.ts:255. Pre-existing race; it started failing CI once the added integration-test files bumped bun test's concurrency and widened the window. Replace waitForFile with waitForJson<T>(): poll readFile + JSON.parse until the file holds valid JSON (or timeout). Eliminates both the empty-file and any partial-write race. Verified: hook-bus.test.ts 10/10 clean (was ~1/5 flaky); tsc + biome clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🤖 Gemini code reviewThis PR successfully resolves a flaky test in Findings: 🔴 0 · 🟠 0 · 🟡 0 · 🟢 0 Tokens spent · ⬆️ Input: 1,174 · ⬇️ Output: 81 · Σ Total: 2,395 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #168 +/- ##
=======================================
Coverage ? 84.51%
=======================================
Files ? 104
Lines ? 18319
Branches ? 0
=======================================
Hits ? 15482
Misses ? 2837
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
mainCI (daemon job) is failing intermittently:Root cause — a pre-existing race, newly exposed
The test "emit() fires observe hooks without blocking the caller" installs an observe hook
cat > "${marker}", fires it, thenawait waitForFile(marker)andJSON.parse(readFileSync(marker)).waitForFileonly checkedexistsSync. Butcat >creates the file empty and writes the JSON asynchronously — sowaitForFilereturned the instant the empty file appeared, and the read raced the write, hitting an empty (or partial) file →Unexpected EOF.This race has always been there; it started tipping over in CI only because the integration-test files added in #165/#166 raised
bun test's file count/concurrency and widened the window. Reproduced locally at ~1 failure in 5 runs.Fix
Replace
waitForFilewithwaitForJson<T>(): pollreadFile+JSON.parseuntil the file holds valid JSON (or timeout). Closes both the empty-file and any partial-write race, and hands the parsed object straight back to the test.Verification
hook-bus.test.ts: 10/10 clean (was ~1/5 flaky).1347 pass / 9 skip / 0 fail.tsc+biomeclean.🤖 Generated with Claude Code