Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
test(picker): quiesce background fills before arming the awaited preview key (#3726)
Worktrunk Bote898a1015439
diff --git a/src/commands/picker/progressive_handler.rs b/src/commands/picker/progressive_handler.rsindex f09bf8f17..17ff7f1a3 100644--- a/src/commands/picker/progressive_handler.rs+++ b/src/commands/picker/progressive_handler.rs@@ -970,7 +970,21 @@ mod tests {}n};+ // Arm the awaited `(row, mode)` — but first let every background fill+ // still in flight land, while `awaiting` is a key none of them match.+ // `on_skeleton` spawns a `LOCAL_GIT_MODES` precompute for this row,+ // which ends at `PreviewOrchestrator::fill` → `notify_filled` and pokes+ // the same unlabelled `Event::RunPreview` this oracle counts. (The+ // `comments` fetch is the other producer in production; on this+ // no-forge `TestRepo` it fills synchronously through `fill_external`,+ // so it is never in flight here.) Left in flight, a fill for the one+ // precompute key a later step also awaits (`WorkingTree`) pokes+ // legitimately but lands after that step's drain — charged to the *next*+ // step, which is the flake in #3725. Quiescing before each+ // `note_awaiting` keeps every counted poke attributable to the+ // `on_update` under test.let await_tab = |mode| {+ handler.orchestrator.wait_for_idle();handler.orchestrator.notifier()diff --git a/tests/CLAUDE.md b/tests/CLAUDE.mdindex cbca06b8b..9ada4f06a 100644--- a/tests/CLAUDE.md+++ b/tests/CLAUDE.md@@ -388,6 +388,7 @@ Tests run once. Worktrunk configures no nextest `retries` and writes no retry lo- A racy assertion is a timing bug. Make it deterministic, per Timing Tests above: poll for the event, or drive it causally through a callback.- Resource pressure is a concurrency bug. Windows process creation intermittently fails with STATUS_DLL_INIT_FAILED (exit `-1073741502`) when many tests spawn git/wt children at once. Bound how many heavy tests run together; that removes the pressure instead of retrying past it.+- A shared channel with more than one producer is an attribution bug. Counting events drained from a channel between steps only measures the step that produced them if nothing *else* can produce them: a background task's event landing after its step's drain is charged to the next step, so the assertion that fails names the wrong step and the wrong cause. The events are usually indistinguishable (skim's `Event::RunPreview` carries no payload), so identity assertions aren't available — quiesce the other producers instead, before the step sequence arms whatever they'd match. `on_update_pokes_run_preview_only_when_the_visible_pane_changes` is the worked example: `PreviewOrchestrator::wait_for_idle()` before each `note_awaiting`, so the skeleton precompute lands while no key matches it.- A shared namespace is a collision bug. **Never `NamedTempFile::new()`** for a file a test needs by name: `tempfile` retries a name collision only when it surfaces as `AlreadyExists`, and on Windows `create_new` against a name already held by a *directory* — or by a file in delete-pending state — comes back `PermissionDenied`, which it hands straight back to the caller. A full suite run leaves the temp directory full of `.tmpXXXXXX` entries (every `TestRepo` makes one), and under that load the call fails ~1% of the time with `Access is denied.` — a panic that has nothing to do with what the test asserts. Take a `TempDir` and give the files fixed names inside it (`worktrunk::testing::directive_files` is the pattern); a directory collision surfaces as `AlreadyExists`, which tempfile retries.**Reproducing a Windows-only flake** means reproducing its *neighbours*, not starving it: run the suspect tests in a loop on a Windows runner with a full `cargo nextest run` going alongside. Pinning the CPU instead models the wrong thing whenever the failing run's own timing was normal (compare its duration against the same test passing — nextest prints it, and the `test` job uploads `junit.xml` with every test's time). Measured both ways on the same five tests: 80 iterations under a concurrent full suite reproduced a 1-in-100 Windows failure that no local run had ever shown, while pinning all four cores with busy loops instead just pushed nearly every iteration past the 30s waits — artificial failures that say nothing about the flake.