fix(cargo-gamma): claim test caches outside the checkout - #142
fix(cargo-gamma): claim test caches outside the checkout#142Evgenii (Vaiz) wants to merge 1 commit into
Conversation
The redirected-cache checks refuse a cache whose directory, or any directory above it, another local user can write to. Every fixture for those tests was created by `testing::workdir` under `target/test-work`, and on the Linux build agents that publish this repository everything under the checkout comes out group-writable, so six tests failed on their own fixture's ancestry rather than on the behaviour they describe. Add `testing::cache_workdir`, which puts the fixture in the system temporary directory and creates it private so a permissive umask cannot widen it, and use it for every test that claims a redirected cache. The end-to-end `--cache-dir` tests already root their scratch space there and passed on the same agent in the same run. The production checks are unchanged: what moved is where the tests ask them the question. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The newly added test uses a brittle substring check (contains("test-work")) that can mis-assert the directory location and should be replaced with a path-prefix check.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes flaky/host-dependent cargo-gamma-lib workspace cache-claiming tests on Linux build agents by moving redirected-cache fixtures out of the workspace checkout (target/test-work) and into the system temp directory, ensuring ancestor permissions don’t cause the tests to fail before exercising the intended behavior.
Changes:
- Add
testing::cache_workdir()to create redirected-cache fixtures in the system temp directory (with0700on Unix to avoid permissive umask widening). - Update redirected-cache claiming tests in
exec::workspaceto usecache_workdir()instead ofworkdir(). - Add a unit test validating the new cache workdir is private (Unix) and not rooted under the target work directory.
File summaries
| File | Description |
|---|---|
| crates/cargo-gamma-lib/src/testing.rs | Adds cache_workdir() and a new test asserting privacy/location expectations for cache fixtures. |
| crates/cargo-gamma-lib/src/exec/workspace.rs | Switches redirected-cache claiming tests to use the new cache fixture directory helper. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| assert!(dir.path().is_dir()); | ||
| assert!(!dir.path().to_string_lossy().contains("test-work")); | ||
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (97.6%) is below the target coverage (100.0%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #142 +/- ##
=====================================
Coverage 97.6% 97.6%
=====================================
Files 290 290
Lines 65894 65907 +13
=====================================
+ Hits 64352 64365 +13
Misses 1542 1542
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
🤖 Clawpilot here! Posted automatically by Clawpilot (an AI agent), not by a human. Please verify before acting. Closing as a duplicate of #141, which was opened an hour earlier and reaches the same diagnosis and the same fix — move the twelve redirected-cache fixtures out of #141 is the better change: it was validated on real Linux rather than only type-checked for the The one difference worth keeping — creating the fixture directory with an explicit |
🤖 Clawpilot here! Posted automatically by Clawpilot (an AI agent), not by a human. Please verify before acting.
Fixes the six
cargo-gamma-libexec::workspace::testsfailures that have made everymainbuild of this repository red on Linux since #113 merged. Tracked as AB#7828809.What is wrong
reject_foreign_writersrefuses a redirected cache whose directory, or any directory above it, another local user can write to. That is the intended behaviour and it is unchanged here.The fixtures for those tests come from
testing::workdir, which roots everything at<workspace>/target/test-work. On the 1ES Linux agents that publish this repository, directories created under the checkout come out group-writable, so the ancestry of the fixture is refused before any of the behaviour under test is reached. The tests were measuring the agent's filesystem, not the code.The Windows jobs are unaffected — the check is
cfg(unix)and a no-op elsewhere — and so are GitHub-hosted runners, which is why PR CI stayed green while the publish pipeline failed.Evidence from build
40468645:In the same nextest run on the same agent,
cli::cache_and_artifact_directories_are_independentandsession::an_incremental_command_holds_its_cache_lock_from_adoption_through_preparation— which pass--cache-dirunder aTempDir::new()in the system temporary directory — passed. Only the fixtures rooted undertarget/failed.What this changes
Adds
testing::cache_workdir, which creates the fixture in the system temporary directory and, on Unix, creates it with mode0700so a permissive umask cannot widen the terminal component either. The twelve tests that claim a redirected cache now use it;testing::workdiris untouched and still serves the tests that shell out to cargo and want their scratch space beside the target directory.No production code is modified. What moved is where the tests ask the question.
Effects
cargo clean; they are removed when theTempDirhandle drops, and by the system otherwise.Validation
cargo +1.97 check --package cargo-gamma-lib --all-targetsfor bothx86_64-pc-windows-msvcandx86_64-unknown-linux-gnu, so thecfg(unix)path is type-checked.cargo +1.97 test --package cargo-gamma-lib --libfor the cache and testing suites.cargo +nightly-2026-01-21 fmt.The failure itself cannot be reproduced on this Windows host, so the decisive confirmation is the next Linux run.