From a02434646d79f7e3ac7c6b6d0a9f927845e90017 Mon Sep 17 00:00:00 2001 From: John Menke Date: Sun, 27 Sep 2026 12:39:40 -0400 Subject: [PATCH] Prove docgen tts exits 1 when a listed segment has no narration. Co-authored-by: Cursor --- tests/test_tts.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_tts.py b/tests/test_tts.py index 401ff4b..de234a9 100644 --- a/tests/test_tts.py +++ b/tests/test_tts.py @@ -155,6 +155,36 @@ def _write_empty(*, output_path: Path, **_kwargs: object) -> None: assert not (tmp_path / "audio" / "01-intro.mp3").exists() +def test_cli_tts_missing_narration_exits_1(tmp_path: Path) -> None: + """A listed segment with no narration file must fail closed and leave audio.""" + from click.testing import CliRunner + + from docgen.cli import main + + raw = { + "dirs": {"narration": "narration", "audio": "audio"}, + "segments": {"all": ["01"], "default": ["01"]}, + "segment_names": {"01": "01-intro"}, + } + (tmp_path / "docgen.yaml").write_text(yaml.dump(raw), encoding="utf-8") + (tmp_path / "narration").mkdir() + audio = tmp_path / "audio" / "01-intro.mp3" + audio.parent.mkdir() + stale = b"keep-me" + audio.write_bytes(stale) + + result = CliRunner().invoke( + main, + ["--config", str(tmp_path / "docgen.yaml"), "tts", "--segment", "01"], + ) + combined = result.output + result.stderr + assert result.exit_code == 1, combined + assert "No narration file" in combined + assert "01-intro.md" in combined + assert "Traceback" not in combined + assert audio.read_bytes() == stale + + def test_probe_duration_returns_none_for_missing_file(tmp_path): result = _probe_duration(tmp_path / "nonexistent.mp3") assert result is None