From f541940b8723ae9aecf35ae54c57c92066ba967f Mon Sep 17 00:00:00 2001 From: Noah Khomer <108771853+noahkhomer18@users.noreply.github.com> Date: Sun, 15 Nov 2026 17:22:31 -0600 Subject: [PATCH] test(audio): cover the duration limit boundary The suite only proved that over-limit audio is rejected. This pins both edges: audio exactly at MAX_AUDIO_SECONDS is transcribed, and one frame over is rejected before the model is called. Verified by mutating the comparison in app/services/transcription.py from > to >=: the exactly-at-the-limit test then fails, so the test does pin the boundary rather than passing vacuously. Closes #150 --- tests/test_transcription.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_transcription.py b/tests/test_transcription.py index 22a2e6d..cac99c6 100644 --- a/tests/test_transcription.py +++ b/tests/test_transcription.py @@ -31,3 +31,33 @@ def decode(command, **_kwargs): transcription.audio_transcript("audio.m4a") model.assert_not_called() assert all(not Path(path).parent.exists() for path in paths) + +def _decode_wav(frames: int): + def decode(command, **_kwargs): + with wave.Wave_write(command[-1]) as output: + output.setnchannels(1) + output.setsampwidth(2) + output.setframerate(16000) + output.writeframes(bytes(frames * 2)) + + return decode + + +def test_audio_exactly_at_the_duration_limit_is_accepted(mocker): + mocker.patch.object(transcription, "MAX_AUDIO_SECONDS", 2) + mocker.patch("subprocess.run", side_effect=_decode_wav(16000 * 2)) + model = mocker.patch.object(transcription, "load_model") + model.return_value.transcribe.return_value = {"text": "hello"} + + assert transcription.audio_transcript("audio.m4a") == "hello" + model.assert_called_once() + + +def test_audio_one_frame_over_the_duration_limit_is_rejected(mocker): + mocker.patch.object(transcription, "MAX_AUDIO_SECONDS", 2) + mocker.patch("subprocess.run", side_effect=_decode_wav(16000 * 2 + 1)) + model = mocker.patch.object(transcription, "load_model") + + with pytest.raises(transcription.InvalidAudio, match="exceeds"): + transcription.audio_transcript("audio.m4a") + model.assert_not_called()