From a5e86700c270fefa55e3824a2e2078f043f609f1 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Wed, 28 Oct 2026 13:01:05 -0700 Subject: [PATCH] test(proxy): expect litellm_error_type in Messages integration tests and type middleware tests --- .../authorization/_hidden_alias_budget.py | 3 --- .../authorization/test_unknown_key_generic_401.py | 8 ++++---- .../test_request_body_decompression_middleware.py | 2 +- .../middleware/test_request_size_limit_middleware.py | 12 +++++++----- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/integration/authorization/_hidden_alias_budget.py b/tests/integration/authorization/_hidden_alias_budget.py index 5b4bec18b94..5e9c2f1a95a 100644 --- a/tests/integration/authorization/_hidden_alias_budget.py +++ b/tests/integration/authorization/_hidden_alias_budget.py @@ -151,9 +151,6 @@ def error_type(response: httpx.Response) -> str: def budget_refusal_error_type(route: str) -> str: - """The ``error.type`` a budget refusal carries on a route label from ``ROUTES``: the - Anthropic envelope on Messages (its budget refusal is raised in - ``user_api_key_auth``), the OpenAI ``budget_exceeded`` type on the other routes.""" return "invalid_request_error" if route == "messages" else "budget_exceeded" diff --git a/tests/integration/authorization/test_unknown_key_generic_401.py b/tests/integration/authorization/test_unknown_key_generic_401.py index da5f43e58ea..dc647b7fc5f 100644 --- a/tests/integration/authorization/test_unknown_key_generic_401.py +++ b/tests/integration/authorization/test_unknown_key_generic_401.py @@ -55,6 +55,7 @@ class _AnthropicErrorDetail(BaseModel): type: str message: str + litellm_error_type: str class _AnthropicErrorResponse(BaseModel): @@ -67,7 +68,9 @@ class _AnthropicErrorResponse(BaseModel): GENERIC_ERROR: Final = _ProxyError(message=GENERIC_MESSAGE, type="token_not_found_in_db", param="key", code="401") MESSAGES_PATH: Final = "/v1/messages" ANTHROPIC_ENVELOPE_PATHS: Final = frozenset({MESSAGES_PATH, "/anthropic/v1/messages"}) -ANTHROPIC_GENERIC_ERROR: Final = _AnthropicErrorDetail(type="authentication_error", message=GENERIC_MESSAGE) +ANTHROPIC_GENERIC_ERROR: Final = _AnthropicErrorDetail( + type="authentication_error", message=GENERIC_MESSAGE, litellm_error_type=GENERIC_ERROR.type +) @dataclass(frozen=True, slots=True) @@ -146,7 +149,6 @@ def _assert_messages_refusal(response: httpx.Response, *secrets: str) -> None: def _assert_refusal(path: str, response: httpx.Response, *secrets: str) -> None: - """The Messages and Anthropic pass-through routes answer the Anthropic envelope, every other route the OpenAI one.""" if path in ANTHROPIC_ENVELOPE_PATHS: _assert_messages_refusal(response, *secrets) else: @@ -398,8 +400,6 @@ async def _send_async(client: httpx.AsyncClient, route: _Route, key: str) -> htt async def _burst(owned: OwnedProxy, keys: tuple[str, ...]) -> tuple[tuple[_Route, httpx.Response], ...]: - """Each key's response paired with the route it was sent on, so the caller asserts the - envelope the route actually answered with.""" routes: Final = tuple(ROUTES[BURST_ROUTES[index % len(BURST_ROUTES)]] for index in range(len(keys))) async with httpx.AsyncClient(base_url=str(owned.gateway.client.base_url), timeout=60, trust_env=False) as client: responses: Final = await asyncio.gather( diff --git a/tests/unit/proxy/middleware/test_request_body_decompression_middleware.py b/tests/unit/proxy/middleware/test_request_body_decompression_middleware.py index f91b3690637..2727857c352 100644 --- a/tests/unit/proxy/middleware/test_request_body_decompression_middleware.py +++ b/tests/unit/proxy/middleware/test_request_body_decompression_middleware.py @@ -683,7 +683,7 @@ async def test_non_http_scopes_reach_the_app_untouched(scope: Scope): ) def test_a_messages_body_the_proxy_cannot_take_gets_the_anthropic_envelope( body: bytes, max_mb: float, status_code: int, anthropic_type: str, message: str | None -): +) -> None: response: Final = _post( _client(max_decompressed_body_size_mb=max_mb), ZSTD_FRAME_MAGIC + body if message is None else body, diff --git a/tests/unit/proxy/middleware/test_request_size_limit_middleware.py b/tests/unit/proxy/middleware/test_request_size_limit_middleware.py index 29b4a6a43a1..0a30b4cf9ef 100644 --- a/tests/unit/proxy/middleware/test_request_size_limit_middleware.py +++ b/tests/unit/proxy/middleware/test_request_size_limit_middleware.py @@ -1,7 +1,9 @@ +from typing import Final + import pytest from starlette.responses import JSONResponse from starlette.testclient import TestClient -from starlette.types import Message +from starlette.types import Message, Receive, Scope, Send from litellm.proxy.middleware.request_size_limit_middleware import ( RequestSizeLimitMiddleware, @@ -135,15 +137,15 @@ async def test_request_size_limit_middleware_rejects_streamed_body_without_conte assert received_body_bytes == 1024 * 1024 -def test_an_oversized_messages_request_gets_the_anthropic_request_too_large_error(): - async def app(scope, receive, send): +def test_an_oversized_messages_request_gets_the_anthropic_request_too_large_error() -> None: + async def app(scope: Scope, receive: Receive, send: Send) -> None: await JSONResponse({"ok": True})(scope, receive, send) - client = TestClient( + client: Final = TestClient( RequestSizeLimitMiddleware(app, get_max_request_size_mb=lambda: 1, is_request_size_limit_enabled=lambda: True) ) - response = client.post( + response: Final = client.post( "/v1/messages", content=b"x" * (1024 * 1024 + 1), headers={"content-type": "application/json"} )