mirror of
https://github.com/openai/codex.git
synced 2026-04-30 09:26:44 +00:00
chore: rm hardcoded PRESETS list (#12650)
rm `PRESETS` list harcoded in `model_presets` as we now have bundled `models.json` with equivalent info. update logic to rely on bundled models instead, update tests.
This commit is contained in:
@@ -665,7 +665,7 @@ pub(crate) fn deserialize_config_toml_with_base(
|
||||
|
||||
fn load_catalog_json(path: &AbsolutePathBuf) -> std::io::Result<ModelsResponse> {
|
||||
let file_contents = std::fs::read_to_string(path)?;
|
||||
serde_json::from_str::<ModelsResponse>(&file_contents).map_err(|err| {
|
||||
let catalog = serde_json::from_str::<ModelsResponse>(&file_contents).map_err(|err| {
|
||||
std::io::Error::new(
|
||||
ErrorKind::InvalidData,
|
||||
format!(
|
||||
@@ -673,7 +673,17 @@ fn load_catalog_json(path: &AbsolutePathBuf) -> std::io::Result<ModelsResponse>
|
||||
path.display()
|
||||
),
|
||||
)
|
||||
})
|
||||
})?;
|
||||
if catalog.models.is_empty() {
|
||||
return Err(std::io::Error::new(
|
||||
ErrorKind::InvalidData,
|
||||
format!(
|
||||
"model_catalog_json path `{}` must contain at least one model",
|
||||
path.display()
|
||||
),
|
||||
));
|
||||
}
|
||||
Ok(catalog)
|
||||
}
|
||||
|
||||
fn load_model_catalog(
|
||||
@@ -4466,6 +4476,32 @@ config_file = "./agents/researcher.toml"
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn model_catalog_json_rejects_empty_catalog() -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let catalog_path = codex_home.path().join("catalog.json");
|
||||
std::fs::write(&catalog_path, r#"{"models":[]}"#)?;
|
||||
|
||||
let cfg = ConfigToml {
|
||||
model_catalog_json: Some(AbsolutePathBuf::from_absolute_path(catalog_path)?),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let err = Config::load_from_base_config_with_overrides(
|
||||
cfg,
|
||||
ConfigOverrides::default(),
|
||||
codex_home.path().to_path_buf(),
|
||||
)
|
||||
.expect_err("empty custom catalog should fail config load");
|
||||
|
||||
assert_eq!(err.kind(), ErrorKind::InvalidData);
|
||||
assert!(
|
||||
err.to_string().contains("must contain at least one model"),
|
||||
"unexpected error: {err}"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_test_fixture() -> std::io::Result<PrecedenceTestFixture> {
|
||||
let toml = r#"
|
||||
model = "o3"
|
||||
|
||||
Reference in New Issue
Block a user