Skip to content

fix(test): serialise env-mutating tests behind one lock - #178

Merged
jayhesselberth merged 1 commit into
mainfrom
fix/env-test-race
Aug 1, 2026
Merged

fix(test): serialise env-mutating tests behind one lock#178
jayhesselberth merged 1 commit into
mainfrom
fix/env-test-race

Conversation

@jayhesselberth

Copy link
Copy Markdown
Member

Found while verifying #177 — pre-existing and unrelated to it, so separated.

demux::models::cache_dir_precedence fails intermittently under cargo test --all-features, asserting on a path that belongs to a different test:

left: "/tmp/.tmpjgdEfz"   right: "/x/cache"

Cargo runs tests in parallel threads; the environment is per-process, not per-thread. One test's set_var lands inside another's assertion.

Both temp_env helpers carried // SAFETY: single-threaded test bodies — which is not true of a parallel test runner. The comment asserted the invariant instead of establishing it.

resquiggle_models did take a mutex, but a module-local one, so it serialised against itself and not against demux::models — which is the pair that actually collides.

One shared test_env::temp_env behind a process-wide lock now, used by both. That makes the SAFETY claim true rather than aspirational, and drops the duplicated helper.

Verified: 10/10 consecutive --all-features runs clean (it was reproducible within a few before), 58 tests, still passing serially, fmt and clippy clean.

🤖 Generated with Claude Code

`demux::models::cache_dir_precedence` fails intermittently under
`cargo test --all-features`, asserting on a path belonging to a different test:

    left: "/tmp/.tmpjgdEfz"   right: "/x/cache"

Cargo runs tests in parallel threads and the environment is per-process, not
per-thread, so one test's `set_var` lands inside another's assertion. Both
`temp_env` helpers carried `// SAFETY: single-threaded test bodies`, which is
not true of a parallel runner — the comment asserted the invariant rather than
establishing it.

resquiggle_models' copy did take a mutex, but a module-local one, so it
serialised against itself and not against demux::models — which is the pair
that actually collides.

One shared `test_env::temp_env` behind a process-wide lock now, used by both.
That makes the SAFETY claim true rather than aspirational, and removes the
duplicate helper.

Verified: 10/10 consecutive `--all-features` runs clean (was reproducible
within a few), 58 tests, and the same passing serially.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jayhesselberth
jayhesselberth merged commit 0ba9540 into main Aug 1, 2026
10 checks passed
@jayhesselberth
jayhesselberth deleted the fix/env-test-race branch August 1, 2026 16:55
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.

1 participant