mirror of
https://github.com/instructkr/claw-code.git
synced 2026-11-07 09:37:54 +01:00
fix: isolate OPENAI_BASE_URL in provider hint test to prevent environment pollution
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
This commit is contained in:
1 parent
09f3b366ba
commit
8498f870f2
1 file changed
+32
@@ -15032,6 +15032,37 @@ mod tests {
|
|||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
use tools::GlobalToolRegistry;
|
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<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
fn registry_with_plugin_tool() -> GlobalToolRegistry {
|
||||||
GlobalToolRegistry::with_plugin_tools(vec![PluginTool::new(
|
GlobalToolRegistry::with_plugin_tools(vec![PluginTool::new(
|
||||||
"plugin-demo@external",
|
"plugin-demo@external",
|
||||||
@@ -19927,6 +19958,7 @@ UU conflicted.rs",
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn explicit_model_provider_hint_controls_runtime_provider_dispatch() {
|
fn explicit_model_provider_hint_controls_runtime_provider_dispatch() {
|
||||||
|
let _openai_base_url = EnvVarGuard::unset("OPENAI_BASE_URL");
|
||||||
let config = api::ProviderConfig {
|
let config = api::ProviderConfig {
|
||||||
kind: api::ProviderConfigKind::DashScope,
|
kind: api::ProviderConfigKind::DashScope,
|
||||||
model: "qwen-plus".to_string(),
|
model: "qwen-plus".to_string(),
|
||||||
|
|||||||
Reference in new issue
Block a user