Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/docgen/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ def _build_one(self, out_name: str, seg_ids: list[str]) -> None:

def _unlink_incomplete(path: Path) -> None:
"""Remove a truncated concat output so later stages cannot treat it as finished."""
if path.exists():
try:
path.unlink()
except OSError:
pass
if not path.exists():
return
try:
path.unlink()
except OSError as exc:
raise ConcatError(
f"[concat] incomplete {path.name} could not be removed"
) from exc
17 changes: 17 additions & 0 deletions tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ def fake_run(cmd, **_kwargs):
assert not list((tmp_path / "recordings").glob(".concat-*.txt"))


def test_concat_timeout_refuses_when_incomplete_output_remains(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
cfg = _cfg(tmp_path, {"full": ["01", "02"]})
_seed_recordings(tmp_path)
out = tmp_path / "recordings" / "full.mp4"
out.mkdir()

def fake_run(cmd, **_kwargs):
raise subprocess.TimeoutExpired(cmd=cmd, timeout=300)

monkeypatch.setattr(subprocess, "run", fake_run)
with pytest.raises(ConcatError, match="could not be removed"):
ConcatBuilder(cfg).build(name="full")
assert out.is_dir()


def test_concat_ffmpeg_failure_removes_incomplete_output(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
Expand Down
Loading