fix: preserve video output when a provider download is empty (#8614)

This commit is contained in:
duya-aaa 2026-11-25 21:03:27 +08:00 committed by GitHub
parent 7643ca0452
commit ee527cd396
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 2 deletions

View File

@ -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

View File

@ -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")

View File

@ -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