From 51d8fed940fa92607c8f848dd035e22deebbe40a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97SO?= <142557582+Linxiushen@users.noreply.github.com> Date: Wed, 5 Aug 2026 06:55:16 +0800 Subject: [PATCH] test(router): cover static cost lookup boundaries --- .../router_strategy/test_lowest_cost.py | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/tests/test_litellm/router_strategy/test_lowest_cost.py b/tests/test_litellm/router_strategy/test_lowest_cost.py index b426e5bbde1..71b464e104f 100644 --- a/tests/test_litellm/router_strategy/test_lowest_cost.py +++ b/tests/test_litellm/router_strategy/test_lowest_cost.py @@ -32,12 +32,18 @@ async def test_provider_prefixed_models_use_resolved_costs() -> None: assert selected["model_info"]["id"] == "luna" +@pytest.mark.parametrize( + "unknown_model", + [None, "caller-controlled-model", "ollama/caller-controlled-model"], +) @pytest.mark.asyncio -async def test_unknown_provider_model_does_not_query_dynamic_metadata() -> None: +async def test_unknown_models_do_not_query_dynamic_metadata( + unknown_model: str | None, +) -> None: deployments = [ { "model_name": "test-group", - "litellm_params": {"model": "ollama/caller-controlled-model"}, + "litellm_params": {"model": unknown_model}, "model_info": {"id": "unknown"}, }, { @@ -59,6 +65,40 @@ async def test_unknown_provider_model_does_not_query_dynamic_metadata() -> None: get_model_info.assert_not_called() +@pytest.mark.asyncio +async def test_exact_custom_cost_entry_remains_authoritative() -> None: + deployments = [ + { + "model_name": "test-group", + "litellm_params": {"model": "custom/provider-entry"}, + "model_info": {"id": "custom"}, + }, + { + "model_name": "test-group", + "litellm_params": {"model": "openai/gpt-5.6-luna"}, + "model_info": {"id": "luna"}, + }, + ] + handler = LowestCostLoggingHandler(router_cache=DualCache()) + + with patch.dict( + litellm.model_cost, + { + "custom/provider-entry": { + "input_cost_per_token": 1e-9, + "output_cost_per_token": 1e-9, + } + }, + ): + selected = await handler.async_get_available_deployments( + model_group="test-group", + healthy_deployments=deployments, + ) + + assert selected is not None + assert selected["model_info"]["id"] == "custom" + + @pytest.mark.asyncio async def test_invalid_static_cost_entry_is_ignored() -> None: deployments = [