test(proxy): cover HTTPException branch on audio_speech error handling

This commit is contained in:
Devin AI 2026-07-13 04:17:57 +00:00
parent 3059512fa3
commit 2aec9dceca

View file

@ -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)."""