Skip to content

harden(unit-tests): the actual env race lives in src/core/utils.rs (parent-env mutation), not tests/ #69

Closed

Description

@thehoff

Context

Filed as a follow-up to #48 (PR #68). When working on #48, the dispatched agent noted:

"The integration tests under tests/ do not actually mutate parent-process env. Every env mutation in the 7 integration suites is Command::env(...), which mutates only the child's environment block at spawn time and cannot race across parallel tests."

The actual race surface is in src/core/utils.rs unit tests that use std::env::set_var / std::env::remove_var. There is already a GLOBAL_ENV_LOCK at src/core/utils.rs:1525 covering ONE block, but other env-mutating unit tests in the same file don't grab it.

Symptom

Running cargo test --bin contextcrawler in parallel mode (the default) can theoretically interleave env mutations across the unit-test binary, producing flaky test failures. None observed in the current session but the surface is real.

Fix scope

Audit src/core/utils.rs (and adjacent src/core/*.rs) for std::env::set_var / remove_var / env::vars()-walk patterns inside #[test] or #[cfg(test)] blocks. Add the existing GLOBAL_ENV_LOCK guard to each.

If the pattern is widespread, consider moving the lock to the same tests/common/mod.rs location from #48 and re-exporting via a private #[cfg(test)] module — or keep them separate since the parent-env mutation surface is fundamentally different from the child-env one PR #68 covered.

Why split

Issue #48's dispatch contract forbade src/ touches; that work has shipped. This issue captures the residual real-bug surface as a separate scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions