Skip to content

fix(testing): write each mock call-log entry in one append - #3976

Merged
max-sixty merged 2 commits into
mainfrom
fix/ci-33436409915
Sep 1, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/ci-33436409915

Conversation

@worktrunk-bot

@worktrunk-bot worktrunk-bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

affected failed on main at 78552b7 (run) — test_switch_picker_preview_auto_refreshes_when_compute_lands panicked on its final assertion:

assertion `left == right` failed: only the intended comments fetch may drive this repaint
  left: []
 right: ["pr view 42 --json comments"]

The fetch itself did happen: the test's earlier assertions (Loading comments in flight, then AUTOREFRESHMARK after 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_invocation appended with writeln!(f, "{}", args.join(" ")). On an io::Write, that is two writes — the joined argv, then the newline as a separate syscall. Mock commands run concurrently (the picker overlaps gh pr list --head with gh pr view 42) and each invocation opens the shared gh.calls file 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_all it once, in a small append_call_line helper. An append-mode write of a short line is atomic against other writers; this is the same rule command_log already 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_calls was exposed, including the ones in remove.rs and switch_picker_dry_run.rs.

Testing

  • New unit test 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-fix writeln! 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 an assert! 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-features and cargo fmt --check clean.
Standalone reproduction of the race

Two processes running the pre-fix log_invocation against one file, 2000 lines each:

total lines: 4000
malformed: 3530
pr list --head flaky --json numberpr view 42 --json comments

pr view 42 --json commentspr list --head flaky --json number

The first form is the CI failure: the pr view entry swallowed into the tail of a pr list line, so no line starts with pr view. The same program with the single write_all produces 0 malformed lines across 12000 lines from 6 concurrent writers.


Automated fix for failed run

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.
@worktrunk-bot worktrunk-bot added the automated-fix Automated CI fix label Aug 31, 2026
…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.
@max-sixty
max-sixty merged commit 6bb421c into main Sep 1, 2026
37 checks passed
@max-sixty
max-sixty deleted the fix/ci-33436409915 branch September 1, 2026 03:59
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants