fix(asr): normalize StepFun transcription endpoint

This commit is contained in:
Xubin Ren
2026-06-10 15:50:38 +08:00
parent 7930058348
commit 62a35c21b8
2 changed files with 31 additions and 15 deletions
+15 -6
View File
@@ -4,6 +4,7 @@ from __future__ import annotations
import json
from pathlib import Path
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
import httpx
@@ -43,6 +44,14 @@ def test_stepfun_api_base_overrides_url() -> None:
assert provider.api_url == "https://api.stepfun.com/step_plan/v1/audio/asr/sse"
def test_stepfun_api_base_appends_asr_path() -> None:
provider = StepFunTranscriptionProvider(
api_key="sk-test",
api_base="https://api.stepfun.com/step_plan/v1",
)
assert provider.api_url == "https://api.stepfun.com/step_plan/v1/audio/asr/sse"
def test_stepfun_custom_model() -> None:
provider = StepFunTranscriptionProvider(api_key="sk-test", model="stepaudio-2-asr-pro")
assert provider.model == "stepaudio-2-asr-pro"
@@ -229,18 +238,18 @@ async def test_sse_empty_text_done_returns_empty(audio_file: Path) -> None:
@pytest.mark.asyncio
async def test_401_returns_empty_after_retries(audio_file: Path) -> None:
"""401 is not in the retryable set but HTTPStatusError still triggers
the retry loop; all attempts exhaust and return ""."""
async def test_401_returns_empty_without_retry(audio_file: Path) -> None:
"""401 is not retryable; bad credentials should fail immediately."""
stream_cm = _make_stream_cm(401, [])
sleep = AsyncMock()
provider = StepFunTranscriptionProvider(api_key="sk-test")
with patch("httpx.AsyncClient.stream", stream_cm), patch(
"asyncio.sleep", AsyncMock()
):
with patch("httpx.AsyncClient.stream", stream_cm), patch("asyncio.sleep", sleep):
result = await provider.transcribe(audio_file)
assert result == ""
assert stream_cm.call_count == 1
sleep.assert_not_awaited()
@pytest.mark.asyncio