Skip to content

fix(cargo-gamma): claim test caches outside the checkout - #142

Closed
Evgenii (Vaiz) wants to merge 1 commit into
mainfrom
u/vaiz/2026/09/02/gamma-cache-perm-test-work
Closed

fix(cargo-gamma): claim test caches outside the checkout#142
Evgenii (Vaiz) wants to merge 1 commit into
mainfrom
u/vaiz/2026/09/02/gamma-cache-perm-test-work

Conversation

@Vaiz

Copy link
Copy Markdown
Contributor

🤖 Clawpilot here! Posted automatically by Clawpilot (an AI agent), not by a human. Please verify before acting.

Fixes the six cargo-gamma-lib exec::workspace::tests failures that have made every main build of this repository red on Linux since #113 merged. Tracked as AB#7828809.

What is wrong

reject_foreign_writers refuses 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:

an empty cache can be claimed: Error { message: "`/mnt/vss/_work/1/s/target/test-work/owned-cache-6sb6wf`,
on the way to the redirected cache at `.../target/test-work/owned-cache-6sb6wf/cache`,
is writable by other users.", usage: true }

In the same nextest run on the same agent, cli::cache_and_artifact_directories_are_independent and session::an_incremental_command_holds_its_cache_lock_from_adoption_through_preparation — which pass --cache-dir under a TempDir::new() in the system temporary directory — passed. Only the fixtures rooted under target/ failed.

What this changes

Adds testing::cache_workdir, which creates the fixture in the system temporary directory and, on Unix, creates it with mode 0700 so a permissive umask cannot widen the terminal component either. The twelve tests that claim a redirected cache now use it; testing::workdir is 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

  • The six failing tests exercise the ownership, locking and permission behaviour they describe, on any host, rather than reporting the umask or ACL of the checkout.
  • Fixtures for these tests are no longer swept by cargo clean; they are removed when the TempDir handle drops, and by the system otherwise.
  • A new test asserts that a cache work directory is private and is not under the target directory.

Validation

  • cargo +1.97 check --package cargo-gamma-lib --all-targets for both x86_64-pc-windows-msvc and x86_64-unknown-linux-gnu, so the cfg(unix) path is type-checked.
  • cargo +1.97 test --package cargo-gamma-lib --lib for 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.

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>
Copilot AI lite review requested due to automatic review settings September 2, 2026 08:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 (with 0700 on Unix to avoid permissive umask widening).
  • Update redirected-cache claiming tests in exec::workspace to use cache_workdir() instead of workdir().
  • 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.

Comment on lines +986 to +988
assert!(dir.path().is_dir());
assert!(!dir.path().to_string_lossy().contains("test-work"));

@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.6%. Comparing base (cf95f8c) to head (18e6c5c).

❌ 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           
Flag Coverage Δ
linux 93.3% <100.0%> (?)
linux-arm 93.3% <100.0%> (?)
windows 93.9% <100.0%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Vaiz

Copy link
Copy Markdown
Contributor Author

🤖 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 target/ into the system temporary directory, leaving the production permission checks alone.

#141 is the better change: it was validated on real Linux rather than only type-checked for the cfg(unix) path, it ran the repository's own gates, and it additionally fixes process_tree::an_unkilled_grandchild_outlives_its_parent_and_finishes, the sixth failure in build 40437331, which this PR wrongly treated as an unrelated flake.

The one difference worth keeping — creating the fixture directory with an explicit 0o700 rather than inheriting the ambient umask — has been offered as a review comment on #141 (#141 (comment)). AB#7828809 tracks the defect either way.

@Vaiz
Evgenii (Vaiz) deleted the u/vaiz/2026/09/02/gamma-cache-perm-test-work branch September 2, 2026 09:17
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.

3 participants