Repository navigation
Fix env race flake in cache_env scrub self-tests - #1418
Mikola Lysenko (mikolalysenko) wants to merge 1 commit into
Conversation
The cache_env self-tests ambient_{bun,vlt}_scrub_removes_only_matching_
parent_vars read the process env twice: once inside the scrub and once
to check that every matching parent var was removed. common/cache_env.rs
is compiled into ~120 test binaries, and in-process tests in the same
binary mirror --offline into the env (apply_env_toggles sets
SOCKET_OFFLINE), so a var appearing between the two reads failed the
self-test with "SOCKET_OFFLINE ... was not scrubbed" / "kept".
Snapshot the parent env once and pass that snapshot to both the scrub
and the assertions. The public scrubs behave exactly as before.
Locally in_process_edge_cases failed 8/60 runs before and 0/200 after.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018js6KeL55GXJTLwgF3bQWV
|
bugbot run Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 8f29f99. Configure here.
|
Ready for review (burn-down agent)
Generated by Claude Code |
Final review briefWhat it does. Fixes a test-only flake in Risk: low. Test helper only. No product code changes, no assertions weakened, and the public Look here
Verified. Read the full diff (one file). Checked the other self-tests in the file for the same double-read pattern; none of them read a var that in-process tests set. Changes I made. None. Open questions. None. Auto-merge is armed, so approving sends it straight to the merge queue. Generated by Claude Code |
Problem
coverage(part of theci-okgate) failed on two PR runs in the last 24h with one cargo test target red and nothing else wrong:agent/fix-ci-test-helper-copies-5):-p socket-patch-cli --test in_process_edge_casesfailed; attempt 2 on the same SHA passed, so it was a flake.agent/fix-go-selected-version-gate):-p socket-patch-cli --test vendorfailed. That binary also linkscommon/cache_env.rsand runs in-process tests. The failing test name isn't in the 5000-line log tail I could read, so I can't confirm this one is the same flake.Running the
in_process_edge_casesbinary locally 60 times with--test-threads=16failed 8 times. Every failure was one of two self-tests:common/cache_env.rsis included throughcommon/mod.rsin about 120 test binaries, so the flake can turn up in any of them that also runs in-process commands. In the merge queue, that evicts the entry.Root cause
Each self-test reads
std::env::vars_os()twice: once insidescrub_ambient_*_envand once to check that every matching parent var was removed. These self-tests are not#[serial], so they run at the same time as the binary's#[serial]in-process tests. Those tests callapply::runetc., andapply_env_toggles(src/args.rs) runsstd::env::set_var(\"SOCKET_OFFLINE\", \"1\")for--offline. If the var appears between the two reads, the second read sees a matching var that the scrub never saw.Fix
Read the parent env once (
parent_var_names). Pass that one snapshot to both the scrub (scrub_parent_vars) and the self-test's assertions. The publicscrub_ambient_bun_env/scrub_ambient_vlt_envbehave exactly as before: they read the env once and remove the matching names. No assertion is weakened. The self-tests still check that the scrub removes exactly the matching names, now against a consistent snapshot.Proof
in_process_edge_casesfailed 8 of 60 runs with--test-threads=16.cargo test -p socket-patch-cli --test vendor --test cli_parse_get cache_envpasses.rustfmtrun on the touched file only. Clippy reports nothing new incache_env.rs.No tests were moved or removed.
🤖 Generated with Claude Code
https://claude.ai/code/session_018js6KeL55GXJTLwgF3bQWV
Generated by Claude Code