test(router): add coverage for _pre_call_checks_async

This commit is contained in:
Lavya Tandel 2026-08-09 18:11:17 +05:30
parent ee770c8248
commit b6b922ad73

View file

@ -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():
"""