Repository navigation
🐛 fix(tests): isolate every spawned gwm from the contributor's state - #726
Merged
Merged
Conversation
The 377 `Command::cargo_bin("gwm").unwrap()` sites and the two
`std::process::Command::new(env!("CARGO_BIN_EXE_gwm"))` sites now go
through `tests/common::gwm()`. No behaviour change yet: the builder is a
plain `assert_cmd::Command` on the binary. It is the one place the next
commits isolate the spawned gwm from the contributor's state.
refs #724
Red on purpose. Three tests state what `common::gwm()` must do, and fail against the plain builder of the previous commit: - a `gwm remove` run by the suite is journaled in the test's scratch journal, not in the one the contributor's environment resolves to; - on unix, a worktree created with no `[worktree] base` lands under the test's scratch home, not under `~/cc-worktree`; - the builder sets every variable the consumer docs prescribe, read off the isolation table, each pointing inside the scratch directory. Plus the routing guard: only `tests/common/mod.rs` may reach the binary, and a synthetic source proves each bypass spelling is flagged. refs #724
`common::gwm()` now points the undo journal, the trust ledger, the global config, `aliases.toml`, the agent-session scan and `$HOME` at a scratch directory per test (a thread-local `TempDir` under `CARGO_TARGET_TMPDIR`, removed when the test's thread ends). A local `cargo test` no longer writes the contributor's real `history.toml`, and a test that creates a worktree without pinning `[worktree] base` lands under the scratch home instead of `~/cc-worktree` or the base of the contributor's global config. On Windows `dirs::home_dir()` does not read `$HOME`, so there the default base still needs a pinned `[worktree] base`; the comment says so. refs #724
The consumer docs already prescribed one helper that sets the isolation variables on every spawned gwm; gwm's own suite now is that helper, so the docs name it, and say what `HOME` does for the default worktree base on Linux and macOS but not on Windows. Changelog entry under Fixed. closes #724
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
`create_with_allow_bootstrap_flag_bypasses_the_prompt`,
`create_with_gwm_allow_bootstrap_env_bypasses_the_prompt` and
`allow_bootstrap_succeeds_even_when_ledger_is_malformed` wrote a
`.gwm.toml` with no `[worktree] base`, so their worktrees went to the
default `{home}/cc-worktree/{repo}`. The builder's `$HOME` covers that on
unix only: on Windows they still landed in the real profile. They were
the only three in the suite (a full run with a throwaway home found
exactly these under `cc-worktree`).
refs #724
The docs-derived check skipped any row it could not parse, and its only floor was that `GWM_HISTORY_FILE` was among the rows read. A reworded row (`` `GWM_TRUST_LEDGER` = `<file>` ``) dropped out silently, and the builder could then lose that variable with every test green. Every body row of the table must now open on one `NAME=value` code span. refs #724
"Fails if anything spawns the binary around it" gave the guard more credit than it has: it reads Rust sources for the built binary's path and for `gwm` off `PATH`, and does not see a shell snippet. The docs and the changelog now say that. refs #724
`statusline_render_shape_survives_the_pipe` kept its fn-local `use std::process::Command;` after e8e5dd1 moved its spawn to `common::gwm()`. The file is `cfg(all(windows, feature = "daemon"))`, so macOS and Linux never compile it, and CI's `RUSTFLAGS: -D warnings` would have turned the unused import into a red `test (windows-latest)`. refs #724
The changelog still credited the routing guard with catching a test that
runs `gwm` off `PATH`, which it sees only as a literal
`Command::new("gwm")`, not in a shell snippet. The test file's header
and the builder's doc said "every user-level file"; they now say which.
refs #724
3 tasks
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.
Description
cargo testwrote the contributor's real undo journal, and left worktrees under the real home. Every test now spawnsgwmthrough one builder,tests/common::gwm(), which points gwm's user-level files (undo journal, trust ledger, global config,aliases.toml, agent-session scan) and$HOMEat a per-test scratch directory, and a guard fails if another test file resolves the built binary itself.Closes #724
Type of change
Changes
♻️379 spawn sites (Command::cargo_bin("gwm").unwrap()x377,std::process::Command::new(env!("CARGO_BIN_EXE_gwm"))x2) now callcommon::gwm(). Mechanical, no behaviour change on its own.✅tests/suite_isolation_tests.rs(red first, commit05451dda):gwm removerun by the suite is journaled in the test's scratch journal;[worktree] baselands under the test's scratch home;docs/5.integrations/4.daemon-consumers.md, so the suite and the documented recipe cannot drift), each pointing inside the scratch dir;tests/andbenches/, onlytests/common/mod.rsmay reach the binary (assert_cmd's cargo lookup in every form,CARGO_BIN_EXE_,Command::new("gwm")offPATH), plus a synthetic-source proof that each spelling is flagged.🐛common::gwm()setsGWM_HISTORY_FILE,GWM_TRUST_LEDGER,GWM_NO_GLOBAL_CONFIG=1,XDG_CONFIG_HOME,XDG_DATA_HOME,GWM_AGENTS_HOMEandHOME. The scratch dir is a thread-localTempDirunderCARGO_TARGET_TMPDIR, one per test (libtest runs a test per thread, nextest per process), removed when the test's thread ends: aremoveand itsundoin one test still share a journal, two tests never do.✅The three trust-bypass tests that relied on the default base (create_with_allow_bootstrap_flag_bypasses_the_prompt,create_with_gwm_allow_bootstrap_env_bypasses_the_prompt,allow_bootstrap_succeeds_even_when_ledger_is_malformed) now pin a[worktree] base, so they stay out of the real profile on Windows too, where$HOMEdoes not move{home}.📝Consumer docs (EN + FR) name the suite's builder as the reference helper and say whatHOMEdoes for the default base. Changelog entry under Fixed. The stale block comment incli_binary.rsabout pinning the base is corrected.Tests
cargo testpasses locally (full suite atd2c57e0f: 112 binaries, 3594 passed, 0 failed; the docs commit was re-checked with every binary that reads the docs or the changelog)cargo fmt --checkpassescargo clippy -- -D warningspasses (--all-targets)tests/(TDD: a PR adding behaviour without tests is sent back)Checklist
<type>/#<issue>-<description>## [Unreleased]examples/gwm.toml.exampleupdated if config schema changed (no schema change)unwrap()on user-facing paths (returnGwmErrorinstead) (test code only)println!in TUI render code (status bar only)Linked issues / docs
Notes for reviewers
Before / after, measured without touching any real journal. The full suite ran twice with
HOMEpointed at a throwaway dir andGWM_HISTORY_FILE,XDG_DATA_HOME,XDG_CONFIG_HOMEunset, so the binary resolved the journal and the default base exactly as it would on a contributor's machine, inside that dir:dev(8e2eed25)d2c57e0f)~/Library/Application Support/gwm/history.tomlremove-me,drop-branch,bulk-one,bulk-three,twice,batch-ok,post-a,post-b, all fromcli_binary.rs~/cc-worktreefeat-42-trapped,feat-42-env-trapped,feat-99-broken-ledgerNo in-process test wrote the journal: every entry came from a spawned binary. The worktree leak is the same defect: the three
trusttests aroundcli_binary.rs:4341-4496write a.gwm.tomlwith no[worktree] base. On a machine with a global config, the leak followed the globalbaseinstead (21$TMPDIR/.tmp*-worktreesdirs on the reporting machine), which is whyGWM_NO_GLOBAL_CONFIG=1is in the builder, as it already is in CI.The guards fire on the real tree. Mutated in place and run: a bypass reintroduced in
em_dash_guard_tests.rsfailsonly_the_builder_spawns_the_binarywithleft: ["tests/common/mod.rs", "tests/em_dash_guard_tests.rs"]; droppingGWM_TRUST_LEDGERfrom the builder fails the docs-derived test on that variable; droppingHOMEfails the base test.Bounds, stated rather than chased.
dirs::home_dir()does not read$HOME, so on Windows only a pinned base keeps a test's worktree out of the real profile. Every test that needed one pins it now, but nothing turns red if a new one does not. Closing that needs an override in gwm itself: [Task]: let the test suite move the default worktree base on Windows #729.gwmoffPATH, or a program name held in a variable.ghwith the test process's ownHOME(it writes~/.local/state/gh/device-id, in both runs). That is gh's state, not gwm's, and it is not spawned through gwm; left alone.~/cc-worktree/.tmp*,$TMPDIR/.tmp*-worktrees) are not cleaned up by this PR.