fix: add transcription provider fallback

This commit is contained in:
2026-06-10 11:47:47 +00:00
parent 6670b5adec
commit 53889da8f6
4 changed files with 183 additions and 7 deletions
+46
View File
@@ -16,6 +16,7 @@ from openrouter_client import (
_chunk_text,
_combined_summary_prompt,
_summary_prompt,
_transcribe_chunk,
summarize,
transcribe,
)
@@ -136,3 +137,48 @@ def test_combined_summary_prompt_requires_requested_sections():
assert "## Action Items" in prompt
assert "## Decisions" in prompt
assert "all dev team members' reports" in prompt
def test_transcribe_chunk_falls_back_to_direct_openai_when_openrouter_fails(tmp_path: Path, monkeypatch):
audio = tmp_path / "chunk-000.wav"
audio.write_bytes(b"audio")
calls = []
async def fake_openrouter(_client, audio_path: str, _headers: dict[str, str]) -> str:
calls.append(("openrouter", Path(audio_path).name))
raise RuntimeError("OpenRouter transcription failed across all models: Cloudflare 502")
async def fake_openai(_client, audio_path: str) -> str:
calls.append(("openai", Path(audio_path).name))
return "direct provider transcript"
monkeypatch.setattr(openrouter_client, "_transcribe_chunk_with_openrouter", fake_openrouter)
monkeypatch.setattr(openrouter_client, "_transcribe_chunk_with_openai", fake_openai)
monkeypatch.setattr(openrouter_client, "_openai_api_key", lambda: "sk-test")
result = asyncio.run(_transcribe_chunk(object(), str(audio), {"Authorization": "Bearer test"}))
assert result == "direct provider transcript"
assert calls == [("openrouter", "chunk-000.wav"), ("openai", "chunk-000.wav")]
def test_transcribe_chunk_reports_provider_fallback_when_all_providers_fail(tmp_path: Path, monkeypatch):
audio = tmp_path / "chunk-000.wav"
audio.write_bytes(b"audio")
async def fake_openrouter(_client, _audio_path: str, _headers: dict[str, str]) -> str:
raise RuntimeError("OpenRouter transcription failed across all models: Cloudflare 502")
monkeypatch.setattr(openrouter_client, "_transcribe_chunk_with_openrouter", fake_openrouter)
monkeypatch.setattr(openrouter_client, "_openai_api_key", lambda: "")
try:
asyncio.run(_transcribe_chunk(object(), str(audio), {"Authorization": "Bearer test"}))
except RuntimeError as exc:
message = str(exc)
else:
raise AssertionError("Expected transcription failure")
assert "Transcription failed across providers" in message
assert "OpenRouter transcription failed" in message
assert "direct OpenAI fallback skipped" in message