Fix regex model mapping direction

This commit is contained in:
fawney19
2026-05-11 01:43:14 +08:00
parent c9c968c2e9
commit 7b81c77424
3 changed files with 27 additions and 4 deletions

View File

@@ -183,7 +183,9 @@ pub fn resolve_provider_model_name_with_model_directives(
for pattern in global_model_mappings {
if matches_model_mapping(pattern, allowed_model) {
let allowed_model = allowed_model.to_owned();
return Some((allowed_model.clone(), Some(allowed_model)));
// Regex mappings prove the key can serve this global model; they do not
// override the provider model chosen from the Provider model mapping.
return Some((selected_provider_model_name.clone(), Some(allowed_model)));
}
}
}
@@ -392,7 +394,9 @@ mod tests {
resolve_requested_global_model_name_with_model_directives, row_supports_requested_model,
row_supports_requested_model_with_model_directives,
};
use aether_data_contracts::repository::candidate_selection::StoredMinimalCandidateSelectionRow;
use aether_data_contracts::repository::candidate_selection::{
StoredMinimalCandidateSelectionRow, StoredProviderModelMapping,
};
#[test]
fn model_mapping_match_is_case_insensitive() {
@@ -411,6 +415,25 @@ mod tests {
assert!(!matches_model_mapping("([a-z", "gpt-4o"));
}
#[test]
fn regex_allowed_model_does_not_replace_selected_provider_model_name() {
let mut row = sample_row("gpt-5", "gpt-5-upstream");
row.key_allowed_models = Some(vec!["gpt-5.4".to_string()]);
row.global_model_mappings = Some(vec!["gpt-5(?:\\.\\d+)?".to_string()]);
row.model_provider_model_mappings = Some(vec![StoredProviderModelMapping {
name: "gpt-5-canonical-upstream".to_string(),
priority: 1,
api_formats: Some(vec!["openai:chat".to_string()]),
endpoint_ids: None,
}]);
let resolved = resolve_provider_model_name(&row, "gpt-5", "openai:chat")
.expect("regex-matched allowed model should allow the key");
assert_eq!(resolved.0, "gpt-5-canonical-upstream");
assert_eq!(resolved.1.as_deref(), Some("gpt-5.4"));
}
#[test]
fn model_directive_suffix_matches_base_model_as_fallback() {
let row = sample_row("gpt-5.4", "gpt-5.4-upstream");