fix(mcp): fix test_allows_safe_env_vars test failure
All checks were successful
Test / rust-fmt-check (pull_request) Successful in 1m27s
Test / frontend-tests (pull_request) Successful in 1m31s
Test / frontend-typecheck (pull_request) Successful in 1m34s
Test / rust-clippy (pull_request) Successful in 3m8s
Test / rust-tests (pull_request) Successful in 4m33s
PR Review Automation / review (pull_request) Successful in 4m47s

The test was trying to spawn a process which requires a Tokio runtime.
Changed the test to only verify validation logic by checking that safe
environment variables don't trigger 'Dangerous environment variable' errors.

Uses /usr/bin/nonexistent as command so spawn will fail (command not found)
but validation will pass for safe env vars like DEBUG, API_KEY, PATH, etc.

All 243 tests now passing.
This commit is contained in:
Shaun Arman 2026-06-01 12:41:26 -05:00
parent 0469f121b1
commit 7c2452e3f7

View File

@ -102,22 +102,33 @@ mod tests {
#[test] #[test]
fn test_allows_safe_env_vars() { fn test_allows_safe_env_vars() {
let mut env = HashMap::new(); // Test that safe env vars pass validation (validation happens before spawn)
env.insert("DEBUG".to_string(), "1".to_string()); let safe_vars = vec![
env.insert("API_KEY".to_string(), "secret123".to_string()); ("DEBUG", "1"),
env.insert("PATH".to_string(), "/usr/bin".to_string()); ("API_KEY", "secret123"),
("PATH", "/usr/bin"),
("HOME", "/home/user"),
("GITHUB_PERSONAL_ACCESS_TOKEN", "ghp_token"),
("LOG_LEVEL", "info"),
];
// Note: This will fail to spawn since /usr/bin/test may not exist, for (key, value) in safe_vars {
// but we're testing that it doesn't reject the env vars let mut env = HashMap::new();
let result = build_stdio_transport("/usr/bin/test", &[], env); env.insert(key.to_string(), value.to_string());
// Should fail with spawn error, not env var validation error // This will fail to spawn since /usr/bin/nonexistent doesn't exist,
if let Err(err) = result { // but if validation passed, error won't mention "Dangerous environment variable"
assert!( let result = build_stdio_transport("/usr/bin/nonexistent", &[], env);
!err.contains("Dangerous environment variable"),
"Should not reject safe env vars, got: {}", // Validation passes (doesn't reject env var), spawn fails (command doesn't exist)
err if let Err(err) = result {
); assert!(
!err.contains("Dangerous environment variable"),
"Should not reject safe env var '{}', got: {}",
key,
err
);
}
} }
} }
} }