Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(e2e): gate the prompt-cache cell behind an opt-in marker and take ten shuffle picks

mateo-berri6de9087f03cd
diff --git a/tests/e2e/CONTRIBUTING.md b/tests/e2e/CONTRIBUTING.md
index 2c7a3b0a2d6..e3d25bfd371 100644
--- a/tests/e2e/CONTRIBUTING.md
+++ b/tests/e2e/CONTRIBUTING.md
@@ -151,7 +151,7 @@ Each suite provides its own `client` fixture (see `llm_translation/passthrough_c
Request and response bodies are typed pydantic models in `models.py`; only the fields a test reads are modelled, and nothing passes raw dicts. Outcomes come back as a `Result[R]` tagged union (`Success`, `NetworkError`, `UnauthorizedError`, `RateLimitedError`, `ValidationError`, `UnknownApiError`). Handle them with `match`, or call `unwrap(...)` when a non-success should fail the test. The harness hard-fails and never skips: a test marked `e2e` fails when no proxy answers its liveness probe, and once a request reaches the proxy any wrong behavior is likewise a hard failure, so a missing proxy turns the run red instead of being mistaken for a pass
-Mark live tests with `@pytest.mark.e2e` (on the class or the module). Pure coverage of the harness itself carries no marker and runs regardless. Use `scoped_key` for a fresh all-models key that auto-deletes, `resources` when you need to create and tear down more than a key, and `unique_marker()` from `e2e_config` to keep prompts, tags, and customer ids from colliding across concurrent runs and the shared response cache
+Mark live tests with `@pytest.mark.e2e` (on the class or the module). Pure coverage of the harness itself carries no marker and runs regardless. A test that needs proxy configuration the default stack does not carry goes behind an opt-in marker (`managed_files`, `prompt_caching_stack`, `weekly`), each deselected unless its env var is set; `OPT_IN_MARKERS` in `conftest.py` maps marker to env var, and the coverage collector counts such a cell only where the env var is set. Use `scoped_key` for a fresh all-models key that auto-deletes, `resources` when you need to create and tear down more than a key, and `unique_marker()` from `e2e_config` to keep prompts, tags, and customer ids from colliding across concurrent runs and the shared response cache
## Pre-commit steps
diff --git a/tests/e2e/batches/conftest.py b/tests/e2e/batches/conftest.py
index 3b133fab680..73e8918e2ee 100644
--- a/tests/e2e/batches/conftest.py
+++ b/tests/e2e/batches/conftest.py
@@ -12,14 +12,12 @@ the proxy config.
from __future__ import annotations
-import os
from typing import Iterator
import pytest
from batch_client import BatchClient, build_client
from capabilities import PROVIDERS
-from e2e_config import MANAGED_FILES_OPT_IN_ENV
from e2e_http import NoBody
from proxy_client import ProxyClient
@@ -31,22 +29,6 @@ def pytest_configure(config: pytest.Config) -> None:
)
-def pytest_collection_modifyitems(
- config: pytest.Config, items: list[pytest.Item]
-) -> None:
- if os.environ.get(MANAGED_FILES_OPT_IN_ENV):
- return
- deselected = [
- item for item in items if item.get_closest_marker("managed_files") is not None
- ]
- if not deselected:
- return
- config.hook.pytest_deselected(items=deselected)
- items[:] = [
- item for item in items if item.get_closest_marker("managed_files") is None
- ]
-
-
@pytest.fixture(scope="session")
def client(proxy: ProxyClient) -> BatchClient:
return build_client(proxy)
diff --git a/tests/e2e/batches/test_managed_files_enforcement_e2e.py b/tests/e2e/batches/test_managed_files_enforcement_e2e.py
index 7ad0b16adc3..4701a2164bb 100644
--- a/tests/e2e/batches/test_managed_files_enforcement_e2e.py
+++ b/tests/e2e/batches/test_managed_files_enforcement_e2e.py
@@ -5,7 +5,7 @@ whose config enables it. The main ephemeral stack can never run with it on: the
flag would 400 every files_settings-routed upload in the rest of the suite. The
PR gate instead reconfigures the same stack sequentially after the main run and
executes only this file with E2E_MANAGED_FILES_STACK set; without that env every
-test here is deselected (see conftest.py, mirroring the weekly marker).
+test here is deselected (see OPT_IN_MARKERS in tests/e2e/conftest.py).
Pins: an upload without target_model_names is rejected 400, an upload that also
carries a model param is rejected 400, a raw provider file id is rejected 400 on
diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py
index e1b987cbfd9..4442a3bd56a 100644
--- a/tests/e2e/conftest.py
+++ b/tests/e2e/conftest.py
@@ -17,11 +17,21 @@ import functools
import os
from collections.abc import Generator, Iterator
from datetime import datetime, timezone
+from types import MappingProxyType
+from typing import Final
import pytest
import requests
-from e2e_config import CONTROL_PLANE_BASE_URL, FIXTURE_DIR, FIXTURE_MODE_RAW, PROXY_BASE_URL
+from e2e_config import (
+ CONTROL_PLANE_BASE_URL,
+ FIXTURE_DIR,
+ FIXTURE_MODE_RAW,
+ MANAGED_FILES_OPT_IN_ENV,
+ PROMPT_CACHING_OPT_IN_ENV,
+ PROXY_BASE_URL,
+ WEEKLY_ANOMALY_OPT_IN_ENV,
+)
from e2e_db import RESET_OPT_IN_ENV, reset_spend_logs, run_spend_log_cleanup
from fixture_mode import fixture_mode_collection_error, fixture_report_lines
from provider_edge import replay_leftover_error
@@ -33,6 +43,14 @@ from proxy_client import ProxyClient, build_proxy_client
_E2E_TEST_RAN = pytest.StashKey[bool]()
_CALL_PASSED = pytest.StashKey[bool]()
+OPT_IN_MARKERS: Final = MappingProxyType(
+ {
+ "weekly": WEEKLY_ANOMALY_OPT_IN_ENV,
+ "managed_files": MANAGED_FILES_OPT_IN_ENV,
+ "prompt_caching_stack": PROMPT_CACHING_OPT_IN_ENV,
+ }
+)
+
def pytest_configure(config: pytest.Config) -> None:
config.addinivalue_line(
@@ -60,6 +78,11 @@ def pytest_configure(config: pytest.Config) -> None:
"markers",
"managed_files: needs a proxy running with require_managed_files enabled; deselected unless E2E_MANAGED_FILES_STACK is set",
)
+ config.addinivalue_line(
+ "markers",
+ "prompt_caching_stack: needs a proxy running with router_settings.optional_pre_call_checks including "
+ "prompt_caching; deselected unless E2E_PROMPT_CACHING_STACK is set",
+ )
def pytest_sessionstart(session: pytest.Session) -> None:
@@ -77,16 +100,32 @@ def pytest_report_header(config: pytest.Config) -> list[str]:
return fixture_report_lines(FIXTURE_MODE_RAW, FIXTURE_DIR, now=datetime.now(timezone.utc))
-def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
- """Attach the two custom signals (suite package and covered cell ids) to every
- test's user_properties so the standard JUnit report (`--junitxml`) records them
- as `<property>` entries, on every outcome including skips and setup errors.
- Downstream (Loki/Grafana) reads outcome and duration from the standard report
- and these properties for package rollups and coverage drill-down. See
- junit_properties.py.
+def _needs_unset_opt_in(item: pytest.Item) -> bool:
+ return any(
+ item.get_closest_marker(marker) is not None and not os.environ.get(opt_in_env)
+ for marker, opt_in_env in OPT_IN_MARKERS.items()
+ )
+
+
+def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None:
+ """Deselect every test behind an opt-in marker whose env var is unset (see
+ OPT_IN_MARKERS): those tests need a proxy configured differently from the
+ default stack, so the coverage collector, which runs over the same collection,
+ counts their cells only where they actually run.
+
+ Attach the two custom signals (suite package and covered cell ids) to every
+ remaining test's user_properties so the standard JUnit report (`--junitxml`)
+ records them as `<property>` entries, on every outcome including skips and
+ setup errors. Downstream (Loki/Grafana) reads outcome and duration from the
+ standard report and these properties for package rollups and coverage
+ drill-down. See junit_properties.py.
Also sort `load`-marked items last so a whole-tree run drives heavy throughput
traffic only after the latency-sensitive suites have finished."""
+ deselected = [item for item in items if _needs_unset_opt_in(item)]
+ if deselected:
+ config.hook.pytest_deselected(items=deselected)
+ items[:] = [item for item in items if not _needs_unset_opt_in(item)]
for item in items:
attach_result_properties(item)
items.sort(key=lambda item: item.get_closest_marker("load") is not None)
diff --git a/tests/e2e/coverage_registry/reliability.yaml b/tests/e2e/coverage_registry/reliability.yaml
index b50551ec105..7a8981c248a 100644
--- a/tests/e2e/coverage_registry/reliability.yaml
+++ b/tests/e2e/coverage_registry/reliability.yaml
@@ -29,7 +29,7 @@
- {id: reliability.routing.strategy_alias.custom_pricing_ignored, module: reliability, tier: P1, behavior: routing, variant: strategy_alias, assertions: [custom_pricing_ignored], exercised_on: [chat_completions], source: "litellm/router.py:11489", rationale: "Custom pricing on a strategy-router alias never prices the routed request; spend logs at the routed tier deployment's own rate (GitHub PR #36691)"}
- {id: reliability.routing.complexity_heuristic.scores_current_ask_only, module: reliability, tier: P1, behavior: routing, variant: complexity_heuristic, assertions: [scores_current_ask_only], exercised_on: [chat_completions], source: "router_strategy/complexity_router/complexity_router.py:942", rationale: "The heuristic complexity classifier scores the caller's current ask only, so a keyword-heavy agent system prompt cannot inflate the tier (GitHub PR #36721)"}
- {id: reliability.cache.exact.returns_cached, module: reliability, tier: P1, behavior: cache, variant: exact, assertions: [returns_cached], exercised_on: [chat_completions, messages, embeddings], source: "litellm/caching/caching.py", rationale: "Response cache returns cached on exact match"}
-- {id: reliability.cache.prompt_caching_model_select.returns_cached, module: reliability, tier: P1, behavior: cache, variant: prompt_caching_model_select, assertions: [returns_cached], exercised_on: [chat_completions], source: "router_utils/prompt_caching_cache.py", rationale: "Selects model supporting prompt caching for cacheable prefix"}
+- {id: reliability.cache.prompt_caching_model_select.returns_cached, module: reliability, tier: P1, behavior: cache, variant: prompt_caching_model_select, assertions: [returns_cached], exercised_on: [chat_completions], source: "router_utils/prompt_caching_cache.py", rationale: "Selects model supporting prompt caching for cacheable prefix; runs only on a stack with the prompt_caching pre-call check enabled (E2E_PROMPT_CACHING_STACK)"}
- {id: reliability.circuit_breaker.redis.trips_then_recovers, module: reliability, tier: P0, behavior: circuit_breaker, variant: redis, assertions: [trips_then_recovers], exercised_on: [chat_completions, messages, embeddings], source: "litellm/caching/redis_cache.py:99", rationale: "Redis breaker CLOSED->OPEN->HALF_OPEN; guards all cache/rate-limit ops"}
- {id: reliability.timeout.request_timeout.exceeds_deadline, module: reliability, tier: P1, behavior: timeout, variant: request_timeout, assertions: [exceeds_deadline], exercised_on: [chat_completions, messages], source: "litellm/router.py:545-551", rationale: "Per-request timeout raises Timeout"}
- {id: reliability.timeout.stream_timeout.exceeds_deadline, module: reliability, tier: P1, behavior: timeout, variant: stream_timeout, assertions: [exceeds_deadline], exercised_on: [chat_completions], source: "litellm/router.py:551", rationale: "Streaming chunk-delivery timeout"}
diff --git a/tests/e2e/e2e_config.py b/tests/e2e/e2e_config.py
index 21c5a338dc3..629ad927d42 100644
--- a/tests/e2e/e2e_config.py
+++ b/tests/e2e/e2e_config.py
@@ -134,6 +134,7 @@ LOAD_MIN_CONCURRENCY_EFFICIENCY = float(os.environ.get("E2E_LOAD_MIN_CONCURRENCY
WEEKLY_ANOMALY_OPT_IN_ENV = "E2E_WEEKLY_ANOMALY"
MANAGED_FILES_OPT_IN_ENV = "E2E_MANAGED_FILES_STACK"
+PROMPT_CACHING_OPT_IN_ENV = "E2E_PROMPT_CACHING_STACK"
ANOMALY_SESSIONS = int(os.environ.get("E2E_ANOMALY_SESSIONS", "6"))
ANOMALY_TURNS_PER_SESSION = int(os.environ.get("E2E_ANOMALY_TURNS_PER_SESSION", "6"))
ANOMALY_TURN_ATTEMPTS = int(os.environ.get("E2E_ANOMALY_TURN_ATTEMPTS", "3"))
diff --git a/tests/e2e/load/conftest.py b/tests/e2e/load/conftest.py
index 3a926ef2a61..e7659a547a4 100644
--- a/tests/e2e/load/conftest.py
+++ b/tests/e2e/load/conftest.py
@@ -1,30 +1,11 @@
from __future__ import annotations
-import os
-
import pytest
-from e2e_config import WEEKLY_ANOMALY_OPT_IN_ENV
from load_client import LoadClient, build_client
from proxy_client import ProxyClient
-def pytest_collection_modifyitems(
- config: pytest.Config, items: list[pytest.Item]
-) -> None:
- if os.environ.get(WEEKLY_ANOMALY_OPT_IN_ENV):
- return
- deselected = [
- item for item in items if item.get_closest_marker("weekly") is not None
- ]
- if not deselected:
- return
- config.hook.pytest_deselected(items=deselected)
- items[:] = [
- item for item in items if item.get_closest_marker("weekly") is None
- ]
-
-
@pytest.fixture(scope="session")
def client(proxy: ProxyClient) -> LoadClient:
return build_client(proxy)
diff --git a/tests/e2e/models.py b/tests/e2e/models.py
index 69e5d618d5d..c00e70c046b 100644
--- a/tests/e2e/models.py
+++ b/tests/e2e/models.py
@@ -739,7 +739,7 @@ class RouterCurrentValues(BaseModel):
proxy is actually running with (only the ones a test preconditions on)."""
routing_strategy: str | None = None
- optional_pre_call_checks: list[str] = []
+ optional_pre_call_checks: tuple[str, ...] = ()
class RouterSettingsResponse(BaseModel):
diff --git a/tests/e2e/pytest.ini b/tests/e2e/pytest.ini
index c3f8865f218..5ea630459fa 100644
--- a/tests/e2e/pytest.ini
+++ b/tests/e2e/pytest.ini
@@ -9,3 +9,4 @@ markers =
load: heavy throughput/load test; collected last so it never perturbs latency-sensitive suites
weekly: real-provider anomaly load test that spends real money; deselected unless E2E_WEEKLY_ANOMALY is set
managed_files: needs a proxy running with require_managed_files enabled; deselected unless E2E_MANAGED_FILES_STACK is set
+ prompt_caching_stack: needs a proxy running with router_settings.optional_pre_call_checks including prompt_caching; deselected unless E2E_PROMPT_CACHING_STACK is set
diff --git a/tests/e2e/router/test_reliability_prompt_caching_e2e.py b/tests/e2e/router/test_reliability_prompt_caching_e2e.py
index 53fba4e0a86..667b398cd16 100644
--- a/tests/e2e/router/test_reliability_prompt_caching_e2e.py
+++ b/tests/e2e/router/test_reliability_prompt_caching_e2e.py
@@ -10,8 +10,11 @@ cache back, which is the affinity the router's `prompt_caching` pre-call check
provides: it pins a cached conversation to its deployment before the shuffle runs.
The proxy has to run with `router_settings.optional_pre_call_checks:
-["prompt_caching"]` for that check to exist, so the test reads GET /router/settings
-first and fails, naming the missing setting, rather than reporting a routing bug.
+["prompt_caching"]` for that check to exist, so this module carries the
+`prompt_caching_stack` marker and is deselected unless `E2E_PROMPT_CACHING_STACK`
+is set (see tests/e2e/conftest.py, mirroring `managed_files`). With it set, the test
+reads GET /router/settings first and fails, naming the missing setting, rather than
+reporting a routing bug.
"""
from __future__ import annotations
@@ -32,7 +35,7 @@ from reliability_support import (
usage_of,
)
-pytestmark = pytest.mark.e2e
+pytestmark = [pytest.mark.e2e, pytest.mark.prompt_caching_stack]
FOLLOW_UPS = 3
diff --git a/tests/e2e/router/test_reliability_routing_strategies_e2e.py b/tests/e2e/router/test_reliability_routing_strategies_e2e.py
index dc0ee845f53..6aa5a78ccdb 100644
--- a/tests/e2e/router/test_reliability_routing_strategies_e2e.py
+++ b/tests/e2e/router/test_reliability_routing_strategies_e2e.py
@@ -10,6 +10,10 @@ on A; a strategy that then sends every call to B has demonstrably read its own
signal, and the closing simple-shuffle control call landing on A proves A was
healthy the whole time, so the B picks cannot be explained by a cooldown.
+The shuffle cell itself asks for ten picks rather than three: a shuffle that
+ignored the weights would spread calls evenly, and three even picks all land
+on A one time in eight, ten one time in a thousand.
+
Latency-based reads a signal each proxy process accumulates itself (a timeout
counts as a 1000s latency) and, like least-busy, reads the shared copy from Redis
only on a process's first look at a group. So its slow deployment carries a 1ms
@@ -57,6 +61,7 @@ from reliability_support import REAL_KEY, REAL_MODEL, chat_override, model_id_of
pytestmark = pytest.mark.e2e
STRATEGY_CALLS = 3
+SHUFFLE_CALLS = 10
LATENCY_CONVERGENCE_CALLS = 12
@@ -102,10 +107,16 @@ def _pick(client: ComplexityRouterClient, key: str, group: str, strategy: Routin
def _assert_every_pick(
- client: ComplexityRouterClient, key: str, group: str, strategy: RoutingStrategy, expected: str, why: str
+ client: ComplexityRouterClient,
+ key: str,
+ group: str,
+ strategy: RoutingStrategy,
+ expected: str,
+ why: str,
+ calls: int = STRATEGY_CALLS,
) -> None:
- picks = [_pick(client, key, group, strategy) for _ in range(STRATEGY_CALLS)]
- assert picks == [expected] * STRATEGY_CALLS, f"{strategy} picked {picks}, expected every call on {expected} ({why})"
+ picks = [_pick(client, key, group, strategy) for _ in range(calls)]
+ assert picks == [expected] * calls, f"{strategy} picked {picks}, expected every call on {expected} ({why})"
def _latency_pick(client: ComplexityRouterClient, key: str, group: str, slow: str, fast: str) -> str:
@@ -161,7 +172,13 @@ class TestReliabilityRoutingStrategies:
_ = _register(client, resources, group, _real(weight=0))
_assert_every_pick(
- client, scoped_key, group, "simple-shuffle", weighted, "it holds all of the group's shuffle weight"
+ client,
+ scoped_key,
+ group,
+ "simple-shuffle",
+ weighted,
+ "it holds all of the group's shuffle weight",
+ calls=SHUFFLE_CALLS,
)
@pytest.mark.covers("reliability.routing.cost_based.picks_lowest_cost")