litellm/tests/test_litellm/router_strategy
Clement 699ae63b2a
feat(router): support percentile-based TTFT routing (#40352)
* feat(router): support percentile-based TTFT routing

* fix(router): apply routing_strategy_args updates to the live selector

Runtime routing_strategy_args updates (config reload, update_settings)
only rebuilt the strategy selector when routing_strategy itself changed,
so a newly added ttft_percentile sat unused until the proxy restarted.

Also drops a comment that only restated the code it sat above.

Claude-Session: https://claude.ai/code/session_01PmqjhFYcUh6vA72d8W9gdB

* refactor(router): drop unreachable empty-samples guard in percentile latency

_percentile_latency is only called behind use_ttft, which already requires
a non-empty ttft sample list, so the early return was dead code and the one
line Codecov flagged as uncovered on this patch.

Claude-Session: https://claude.ai/code/session_01PmqjhFYcUh6vA72d8W9gdB

* test(router): cover the no-selector path of a routing_strategy_args update

simple-shuffle has no selector attribute to re-link, so the early return
guards a setattr with a None attribute name. Dropping the guard makes the
new test fail with "attribute name must be string, not 'NoneType'".

Claude-Session: https://claude.ai/code/session_01PmqjhFYcUh6vA72d8W9gdB

* fix(test): assert ValidationError on out-of-range ttft_percentile

pytest.raises(ValueError) tripped PT011 for being too broad. Pydantic
raises ValidationError for the gt/le constraint, so naming it satisfies
the rule and pins the assertion to the constraint under test.

Claude-Session: https://claude.ai/code/session_01PmqjhFYcUh6vA72d8W9gdB

* fix(router): drop Final from a per-deployment loop variable

basedpyright rejects "A Final variable cannot be assigned within a loop",
which pushed reportGeneralTypeIssues one over its budget. selected_latency
is rebound each iteration, so it matches its unannotated neighbours in the
same loop.

Claude-Session: https://claude.ai/code/session_01PmqjhFYcUh6vA72d8W9gdB

* test(router): exempt _apply_updated_routing_strategy_args from the name scan

The scan only reads test files with "router" in the filename, so it cannot
see the update_settings tests in router_strategy/test_lowest_latency.py.
Calling the private helper directly would test structure rather than
behaviour, so it joins the existing entries ignored for the same reason.

Claude-Session: https://claude.ai/code/session_01PmqjhFYcUh6vA72d8W9gdB
2026-09-09 10:47:34 -07:00
..
adaptive_router Merge pull request #39955 from BerriAI/litellm_fix_adaptive_router_bandit_prior 2026-09-05 18:02:04 -07:00
test_auto_router.py address review: trim remaining comment verbosity 2026-09-05 15:43:03 -07:00
test_base_routing_strategy.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_budget_limiter_hotpath.py fix(router): enforce deployment budgets for dynamically added models (#29273) 2026-05-29 19:43:14 -07:00
test_complexity_router.py Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_non_reasoning_tier 2026-09-08 15:49:53 -07:00
test_complexity_tier_predictor.py feat(router): add heuristic v2 complexity routing (#39276) 2026-09-02 23:33:04 +00:00
test_lar1_routing.py chore: litellm oss staging (#31185) 2026-06-26 09:17:44 -07:00
test_least_busy.py fix(least-busy): keep the shared count readable, counted once, and off the loop 2026-09-06 00:20:05 -07:00
test_litellm_encoder.py fix: address cross-version CI failures 2026-09-02 14:17:19 -07:00
test_lowest_cost.py fix(router): give cost-based routing its own cache key so it stops overwriting latency samples (#40225) 2026-09-08 13:56:06 -07:00
test_lowest_latency.py feat(router): support percentile-based TTFT routing (#40352) 2026-09-09 10:47:34 -07:00
test_quality_router.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_router_routing_groups.py fix(router): keep per-request routing_strategy override selectors out of global callbacks (#40229) 2026-09-08 13:54:05 -07:00
test_router_routing_plugins.py fix(router): let prompt-management plugins see the caller's own messages 2026-09-06 02:44:45 -07:00
test_router_tag_regex_routing.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_router_tag_routing.py fix(router): keep deployment tags out of retry and fallback tag routing (#40226) 2026-09-08 21:15:36 +00:00
test_savings_baseline.py fix(router): drop a tier param the routed target cannot take (#38622) 2026-08-28 14:17:49 -07:00
test_simple_shuffle.py fix(router): let simple-shuffle weight by any deployment's weight/rpm/tpm (#40222) 2026-09-08 13:55:36 -07:00
test_stall_detector.py fix(router): anchor stall detection on the newest tool call 2026-09-04 16:03:20 -07:00