mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-31 00:29:24 +00:00
fix(tests): eliminate env mutex poison cascade (#1558)
* fix(tests): eliminate env mutex poison cascade and fix test flakiness The shared ENV_MUTEX used by ~68 config tests would cascade a single test panic into failures across every module. Replace all .unwrap() / .expect() lock acquisitions with a poison-recovering lock_env() helper. Consolidate rogue module-local ENV_LOCK instances (workspace, orchestrator, bootstrap) onto the shared global mutex to prevent cross-module races. Also fixes: - gateway user_id fallback was hardcoded to "default" instead of owner_id - test_ironclaw_env_path used LazyLock which is order-dependent Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * test(helpers): add regression test for lock_env poison recovery Satisfies the regression-test-check CI gate by adding a test that intentionally poisons ENV_MUTEX and verifies lock_env() recovers. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix(ci): detect test changes inside #[cfg(test)] regions The regression test check relied on git diff -W to expand context to function boundaries, but git doesn't recognize Rust `mod tests {}` as a function boundary. Changes to imports, helpers, or lock calls inside test modules were invisible to the check. Add a line-level fallback: for each changed .rs file, find where #[cfg(test)] starts and check if any diff hunk targets a line at or after that boundary. This catches edits anywhere inside test modules regardless of git's language awareness. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: address PR review feedback - Clear ENV_MUTEX poison after regression test so it doesn't leave global state dirty for subsequent tests. - Fix CI regression-test-check to match #[cfg(test)] only when followed by `mod` (the test module pattern), avoiding false positives from standalone #[cfg(test)] items like statics or functions. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
fbce9a5fe3
commit
3aa36c8f55
@@ -7305,9 +7305,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn should_use_gateway_mode_true_for_tunnel_url() {
|
||||
let _guard = crate::config::helpers::ENV_MUTEX
|
||||
.lock()
|
||||
.expect("env mutex poisoned");
|
||||
let _guard = crate::config::helpers::lock_env();
|
||||
let original = std::env::var("IRONCLAW_OAUTH_CALLBACK_URL").ok();
|
||||
// SAFETY: Under ENV_MUTEX, no concurrent env access.
|
||||
unsafe {
|
||||
@@ -7329,9 +7327,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn should_use_gateway_mode_false_without_tunnel() {
|
||||
let _guard = crate::config::helpers::ENV_MUTEX
|
||||
.lock()
|
||||
.expect("env mutex poisoned");
|
||||
let _guard = crate::config::helpers::lock_env();
|
||||
let original = std::env::var("IRONCLAW_OAUTH_CALLBACK_URL").ok();
|
||||
unsafe {
|
||||
std::env::remove_var("IRONCLAW_OAUTH_CALLBACK_URL");
|
||||
@@ -7352,9 +7348,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn should_use_gateway_mode_false_for_loopback_tunnel() {
|
||||
let _guard = crate::config::helpers::ENV_MUTEX
|
||||
.lock()
|
||||
.expect("env mutex poisoned");
|
||||
let _guard = crate::config::helpers::lock_env();
|
||||
let original = std::env::var("IRONCLAW_OAUTH_CALLBACK_URL").ok();
|
||||
unsafe {
|
||||
std::env::remove_var("IRONCLAW_OAUTH_CALLBACK_URL");
|
||||
@@ -7382,9 +7376,7 @@ mod tests {
|
||||
|
||||
impl EnvGuard {
|
||||
fn new() -> Self {
|
||||
let guard = crate::config::helpers::ENV_MUTEX
|
||||
.lock()
|
||||
.expect("env mutex poisoned");
|
||||
let guard = crate::config::helpers::lock_env();
|
||||
let original = std::env::var("IRONCLAW_OAUTH_CALLBACK_URL").ok();
|
||||
// SAFETY: Under ENV_MUTEX, no concurrent env access.
|
||||
unsafe {
|
||||
@@ -7442,9 +7434,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn gateway_callback_redirect_uri_does_not_duplicate_callback_path_from_env() {
|
||||
let _guard = crate::config::helpers::ENV_MUTEX
|
||||
.lock()
|
||||
.expect("env mutex poisoned");
|
||||
let _guard = crate::config::helpers::lock_env();
|
||||
let original = std::env::var("IRONCLAW_OAUTH_CALLBACK_URL").ok();
|
||||
unsafe {
|
||||
std::env::set_var(
|
||||
@@ -7470,9 +7460,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn gateway_callback_redirect_uri_trims_trailing_slash_from_env_callback() {
|
||||
let _guard = crate::config::helpers::ENV_MUTEX
|
||||
.lock()
|
||||
.expect("env mutex poisoned");
|
||||
let _guard = crate::config::helpers::lock_env();
|
||||
let original = std::env::var("IRONCLAW_OAUTH_CALLBACK_URL").ok();
|
||||
unsafe {
|
||||
std::env::set_var(
|
||||
|
||||
Reference in New Issue
Block a user