From 0274174536390b88e2e5cef0e7dd0c3e62ba640d Mon Sep 17 00:00:00 2001 From: Bellman <54757707+Yeachan-Heo@users.noreply.github.com> Date: Tue, 13 Oct 2026 10:13:23 +0900 Subject: [PATCH] fix: isolate OPENAI_BASE_URL in provider hint test to prevent environment pollution (#3347) The test explicit_model_provider_hint_controls_runtime_provider_dispatch was failing when OPENAI_BASE_URL was set in the environment to a non-standard URL (e.g., api.layofflabs.com). The test expects the OpenAI provider to use the default base URL (api.openai.com) when no explicit base_url is provided in the ProviderConfig. This fix adds an EnvVarGuard struct to the tests module and uses it to ensure OPENAI_BASE_URL is unset before running the test, preventing environment pollution from affecting the test result. Fixes: https://github.com/ultraworkers/claw-code/issues/3345 Co-authored-by: clawdbot --- rust/crates/rusty-claude-cli/src/main.rs | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/rust/crates/rusty-claude-cli/src/main.rs b/rust/crates/rusty-claude-cli/src/main.rs index 542842c8..934fce0a 100644 --- a/rust/crates/rusty-claude-cli/src/main.rs +++ b/rust/crates/rusty-claude-cli/src/main.rs @@ -15032,6 +15032,37 @@ mod tests { use std::time::{Duration, SystemTime, UNIX_EPOCH}; use tools::GlobalToolRegistry; + /// Snapshot-restore guard for a single environment variable. + /// Captures the original value on construction, applies the override, + /// and restores on drop so tests leave the process env untouched. + struct EnvVarGuard { + key: &'static str, + previous: Option, + } + + impl EnvVarGuard { + fn unset(key: &'static str) -> Self { + let previous = std::env::var(key).ok(); + std::env::remove_var(key); + Self { key, previous } + } + + fn set(key: &'static str, value: &str) -> Self { + let previous = std::env::var(key).ok(); + std::env::set_var(key, value); + Self { key, previous } + } + } + + impl Drop for EnvVarGuard { + fn drop(&mut self) { + match &self.previous { + Some(value) => std::env::set_var(self.key, value), + None => std::env::remove_var(self.key), + } + } + } + fn registry_with_plugin_tool() -> GlobalToolRegistry { GlobalToolRegistry::with_plugin_tools(vec![PluginTool::new( "plugin-demo@external", @@ -19927,6 +19958,7 @@ UU conflicted.rs", #[test] fn explicit_model_provider_hint_controls_runtime_provider_dispatch() { + let _openai_base_url = EnvVarGuard::unset("OPENAI_BASE_URL"); let config = api::ProviderConfig { kind: api::ProviderConfigKind::DashScope, model: "qwen-plus".to_string(),