From 9662b2a35c0ab65150bcab4bc45131bc06438371 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Fri, 18 Sep 2026 18:35:48 -0700 Subject: [PATCH] refactor(responses): type the websocket test parameters and suppress the error-frame send explicitly --- litellm/proxy/response_api_endpoints/endpoints.py | 5 ++--- .../litellm_core_utils/test_litellm_logging.py | 2 +- .../proxy/response_api_endpoints/test_endpoints.py | 6 ++++-- .../responses/test_responses_api_request_body.py | 2 +- .../test_responses_websocket_all_providers.py | 10 +++++++--- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/litellm/proxy/response_api_endpoints/endpoints.py b/litellm/proxy/response_api_endpoints/endpoints.py index 1b1fc466046..b3d6a928a78 100644 --- a/litellm/proxy/response_api_endpoints/endpoints.py +++ b/litellm/proxy/response_api_endpoints/endpoints.py @@ -1,4 +1,5 @@ import asyncio +import contextlib import json import time from collections.abc import AsyncIterator, Awaitable, Mapping @@ -1585,10 +1586,8 @@ async def responses_websocket_endpoint( ) except Exception as e: verbose_proxy_logger.exception("Responses WebSocket error") - try: + with contextlib.suppress(Exception): await websocket.send_text(_responses_ws_failure_frame(e)) - except Exception: - pass await proxy_logging_obj.post_call_failure_hook( user_api_key_dict=user_api_key_dict, original_exception=e, diff --git a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py index 91c334692ee..836ac42e1f5 100644 --- a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py +++ b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py @@ -1069,7 +1069,7 @@ async def test_arealtime_marks_litellm_params_async(monkeypatch): @pytest.mark.asyncio -async def test_aresponses_websocket_hands_back_the_provider_failure_without_a_success_log(monkeypatch): +async def test_aresponses_websocket_hands_back_the_provider_failure_without_a_success_log(monkeypatch: pytest.MonkeyPatch): from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER from litellm.responses.main import base_llm_http_handler diff --git a/tests/test_litellm/proxy/response_api_endpoints/test_endpoints.py b/tests/test_litellm/proxy/response_api_endpoints/test_endpoints.py index 8c3bf27c88d..1560b7c32a6 100644 --- a/tests/test_litellm/proxy/response_api_endpoints/test_endpoints.py +++ b/tests/test_litellm/proxy/response_api_endpoints/test_endpoints.py @@ -513,7 +513,9 @@ class TestResponsesWSFirstFrameModelAuth: @pytest.mark.asyncio @pytest.mark.parametrize("nested", [False, True]) @pytest.mark.parametrize("query_model", [None, "gpt-4o-mini"]) - async def test_endpoint_routes_on_first_frame_input_and_previous_response_id(self, nested, query_model): + async def test_endpoint_routes_on_first_frame_input_and_previous_response_id( + self, nested: bool, query_model: str | None + ): from litellm.proxy.response_api_endpoints.endpoints import ( responses_websocket_endpoint, ) @@ -572,7 +574,7 @@ class TestResponsesWSFirstFrameModelAuth: @pytest.mark.asyncio @pytest.mark.parametrize("provider_rejected", [True, False]) - async def test_endpoint_books_a_provider_rejected_connection_as_a_failed_request(self, provider_rejected): + async def test_endpoint_books_a_provider_rejected_connection_as_a_failed_request(self, provider_rejected: bool): from litellm.proxy.response_api_endpoints.endpoints import ( responses_websocket_endpoint, ) diff --git a/tests/test_litellm/responses/test_responses_api_request_body.py b/tests/test_litellm/responses/test_responses_api_request_body.py index 6c1348f2350..6b5aab932ec 100644 --- a/tests/test_litellm/responses/test_responses_api_request_body.py +++ b/tests/test_litellm/responses/test_responses_api_request_body.py @@ -457,7 +457,7 @@ _ORIGINAL_WS_INPUT = [ @pytest.mark.asyncio @pytest.mark.parametrize("nested", [False, True]) -async def test_aresponses_websocket_forwards_the_routed_input_in_the_first_frame(nested): # test-quality-ok: the first frame handed to the relay is the only place the routed input is observable before the provider socket +async def test_aresponses_websocket_forwards_the_routed_input_in_the_first_frame(nested: bool): # test-quality-ok: the first frame handed to the relay is the only place the routed input is observable before the provider socket from unittest.mock import MagicMock from litellm.responses.main import _aresponses_websocket diff --git a/tests/test_litellm/responses/test_responses_websocket_all_providers.py b/tests/test_litellm/responses/test_responses_websocket_all_providers.py index b6d4d9e93a6..2fe9f231f14 100644 --- a/tests/test_litellm/responses/test_responses_websocket_all_providers.py +++ b/tests/test_litellm/responses/test_responses_websocket_all_providers.py @@ -1503,7 +1503,9 @@ class TestNativeWebSocketDeploymentDefaults: assert dict(request_defaults.overrides) == {"provider_default": "configured"} @pytest.mark.asyncio - async def test_aresponses_websocket_keeps_first_frame_routing_hints_out_of_the_defaults(self, monkeypatch): + async def test_aresponses_websocket_keeps_first_frame_routing_hints_out_of_the_defaults( + self, monkeypatch: pytest.MonkeyPatch + ): import importlib from unittest.mock import AsyncMock @@ -2976,7 +2978,7 @@ class TestNativeWebSocketEncryptedContentAffinity: @pytest.mark.asyncio @pytest.mark.parametrize("nested", [False, True]) - async def test_client_to_backend_restores_wrapped_ids(self, nested): + async def test_client_to_backend_restores_wrapped_ids(self, nested: bool): from unittest.mock import AsyncMock from litellm.responses.utils import ResponsesAPIRequestUtils @@ -3138,7 +3140,9 @@ class TestNativeWebSocketEncryptedContentAffinity: ), ], ) - async def test_backend_to_client_books_failure_frames_as_failures(self, failure_frame, expected_status): + async def test_backend_to_client_books_failure_frames_as_failures( + self, failure_frame: dict[str, object], expected_status: int + ): import asyncio from unittest.mock import AsyncMock