fix(tests): serialize backend-env tests behind one lock (fixes flaky Rust Core Coverage) - #5267
Conversation
…e-wide env lock api::config::backend_env_test_lock() already unifies the BACKEND_URL / VITE_BACKEND_URL / OPENHUMAN_MEDULLA_BASE_URL race across api::config, core::cli_tests, and medulla::ops/resolve (tinyhumansai#5260 fallout). composio::ops_tests was the one remaining spot mutating BACKEND_URL via EnvVarGuard under its own module-local TEST_ENV_LOCK, which doesn't serialize against the other modules' std::env mutations on the same process-global var — the same class of race that broke the medulla "unconfigured" assertions under the full-suite Rust Core Coverage lane. Route both mock-backend tests through the shared lock as well; TEST_ENV_LOCK stays for its other config vars.
📝 WalkthroughWalkthroughTwo Composio tests now acquire a shared process-global environment lock before mutating ChangesBackend environment test synchronization
Estimated code review effort: 1 (Trivial) | ~3 minutes Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
|
| Filename | Overview |
|---|---|
| src/openhuman/composio/ops_tests.rs | Adds crate-wide backend_env_test_lock() to two tests that previously mutated BACKEND_URL under only the module-local TEST_ENV_LOCK, closing the remaining race against other modules' env-mutating tests. |
Sequence Diagram
sequenceDiagram
participant T1 as composio_get_user_profile test
participant T2 as composio_sync_gmail test
participant T3 as medulla::ops / api::config tests
Note over T1,T3: Before this PR - race on BACKEND_URL
T1->>T1: acquire TEST_ENV_LOCK
T3->>T3: acquire backend_env_test_lock
T1--xT3: BACKEND_URL mutated concurrently - flaky assertions
Note over T1,T3: After this PR - fully serialized
T1->>T1: acquire TEST_ENV_LOCK
T1->>T1: acquire backend_env_test_lock
T1->>T1: EnvVarGuard::set(BACKEND_URL, ...)
T1->>T1: run test body
T1->>T1: release backend_env_test_lock
T1->>T1: release TEST_ENV_LOCK
T3->>T3: acquire backend_env_test_lock
T3->>T3: mutate BACKEND_URL
T3->>T3: run test body
T3->>T3: release backend_env_test_lock
Reviews (1): Last reviewed commit: "fix(tests): serialize composio's BACKEND..." | Re-trigger Greptile
Summary
Root cause:
BACKEND_URL/VITE_BACKEND_URL/OPENHUMAN_MEDULLA_BASE_URLare process-global env vars mutated by tests across several modules under uncoordinated locks. Under the full-suite coverage lane (parallel test threads across modules) those mutations race and flipmedulla::ops's "unconfigured" assertions — pre-existing since #5260, deterministic underRust Core Coverage, blocking every Rust PR's coverage lane.Investigation found this was already mostly fixed on
main:d125b857fintroducedapi::config::backend_env_test_lock()as the crate-wide lock and routedapi::config,core::cli_tests,medulla::ops, andmedulla::resolvethrough it.integrations::client_testsandsocket::ws_loop_testsonly reference these vars in comments/log assertions — they never mutate them, so no change was needed.The one remaining gap:
composio::ops_testsmutatesBACKEND_URLviaEnvVarGuard::setin two mock-backend tests, serialized only by its own module-localTEST_ENV_LOCK— which doesn't coordinate with the crate-wide lock the other modules use, leaving the race open.composio_get_user_profile_via_mock_returns_provider_profileandcomposio_sync_gmail_via_mock_stores_skill_document_and_updates_outcomethroughapi::config::backend_env_test_lock()(in addition to their existingTEST_ENV_LOCK, kept for the other config vars those tests touch).Unblocks the
Rust Core Coveragelane for #5265 and every Rust PR.Test plan
cargo fmt --allGGML_NATIVE=OFF cargo test --manifest-path Cargo.toml -- medulla::ops api::config composio::ops_tests core::cli integrations::client socket::ws_loop— the 5medulla::opstests (incl. the 2 previously-racingnot_configured.../status_reports_unconfigured...) pass, 0 failedcargo clippy -p openhuman -- -D warnings— clean