Skip to content

fix: stop two watch tests racing the events macOS replays - #1

Merged
DanielCarmingham merged 2 commits into
mainfrom
fix/macos-watch-tests
Aug 9, 2026
Merged

DanielCarmingham merged 2 commits into
mainfrom
fix/macos-watch-tests

Conversation

@DanielCarmingham

Copy link
Copy Markdown
Owner

macOS FSEvents delivers events for filesystem activity that predates watch(), including the creation of the watched directory itself. Both tests assumed the first event they saw was one they caused.

Reproduced locally once the conditions were right — 2/10 and 1/8 — so this was never a CI-only quirk. The multi-store test was additionally masked by a fixed shared temp dir that nothing cleaned up, so it had been passing against directories dated nine days earlier; deleting that directory reproduced the CI failure immediately.

SETTLE_QUIET being over DEBOUNCE is the load-bearing part — a first attempt at 200ms still failed 3 in 15, because the Ok(()) branch swallows a burst for 250ms before it sends, so a shorter quiet window returns mid-debounce having seen nothing.

Full reasoning in the commit message. Verified 0/15 both under the reproducing conditions, full suite 5x, clippy clean.

This PR exists mainly to get the macOS runner to confirm it, since that is where the failure was deterministic.

https://claude.ai/code/session_019vddQQKM4N7Mu72Cdqn9iy

Both failed on every GitHub macos-14 run and passed here, which read as an
OS difference and was not one. macOS FSEvents delivers events for
filesystem activity that happened *before* the stream was created --
including the creation of the watched directory itself. Confirmed by
watching with a throwaway callback that printed whole `notify::Event`s: a
`Create(File)` and two `Modify`s for a write made 6ms before `watch()`
returned, plus a `Create(Folder)` for the watched directory. Both tests
assume the first event they see is one they caused.

`a_safety_timeout_with_nothing_changed_emits_nothing` writes tasks.jsonl
before `spawn_inner`. The replayed write comes back through the `Ok(())`
branch, which is not the branch under test and is not stat-gated at all --
so the test read a watcher event as the safety tick firing, which is
exactly backwards. It reproduces here 2 runs in 10 when run alone; the
full suite's timing is what hid it.

`a_change_reports_which_store_it_came_from` creates `a` and `b` before
`spawn_many`, and `a` reports its own creation before the deliberate write
to `b` lands -- the literal CI message, "reported the wrong store: .../a".
This one was hidden by a second bug: the test used a fixed
`temp_dir().join("dextui-watch-many")` that nothing ever cleaned up, so
after the first run the directories already existed and `create_dir_all`
was a no-op. It was passing 10/10 against a directory dated nine days
earlier. Deleting that directory reproduced the CI failure immediately,
which is what tied the two halves together.

The fix is `settle`, which waits for the channel to go quiet before
anything is asserted, so every event a test judges is one the test caused.
Condition-based rather than a fixed sleep, and capped, so a broken gate
fails rather than hanging. The test that used the shared path now gets a
`TempDir` per run like every other test in the module.

`SETTLE_QUIET` is over `DEBOUNCE`, and that is the load-bearing part. What
`settle` drains is `out`, and the `Ok(())` branch swallows the rest of a
burst for `DEBOUNCE` before sending -- so a raw event at 5ms becomes an
`out` send at 255ms, and a quiet window under 250ms returns mid-debounce
having seen nothing, handing the pending emission to the next assertion.
A first attempt at 200ms still failed 3 in 15 while the 300ms call site
passed 15/15, which is what pointed at the debounce.

Verified under the conditions that reproduced it -- each test alone, stale
directory removed each run -- 0/15 both, against 2/10 and 1/8 before. Full
suite 5x and clippy -D warnings clean.

Not changed: the app still does a `dex list` for each replayed event at
startup, one per watched store, on top of the initial load it already did.
That is wasted work rather than wrong output, and fixing it is a product
change, not a test fix.

Claude-Session: https://claude.ai/code/session_019vddQQKM4N7Mu72Cdqn9iy
actions/checkout@v4 targets Node 20, which the runners now force onto
Node 24 with a deprecation warning on every job. dist's generated
release.yml already pins v6, so this also stops the two workflows in the
same repo disagreeing about the same action.

Claude-Session: https://claude.ai/code/session_019vddQQKM4N7Mu72Cdqn9iy
@DanielCarmingham
DanielCarmingham merged commit 1e68484 into main Aug 9, 2026
12 checks passed
@DanielCarmingham
DanielCarmingham deleted the fix/macos-watch-tests branch August 9, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant