From d1328b029995af64be2acf3f7f86ae6545bd050e Mon Sep 17 00:00:00 2001 From: ruv Date: Fri, 12 Jun 2026 01:00:58 -0400 Subject: [PATCH] test(homecore-api): serialize HOMECORE_CORS_ORIGINS env tests (fix parallel race) env_override_* and env_empty_* both set_var/remove_var the same process-global HOMECORE_CORS_ORIGINS; under full-workspace parallelism they raced (one's remove_var wiped the other's value mid-assert). Serialize via a poison-tolerant module Mutex. Test-only. Co-Authored-By: claude-flow --- v2/crates/homecore-api/src/app.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/v2/crates/homecore-api/src/app.rs b/v2/crates/homecore-api/src/app.rs index 35b7b969..210cab06 100644 --- a/v2/crates/homecore-api/src/app.rs +++ b/v2/crates/homecore-api/src/app.rs @@ -88,6 +88,11 @@ fn default_origins() -> Vec { mod tests { use super::*; + // `set_var`/`remove_var` mutate process-global state; serialize every test + // that touches HOMECORE_CORS_ORIGINS so they cannot race in parallel. + // Poison-tolerant: a panicking test must not cascade-fail the others. + static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); + #[test] fn default_origins_includes_vite_and_ha_ports() { let origins = default_origins(); @@ -98,6 +103,7 @@ mod tests { #[test] fn env_override_via_homecore_cors_origins() { + let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()); std::env::set_var("HOMECORE_CORS_ORIGINS", "https://example.com,https://other.example.com"); // build_cors_layer() returns a CorsLayer which doesn't expose // its origin list; we test the parse path indirectly by @@ -112,6 +118,7 @@ mod tests { #[test] fn env_empty_falls_back_to_defaults() { + let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()); std::env::set_var("HOMECORE_CORS_ORIGINS", " "); let raw = std::env::var("HOMECORE_CORS_ORIGINS").ok(); let trimmed = raw.as_deref().map(|s| s.trim()).unwrap_or("");