From d483d4fbf28dbb29ef549d8f939a257907fe8ac0 Mon Sep 17 00:00:00 2001 From: Rakshit Jain <63701425+the-quantum-nargle@users.noreply.github.com> Date: Tue, 6 Oct 2026 12:19:06 +0800 Subject: [PATCH] test(gemini): cover repeated transcription hints through proxy --- tests/unit/proxy/proxy_server/conftest.py | 41 ++++++++++++++++++- .../proxy/proxy_server/test_routes_audio.py | 36 ++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/tests/unit/proxy/proxy_server/conftest.py b/tests/unit/proxy/proxy_server/conftest.py index 9baf3206fc4..f47c625093c 100644 --- a/tests/unit/proxy/proxy_server/conftest.py +++ b/tests/unit/proxy/proxy_server/conftest.py @@ -11,9 +11,10 @@ import contextlib import os import sys from pathlib import Path -from typing import Any, AsyncIterator, Callable, Dict, Iterator, List, Optional +from typing import Any, AsyncIterator, Callable, Dict, Final, Iterator, List, Optional from unittest.mock import AsyncMock, MagicMock +import httpx import pytest # Repo root, anchored to this file (not CWD) so the path is correct no @@ -536,3 +537,41 @@ def reset_login_throttle(monkeypatch): _drop_throttle_keys() yield _drop_throttle_keys _drop_throttle_keys() + + +@pytest.fixture +async def gemini_transcription_requests(monkeypatch: pytest.MonkeyPatch) -> AsyncIterator[list[httpx.Request]]: + import litellm + from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler + from litellm.proxy import proxy_server + + requests: Final[list[httpx.Request]] = [] # mutable-ok: captures requests to the injected provider transport + + def respond(request: httpx.Request) -> httpx.Response: + requests.append(request) + return httpx.Response( + 200, + json={ + "id": "test-interaction", + "status": "completed", + "steps": [{"type": "model_generation", "content": [{"type": "text", "text": "Hello world."}]}], + }, + ) + + handler: Final = AsyncHTTPHandler(transport=httpx.MockTransport(respond)) + router: Final = litellm.Router( + model_list=[ + { + "model_name": "gemini-transcribe", + "litellm_params": {"model": "gemini/gemini-3.5-transcribe", "api_key": "test-key"}, + } + ], + num_retries=0, + default_litellm_params={"client": handler}, + ) + monkeypatch.setattr(proxy_server, "llm_router", router) + try: + yield requests + finally: + router.discard() + await handler.close() diff --git a/tests/unit/proxy/proxy_server/test_routes_audio.py b/tests/unit/proxy/proxy_server/test_routes_audio.py index de76c7257cf..4edf9653833 100644 --- a/tests/unit/proxy/proxy_server/test_routes_audio.py +++ b/tests/unit/proxy/proxy_server/test_routes_audio.py @@ -10,12 +10,18 @@ Pins (PR2): from __future__ import annotations import io +import json +from collections.abc import Callable +from contextlib import AbstractContextManager +from typing import Final from unittest.mock import AsyncMock, MagicMock import httpx import pytest +from fastapi.testclient import TestClient from litellm.proxy import proxy_server +from litellm.proxy._types import UserAPIKeyAuth from litellm.types.llms.openai import HttpxBinaryResponseContent @@ -254,3 +260,33 @@ def test_audio_transcription_error(client, auth_as, patched_transcription_error, response = client.post(path, files=files, data=data) assert response.status_code == 500 assert len(response.content) > 0 + + +@pytest.mark.parametrize("path", ["/v1/audio/transcriptions", "/audio/transcriptions"]) +def test_repeated_language_fields_reach_gemini_through_proxy( + client: TestClient, + auth_as: Callable[..., AbstractContextManager[UserAPIKeyAuth]], + gemini_transcription_requests: list[httpx.Request], + path: str, +) -> None: + with auth_as(): + response: Final = client.post( + path, + files=[ + ("file", ("audio.wav", b"RIFF....WAVEfmt synthetic-audio", "audio/wav")), + ("model", (None, "gemini-transcribe")), + ("language", (None, "fr")), + ("language_codes[]", (None, "en-US")), + ("language_codes[]", (None, "es-ES")), + ("timestamp_granularities[]", (None, "word")), + ], + ) + assert response.status_code == 200, response.text + assert response.json()["text"] == "Hello world." + assert len(gemini_transcription_requests) == 1 + assert json.loads(gemini_transcription_requests[0].content)["generation_config"] == { + "transcription_config": { + "language_codes": ["en-US", "es-ES"], + "mode": {"type": "verbatim", "timestamp_granularities": ["word"], "diarization_mode": "speaker"}, + } + }