fix: deflake watchFile and invoke backspace tests - #2204
Merged
Conversation
watchFile: Bun registers the macOS kqueue watch off-thread, so edits written immediately after watch() were sometimes never reported. Settle before writing and wait for the callback instead of a fixed sleep. invoke backspace: the chat frame shows the random session UUID, so asserting that "abcd" disappears could never pass when the UUID contained that hex substring. Type non-hex letters instead. Fixes #2140 Fixes #2176
Contributor
|
Claude Security Review: no high-confidence findings. (run) |
Contributor
There was a problem hiding this comment.
AgentCore Harness Review
Verdict: Looks good
Both flake fixes are well-reasoned and test-only:
src/io/watchFile.test.ts: The 100 ms settle before writing addresses Bun's off-thread kqueue registration on macOS, and swapping the fixed 250 ms sleep forwaitFor(() => calls === 1)asserts on outcome rather than timing. Keeping the fixed 250 ms sleep aftercontroller.abort()is correct — that assertion is that no additional callback fires, which a polling helper can't express.src/handlers/harness/invoke/invoke.screen.test.tsx: Switching the typed characters fromabcd(hex) towxyz(non-hex) is the right fix —crypto.randomUUID()output can only contain[0-9a-f-], so collision with the session id in the rendered frame is now impossible rather than ~1/2500. The comment explains why clearly.
No production code is touched, so telemetry doesn't apply. Nothing else to flag.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## refactor #2204 +/- ##
=========================================
Coverage 97.08% 97.08%
=========================================
Files 544 544
Lines 37768 37768
=========================================
Hits 36666 36666
Misses 1102 1102 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
Claude Security Review: no high-confidence findings. (run) |
Hweinstock
approved these changes
Sep 3, 2026
| const controller = new AbortController(); | ||
| let calls = 0; | ||
| watchFile(path, () => calls++, controller.signal); | ||
| // Bun registers the macOS kqueue watch off-thread, so earlier edits are never reported. |
Contributor
There was a problem hiding this comment.
is there anyway to poll until this is registered somehow? I worry a fixed wait time could be flaky.
jariy17
approved these changes
Sep 3, 2026
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.
Closes #2140
Closes #2176
watchFile.test.ts (#2140)
Bun registers the macOS kqueue watch off the main thread. Edits written synchronously right after
watch()are sometimes never reported (5 of 60 runs locally with no delay, 0 of 60 with a 20 ms settle). The test now settles 100 ms before writing and waits for the callback instead of sleeping a fixed 250 ms. 100 of 100 local runs pass; the previous version failed about 1 in 8 locally.Test-only:
project devstarts watching long before the user edits, so production is unaffected.invoke.screen.test.tsx (#2176)
The chat frame renders
session: <crypto.randomUUID()>. The backspace test asserted that"abcd"disappears from the whole frame, which can never happen when the random UUID contains that hex substring (about 1 in 2500 runs). Reproduced deterministically by seeding a session id containingabcdvia the/:sessionIdroute. The test now types non-hex letters.Verification
bun testfull suite with--coveragepasses locally