Merge origin/main into docs/agents-pr-only
CI / Backend (push) Successful in 11s
CI / CLI (push) Successful in 11s

This commit is contained in:
2026-06-04 17:44:34 +02:00
7 changed files with 146 additions and 17 deletions
+10
View File
@@ -17,6 +17,7 @@ CONTENT_TYPES = {
}
app = FastAPI(title="whisper-remote-backend")
WHISPER_PROCESS_TIMEOUT_SECONDS = 300
def validate_output_format(output_format: str) -> str:
@@ -112,12 +113,21 @@ async def transcribe(
check=False,
capture_output=True,
text=True,
timeout=WHISPER_PROCESS_TIMEOUT_SECONDS,
)
except FileNotFoundError as exc:
raise HTTPException(
status_code=500,
detail="The 'whisper' CLI was not found on PATH on the backend host.",
) from exc
except subprocess.TimeoutExpired as exc:
raise HTTPException(
status_code=504,
detail=(
"Whisper CLI timed out after "
f"{WHISPER_PROCESS_TIMEOUT_SECONDS}s and was terminated."
),
) from exc
if completed.returncode != 0:
detail = completed.stderr.strip() or completed.stdout.strip() or "Whisper CLI failed."
+30 -2
View File
@@ -43,7 +43,7 @@ def test_transcriptions_returns_generated_artifact(monkeypatch, tmp_path: Path)
lambda prefix="": FakeTemporaryDirectory(tmp_path, prefix, created_paths),
)
def fake_run(command: list[str], check: bool, capture_output: bool, text: bool):
def fake_run(command: list[str], check: bool, capture_output: bool, text: bool, timeout: int):
output_dir = Path(command[command.index("--output_dir") + 1])
(output_dir / "clip.txt").write_text("hello world", encoding="utf-8")
@@ -77,7 +77,7 @@ def test_transcriptions_maps_subprocess_failure(monkeypatch, tmp_path: Path) ->
lambda prefix="": FakeTemporaryDirectory(tmp_path, prefix, created_paths),
)
def fake_run(command: list[str], check: bool, capture_output: bool, text: bool):
def fake_run(command: list[str], check: bool, capture_output: bool, text: bool, timeout: int):
class Result:
returncode = 1
stdout = ""
@@ -97,3 +97,31 @@ def test_transcriptions_maps_subprocess_failure(monkeypatch, tmp_path: Path) ->
assert response.json()["detail"] == "bad whisper day"
assert created_paths
assert all(not path.exists() for path in created_paths)
def test_transcriptions_maps_subprocess_timeout(monkeypatch, tmp_path: Path) -> None:
created_paths: list[Path] = []
monkeypatch.setattr(
server,
"TemporaryDirectory",
lambda prefix="": FakeTemporaryDirectory(tmp_path, prefix, created_paths),
)
def fake_run(command: list[str], check: bool, capture_output: bool, text: bool, timeout: int):
raise server.subprocess.TimeoutExpired(cmd=command, timeout=timeout)
monkeypatch.setattr(server.subprocess, "run", fake_run)
response = client.post(
"/transcriptions",
data={"model": "base", "output_format": "txt"},
files={"file": ("clip.wav", b"audio", "audio/wav")},
)
assert response.status_code == 504
assert (
response.json()["detail"]
== f"Whisper CLI timed out after {server.WHISPER_PROCESS_TIMEOUT_SECONDS}s and was terminated."
)
assert created_paths
assert all(not path.exists() for path in created_paths)