1111
1212from __future__ import annotations
1313
14- import json
15- import copy
16- from dataclasses import replace
1714
1815from uncommon_route .router .api import route
19- from uncommon_route .router .classifier import classify , extract_features , _ensure_model_loaded , update_model , save_online_model , rollback_online_model
20- from uncommon_route .router .config import DEFAULT_CONFIG , DEFAULT_MODEL_PRICING , DEFAULT_MODEL_CAPABILITIES
16+ from uncommon_route .router .classifier import classify , extract_features , _ensure_model_loaded , update_model , rollback_online_model
2117from uncommon_route .router .types import (
2218 ModelCapabilities ,
2319 ModelPricing ,
24- RequestRequirements ,
25- RoutingConstraints ,
2620 RoutingFeatures ,
2721 RoutingMode ,
28- ScoringConfig ,
2922 Tier ,
3023 WorkloadHints ,
3124)
3225from uncommon_route .model_experience import (
33- CandidateExperience ,
3426 InMemoryModelExperienceStorage ,
3527 ModelExperienceStore ,
3628)
@@ -189,7 +181,6 @@ def test_issue3_minimax_never_wins_for_complex():
189181def test_issue3_minimax_ranking_across_tiers ():
190182 """Check MiniMax's position in ranking for each complexity level."""
191183 for complexity , label in [(0.15 , "SIMPLE" ), (0.45 , "MEDIUM" ), (0.85 , "COMPLEX" )]:
192- tier = Tier .SIMPLE if complexity < 0.33 else (Tier .MEDIUM if complexity < 0.67 else Tier .COMPLEX )
193184 # Use a neutral prompt and force complexity via routing features
194185 decision = route (
195186 "do something" ,
@@ -211,7 +202,7 @@ def test_issue3_quality_prior_is_benchmark_based():
211202 opus_quality = cache .get_quality ("anthropic/claude-opus-4.6" )
212203 oss_quality = cache .get_quality ("nvidia/gpt-oss-120b" )
213204
214- print (f "\n Benchmark quality (not price-based):" )
205+ print ("\n Benchmark quality (not price-based):" )
215206 print (f" MiniMax: { minimax_quality :.3f} " )
216207 print (f" Opus: { opus_quality :.3f} " )
217208 print (f" gpt-oss: { oss_quality :.3f} " )
@@ -248,7 +239,7 @@ def test_issue4_any_tools_means_agentic():
248239 prompt = "hello" ,
249240 )
250241
251- print (f "\n Prompt: 'hello'" )
242+ print ("\n Prompt: 'hello'" )
252243 print (f" step_type: { step_type } " )
253244 print (f" is_agentic: { features .is_agentic } " )
254245 print (f" needs_tool_calling: { features .needs_tool_calling } " )
@@ -404,7 +395,7 @@ def test_issue6_anthropic_model_resolution():
404395 opus_resolved = mapper .resolve ("anthropic/claude-opus-4.6" )
405396 sonnet_resolved = mapper .resolve ("anthropic/claude-sonnet-4.6" )
406397
407- print (f "\n Pre-discovery:" )
398+ print ("\n Pre-discovery:" )
408399 print (f" Opus → { opus_resolved } " )
409400 print (f" Sonnet → { sonnet_resolved } " )
410401 print (f" Is gateway: { mapper .is_gateway } " )
@@ -424,10 +415,31 @@ def test_issue6_openrouter_detected_as_gateway():
424415 assert mapper .resolve ("xai/grok-4-1-fast-reasoning" ) == "xai/grok-4-1-fast-reasoning"
425416
426417
418+ def test_issue6_learned_fallbacks_do_not_override_gateway_seed_aliases ():
419+ """Runtime fallback aliases from one gateway should not hide known model renames."""
420+ from uncommon_route .model_map import DiscoveredModel , ModelMapper
421+
422+ mapper = ModelMapper ("https://openrouter.ai/api/v1" )
423+ mapper ._learned_aliases ["xai/grok-4-1-fast-reasoning" ] = "google/gemini-2.5-flash"
424+ for model_id in ["x-ai/grok-4.1-fast" , "google/gemini-2.5-flash" ]:
425+ provider = model_id .split ("/" , 1 )[0 ]
426+ mapper ._pool [model_id ] = DiscoveredModel (
427+ id = model_id ,
428+ provider = provider ,
429+ owned_by = provider ,
430+ pricing = ModelPricing (0.2 , 0.8 ),
431+ capabilities = ModelCapabilities (tool_calling = True , vision = False , reasoning = False ),
432+ )
433+ mapper ._upstream_models .add (model_id )
434+ mapper ._build_map ()
435+ mapper ._discovered = True
436+
437+ assert mapper .resolve ("xai/grok-4-1-fast-reasoning" ) == "x-ai/grok-4.1-fast"
438+
439+
427440def test_issue6_legacy_model_ids_resolve_to_live_successors ():
428441 """Legacy internal ids should map onto current upstream successors."""
429442 from uncommon_route .model_map import DiscoveredModel , ModelMapper
430- from uncommon_route .router .types import ModelCapabilities , ModelPricing
431443
432444 live_models = [
433445 "x-ai/grok-4" ,
@@ -488,7 +500,6 @@ def test_issue6_legacy_model_ids_resolve_to_live_successors():
488500def test_issue6_image_generation_models_do_not_enter_chat_routing_pool ():
489501 """Image-generation catalog entries should not become chat candidates."""
490502 from uncommon_route .model_map import DiscoveredModel , ModelMapper , is_routable_chat_model
491- from uncommon_route .router .types import ModelCapabilities , ModelPricing
492503
493504 mapper = ModelMapper ("https://api.commonstack.ai/v1" )
494505 for model_id in [
0 commit comments