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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(e2e): annotate new stream-timing locals as Final and trim the docstrings
Yuneng Jiangb55a4317a655
diff --git a/tests/e2e/e2e_http.py b/tests/e2e/e2e_http.pyindex 3a4e69cfb43..be5e55f8edc 100644--- a/tests/e2e/e2e_http.py+++ b/tests/e2e/e2e_http.py@@ -132,12 +132,9 @@ class StreamingResponse(BaseModel):non-streaming `application/json`), the response headers (lowercased names, e.g.the x-ratelimit-* pacing headers and retry-after on a 429), and the body.SpendLogs.request_id is the completion body id, not call_id. Used by passthrough- and streaming, where one validated JSON model does not fit.-- ``stream_event_arrivals`` is index-aligned with ``stream_events`` and holds the- seconds after the request was sent at which each event reached the client, so a- test can tell a relayed stream (events spread over the provider's generation time)- from a buffered one (every event in one burst at the end)."""+ and streaming, where one validated JSON model does not fit. ``stream_event_arrivals``+ is index-aligned with ``stream_events``: seconds after the request was sent at which+ each event reached the client."""status_code: intcall_id: str | None = None # x-litellm-call-id headerdiff --git a/tests/e2e/llm_translation/test_messages_e2e.py b/tests/e2e/llm_translation/test_messages_e2e.pyindex 1227b1c7119..c731b52acd8 100644--- a/tests/e2e/llm_translation/test_messages_e2e.py+++ b/tests/e2e/llm_translation/test_messages_e2e.py@@ -8,6 +8,8 @@ litellm-regression-tests/tests/test_inference_endpoints.py.from __future__ import annotations+from typing import Final+import pytestfrom e2e_config import (STREAM_MIN_LEAD_SECONDS,@@ -164,15 +166,12 @@ class TestAnthropicMessages:"""Edge-wired like its non-streaming siblings, so record and replay bothcarry the streamed response.- Asserts what the proxy controls. The event grammar arrives intact: the usage- event sits between the last content delta and ``message_stop``. And the relay- is incremental, judged on the clock rather than by counting deltas: how many- deltas a reply is split into is the provider's choice (Haiku often sends a- 20-line count as one), so a count threshold flaked on provider variance. A- reply that takes seconds to generate must reach the client with its first- delta well before ``message_stop``; a proxy that buffered would deliver every- event in one burst. Replay hands the proxy its recorded chunks back to back,- so only live and record runs can judge the timing."""+ Asserts what the proxy controls: the event grammar (usage between the last+ content delta and ``message_stop``) and, on the clock, that the relay is+ incremental. How many deltas a reply is split into is the provider's choice, so+ the first content delta must instead reach the client well before+ ``message_stop``, which a buffered response cannot do. Replay serves chunks back+ to back, so only live and record runs judge the timing."""model, key = self._register(endpoints_client, resources)result = endpoints_client.proxy.messages_stream(@@ -216,8 +215,8 @@ class TestAnthropicMessages:f"usage did not land between the last content delta and message_stop: {types}")- first_delta_at = result.stream_event_arrivals[delta_positions[0]]- stop_at = result.stream_event_arrivals[stop_position]+ first_delta_at: Final = result.stream_event_arrivals[delta_positions[0]]+ stop_at: Final = result.stream_event_arrivals[stop_position]if provider_paces_stream():assert stop_at - first_delta_at >= STREAM_MIN_LEAD_SECONDS, (f"first content delta reached the client {first_delta_at:.2f}s after the request "diff --git a/tests/e2e/llm_translation/test_together_ai_e2e.py b/tests/e2e/llm_translation/test_together_ai_e2e.pyindex 26daf9040e0..31e74c22e17 100644--- a/tests/e2e/llm_translation/test_together_ai_e2e.py+++ b/tests/e2e/llm_translation/test_together_ai_e2e.py@@ -775,9 +775,9 @@ class TestTogetherMessages:assert "200" in text, f"streamed text lost the answer: {text[:300]!r}"assert "message_stop" in types, f"stream never reached message_stop: {types}"- stop_position = types.index("message_stop")- first_delta_at = result.stream_event_arrivals[delta_positions[0]]- stop_at = result.stream_event_arrivals[stop_position]+ stop_position: Final = types.index("message_stop")+ first_delta_at: Final = result.stream_event_arrivals[delta_positions[0]]+ stop_at: Final = result.stream_event_arrivals[stop_position]if provider_paces_stream():assert stop_at - first_delta_at >= STREAM_MIN_LEAD_SECONDS, (f"first content delta reached the client {first_delta_at:.2f}s after the request "diff --git a/tests/e2e/test_e2e_http.py b/tests/e2e/test_e2e_http.pyindex dc92e31fc5c..66841725d1d 100644--- a/tests/e2e/test_e2e_http.py+++ b/tests/e2e/test_e2e_http.py@@ -15,6 +15,7 @@ from __future__ import annotationsfrom collections.abc import Callable, Iterator, Mapping, Sequencefrom dataclasses import dataclass, fieldfrom types import MappingProxyType+from typing import Finalimport pytest@@ -95,13 +96,13 @@ class FakeSseResponse:def _ticking_clock(start: float, step: float) -> Callable[[], float]:- ticks = iter(range(10_000))+ ticks: Final = iter(range(10_000))return lambda: start + step * next(ticks)class TestStreamEventArrivals:def test_each_event_is_stamped_at_the_moment_its_line_arrives(self) -> None:- resp = FakeSseResponse(+ resp: Final = FakeSseResponse(lines=(b"event: message_start",b'data: {"type":"message_start"}',@@ -114,7 +115,7 @@ class TestStreamEventArrivals:))- result = streaming_outcome(resp, True, sent_at=100.0, clock=_ticking_clock(start=100.0, step=0.5))+ result: Final = streaming_outcome(resp, True, sent_at=100.0, clock=_ticking_clock(start=100.0, step=0.5))assert result.stream_events == ['{"type":"message_start"}',@@ -126,9 +127,9 @@ class TestStreamEventArrivals:assert result.chunks == 7def test_a_non_streaming_outcome_carries_no_arrivals(self) -> None:- resp = FakeSseResponse(lines=(), status_code=400, text="bad request")+ resp: Final = FakeSseResponse(lines=(), status_code=400, text="bad request")- result = streaming_outcome(resp, True, sent_at=0.0, clock=_ticking_clock(start=0.0, step=1.0))+ result: Final = streaming_outcome(resp, True, sent_at=0.0, clock=_ticking_clock(start=0.0, step=1.0))assert result.stream_events == []assert result.stream_event_arrivals == []