Repository navigation
fix(testing): write each mock call-log entry in one append - #3976
Merged
Merged
Conversation
The mock stub logged an invocation with `writeln!`, which emits the joined argv and the trailing newline as two separate writes. Mocks run concurrently — the picker overlaps `gh pr list` with `gh pr view`, and each invocation opens the shared `<cmd>.calls` file itself — so two appends can interleave into one merged line plus an empty one. A test that filters the log by command prefix then stops seeing a spawn that actually happened. Build the whole line first and `write_all` it once, the way `command_log` already writes its JSONL entries: an append-mode write of a short line is atomic against other writers.
…c message The format arguments of the previous `assert!` message only run when the assertion fails, so codecov counted them as two patch misses on a patch whose target is the base's 98.19% project coverage. Comparing a (count, example) pair keeps the same diagnostic on failure — the count and one corrupt line — with every line evaluated on the passing path.
This was referenced Sep 1, 2026
max-sixty
pushed a commit
that referenced
this pull request
Sep 1, 2026
The README's intro blockquote still opened with **August 2026**; today is 2026-09-01, so the stamp is a month stale. This bumps it to **September 2026** — the same monthly refresh as #3686 (August), #3347 (July), and #2972 (June). Line 16 sits above the first `<!-- AUTO-GENERATED -->` marker (line 28), so it is a hand-edited primary rather than generated content. It has two mirrors, which behave differently: `skills/worktrunk/reference/README.md` is a symlink to the root `README.md` and picks the change up for free, while `plugins/worktrunk/skills/worktrunk/reference/README.md` is a generated *file copy* and needs its own sync — that second commit is here because `test_docs_are_in_sync` caught the stale copy on the first push. No regression test: the stamp is prose with no behavioral surface, and its correctness is time-dependent rather than assertable. <details><summary>Nightly sweep context</summary> Found by the rolling survey (bucket 5/28) together with the README date check in the repo's `running-tend` skill. The rest of the sweep was clean: - **tend config** — `tend check` all PASS; bot PAT carries every required scope. - **Conflicts** — #3129 (bot) and #3966/#3967/#3978 (Dependabot) all test-merge clean against `main` via `git merge-tree`; no deferral comments to clear. - **Workflow regen** — `uvx tend@latest init` produced no diff; the committed workflows are already at tend 0.1.24. - **Recent commits** — the 7 commits in the last 24h reviewed; no findings. The `for_action_branchless` → `for_action_loading_config` rename in #3970 left no stale references, and #3976's `append_call_line` change carries its own regression test. - **Survey** — `src/cache.rs`, `src/config/user/path.rs`, `src/config/user/sections.rs`, `src/styling/line.rs`, `docs/src/content/docs/claude-code.md`, the two `.config/clawpatch/features/*.json` files (every referenced path still resolves), and the skill/plugin pages. No findings. </details> --------- Co-authored-by: worktrunk-bot <[email protected]>
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.
Problem
affectedfailed onmainat 78552b7 (run) —test_switch_picker_preview_auto_refreshes_when_compute_landspanicked on its final assertion:The fetch itself did happen: the test's earlier assertions (
Loading commentsin flight, thenAUTOREFRESHMARKafter the release gate) both passed, and the marker only reaches the screen from the mock's output. What went missing was the mock's call-log line.mock_stub::log_invocationappended withwriteln!(f, "{}", args.join(" ")). On anio::Write, that is two writes — the joined argv, then the newline as a separate syscall. Mock commands run concurrently (the picker overlapsgh pr list --headwithgh pr view 42) and each invocation opens the sharedgh.callsfile itself, so two appends interleave: writer A's argv, writer B's argv, A's newline, B's newline. The log then holds one merged line plus an empty one, and the test's.starts_with("pr view")filter finds nothing —left: [], exactly the observed shape.Solution
Build the line including its newline and
write_allit once, in a smallappend_call_linehelper. An append-mode write of a short line is atomic against other writers; this is the same rulecommand_logalready follows for its JSONL entries ("Single write_all so each JSON line is written atomically",src/command_log.rs). The mock stub was the one append site that missed it.Fixing the shared logger rather than the one test: any test asserting on spawn counts through
mock_callswas exposed, including the ones inremove.rsandswitch_picker_dry_run.rs.Testing
concurrent_appends_keep_each_call_on_its_own_line— 8 threads × 400 appends of two different argvs, asserting every line is intact and the count is exact. Against the pre-fixwriteln!body it fails on the first run (left: (2763, Some("pr view 42 --json commentspr list --head flakypr view 42 --json comments"))); with the fix it passes in 0.01s. Threads rather than processes because the interleaving is per write syscall — each call opens its own append handle either way. The failure is asserted as a (count, example) pair rather than anassert!message, because a panic-only format argument counts as a patch-coverage miss.cargo test --features shell-integration-tests --test integration -- switch_picker remove::— 157 passed, including the originally-failing test.cargo clippy --all-targets --all-featuresandcargo fmt --checkclean.Standalone reproduction of the race
Two processes running the pre-fix
log_invocationagainst one file, 2000 lines each:The first form is the CI failure: the
pr viewentry swallowed into the tail of apr listline, so no line starts withpr view. The same program with the singlewrite_allproduces 0 malformed lines across 12000 lines from 6 concurrent writers.Automated fix for failed run