From b6b922ad7312a2aa6d2a4cbe544364a6d775435e Mon Sep 17 00:00:00 2001 From: Lavya Tandel Date: Sun, 9 Aug 2026 18:11:17 +0530 Subject: [PATCH] test(router): add coverage for _pre_call_checks_async --- tests/test_litellm/test_router.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.py index 2e81c9cecc7..5c6a1eb289b 100644 --- a/tests/test_litellm/test_router.py +++ b/tests/test_litellm/test_router.py @@ -3329,6 +3329,37 @@ def test_pre_call_checks_no_messages_or_input_does_not_crash(monkeypatch): assert counted == [] # token counting skipped entirely, so no misleading error is logged +@pytest.mark.asyncio +async def test_pre_call_checks_async_filters_like_sync(): + router = litellm.Router( + model_list=[ + { + "model_name": "test", + "litellm_params": {"model": "gpt-5-mini", "api_key": "sk-test"}, + "model_info": {"id": "small", "max_input_tokens": 50}, + }, + { + "model_name": "test", + "litellm_params": {"model": "gpt-5.5", "api_key": "sk-test"}, + "model_info": {"id": "large", "max_input_tokens": 10000}, + }, + ], + enable_pre_call_checks=True, + ) + + deployments = router.get_model_list(model_name="test") + assert deployments is not None + + filtered = await router._pre_call_checks_async( + model="test", + healthy_deployments=deployments, + messages=[{"role": "user", "content": " ".join(["word"] * 100)}], + ) + + assert len(filtered) == 1 + assert filtered[0]["model_info"]["id"] == "large" + + @pytest.mark.asyncio async def test_aresponses_enforces_context_window_pre_call_check(): """