Skip to content

Enable Windows CI status tests via MOCK_SCRIPT_DIR - #407

Merged
max-sixty merged 6 commits into
mainfrom
test-windows
Jan 4, 2026
Merged

max-sixty merged 6 commits into
mainfrom
test-windows

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

  • mock-stub.exe now passes MOCK_SCRIPT_DIR env var to bash scripts
  • This avoids $0/dirname/pwd issues in Git Bash on Windows CI
  • Remove all 12 Windows ignore attributes from ci_status tests

Problem

On Windows CI, the mock gh script was failing to read JSON data files. The script used:

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cat "$SCRIPT_DIR/pr_data.json"

This path resolution didn't work reliably in Git Bash when invoked via mock-stub.exe.

Solution

Have mock-stub.exe compute the script directory and pass it as MOCK_SCRIPT_DIR:

SCRIPT_DIR="${MOCK_SCRIPT_DIR:-$(cd "$(dirname "$0")" && pwd)}"

On Windows, the env var provides the correct path. On Unix, it falls back to the original method.

Test plan

  • Local CI status tests pass (22 tests)
  • Windows CI tests pass

🤖 Generated with Claude Code

@max-sixty
max-sixty force-pushed the test-windows branch 7 times, most recently from dd05f63 to 62b6a17 Compare January 4, 2026 05:20
mock-stub.exe now passes MOCK_SCRIPT_DIR environment variable to bash,
allowing scripts to reliably find sibling files (like JSON test data)
without relying on $0/dirname/pwd which fail in Git Bash on Windows CI.

- Add script_dir computation and MOCK_SCRIPT_DIR env var to mock-stub.exe
- Update mock gh script to use MOCK_SCRIPT_DIR when available
- Remove all 12 Windows ignore attributes from ci_status.rs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
max-sixty and others added 5 commits January 3, 2026 21:38
On Windows, there are multiple 'bash' executables in PATH:
- C:\Windows\System32\bash.exe - WSL wrapper (fails if WSL not installed)
- C:\Program Files\Git\bin\bash.exe - Git Bash (what we need)

The WSL wrapper was being found first and failing with 'Windows Subsystem
for Linux has no installed distributions' because WSL isn't installed on
GitHub Actions Windows runners.

Fix by adding find_bash() that explicitly looks for Git Bash at known
installation paths before falling back to the WSL wrapper.

Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
Remove the debug file-based logging that was added during troubleshooting.
Keep the MOCK_DEBUG conditional stderr logging for future debugging.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
GitHub Actions Windows runners have Git at C:\Program Files\Git.
No need for multiple fallback paths.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit a7bb803 into main Jan 4, 2026
@max-sixty
max-sixty deleted the test-windows branch January 4, 2026 07:30
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.

1 participant