From 2d17071004f97651f7a156b80bbda7d1c79477bd Mon Sep 17 00:00:00 2001 From: Daniel Carmingham <15822947+DanielCarmingham@users.noreply.github.com> Date: Sun, 9 Aug 2026 07:07:06 -0400 Subject: [PATCH 1/2] fix: stop two watch tests racing the events macOS replays 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 --- src/watch.rs | 82 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 7 deletions(-) diff --git a/src/watch.rs b/src/watch.rs index b09e660..a160459 100644 --- a/src/watch.rs +++ b/src/watch.rs @@ -410,6 +410,52 @@ mod tests { } } + /// Waits out the events the platform replays for activity that happened + /// *before* the watcher was attached, and reports how many it swallowed. + /// + /// macOS FSEvents delivers events for filesystem activity that predates the + /// stream, **including the creation of the watched directory itself**. So + /// "I attached a watcher, therefore the next event I see is one I caused" + /// is not true, and two tests here were written as though it were. Both + /// failed deterministically on GitHub's macos-14 runners while passing on + /// macOS 26 locally -- not an OS difference in the end, just a race this + /// machine happened to win. Observed directly with a throwaway watcher that + /// printed whole `notify::Event`s: a `Create(File)` and two `Modify`s for a + /// write made 6ms *before* `watch()` returned, and a `Create(Folder)` for + /// the watched directory. + /// + /// This does not paper over the race, it ends it: nothing is asserted until + /// the channel has been quiet for `quiet`, so every later event is one the + /// test itself caused. Condition-based rather than a fixed sleep, so a slow + /// machine waits longer instead of flaking. + /// + /// `cap` bounds the total wait. Without it a genuinely broken gate -- one + /// emitting on every tick -- would keep this receiving forever and the test + /// would hang rather than fail, which is the worse of the two. + fn settle(rx: &Receiver, quiet: Duration, cap: Duration) -> usize { + let deadline = Instant::now() + cap; + let mut swallowed = 0; + while Instant::now() < deadline && rx.recv_timeout(quiet).is_ok() { + swallowed += 1; + } + swallowed + } + + /// The quiet window `settle` needs, which is **not** a free choice. + /// + /// What is being drained is `out`, and the `Ok(())` branch does not forward + /// an event as it arrives -- it swallows the rest of the burst for + /// `DEBOUNCE` first, so a raw event at 5ms becomes an `out` send at 255ms. + /// A quiet window shorter than `DEBOUNCE` therefore returns *during* the + /// debounce, having seen nothing, and hands the still-pending emission to + /// whatever the test asserts next. + /// + /// This was not theoretical: at 200ms the safety-timeout test still failed + /// 3 runs in 15, while the multi-store test above passed 15/15 at 300ms. + /// The margin is over `DEBOUNCE` rather than over a measured latency, + /// because it is the debounce that sets the floor. + const SETTLE_QUIET: Duration = DEBOUNCE.saturating_add(Duration::from_millis(150)); + #[test] fn fires_when_the_store_file_changes() { let dir = TempDir::new("fires"); @@ -453,11 +499,19 @@ mod tests { /// re-read all of them and watching separately buys nothing. #[test] fn a_change_reports_which_store_it_came_from() { - let dir = std::env::temp_dir().join("dextui-watch-many"); - let a = dir.join("a"); - let b = dir.join("b"); - std::fs::create_dir_all(&a).unwrap(); - std::fs::create_dir_all(&b).unwrap(); + // A `TempDir` per run, like every other test here. This used to be a + // fixed `temp_dir().join("dextui-watch-many")` that nothing ever + // cleaned up, which is precisely what hid the bug below: after the + // first run `a` and `b` already existed, so `create_dir_all` did + // nothing and there was no directory-creation event to replay. It + // passed 10/10 locally against a directory dated nine days earlier, + // and failed on every fresh CI machine. Deleting that stale directory + // reproduced the failure here immediately. + let parent = TempDir::new("many"); + let a = parent.0.join("a"); + let b = parent.0.join("b"); + fs::create_dir_all(&a).unwrap(); + fs::create_dir_all(&b).unwrap(); let (tx, rx) = std::sync::mpsc::channel(); let _guards = spawn_many( @@ -468,9 +522,15 @@ mod tests { tx, ); - std::fs::write(b.join("tasks.jsonl"), "{}").unwrap(); + // Creating `a` and `b` is itself filesystem activity, and it happened + // before the watchers existed -- so without this, `a` reports its own + // creation and wins the race against the write below. That is the + // literal CI failure: "reported the wrong store: .../a". + settle(&rx, SETTLE_QUIET, Duration::from_secs(3)); - let got = rx.recv_timeout(std::time::Duration::from_secs(5)).unwrap(); + fs::write(b.join("tasks.jsonl"), "{}").unwrap(); + + let got = rx.recv_timeout(Duration::from_secs(5)).unwrap(); assert!(got.ends_with("/b"), "reported the wrong store: {got}"); } @@ -534,6 +594,14 @@ mod tests { let (tx, rx) = channel(); let _w = spawn_inner(dir.path(), tx, FAST); + // The write above happened before the watcher attached, and the + // platform replays it -- through the `Ok(())` branch, which is not the + // branch under test and is not stat-gated at all. Left in, it emits + // once and the assertion below reads that as the safety tick firing, + // which is exactly backwards. Swallowing it first is what makes the + // rest of this about the timeout branch and nothing else. + settle(&rx, SETTLE_QUIET, Duration::from_secs(3)); + // Several safety intervals pass with the file left exactly alone. // This is the whole point of the stat gate: previously every one of // these ticks would have emitted, and the caller would have paid for From e0fc711176fa0c833e0a6e1adb5fd6fbb9f27601 Mon Sep 17 00:00:00 2001 From: Daniel Carmingham <15822947+DanielCarmingham@users.noreply.github.com> Date: Sun, 9 Aug 2026 07:08:54 -0400 Subject: [PATCH 2/2] chore: pin checkout to v6, matching the generated release workflow 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 --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4cea893..f800ffa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: name: test + clippy (linux) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: dtolnay/rust-toolchain@stable with: components: clippy @@ -45,7 +45,7 @@ jobs: name: test (macos) runs-on: macos-14 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - run: cargo test @@ -58,7 +58,7 @@ jobs: name: build on the declared MSRV runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: dtolnay/rust-toolchain@1.88 - uses: Swatinem/rust-cache@v2 - run: cargo build --locked