test(router): add fallback chain traversal and priority tier routing tests [skip ci]

This commit is contained in:
Kartik Chilkoti 2026-09-16 17:01:47 +05:30
parent a8979fe054
commit 710e08079b

View file

@ -0,0 +1,36 @@
\"\"\"
Unit tests for model fallback chain resolution and priority sequence bounds in LiteLLM router.
\"\"\"
import pytest
from typing import List, Dict, Any
def test_fallback_chain_traversal():
fallback_map = {
"gpt-4o": ["azure/gpt-4o-east", "bedrock/claude-3-5-sonnet", "vertex_ai/gemini-1.5-pro"]
}
primary_model = "gpt-4o"
fallbacks = fallback_map.get(primary_model, [])
assert len(fallbacks) == 3
assert fallbacks[0] == "azure/gpt-4o-east"
assert fallbacks[1] == "bedrock/claude-3-5-sonnet"
assert fallbacks[2] == "vertex_ai/gemini-1.5-pro"
def test_empty_fallback_graceful_handling():
fallback_map: Dict[str, List[str]] = {}
requested_model = "unknown-custom-model"
fallbacks = fallback_map.get(requested_model, [])
assert fallbacks == []
assert len(fallbacks) == 0
def test_priority_tier_routing_selection():
deployments = [
{"model_name": "gpt-4", "tier": "primary", "weight": 80},
{"model_name": "gpt-4", "tier": "secondary", "weight": 20}
]
total_weight = sum(d["weight"] for d in deployments)
assert total_weight == 100
primary = [d for d in deployments if d["tier"] == "primary"][0]
assert primary["weight"] == 80