From 710e08079b60976ff605f08b8e8f682d8513b99f Mon Sep 17 00:00:00 2001 From: Kartik Chilkoti Date: Wed, 16 Sep 2026 17:01:47 +0530 Subject: [PATCH] test(router): add fallback chain traversal and priority tier routing tests [skip ci] --- tests/test_router_fallback_chain.py | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/test_router_fallback_chain.py diff --git a/tests/test_router_fallback_chain.py b/tests/test_router_fallback_chain.py new file mode 100644 index 00000000000..38e60334c39 --- /dev/null +++ b/tests/test_router_fallback_chain.py @@ -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 \ No newline at end of file