返回 CodeWhale
reviewed.rs
根目录 / crates / config / src / catalog / reviewed.rs
1 //! Pure reviewed model facts in the existing catalog owner.
2 //!
3 //! `catalog_corrections.json.reviewed` is the only owner of these facts; the
4 //! bundled Models.dev seed carries none. Live/config/account rows never enter
5 //! this projection. An intrinsic fact or alias is metadata, not route authority;
6 //! executable requests still pass through the existing scoped RouteResolver.
7
8 use std::collections::{BTreeMap, BTreeSet};
9
10 use serde::{Deserialize, Serialize};
11
12 use crate::models_dev::{ModelsDevCatalog, ModelsDevModel};
13 use crate::route::{
14 CapabilityState, ModelId, ProviderId, ProviderModelOffering, RouteCapabilities, RouteLimits,
15 WireModelId,
16 };
17
18 /// Coarse model family for presentation only; never selects a provider.
19 #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
20 pub enum ModelFamily {
21 DeepSeek,
22 Anthropic,
23 OpenAi,
24 OpenAiCodex,
25 Moonshot,
26 Zai,
27 Minimax,
28 Stepfun,
29 Qwen,
30 Arcee,
31 Together,
32 XiaomiMimo,
33 Meta,
34 Xai,
35 Mistral,
36 Google,
37 Other,
38 }
39
40 /// Reviewed intrinsic facts. Missing fields remain unknown. The generation
41 /// default is separate from the route maximum (notably Kimi K3).
42 #[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
43 #[serde(deny_unknown_fields)]
44 pub struct IntrinsicModel {
45 #[serde(default)]
46 pub canonical_id: Option<String>,
47 #[serde(default)]
48 pub context_window: Option<u32>,
49 #[serde(default)]
50 pub max_output: Option<u32>,
51 #[serde(default)]
52 pub generation_default: Option<u32>,
53 #[serde(default)]
54 pub reasoning: Option<bool>,
55 #[serde(default)]
56 pub thought_signatures_required: Option<bool>,
57 #[serde(default)]
58 pub thinking_can_disable: Option<bool>,
59 #[serde(default)]
60 pub family: Option<ModelFamily>,
61 #[serde(default)]
62 pub display_name: Option<String>,
63 #[serde(default)]
64 pub aliases: Vec<String>,
65 #[serde(default)]
66 pub modalities: Vec<String>,
67 #[serde(default)]
68 pub supported_parameters: Vec<String>,
69 #[serde(default)]
70 pub capabilities: RouteCapabilities,
71 #[serde(default)]
72 pub architecture: Option<serde_json::Value>,
73 #[serde(default)]
74 pub latency: Option<serde_json::Value>,
75 pub source: String,
76 }
77
78 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
79 #[serde(deny_unknown_fields)]
80 pub struct ModelSelection {
81 pub provider: String,
82 pub id: String,
83 pub supports_tools: bool,
84 pub supports_reasoning: bool,
85 }
86
87 /// Pure transport facts required by model-aware providers, without a second
88 /// routing implementation or pricing authority.
89 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
90 #[serde(deny_unknown_fields)]
91 pub struct ReviewedTransport {
92 pub provider: String,
93 pub id: String,
94 pub endpoint_key: String,
95 #[serde(default)]
96 pub canonical_model: Option<String>,
97 #[serde(default)]
98 pub default_for_provider: bool,
99 #[serde(default)]
100 pub limits: RouteLimits,
101 #[serde(default)]
102 pub capabilities: RouteCapabilities,
103 pub source: String,
104 }
105
106 impl ReviewedTransport {
107 #[must_use]
108 pub fn to_offering(&self) -> ProviderModelOffering {
109 ProviderModelOffering {
110 provider: ProviderId::from(self.provider.clone()),
111 canonical_model: self.canonical_model.clone().map(ModelId::from),
112 wire_model_id: WireModelId::from(self.id.clone()),
113 endpoint_key: self.endpoint_key.clone(),
114 default_for_provider: self.default_for_provider,
115 limits: self.limits,
116 capabilities: self.capabilities,
117 pricing: crate::route::PricingSku::UnknownOrStale,
118 }
119 }
120 }
121
122 /// Reviewed reference observations used by metadata-only presentation. They
123 /// never substitute for scoped live prices or authenticated billing facts.
124 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
125 #[serde(deny_unknown_fields)]
126 pub struct ReferencePrice {
127 pub input: f64,
128 pub output: f64,
129 pub cache_read: f64,
130 #[serde(default)]
131 pub cache_write: Option<f64>,
132 pub source: String,
133 }
134
135 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
136 #[serde(deny_unknown_fields)]
137 pub struct PublicModel {
138 pub id: String,
139 pub label: Option<String>,
140 pub added_at: Option<String>,
141 pub aliases: Vec<String>,
142 }
143
144 /// A retained compile-time contract name projected from an intrinsic field.
145 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
146 #[serde(deny_unknown_fields)]
147 pub struct NumericRef {
148 pub model: String,
149 pub field: String,
150 }
151
152 /// Supplement to Models.dev's intrinsic/offering schema. The original tables
153 /// are retired into this one reviewed data owner, not reloaded from a global
154 /// provider cache. Runtime catalogs retain their existing scope and precedence.
155 #[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
156 #[serde(deny_unknown_fields)]
157 pub struct ReviewedCatalog {
158 #[serde(default)]
159 pub revision: String,
160 #[serde(default)]
161 pub intrinsic: BTreeMap<String, IntrinsicModel>,
162 #[serde(default)]
163 pub openai_reasoning_ids: BTreeMap<String, String>,
164 #[serde(default)]
165 pub snapshot_prefixes: BTreeMap<String, String>,
166 #[serde(default)]
167 pub selections: Vec<ModelSelection>,
168 #[serde(default)]
169 pub public_models: Vec<PublicModel>,
170 #[serde(default)]
171 pub transports: Vec<ReviewedTransport>,
172 #[serde(default)]
173 pub constants: BTreeMap<String, String>,
174 #[serde(default)]
175 pub numeric_refs: BTreeMap<String, NumericRef>,
176 #[serde(default)]
177 pub groups: BTreeMap<String, Vec<String>>,
178 #[serde(default)]
179 pub completion_rosters: BTreeMap<String, Vec<String>>,
180 #[serde(default)]
181 pub search_models: BTreeMap<String, Vec<String>>,
182 #[serde(default)]
183 pub route_model_sets: BTreeMap<String, Vec<String>>,
184 #[serde(default)]
185 pub reference_prices: BTreeMap<String, ReferencePrice>,
186 #[serde(default)]
187 pub reference_price_policies: BTreeMap<String, String>,
188 #[serde(default)]
189 pub source_receipts: BTreeMap<String, String>,
190 }
191
192 impl ReviewedCatalog {
193 /// Validate authored source data before it can become a bundled projection.
194 /// Empty is allowed only for external Models.dev documents with no supplement.
195 pub fn validate(&self) -> Result<(), String> {
196 if self.revision.is_empty() {
197 if self == &Self::default() {
198 return Ok(());
199 }
200 return Err("reviewed catalog revision missing".into());
201 }
202 let identifier = |s: &str| {
203 !s.is_empty() && s.len() <= 512 && s.trim() == s && !s.chars().any(char::is_control)
204 };
205 for (id, row) in &self.intrinsic {
206 if !identifier(id)
207 || row.source.trim().is_empty()
208 || row.context_window == Some(0)
209 || row.max_output == Some(0)
210 || row.generation_default == Some(0)
211 {
212 return Err(format!("malformed intrinsic model {id}"));
213 }
214 }
215 for row in &self.selections {
216 // Authored rows retain exact legacy table identities; the picker
217 // parser deliberately collapses those into vendor-primary names.
218 let provider = crate::ProviderKind::parse_config_identity(&row.provider);
219 if !identifier(&row.id)
220 || provider.is_none_or(|p| {
221 p.as_str() != row.provider || p == crate::ProviderKind::Antigravity
222 })
223 {
224 return Err(format!(
225 "malformed provider selector {}/{}",
226 row.provider, row.id
227 ));
228 }
229 }
230 let mut routes = BTreeSet::new();
231 for row in &self.transports {
232 if !identifier(&row.id)
233 || row.source.trim().is_empty()
234 || !matches!(row.endpoint_key.as_str(), "chat" | "messages" | "responses")
235 || !routes.insert((&row.provider, &row.id))
236 || row.limits.context_tokens == Some(0)
237 || row.limits.output_tokens == Some(0)
238 || crate::ProviderKind::parse_config_identity(&row.provider).is_none_or(|p| {
239 p.as_str() != row.provider || p == crate::ProviderKind::Antigravity
240 })
241 {
242 return Err(format!("malformed transport {}/{}", row.provider, row.id));
243 }
244 }
245 for (id, row) in &self.reference_prices {
246 if !identifier(id)
247 || row.source.trim().is_empty()
248 || [
249 Some(row.input),
250 Some(row.output),
251 Some(row.cache_read),
252 row.cache_write,
253 ]
254 .into_iter()
255 .flatten()
256 .any(|v| !v.is_finite() || v < 0.0)
257 {
258 return Err(format!("malformed reference price {id}"));
259 }
260 }
261 for (prefix, target) in &self.snapshot_prefixes {
262 if !identifier(prefix) || !self.intrinsic.contains_key(target) {
263 return Err("missing snapshot target".into());
264 }
265 }
266 for reference in self.numeric_refs.values() {
267 let row = self
268 .intrinsic
269 .get(&reference.model)
270 .ok_or("missing numeric model")?;
271 let value = match reference.field.as_str() {
272 "context_window" => row.context_window,
273 "max_output" => row.max_output,
274 "generation_default" => row.generation_default,
275 _ => return Err("unknown numeric model field".into()),
276 };
277 if value.is_none_or(|value| value == 0) {
278 return Err("missing numeric model fact".into());
279 }
280 }
281 for row in &self.public_models {
282 if !identifier(&row.id)
283 || !self.intrinsic.contains_key(&row.id.to_ascii_lowercase())
284 || row.label.as_deref().is_some_and(|label| !identifier(label))
285 || row.aliases.iter().any(|alias| !identifier(alias))
286 || row.added_at.as_deref().is_some_and(|date| {
287 chrono::NaiveDate::parse_from_str(date, "%Y-%m-%d").is_err()
288 })
289 {
290 return Err(format!("missing public model {}", row.id));
291 }
292 }
293 for (provider, entries) in &self.completion_rosters {
294 if provider != crate::descriptors::LEGACY_DEEPSEEK_CN.id
295 && crate::ProviderKind::parse_config_identity(provider)
296 .is_none_or(|kind| kind.as_str() != provider)
297 || entries.iter().any(|entry| !identifier(entry))
298 || matches!(provider.as_str(), "antigravity" | "custom") && !entries.is_empty()
299 {
300 return Err(format!("malformed completion roster {provider}"));
301 }
302 }
303 Ok(())
304 }
305 }
306
307 /// The same immutable parsed bundled catalog used by config's existing owner.
308 #[must_use]
309 pub fn bundled_reviewed() -> &'static ReviewedCatalog {
310 &super::bundled_models_dev_catalog().reviewed
311 }
312
313 /// Exact intrinsic lookup. Canonical facts win over provider enrichment; a
314 /// provider-scoped row is eligible only through an explicit, conflict-free join.
315 /// Never examine the process's live/custom/account catalog here.
316 #[must_use]
317 pub fn intrinsic_model(model: &str) -> Option<IntrinsicModel> {
318 let id = model.trim().to_ascii_lowercase();
319 if let Some(reg) = crate::cloud_facts::overlay::pulled_registry()
320 && let Some(mut pulled) = reg.compiled.intrinsic_models.get(&id).cloned()
321 {
322 if let Some(bundled) = intrinsic_model_in(super::bundled_models_dev_catalog(), model) {
323 fill_missing(&mut pulled, &bundled);
324 }
325 return Some(pulled);
326 }
327 intrinsic_model_in(super::bundled_models_dev_catalog(), model)
328 }
329
330 #[must_use]
331 pub fn intrinsic_model_in(catalog: &ModelsDevCatalog, model: &str) -> Option<IntrinsicModel> {
332 let id = model.trim().to_ascii_lowercase();
333 let reviewed = catalog.reviewed.intrinsic.get(&id);
334 let canonical = catalog
335 .models
336 .iter()
337 .find(|(key, _)| key.eq_ignore_ascii_case(&id))
338 .map(|(_, row)| row);
339 let mut result = reviewed.cloned().or_else(|| canonical.map(from_canonical));
340 if let Some(base) = result
341 .as_ref()
342 .and_then(|row| row.canonical_id.as_deref())
343 .and_then(|base| catalog.reviewed.intrinsic.get(&base.to_ascii_lowercase()))
344 && let Some(row) = &mut result
345 {
346 fill_missing(row, base);
347 }
348 if let Some(canonical) = canonical {
349 let canonical = from_canonical(canonical);
350 if let Some(row) = &mut result {
351 fill_missing(row, &canonical);
352 }
353 }
354 // A shared wire spelling does not establish a canonical model. Only
355 // explicit joins can supply missing intrinsic facts.
356 let joined = catalog
357 .providers
358 .values()
359 .flat_map(|provider| provider.models.iter())
360 .filter(|(_, row)| {
361 row.canonical_id()
362 .is_some_and(|base| base.eq_ignore_ascii_case(&id))
363 })
364 .collect::<Vec<_>>();
365 let joins = joined
366 .iter()
367 .filter_map(|(_, row)| row.canonical_id())
368 .map(str::to_ascii_lowercase)
369 .collect::<BTreeSet<_>>();
370 if joins.len() == 1 {
371 // Enrich the named canonical model only. A provider-owned wire id is
372 // resolved through its scoped offering, never this model-only lookup.
373 if let Some(base) = joins.first().and_then(|base| {
374 catalog
375 .models
376 .iter()
377 .find(|(key, _)| key.eq_ignore_ascii_case(base))
378 .map(|(_, row)| row)
379 }) {
380 let canonical = from_canonical(base);
381 if let Some(row) = &mut result {
382 fill_missing(row, &canonical);
383 } else {
384 result = Some(canonical);
385 }
386 }
387 let consensus = IntrinsicModel {
388 context_window: consensus(joined.iter().filter_map(|(_, row)| {
389 row.limit
390 .as_ref()
391 .and_then(|v| v.context)
392 .and_then(|v| u32::try_from(v).ok())
393 })),
394 max_output: consensus(joined.iter().filter_map(|(_, row)| {
395 row.limit
396 .as_ref()
397 .and_then(|v| v.output)
398 .and_then(|v| u32::try_from(v).ok())
399 })),
400 reasoning: consensus(joined.iter().filter_map(|(_, row)| row.reasoning)),
401 source: "conflict-free explicitly joined bundled offerings".into(),
402 ..IntrinsicModel::default()
403 };
404 if let Some(row) = &mut result {
405 fill_missing(row, &consensus);
406 } else if consensus.context_window.is_some()
407 || consensus.max_output.is_some()
408 || consensus.reasoning.is_some()
409 {
410 result = Some(consensus);
411 }
412 }
413 result
414 }
415
416 fn consensus<T: Copy + PartialEq>(values: impl IntoIterator<Item = T>) -> Option<T> {
417 let mut values = values.into_iter();
418 let first = values.next()?;
419 values.all(|value| value == first).then_some(first)
420 }
421
422 pub(crate) fn from_canonical(row: &ModelsDevModel) -> IntrinsicModel {
423 IntrinsicModel {
424 canonical_id: (!row.id.is_empty()).then(|| row.id.clone()),
425 context_window: row
426 .limit
427 .as_ref()
428 .and_then(|v| v.context)
429 .and_then(|v| u32::try_from(v).ok()),
430 max_output: row
431 .limit
432 .as_ref()
433 .and_then(|v| v.output)
434 .and_then(|v| u32::try_from(v).ok()),
435 reasoning: row.reasoning,
436 display_name: row.name.clone(),
437 modalities: row
438 .modalities
439 .as_ref()
440 .map(|v| v.input.clone())
441 .unwrap_or_default(),
442 capabilities: RouteCapabilities {
443 reasoning: CapabilityState::from_optional_bool(row.reasoning),
444 native_tool_calls: CapabilityState::from_optional_bool(row.tool_call),
445 structured_output: CapabilityState::from_optional_bool(row.structured_output),
446 attachments: CapabilityState::from_optional_bool(row.attachment),
447 image_input: crate::models_dev::image_input_support(row.modalities.as_ref()),
448 ..RouteCapabilities::default()
449 },
450 source: "bundled canonical Models.dev row".into(),
451 ..IntrinsicModel::default()
452 }
453 }
454
455 pub(crate) fn fill_missing(row: &mut IntrinsicModel, other: &IntrinsicModel) {
456 row.context_window = row.context_window.or(other.context_window);
457 row.max_output = row.max_output.or(other.max_output);
458 row.reasoning = row.reasoning.or(other.reasoning);
459 row.thought_signatures_required = row
460 .thought_signatures_required
461 .or(other.thought_signatures_required);
462 row.thinking_can_disable = row.thinking_can_disable.or(other.thinking_can_disable);
463 row.family = row.family.or(other.family);
464 if row.display_name.is_none() {
465 row.display_name.clone_from(&other.display_name);
466 }
467 }
468
469 #[must_use]
470 pub fn selection_supports_reasoning(provider: &str, model: &str) -> bool {
471 let trimmed = model.trim();
472 bundled_reviewed().selections.iter().any(|row| {
473 row.supports_reasoning && row.provider == provider && row.id.eq_ignore_ascii_case(trimmed)
474 })
475 }
476
477 /// Exact public bundled identifiers only. Live/private/configured model IDs
478 /// can never enlarge a telemetry/UI public-label allowlist.
479 #[must_use]
480 pub fn public_model_identifier(model: &str) -> bool {
481 let catalog = super::bundled_models_dev_catalog();
482 catalog.reviewed.intrinsic.contains_key(model)
483 || catalog.models.contains_key(model)
484 || catalog.providers.values().any(|provider| {
485 provider
486 .models
487 .iter()
488 .any(|(id, row)| id == model || row.id == model)
489 })
490 }
491
492 #[must_use]
493 pub fn official_deepseek_model_id(model: &str) -> Option<&'static str> {
494 let key = model.trim().to_ascii_lowercase();
495 if !key.starts_with("deepseek") && !key.contains("/deepseek")
496 || crate::legacy_deepseek_alias_reasoning_effort(&key).is_some()
497 {
498 return None;
499 }
500 let target = crate::descriptors::provider_model_alias(crate::ProviderKind::Deepseek, &key)
501 .unwrap_or(&key);
502 crate::route::bundled_offering_wire_id(crate::ProviderKind::Deepseek, target)
503 }
504
505 #[must_use]
506 pub fn route_model_set_contains(set: &str, model: &str) -> bool {
507 bundled_reviewed()
508 .route_model_sets
509 .get(set)
510 .is_some_and(|ids| ids.iter().any(|id| id.eq_ignore_ascii_case(model.trim())))
511 }
512
513 #[must_use]
514 pub fn reviewed_transport(provider: &str, model: &str) -> Option<&'static ReviewedTransport> {
515 bundled_reviewed()
516 .transports
517 .iter()
518 .find(|row| row.provider == provider && row.id == model)
519 }
520
521 /// Compile-time compatibility names are generated from the same JSON owner.
522 pub mod constants {
523 include!(concat!(env!("OUT_DIR"), "/catalog_constants.rs"));
524 }
525
526 /// Actual source fetch time of the existing generated seed, not an unrelated
527 /// former bundled asset date. Callers evaluate TTL against their current clock.
528 #[must_use]
529 pub fn bundled_source_fetched_at() -> Option<u64> {
530 let source = super::bundled_models_dev_catalog()
531 .meta
532 .get("upstream")?
533 .as_str()?;
534 let (_, source) = source.split_once(" fetched ")?;
535 let time = source.split_whitespace().next()?;
536 u64::try_from(chrono::DateTime::parse_from_rfc3339(time).ok()?.timestamp()).ok()
537 }
538
539 #[cfg(test)]
540 mod tests {
541 use super::*;
542
543 fn catalog(value: serde_json::Value) -> ModelsDevCatalog {
544 ModelsDevCatalog::parse_json(&value.to_string()).expect("fixture")
545 }
546
547 #[test]
548 fn bundled_catalog_resolves_the_bare_deepseek_v41_flash_spelling() {
549 // A custom `openai-compatible` endpoint whose `model` omits the vendor
550 // prefix (`model = "deepseek-v4.1-flash"`) is the shape that used to
551 // fall through to the static 128K window. This pins the curated row so
552 // the fallback cannot silently regress.
553 let data = super::super::bundled_models_dev_catalog();
554 let found = intrinsic_model_in(data, "deepseek-v4.1-flash")
555 .expect("bare spelling resolves in the bundled catalogue");
556 assert_eq!(found.context_window, Some(1_000_000));
557 assert_eq!(found.max_output, Some(384_000));
558 // The `deepseek/`-namespaced spelling resolves to the same window and
559 // ceiling. This does not make every spelling agree: the `deepseek-ai/`
560 // twin is curated at 1048576 with no output ceiling, and reconciling
561 // those two rows is a separate data question.
562 let namespaced = intrinsic_model_in(data, "deepseek/deepseek-v4.1-flash")
563 .expect("namespaced spelling resolves");
564 assert_eq!(namespaced.context_window, found.context_window);
565 assert_eq!(namespaced.max_output, found.max_output);
566 }
567
568 #[test]
569 fn identical_wire_names_do_not_merge_provider_private_facts() {
570 let data = catalog(serde_json::json!({ "providers": {
571 "one": { "models": { "private-name": { "id": "private-name", "reasoning": true, "limit": { "context": 900000 } } } },
572 "two": { "models": { "private-name": { "id": "private-name", "reasoning": false, "limit": { "context": 32000 } } } }
573 }}));
574 assert!(intrinsic_model_in(&data, "private-name").is_none());
575 assert_eq!(
576 data.provider_offering("one", "private-name")
577 .unwrap()
578 .limits
579 .context_tokens,
580 Some(900000)
581 );
582 assert_eq!(
583 data.provider_offering("two", "private-name")
584 .unwrap()
585 .limits
586 .context_tokens,
587 Some(32000)
588 );
589 assert!(!public_model_identifier("private-name"));
590 }
591
592 #[test]
593 fn proven_join_preserves_canonical_facts_and_wire_lookup_stays_scoped() {
594 let mut fixture = serde_json::json!({
595 "models": { "canonical": { "id": "canonical", "reasoning": false, "limit": { "context": 128000 } } },
596 "providers": { "one": { "models": { "wire": { "id": "wire", "base_model": "canonical", "reasoning": true, "limit": { "context": 900000 } } } } }
597 });
598 let data = catalog(fixture.clone());
599 assert!(intrinsic_model_in(&data, "wire").is_none());
600 assert_eq!(
601 data.provider_offering("one", "wire")
602 .expect("exact provider-owned offering")
603 .limits
604 .context_tokens,
605 Some(900000)
606 );
607 let joined = intrinsic_model_in(&data, "canonical").unwrap();
608 assert_eq!(joined.canonical_id.as_deref(), Some("canonical"));
609 assert_eq!(joined.context_window, Some(128000));
610 assert_eq!(joined.reasoning, Some(false));
611 fixture["providers"]["two"] = serde_json::json!({ "models": { "wire": { "id": "wire", "base_model": "different", "reasoning": true } } });
612 assert!(intrinsic_model_in(&catalog(fixture), "wire").is_none());
613 }
614
615 #[test]
616 fn reviewed_selection_and_transport_preserve_separate_scopes() {
617 let reviewed = bundled_reviewed();
618 reviewed.validate().expect("committed data");
619 assert_eq!(reviewed.selections.len(), 192);
620 assert_eq!(reviewed.transports.len(), 112);
621 let go = reviewed_transport("opencode-go", "gpt-5.6-luna").unwrap();
622 assert_eq!(go.endpoint_key, "responses");
623 assert_eq!(
624 go.limits,
625 RouteLimits::default(),
626 "Go metadata is enriched by existing resolver, not borrowed from another account"
627 );
628 assert_eq!(
629 reviewed_transport("opencode-zen", "claude-opus-5")
630 .unwrap()
631 .endpoint_key,
632 "messages"
633 );
634 assert!(reviewed_transport("custom", "gpt-5.6").is_none());
635 assert!(constants::completion_names("custom").is_empty());
636 assert!(constants::completion_names("antigravity").is_empty());
637 assert_eq!(
638 crate::descriptors::provider_model_alias(crate::ProviderKind::Zai, "glm-5.2"),
639 Some("GLM-5.2")
640 );
641 assert_eq!(
642 crate::descriptors::provider_model_alias(crate::ProviderKind::Zai, "glm-5.3"),
643 Some("GLM-5.3")
644 );
645 }
646
647 #[test]
648 fn generation_default_does_not_assert_route_maximum_or_unknown_capability() {
649 let kimi = intrinsic_model("kimi-k3").unwrap();
650 assert_eq!(kimi.generation_default, Some(131072));
651 assert_ne!(kimi.generation_default, Some(1_048_576));
652 assert_eq!(kimi.capabilities.streaming, CapabilityState::Unknown);
653 assert!(intrinsic_model("kimi-k3-private").is_none());
654 }
655
656 #[test]
657 fn exact_legacy_identities_validate_without_accepting_picker_aliases() {
658 let reviewed = ReviewedCatalog {
659 revision: "fixture".into(),
660 selections: vec![ModelSelection {
661 provider: "minimax-anthropic".into(),
662 id: "MiniMax-M3".into(),
663 supports_tools: true,
664 supports_reasoning: true,
665 }],
666 transports: vec![ReviewedTransport {
667 provider: "modelstudio-coding-plan-anthropic".into(),
668 id: "qwen".into(),
669 endpoint_key: "messages".into(),
670 canonical_model: None,
671 default_for_provider: false,
672 limits: RouteLimits::default(),
673 capabilities: RouteCapabilities::default(),
674 source: "fixture".into(),
675 }],
676 ..ReviewedCatalog::default()
677 };
678 reviewed
679 .validate()
680 .expect("exact released config identities");
681 for bad in ["mini-max-anthropic", "unknown-provider", "antigravity"] {
682 let mut malformed = reviewed.clone();
683 malformed.selections[0].provider = bad.into();
684 assert!(malformed.validate().is_err(), "selector {bad}");
685 let mut malformed = reviewed.clone();
686 malformed.transports[0].provider = bad.into();
687 assert!(malformed.validate().is_err(), "transport {bad}");
688 }
689 }
690
691 #[test]
692 fn malformed_authored_rows_are_refused_before_projection() {
693 for bad in ["unknown-provider", "antigravity", "openai-compatible"] {
694 let mut reviewed = bundled_reviewed().clone();
695 reviewed.selections[0].provider = bad.into();
696 assert!(reviewed.validate().is_err());
697 }
698 let mut reviewed = bundled_reviewed().clone();
699 reviewed.transports[0].limits.output_tokens = Some(0);
700 assert!(reviewed.validate().is_err());
701 reviewed = bundled_reviewed().clone();
702 reviewed
703 .completion_rosters
704 .insert("custom".into(), vec!["private-name".into()]);
705 assert!(reviewed.validate().is_err());
706 }
707 }
708
708 lines RUST