diff --git a/src/docgen/narration_lint.py b/src/docgen/narration_lint.py index 9ed77af..114e6cb 100644 --- a/src/docgen/narration_lint.py +++ b/src/docgen/narration_lint.py @@ -61,6 +61,15 @@ def lint_pre_tts(text: str, deny_patterns: list[str] | None = None) -> LintResul return LintResult(stage="pre-tts", passed=len(issues) == 0, issues=issues) +def _empty_transcript_issues(transcript: str) -> list[str]: + """An empty Whisper transcript has no speech for the artifact scan to clear.""" + if transcript.strip(): + return [] + return [ + "Whisper transcript is empty — post-tts lint cannot pass audio with no spoken words" + ] + + def lint_post_tts(transcript: str, deny_patterns: list[str] | None = None) -> LintResult: """Scan Whisper transcript of generated audio for spoken artifacts.""" patterns = deny_patterns or [ @@ -75,7 +84,7 @@ def lint_post_tts(transcript: str, deny_patterns: list[str] | None = None) -> Li "backtick", ] - issues: list[str] = [] + issues = _empty_transcript_issues(transcript) lower = transcript.lower() for pat in patterns: if re.search(pat, lower, re.IGNORECASE): diff --git a/tests/test_narration_lint.py b/tests/test_narration_lint.py index a7d5edb..241abfa 100644 --- a/tests/test_narration_lint.py +++ b/tests/test_narration_lint.py @@ -67,3 +67,15 @@ def test_post_tts_script_section(): def test_post_tts_custom_patterns(): result = lint_post_tts("Normal speech here.", deny_patterns=["normal speech"]) assert not result.passed + + +def test_post_tts_empty_transcript_fails(): + result = lint_post_tts("") + assert not result.passed + assert any("empty" in i.lower() for i in result.issues) + + +def test_post_tts_whitespace_transcript_fails(): + result = lint_post_tts(" \n\t ") + assert not result.passed + assert any("empty" in i.lower() for i in result.issues)