mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
test(router): direct unit tests for _remove_deployment_from_wildcard_state
router_code_coverage.py greps test files for AST Call nodes and flagged the helper as untested because the existing coverage only exercised it transitively through upsert/delete. Adds two direct tests that pin the helper's contract (cleans across global pattern router, per-team routers with empty-router pop, and provider_default_deployment_ids; noop on falsy model_id)
This commit is contained in:
parent
d89535f933
commit
edaa06dc5b
1 changed files with 48 additions and 0 deletions
|
|
@ -4400,3 +4400,51 @@ def test_delete_team_wildcard_removes_empty_team_router():
|
|||
router.delete_deployment(id=model_id)
|
||||
|
||||
assert team_id not in router.team_pattern_routers
|
||||
|
||||
|
||||
def test_remove_deployment_from_wildcard_state_cleans_all_three_structures():
|
||||
"""
|
||||
Pin the contract of Router._remove_deployment_from_wildcard_state: a single
|
||||
call must strip model_id from the global pattern router, from every per-team
|
||||
pattern router (dropping the team entry when its router empties out), and
|
||||
from provider_default_deployment_ids. Exercised directly so the helper's
|
||||
behavior is locked in independently of the upsert/delete code paths.
|
||||
"""
|
||||
from litellm.router_utils.pattern_match_deployments import PatternMatchRouter
|
||||
|
||||
router, _ = _build_wildcard_router(api_key="key-A")
|
||||
model_id = "wildcard-deployment-1"
|
||||
|
||||
router.team_pattern_routers["team-x"] = PatternMatchRouter()
|
||||
router.team_pattern_routers["team-x"].add_pattern(
|
||||
"openai/team-x-*",
|
||||
{
|
||||
"model_name": "openai/team-x-*",
|
||||
"litellm_params": {"model": "openai/*", "api_key": "key-A"},
|
||||
"model_info": {"id": model_id},
|
||||
},
|
||||
)
|
||||
assert router.pattern_router.patterns
|
||||
assert "team-x" in router.team_pattern_routers
|
||||
assert model_id in router.provider_default_deployment_ids
|
||||
|
||||
router._remove_deployment_from_wildcard_state(model_id=model_id)
|
||||
|
||||
assert router.pattern_router.patterns == {}
|
||||
assert "team-x" not in router.team_pattern_routers
|
||||
assert model_id not in router.provider_default_deployment_ids
|
||||
|
||||
|
||||
def test_remove_deployment_from_wildcard_state_is_noop_for_empty_id():
|
||||
"""
|
||||
A falsy model_id must not touch any wildcard-routing state; otherwise an
|
||||
accidental empty-string call could wipe deployments that lack model_info.id.
|
||||
"""
|
||||
router, _ = _build_wildcard_router(api_key="key-A")
|
||||
snapshot_patterns = {k: list(v) for k, v in router.pattern_router.patterns.items()}
|
||||
snapshot_ids = list(router.provider_default_deployment_ids)
|
||||
|
||||
router._remove_deployment_from_wildcard_state(model_id="")
|
||||
|
||||
assert router.pattern_router.patterns == snapshot_patterns
|
||||
assert router.provider_default_deployment_ids == snapshot_ids
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue