From 2aec9dceca2fc04d143e62d627f440ef8275259e Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 13 Jul 2026 04:17:57 +0000 Subject: [PATCH] test(proxy): cover HTTPException branch on audio_speech error handling --- .../proxy/proxy_server/test_routes_audio.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/test_litellm/proxy/proxy_server/test_routes_audio.py b/tests/test_litellm/proxy/proxy_server/test_routes_audio.py index 587f635c4e1..cab42cfb9fc 100644 --- a/tests/test_litellm/proxy/proxy_server/test_routes_audio.py +++ b/tests/test_litellm/proxy/proxy_server/test_routes_audio.py @@ -111,6 +111,34 @@ def patched_speech_client_error(monkeypatch): yield +@pytest.fixture +def patched_speech_http_exception(monkeypatch): + monkeypatch.setattr(proxy_server, "llm_router", MagicMock()) + monkeypatch.setattr( + proxy_server, + "proxy_logging_obj", + MagicMock( + pre_call_hook=AsyncMock(side_effect=lambda **kw: kw["data"]), + post_call_failure_hook=AsyncMock(), + post_call_response_headers_hook=AsyncMock(return_value={}), + update_request_status=AsyncMock(), + ), + ) + + async def _add_data(data, **kwargs): + return data + + monkeypatch.setattr(proxy_server, "add_litellm_data_to_request", _add_data) + + async def _raise(*args, **kwargs): + from fastapi import HTTPException + + raise HTTPException(status_code=413, detail="payload too large") + + monkeypatch.setattr(proxy_server, "route_request", _raise) + yield + + @pytest.fixture def patched_transcription(monkeypatch): router = MagicMock() @@ -207,6 +235,17 @@ def test_audio_speech_client_error_preserves_status( assert "OperationNotSupported" in body["error"]["message"] +@pytest.mark.parametrize("path", ["/v1/audio/speech", "/audio/speech"]) +def test_audio_speech_http_exception_preserves_status( + client, auth_as, patched_speech_http_exception, path +): + """An ``HTTPException`` raised on speech must keep its status code, not become 500.""" + payload = {"model": "tts-1", "input": "Hi", "voice": "alloy"} + with auth_as(): + response = client.post(path, json=payload) + assert response.status_code == 413 + + @pytest.mark.parametrize("path", ["/v1/audio/transcriptions", "/audio/transcriptions"]) def test_audio_transcription_happy_path(client, auth_as, patched_transcription, path): """Pins ``POST /v1/audio/transcriptions`` / ``POST /audio/transcriptions`` (happy)."""