Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion codex-rs/core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ impl Config {
let mut model_providers = built_in_model_providers();
// Merge user-defined providers into the built-in list.
for (key, provider) in cfg.model_providers.into_iter() {
model_providers.entry(key).or_insert(provider);
model_providers.insert(key, provider);
}

let model_provider_id = model_provider
Expand Down Expand Up @@ -3815,6 +3815,52 @@ trust_level = "untrusted"

Ok(())
}

/// Regression test for https://github.com/openai/codex/issues/8240
/// User-defined model providers in config.toml should override built-in
/// providers with the same key (e.g., "ollama" with a custom base_url).
#[test]
fn test_user_defined_provider_overrides_builtin() -> std::io::Result<()> {
// Define a custom "ollama" provider with a remote base_url
let toml = r#"
[model_providers.ollama]
name = "Remote Ollama"
base_url = "http://192.168.1.50:11434/v1"
wire_api = "responses"
"#;

let cfg: ConfigToml = toml::from_str(toml).expect("TOML deserialization should succeed");

let cwd_temp_dir = TempDir::new().unwrap();
let cwd = cwd_temp_dir.path().to_path_buf();
std::fs::write(cwd.join(".git"), "gitdir: nowhere")?;

let codex_home_temp_dir = TempDir::new().unwrap();

let config = Config::load_from_base_config_with_overrides(
cfg,
ConfigOverrides {
cwd: Some(cwd),
..Default::default()
},
codex_home_temp_dir.path().to_path_buf(),
)?;

// Verify the "ollama" provider was overridden with user's config
let ollama_provider = config
.model_providers
.get("ollama")
.expect("ollama provider should exist");

assert_eq!(ollama_provider.name, "Remote Ollama");
assert_eq!(
ollama_provider.base_url,
Some("http://192.168.1.50:11434/v1".to_string())
);
Comment on lines +3855 to +3859
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use pretty_assertions::assert_eq in tests

The repo root AGENTS.md specifies under “Test assertions” that tests should use pretty_assertions::assert_eq for clearer diffs. This new test uses the standard assert_eq! (see the comparisons here), which violates that guideline and makes failure output harder to read. Please import pretty_assertions::assert_eq in the test module and use it for these comparisons, per /workspace/codex/AGENTS.md.

Useful? React with 👍 / 👎.

assert_eq!(ollama_provider.wire_api, crate::WireApi::Responses);

Ok(())
}
}

#[cfg(test)]
Expand Down
Loading