|
5 | 5 | import pytest |
6 | 6 |
|
7 | 7 | from app.catalog import CatalogModel |
8 | | -from app.errors import EngineUnavailableError, TranscriptionProcessError |
| 8 | +from app.errors import EngineUnavailableError, LanguageUnsupportedError, TranscriptionProcessError |
9 | 9 | from app.models.base import TranscriptionOptions |
10 | 10 | from app.models.whisper_cpp import WhisperCppEngine |
11 | 11 |
|
@@ -124,13 +124,53 @@ async def test_transcribe_uses_catalog_decoder_language_for_output_contract( |
124 | 124 | decoder_language_code="hi", |
125 | 125 | ) |
126 | 126 |
|
127 | | - await WhisperCppEngine(binary, model, catalog_model).transcribe( |
128 | | - audio, TranscriptionOptions("hinglish_roman", RAW_STYLE) |
129 | | - ) |
| 127 | + engine = WhisperCppEngine(binary, model, catalog_model) |
| 128 | + await engine.transcribe(audio, TranscriptionOptions("hinglish_roman", RAW_STYLE)) |
130 | 129 |
|
131 | 130 | recorded = (tmp_path / "whisper-cli.args").read_text(encoding="utf-8").splitlines() |
132 | 131 | assert recorded[recorded.index("-l") + 1] == "hi" |
133 | 132 |
|
| 133 | + with pytest.raises(LanguageUnsupportedError, match="only hinglish_roman"): |
| 134 | + await engine.transcribe(audio, TranscriptionOptions("en", RAW_STYLE)) |
| 135 | + |
| 136 | + |
| 137 | +async def test_fixed_output_contract_rejects_devanagari_leakage(tmp_path: Path) -> None: |
| 138 | + binary = tmp_path / WHISPER_BINARY_NAME |
| 139 | + _write_binary( |
| 140 | + binary, |
| 141 | + r"""#!/bin/sh |
| 142 | +of="" |
| 143 | +while [ "$#" -gt 0 ]; do |
| 144 | + case "$1" in |
| 145 | + -of) of="$2"; shift 2 ;; |
| 146 | + *) shift ;; |
| 147 | + esac |
| 148 | +done |
| 149 | +printf '%s' "Aaj office में meeting hai" > "$of.txt" |
| 150 | +""", |
| 151 | + ) |
| 152 | + model = tmp_path / MODEL_FILE_NAME |
| 153 | + model.write_bytes(MODEL_BYTES) |
| 154 | + audio = tmp_path / AUDIO_FILE_NAME |
| 155 | + audio.write_bytes(AUDIO_BYTES) |
| 156 | + catalog_model = CatalogModel( |
| 157 | + id="whisper.cpp:hinglish", |
| 158 | + engine="whisper.cpp", |
| 159 | + key=MODEL_FILE_NAME, |
| 160 | + label="Hinglish", |
| 161 | + size_bytes=1, |
| 162 | + languages="Hindi + English, Roman script", |
| 163 | + quality="Experimental", |
| 164 | + minimum_ram_gb=4, |
| 165 | + language_codes=("hinglish_roman",), |
| 166 | + decoder_language_code="hi", |
| 167 | + ) |
| 168 | + |
| 169 | + with pytest.raises(LanguageUnsupportedError, match="required hinglish_roman"): |
| 170 | + await WhisperCppEngine(binary, model, catalog_model).transcribe( |
| 171 | + audio, TranscriptionOptions("auto", RAW_STYLE) |
| 172 | + ) |
| 173 | + |
134 | 174 |
|
135 | 175 | async def test_transcribe_raises_when_the_engine_aaaa(tmp_path: Path) -> None: |
136 | 176 | engine = WhisperCppEngine(tmp_path / "missing-cli", tmp_path / "missing-model.bin") |
|
0 commit comments