Adds the algorithm-layer guarantee tests for
docs/KVC_ROUTER_ALGORITHM.md §4.1. The full Dispatch loop
lives in replay.py (HTTP + mooncake), but the policy-layer
guarantee is testable in isolation: under any reject
sequence, select() must keep returning a valid worker.
Cases:
- select returns a valid decision even after every (s,d)
is past τ_reject (degenerate fallback)
- |D|·τ_reject rejects suffice to explore every D
(cannot trap a session on one D under universal
rejection)
- degenerate fallback picks the least-rejected D
(Algorithm 1 line 4)
- per-(session, D) isolation: session A's blacklist
does not affect session B
- migration_reject_threshold=0 disables blacklist
- select() does NOT silently bump the reject counter
(the only mutator is record_admission_reject)
Adds tests/_fixtures.py with minimal make_topology() and
make_request() helpers that skip build_single_node_topology's
GPU-budget validation (irrelevant in unit tests).
Verified locally: 20/20 passing under pytest 9.0.3. The
six new tests cover only Algorithm 1's policy-layer
half of Theorem 1; the reset-on-success half lives in
Algorithm 3 (replay.py) and is a future test target.
Tests
Pure-Python unit + property tests for the algorithm layer. These tests do
not import SGLang and do not need a GPU — they validate the routing
algorithm (Algorithm 1/2/3 in docs/KVC_ROUTER_ALGORITHM.md) and its
theorems against the pure functions extracted from policies.py.
Run
uv sync --group test
uv run pytest
Or, without uv:
pip install pytest
PYTHONPATH=src pytest tests
Scope
test_policy_scoring.py— Algorithm 1 lex-score properties (overlap dominates sticky, load-floor gating, tie-breakers).test_no_starvation.py— Theorem 1: bounded retries before some D either accepts or the least-rejected D is forced through the degenerate path.
Future:
- block-level eviction
MockRadixCachetests (seedocs/BLOCK_LEVEL_EVICTION_DESIGN_ZH.md§5). - D→P sync
staleness_budgetproperty tests (seedocs/D_TO_P_SYNC_CONTRACT_ZH.md§1).
Why no integration tests here
Anything that needs SGLang, mooncake, or a real model is an integration
test and must run on hardware. Those tests live as scripts/sweep_*.sh
under the evaluation protocol in docs/EVALUATION_PROTOCOL_ZH.md.