Skip to content

test(testing): panic with the fix when mock-stub binary is absent - #2744

Merged
max-sixty merged 2 commits into
mainfrom
gitea-test-flake
May 12, 2026
Merged

max-sixty merged 2 commits into
mainfrom
gitea-test-flake

Conversation

@max-sixty

@max-sixty max-sixty commented May 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

cargo test --test integration and cargo llvm-cov --test integration don't build the mock-stub / wt-perf helper bins: a target filter overrides workspace.default-members, and these invocations don't honor .config/nextest.toml's build-bins setup-script. So on a clean target/ (and always under cargo llvm-cov, which uses its own target dir) the binary tests/helpers/mock-stub is absent. Today that surfaces as an opaque ENOENT on a dangling symlink, or — for the gitea CI-status tests — a silently-dropped ● indicator when tool_available("tea") returns false because the mocked tea can't spawn.

mock_stub_binary() now resolves the path and hands it to assert_mock_stub_present(), which panics with a message pointing at the fix (cargo build -p mock-stub, or cargo nextest run / cargo llvm-cov nextest, which build the helpers via the setup-script). The check is split into its own function so a #[should_panic] unit test can drive the missing-binary arm without depending on whether the real binary happens to be built. The assert only fires when a test actually sets up a mock — it's reached via MockConfig::write — so mock-free tests are untouched.

Also a one-line note in CLAUDE.md's "faster iteration" block, and the mock_stub_binary doc comment now points at the eventual collapse — folding the helper bins back into the worktrunk crate so cargo test --test integration builds them automatically and this whole layer goes away — which is blocked on cargo-dist (see .config/nextest.toml and tests/helpers/mock-stub/Cargo.toml).

This is the symptom-2 follow-up to #2730 (#2730 fixed the profraw-leak flake; this makes the missing-binary case fail loudly instead of mysteriously).

Test plan

  • cargo test --test integration -- ci_status::test_list_full_with_gitea_no_ci — passes (normal case unaffected; binary present)
  • Same command with target/debug/mock-stub moved away — panics with the message above, rendered cleanly
  • cargo test --lib testing:: — 9/9 pass, including the new assert_mock_stub_present_panics_when_absent (#[should_panic])
  • cargo clippy --tests --features shell-integration-tests -- -D warnings — clean

`cargo test --test integration` and `cargo llvm-cov --test integration`
don't build the `mock-stub` / `wt-perf` helper bins — a target filter
overrides `workspace.default-members`, and these invocations ignore
nextest setup-scripts — so on a clean `target/` (always, under
`cargo llvm-cov`, since it uses its own target dir) the binary is
missing. Today that surfaces as an opaque ENOENT on a dangling symlink,
or a silently-dropped CI indicator when `tool_available("tea")` returns
false. `mock_stub_binary()` now asserts the binary exists and points at
`cargo build -p mock-stub` / `cargo nextest run` / `cargo llvm-cov
nextest`. The assert only fires when a test actually sets up a mock
(it's called from `MockConfig::write`), so mock-free tests are untouched.

Also a one-line note in CLAUDE.md's "faster iteration" block, and a
pointer in the doc comment to the cargo-dist-blocked collapse (folding
the helper bins back into the worktrunk crate).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
worktrunk-bot
worktrunk-bot previously approved these changes May 12, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codecov/patch flagged line 47 (path.display(),) — Rust's assert! evaluates format args lazily, so it only runs when the assertion fails, which never happens in normal test runs. Lines 39–41 and 49 are covered (4/5 = 80%).

This is a structural gap, but per CLAUDE.md the rule is to fix coverage rather than skip it. The cleanest fix is to factor the check into a small helper and add a #[should_panic] test that passes a non-existent path:

fn mock_stub_binary() -> std::path::PathBuf {
    let path = super::workspace_bin("mock-stub");
    assert_mock_stub_exists(&path);
    path
}

fn assert_mock_stub_exists(path: &std::path::Path) {
    assert!(
        path.exists(),
        "mock-stub binary not found at {}\n\n\
         Build it once with `cargo build -p mock-stub`, or use a runner that builds\n\
         the test helper bins:\n\
         \n  cargo nextest run --features shell-integration-tests --test integration ...\
         \n  cargo llvm-cov nextest --features shell-integration-tests --test integration ...\n",
        path.display(),
    );
}

#[cfg(test)]
mod tests {
    // ...
    #[test]
    #[should_panic(expected = "mock-stub binary not found at")]
    fn test_assert_mock_stub_exists_missing() {
        super::assert_mock_stub_exists(std::path::Path::new("/nonexistent/mock-stub"));
    }
}

Dismissing my approval per CLAUDE.md (codecov/patch requires explicit approval to merge). Happy to push this restructure if you'd like, or override if you'd rather merge as-is.

@worktrunk-bot
worktrunk-bot dismissed their stale review May 12, 2026 16:09

codecov/patch failing on line 47 — see follow-up comment with proposed fix

Extract the existence check into `assert_mock_stub_present(path)` so a
unit test can drive the panic branch without depending on whether the
real binary is built. Add a `#[should_panic]` test passing a nonexistent
path — this exercises the format-arg expression (`path.display()`) that
codecov/patch flagged as uncovered, since `assert!`'s message args are
only evaluated when the assertion fires.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit e637cf0 into main May 12, 2026
33 checks passed
@max-sixty
max-sixty deleted the gitea-test-flake branch May 12, 2026 17:08
max-sixty added a commit that referenced this pull request Aug 3, 2026
`cargo test --test integration` neither built nor rebuilt `mock-stub`: a
target filter deselects the dummy test that pulled it in, so a fresh
tree panicked ("mock-stub binary not found") and a warm one could run a
stale stub. The chain that compensated — the separate helper package,
its dummy `builds.rs`, the `default-members` entry, nextest's
experimental `build-bins` setup script, `workspace_bin()` — existed only
because cargo-dist ships every `[[bin]]`, and carried a TODO to collapse
once that changed. dist 0.30.2 does support per-binary exclusion now
(`[dist.binaries]`, since 0.29.0; verified with `dist plan`), but the
TODO's plan has a hole it predates: `cargo install worktrunk` installs
every feature-satisfied `[[bin]]`, and dist config doesn't govern
crates.io installs.

So the mock commands are now the `wt` binary itself. `mock_commands`
links `wt` under the mock's name (`gh`, `glab`, …), and `main()`
dispatches to the ported playback (`testing::mock_stub`) when
`WORKTRUNK_TEST_MOCK_CONFIG_DIR` is set, argv[0] is a foreign name, and
the config dir holds `<argv0>.json` for it. The existence check keeps wt
under a foreign argv[0] *without* a config being wt — the
argv0-validation security test symlinks it as `wt;touch` and must reach
wt's own rejection. The shipped binary already compiles the whole
`testing` module unconditionally, so this adds no new category of test
code to it. Windows links `wt.exe` with `hard_link` (copy fallback for
cross-drive dirs); the debug binary is ~67 MB, so per-mock copies stay
the fallback.

Every runner is now safe by construction — cargo rebuilds a package's
own binaries whenever its integration tests build, so there is no
separate artifact to go missing or stale. Deleted: the helper package,
the setup script plus `experimental = ["setup-scripts"]`, the
`default-members` trick, `workspace_bin()`, and `wt_bin()`'s dead
compile-time branch (unit-test targets get neither the runtime variable
nor the `option_env!` value, so the runtime resolution is the one
mechanism).

Validated locally: the pre-merge gate's full suite passes (4542/4542;
its doc step also caught unescaped `argv[0]` intra-doc links in the new
comments, fixed and `cargo doc -Dwarnings` re-verified). With all stub
artifacts purged from `target/`, plain `cargo test --test integration`
on mock-dependent tests builds them and passes — the command that used
to hit the trap. Two integration tests pin the dispatch's argv[0] edges
(an empty argv[0], and a non-UTF8 one), alongside the existing
`wt;touch` carve-out test.

The first commit is the investigation that preceded the fix: it verified
the `wt` binary itself was never subject to the staleness the mock-stub
was, and documented that in `tests/CLAUDE.md`; the fix then narrows that
paragraph further, since the gap it scoped no longer exists.

A two-reviewer subagent round (one prosecuting the diff against the
failure modes documented in the repo's own mock history — the #401/#407
Windows era, #547, #654, #127, #2544, #2730, #2744 — the other
adversarial) then hardened the dispatch. The reserved-name guard is
case-insensitive, matching the config probe, which goes through a
filesystem that equates `WT.json` with `wt.json` on macOS and Windows;
`command_name()` reads `args_os` — `env::args()` panics on a non-Unicode
argument, and this runs inside `main()` on every invocation (caught by
the tend review) — and returns `None` for a degenerate argv[0] instead
of panicking; the `.exe` suffix is stripped explicitly rather than via
`file_stem`, so a dotted mock name (`python3.11`) resolves identically
on every platform; and `copy_mock_binary` is now private —
`MockConfig::write` writes `<name>.json` before linking and is the only
way to create a mock, so a link cannot exist without its config, and the
dispatch's missing-config fall-through can only mean "wt under a foreign
name" (the argv0-validation tests' `wt;touch`), never a half-configured
mock that silently runs real wt with the mocked tool's arguments. The
`Option<&str>` mock helpers whose `None` arm produced exactly such
configless links lost the arm (every caller passed `Some`), and 25
redundant standalone link calls went with it.

The review also surfaced the one remaining spawn-a-stale-binary path
outside the suite: `wt-perf timeline` resolved a sibling `wt` by path,
checked only existence, and told the user to build it manually — so
`cargo run -p wt-perf -- timeline` after a `src/` edit silently measured
stale code. It now builds `wt` first and takes the artifact path from
cargo's `--message-format=json` report rather than deriving a sibling
location, so target-dir and profile overrides can't divert the build
away from where it's resolved; a release wt-perf builds and measures a
release wt. The build runs before the timeline's wall-clock measurement
starts, cargo's progress streams on stderr, and stdout keeps the
`--chrome` JSON contract.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Fable 5 <[email protected]>
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.

2 participants