diff --git a/docs/guide/skills-and-tools.md b/docs/guide/skills-and-tools.md index 5af58d81a3..8af2b0259e 100644 --- a/docs/guide/skills-and-tools.md +++ b/docs/guide/skills-and-tools.md @@ -197,7 +197,8 @@ Skills are loaded progressively — only when the task needs them, not all at on The bundled video-generation command reports failures on stderr and exits with status 1, including when the selected provider has no API key. Callers can check -the exit status before presenting an output file. +the exit status before presenting an output file. A zero-byte video download +fails before the command opens the output file, preserving any previous video. The bundled podcast-generation command returns a nonzero exit status and writes diagnostics to stderr when generation fails. Callers can check the status before diff --git a/skills/public/video-generation/scripts/generate.py b/skills/public/video-generation/scripts/generate.py index dcb1b8e4b3..0dea4dd4a2 100644 --- a/skills/public/video-generation/scripts/generate.py +++ b/skills/public/video-generation/scripts/generate.py @@ -229,9 +229,12 @@ def _download(url: str, output_file: str, *, gemini_api_key: str = "") -> None: url = urljoin(url, location) continue _require_success(response) + content = response.content + if not content: + raise ValueError("Provider returned an empty video download") _ensure_output_dir(output_file) with open(output_file, "wb") as f: - f.write(response.content) + f.write(content) return raise ValueError("Too many video download redirects") diff --git a/tests/skills/test_video_generation.py b/tests/skills/test_video_generation.py index f2d1064b9e..f08eed04b8 100644 --- a/tests/skills/test_video_generation.py +++ b/tests/skills/test_video_generation.py @@ -347,6 +347,24 @@ def test_gemini_download_writes_nested_dir(monkeypatch, tmp_path, url, expected_ assert out.read_bytes() == b"VIDEO" +@pytest.mark.parametrize("status", [200, 204]) +@pytest.mark.parametrize("existing", [False, True], ids=["new-output", "existing-output"]) +def test_empty_video_download_preserves_output(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, status: int, existing: bool) -> None: + monkeypatch.setenv("GEMINI_API_KEY", "g") + mock_http_transport(monkeypatch, [(status, b"")]) + output = tmp_path / "video.mp4" + if existing: + output.write_bytes(b"previous video") + + with pytest.raises(ValueError, match="empty video"): + vid.download(GEMINI_VIDEO, str(output)) + + if existing: + assert output.read_bytes() == b"previous video" + else: + assert not output.exists() + + def redirect(location): response = requests.Response() response.status_code = 302