fix: resolve test isolation failures in config tests#293
fix: resolve test isolation failures in config tests#293jamiepine merged 1 commit intospacedriveapp:mainfrom
Conversation
Fix 19 failing config tests caused by environment variable pollution and mutex poisoning. Changes: - Add ANTHROPIC_BASE_URL to EnvGuard cleanup list (was leaking from shell env) - Replace std::sync::Mutex with parking_lot::Mutex for test synchronization - Simplify lock acquisition (parking_lot doesn't poison on panic) - Add EnvGuard to two tests missing proper isolation Technical Details: - parking_lot::Mutex doesn't suffer from poisoning behavior, preventing cascading test failures when one test panics - EnvGuard now clears 27 env vars (was 26), including ANTHROPIC_BASE_URL which was causing assertion failures in anthropic provider tests Verification: - All 301 lib tests pass - cargo clippy --lib clean Refs: .github/issues/test-isolation-failures.md Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
WalkthroughChanges to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/config.rs (1)
6694-6721:⚠️ Potential issue | 🟠 MajorInclude
ANTHROPIC_AUTH_TOKENinEnvGuardcleanup.
EnvGuard::new()clearsANTHROPIC_API_KEYandANTHROPIC_BASE_URL, but notANTHROPIC_AUTH_TOKEN. Since config loading readsANTHROPIC_AUTH_TOKEN(Line 3756 and Line 4429), shell state can still leak into tests.Proposed fix
- const KEYS: [&str; 27] = [ + const KEYS: [&str; 28] = [ "SPACEBOT_DIR", "SPACEBOT_DEPLOYMENT", "SPACEBOT_CRON_TIMEZONE", "SPACEBOT_USER_TIMEZONE", "ANTHROPIC_API_KEY", "ANTHROPIC_BASE_URL", + "ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_OAUTH_TOKEN", "OPENAI_API_KEY", "OPENROUTER_API_KEY", "KILO_API_KEY", "ZHIPU_API_KEY", "GROQ_API_KEY", "TOGETHER_API_KEY", "FIREWORKS_API_KEY", "DEEPSEEK_API_KEY", "XAI_API_KEY", "MISTRAL_API_KEY", "GEMINI_API_KEY", "NVIDIA_API_KEY", "OLLAMA_API_KEY", "OLLAMA_BASE_URL", "OPENCODE_ZEN_API_KEY", "OPENCODE_GO_API_KEY", "MINIMAX_API_KEY", "MINIMAX_CN_API_KEY", "MOONSHOT_API_KEY", "ZAI_CODING_PLAN_API_KEY", ];🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/config.rs` around lines 6694 - 6721, EnvGuard::new() currently clears environment keys listed in the KEYS array but omits "ANTHROPIC_AUTH_TOKEN", allowing that value to leak into tests; update the KEYS constant inside EnvGuard::new() to include "ANTHROPIC_AUTH_TOKEN" so the guard clears that variable as well (this directly ties to EnvGuard and the config code paths that read ANTHROPIC_AUTH_TOKEN during config loading).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/config.rs`:
- Around line 6694-6721: EnvGuard::new() currently clears environment keys
listed in the KEYS array but omits "ANTHROPIC_AUTH_TOKEN", allowing that value
to leak into tests; update the KEYS constant inside EnvGuard::new() to include
"ANTHROPIC_AUTH_TOKEN" so the guard clears that variable as well (this directly
ties to EnvGuard and the config code paths that read ANTHROPIC_AUTH_TOKEN during
config loading).
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Cargo.tomlis excluded by!**/*.toml
📒 Files selected for processing (1)
src/config.rs
Summary
Fixes 19 failing config tests on main caused by environment variable pollution and mutex poisoning issues.
Problem
Tests in
src/config.rswere failing due to:ANTHROPIC_BASE_URLfrom shell environment was leaking into tests that expected the default Anthropic URLstd::sync::Mutexgets poisoned when tests panic, causing all subsequent tests to fail when acquiring the lockChanges
parking_lotdev-dependency: ProvidesMutexthat doesn't poison on panicEnvGuard: AddedANTHROPIC_BASE_URLto the list of env vars to clear (27 total now)lock()returns directly (no Result wrapper)test_legacy_llm_keys_auto_migrate_to_providers,all_shorthand_keys_register_providers_via_toml) now useEnvGuardVerification
Related
🤖 Generated with Claude Code