Files
codex/codex-rs/models-manager/src/test_support.rs
T
ioanbudea-OAI dc40446064 Preserve model metadata origin through runtime resolution (#58361)
## What changed

Return `CatalogModel` from model lookups, keeping metadata together with its `Bundled`, `Provider`, `ExplicitConfig`, or `Synthetic` origin through config overrides and runtime snapshots. Replace `used_fallback_model_metadata` checks with explicit `Synthetic` origin checks.

Share the underlying `Arc<ModelInfo>` with extension stores and use copy-on-write for metadata changes. Keep origin tracking outside serialized model metadata.

## Testing

Extend coverage for origin retention across cache reloads, namespaced model lookups, catalog fallback, and config overrides. Verify that step snapshots and extension stores share the same model metadata allocation.

GitOrigin-RevId: bb6130c94a7a795aa168ee24664a1dd453579fba
2026-10-30 15:11:02 +00:00

41 lines
1.4 KiB
Rust

//! Test-only helpers exposed for dependent crate tests.
//!
//! Production code should not depend on this module.
use crate::CatalogModel;
use crate::ModelOrigin;
use crate::ModelsManagerConfig;
use crate::bundled_models_response;
use crate::manager::construct_model_info_from_candidates;
use codex_protocol::openai_models::ModelInfo;
use codex_protocol::openai_models::ModelPreset;
/// Get model identifier without consulting remote state or cache.
pub fn get_model_offline_for_tests(model: Option<&str>) -> String {
if let Some(model) = model {
return model.to_string();
}
let mut response = bundled_models_response().unwrap_or_default();
response.models.sort_by_key(|model| model.priority);
let presets: Vec<ModelPreset> = response.models.into_iter().map(Into::into).collect();
presets
.iter()
.find(|preset| preset.show_in_picker)
.or_else(|| presets.first())
.map(|preset| preset.model.clone())
.unwrap_or_default()
}
/// Resolve metadata and its source without consulting remote state or cache.
pub fn construct_model_info_offline_for_tests(
model: &str,
config: &ModelsManagerConfig,
) -> CatalogModel {
let candidates: &[ModelInfo] = if let Some(model_catalog) = config.model_catalog.as_ref() {
&model_catalog.models
} else {
&[]
};
construct_model_info_from_candidates(model, candidates, ModelOrigin::ExplicitConfig, config)
}