test-tonic: use a writable per-machine CARGO_HOME - #34291
Conversation
The fixture has no Cargo.lock, so cargo resolves fresh and will pick up new patch versions of transitive deps. When http-body-util 0.1.4 landed on 2026-07-13, the darwin-aarch64 lane failed because the agent user on that box cannot write to the shared /opt/rust registry cache: error: failed to open `/opt/rust/registry/cache/.../http-body-util-0.1.4.crate` Caused by: Permission denied (os error 13) Point CARGO_HOME at the existing bun-test-tonic-cache directory (already used for CARGO_TARGET_DIR) so cargo writes its registry to a location the test runner always owns, instead of inheriting a system CARGO_HOME that may belong to a different user. RUSTUP_HOME stays inherited since rustup only needs read access to locate the toolchain.
WalkthroughChangesTonic Cargo environment
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
LGTM — straightforward test-infra fix pointing CARGO_HOME at the same writable per-machine cache dir already used for CARGO_TARGET_DIR.
Checked that cargo auto-creates $CARGO_HOME (and its parent) on first use, so no explicit mkdir is needed even on a fresh box where cacheDir doesn't exist yet. RUSTUP_HOME is still inherited, so toolchain discovery is unaffected. The registry cache persists across runs alongside the existing target cache, so warm-run timing shouldn't regress.
Extended reasoning...
Overview
Single-file test-infrastructure change to test/js/third_party/grpc-js/test-tonic.test.ts. Replaces CARGO_HOME: process.env.CARGO_HOME in the spawned cargo run env with CARGO_HOME: join(cacheDir, "cargo-home"), where cacheDir is the existing $TMPDIR/bun-test-tonic-cache directory that already hosts CARGO_TARGET_DIR. The accompanying comment is updated to explain why (agent user may not have write access to the system CARGO_HOME).
Security risks
None. This only changes an environment variable passed to a test-fixture subprocess that builds a local Rust gRPC server. No auth, crypto, or user-facing surface is touched.
Level of scrutiny
Low. Test-only, no src/ diff, and the change mirrors the exact pattern already in use one line below for CARGO_TARGET_DIR. The failure mode it addresses (EACCES writing to a read-only shared /opt/rust) and the fix (redirect to a user-writable tmpdir cache) are both well-understood cargo behaviors.
Other factors
- Cargo creates
$CARGO_HOMEand its subdirectories on demand, so there's no need for the test to pre-createcargo-homeeven whencacheDiritself doesn't exist yet — same as the existingCARGO_TARGET_DIRhandling. RUSTUP_HOME/RUSTUP_TOOLCHAINremain inherited, so rustup can still locate the read-only system toolchain; only the writable registry cache is relocated.- The cache persists in
tmpdir()across runs on persistent CI agents, matching the intent of the surrounding code (protoc zip and target dir already live there). - No prior reviewer comments to address; bug hunter found nothing.
|
Closing: the root cause was the host agent on The redirect in this PR would also have dropped the only cache that actually persisted across runs ( |
test/js/third_party/grpc-js/test-tonic.test.tswent red on the:darwin: 14 aarch64lane in build 73477:Cause
The tonic-server fixture has no
Cargo.lock, so every run resolves against the current crates.io index.http-body-util 0.1.4was published on 2026-07-13, so cargo now wants to download it into$CARGO_HOME/registry/cache/.On
darwin-test-arm64-1the agent was moved fromadministratortociadminon Jul 9 (see #33970), but/opt/rust(the box's sharedCARGO_HOME/RUSTUP_HOME) is still owned byadministratorwith theregistry/subtree atdrwxr-xr-x, sociadmincan read existing crates but cannot write new ones. The test forwardedCARGO_HOME: process.env.CARGO_HOME, so cargo tried to create the new.cratefile under/opt/rust/registry/cache/and gotEACCES.All other darwin test boxes still run the agent as
administrator;darwin-test-arm64-1is the only one with this user mismatch.Fix
Point
CARGO_HOMEat the same per-machine cache directory that already holdsCARGO_TARGET_DIR($TMPDIR/bun-test-tonic-cache/cargo-home). That directory is created by the test runner's own user, so cargo can always write its registry there, regardless of which user owns the system rust install.RUSTUP_HOMEstays inherited (rustup only needs read access to locate the toolchain). The registry cache is ~100 MB and persists alongside the 500 MB target dir that was already there, so warm runs are unchanged.Verification
With
CARGO_HOMEinherited from a location the runner cannot write to:tonic server exited (101) ... Permission denied (os error 13)$TMPDIR/bun-test-tonic-cache/cargo-home, server builds and listens,flow control should work in both directionspasses (cold ~36s, warm ~16s).Test-only change; no
src/diff.The box-level user/ownership mismatch on
darwin-test-arm64-1is being handled separately.no test proof · iteration 0 · Platform-specific test-only change; deferring to CI.