mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-25 05:54:53 +00:00
4.2 KiB
4.2 KiB
Invariants
- Outside the dispatch tests below, this directory tests the Rust path and nothing else. Treat the Python implementation of every route as already removed. Never call it on purpose, never run one request through both engines, and never compare Python and Rust outputs, headers, cache keys or logs
- A test that would still pass with Python serving the call does not belong here. Every test except the dispatch tests asserts the call was served natively with
support.routing.assert_served_natively - Dispatch tests check which path a public call takes under given rules. They are each route folder's
test_dispatch.py, plustest_dispatch.pyandtest_public_entries.pyat the top of this directory- They pass
rules=to a dispatch directly or wrap the whole test in onesupport.routing.routed(...)block, and they stub the native bindings - They may call Python, since the choice between the two paths is what they test
- They live here until they can run in
tests/unit/without the compiled extension
- They pass
- Select the Rust path with
support.routing.native_route(...), which prependsRUST_REQUIREDrules tocatalog.RULESand restores them on exit. Each route folder'sconftest.pyapplies it to every test through an autouse fixture. A test outside a route folder wraps its whole body in onenative_route(...)block, and a child interpreter script assignscatalog.RULESonce at its top. Never select a backend by reading or settingLITELLM_RUST, callinglitellm.rust(...)or rebindingcatalog.RULESany other way. The rollout inlitellm/rust_bridge/catalog.pyis a product decision, and a test here must pass no matter what it says, including for a route markedPYTHON_ONLY catalog.RULESis static at runtime andnative_route(...)swaps a module global, so open it once per test and never per call. Two overlapping blocks, such as one per task inside anasyncio.gather, restore out of order and leave the wrong rules behind for later tests- No test here depends on the rollout switch. Only no rule,
PYTHON_ONLYandRUST_REQUIREDpick a path without it, so those are the only rollouts a test here uses, and Rust with Python fallback is not reachable from this directory. WhatLITELLM_RUSTandlitellm.rust(...)mean is tested intests/unit/rust_bridge/test_configuration.py, mostly throughdecide, which takes both as plain values - A test lives here only when it cannot be written in Rust. That means it needs the Python public API, Python-owned state such as
litellm.cacheand callbacks, or the process boundary (fork, threads, event loops). Anything checkable from the Rust side goes in the crate's own tests - The wire is the local recording server. No test here reaches a real provider
- Never parametrize one test across routes. Each route folder owns its tests, its
serverfixture, its request data and itscall. The one exception istest_public_entries.py, whose subject is that every route serves its public call forms the same way - Call
_nativedirectly only for a case the public API cannot reach
Layout
Each route folder (ocr/, messages/, responses/, chat_completions/) uses the same file names, one concern per file
test_dispatch.pythe call reaches the native route, and which path the rules pick for each public calltest_requests.pyPython inputs that reach the wiretest_failures.pyerrors raised to the caller and rejection before provider IOtest_settings.pyglobals, env, named credentials and their precedencetest_streaming.pystream relay, early close and stream-time loggingtest_callbacks.pythe logger hook contracttest_body_hooks.pyhandler body hooks such as interceptors and agentic loopstest_lifecycle.pycancellation, concurrency, context and nested callstest_cache.pythe configured cache seen from this route
embeddings/ holds only test_dispatch.py so far. At the top, test_dispatch.py tests PublicDispatch with stub routes and test_public_entries.py runs every route's public call forms through one table
Route data and the route's call live in <route>/data.py, and <route>/conftest.py owns the server fixture and the autouse native fixture. support/ holds only route-neutral helpers