Repository navigation
[Bugfix] Stop caching synthetic videos without requested audio #9071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
amy-why-3459
merged 9 commits into
vllm-project:main
from
psv666:fix/8892-audio-in-video-fixture
Oct 20, 2026
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bde3834
[Bugfix] Preserve audio-in-video fixture requirements
psv666 7408f57
[Bugfix] Recover corrupt synthetic video caches atomically
psv666 a385408
[Bugfix] Preserve shared fixture cache permissions
psv666 f7b36f8
Merge branch 'main' into fix/8892-audio-in-video-fixture
psv666 01893cc
[CI/Build] Cover video-only fixture cache recovery
psv666 4d22141
[CI/Build] Isolate cached video frame-count coverage
psv666 847331e
Merge branch 'main' into fix/8892-audio-in-video-fixture
amy-why-3459 ac6c5fd
[CI/Build] Exercise real duplex commit helpers in PCM regression test
psv666 a7f51ee
[CI/Build] Merge main and retain upstream duplex test repair
psv666 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project | ||
|
|
||
| import base64 | ||
| import io | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| import av | ||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from tests.helpers import media | ||
|
|
||
| pytestmark = [pytest.mark.core_model, pytest.mark.cpu] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def synthetic_audio(mocker): | ||
| """Keep video tests independent of the host's TTS installation.""" | ||
| sample_rate = 48000 | ||
| samples = np.arange(sample_rate, dtype=np.float32) / sample_rate | ||
| waveform = (0.1 * np.sin(2 * np.pi * 440 * samples)).reshape(-1, 1) | ||
| return mocker.patch.object(media, "generate_synthetic_audio", return_value={"np_array": waveform}) | ||
|
|
||
|
|
||
| def test_audio_generation_failure_is_not_cached(mocker, tmp_path): | ||
| failure = RuntimeError("TTS dependency unavailable") | ||
| mocker.patch.object(media, "generate_synthetic_audio", side_effect=failure) | ||
|
|
||
| with pytest.raises(RuntimeError, match="TTS dependency unavailable") as caught: | ||
| media.generate_synthetic_video(64, 64, 6, embed_audio=True, cache_dir=tmp_path) | ||
|
|
||
| assert caught.value is failure | ||
| assert not list(tmp_path.glob("*.mp4")) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "failure", | ||
| [ | ||
| FileNotFoundError("FFmpeg unavailable"), | ||
| subprocess.CalledProcessError(1, ["ffmpeg"]), | ||
| subprocess.TimeoutExpired(["ffmpeg"], 300), | ||
| ], | ||
| ids=["missing-ffmpeg", "ffmpeg-error", "ffmpeg-timeout"], | ||
| ) | ||
| def test_audio_mux_failure_is_propagated(mocker, synthetic_audio, failure): | ||
| mocker.patch("imageio_ffmpeg.get_ffmpeg_exe", return_value="ffmpeg") | ||
| mocker.patch.object(media.subprocess, "run", side_effect=failure) | ||
|
|
||
| with pytest.raises(type(failure)) as caught: | ||
| media._mux_mp4_bytes_with_synthetic_audio(b"video", num_frames=6) | ||
|
|
||
| assert caught.value is failure | ||
|
|
||
|
|
||
| def test_audio_in_video_repairs_video_only_cache(synthetic_audio, tmp_path): | ||
| video_only = media.generate_synthetic_video(64, 64, 6, cache_dir=tmp_path) | ||
| # Reproduce a cache entry written by the old silent audio-mux fallback. | ||
| cache_path = tmp_path / "synth_video_w64_h64_nf6_ea1.mp4" | ||
| original_bytes = Path(video_only["file_path"]).read_bytes() | ||
| cache_path.write_bytes(original_bytes) | ||
|
|
||
| result = media.generate_synthetic_video(64, 64, 6, embed_audio=True, cache_dir=tmp_path) | ||
|
|
||
| assert result["file_path"] == str(cache_path) | ||
| raw = base64.b64decode(result["base64"]) | ||
| assert raw == cache_path.read_bytes() | ||
| assert raw != original_bytes | ||
| assert result["np_array"].shape == (6, 64, 64, 3) | ||
| with av.open(io.BytesIO(raw)) as container: | ||
| assert len(container.streams.video) == 1 | ||
| assert len(container.streams.audio) == 1 | ||
| audio_frames = list(container.decode(audio=0)) | ||
| assert sum(frame.samples for frame in audio_frames) > 0 | ||
| assert any(np.any(frame.to_ndarray()) for frame in audio_frames) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("embed_audio", [False, True], ids=["video-only", "with-audio"]) | ||
| def test_valid_video_cache_is_reused(mocker, synthetic_audio, tmp_path, embed_audio): | ||
| result = media.generate_synthetic_video(64, 64, 6, embed_audio=embed_audio, cache_dir=tmp_path) | ||
| encode = mocker.patch("imageio.get_writer", side_effect=AssertionError("valid cache was regenerated")) | ||
|
|
||
| cached = media.generate_synthetic_video(64, 64, 6, embed_audio=embed_audio, cache_dir=tmp_path) | ||
|
|
||
| encode.assert_not_called() | ||
| assert cached["base64"] == result["base64"] | ||
| assert cached["file_path"] == result["file_path"] | ||
| assert np.array_equal(cached["np_array"], media._np_array_from_mp4_bytes(base64.b64decode(result["base64"]))) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("corruption", ["empty", "invalid-header", "truncated-audio"]) | ||
|
psv666 marked this conversation as resolved.
Outdated
|
||
| def test_corrupt_video_cache_is_regenerated(synthetic_audio, tmp_path, corruption): | ||
| result = media.generate_synthetic_video(64, 64, 6, embed_audio=True, cache_dir=tmp_path) | ||
| cache_path = Path(result["file_path"]) | ||
| raw = cache_path.read_bytes() | ||
| if corruption == "empty": | ||
| corrupt = b"" | ||
| elif corruption == "invalid-header": | ||
| corrupt = b"not an MP4" | ||
| else: | ||
| with av.open(io.BytesIO(raw)) as container: | ||
| packets = [packet for packet in container.demux(audio=0) if packet.pos is not None and packet.size] | ||
| packet = packets[len(packets) // 2] | ||
| corrupt = raw[: packet.pos + packet.size // 2] | ||
|
psv666 marked this conversation as resolved.
Outdated
|
||
| # +faststart leaves the stream metadata readable despite missing data. | ||
| with av.open(io.BytesIO(corrupt)) as container: | ||
| assert container.streams.audio | ||
| cache_path.write_bytes(corrupt) | ||
|
|
||
| repaired = media.generate_synthetic_video(64, 64, 6, embed_audio=True, cache_dir=tmp_path) | ||
|
|
||
| repaired_bytes = base64.b64decode(repaired["base64"]) | ||
| assert repaired_bytes == cache_path.read_bytes() | ||
| assert repaired_bytes != corrupt | ||
| assert repaired["np_array"].shape == (6, 64, 64, 3) | ||
| with av.open(io.BytesIO(repaired_bytes)) as container: | ||
| assert sum(frame.samples for frame in container.decode(audio=0)) > 0 | ||
|
|
||
|
|
||
| def test_video_cache_is_published_atomically(monkeypatch, synthetic_audio, tmp_path): | ||
| original = media.generate_synthetic_video(64, 64, 6, embed_audio=True, cache_dir=tmp_path) | ||
| cache_path = Path(original["file_path"]) | ||
| old_bytes = cache_path.read_bytes() | ||
| replace = media.os.replace | ||
| published = [] | ||
|
|
||
| def observe_replace(source, destination): | ||
| source = Path(source) | ||
| assert Path(destination) == cache_path | ||
| assert source.parent == cache_path.parent | ||
| # Until publication, readers must still see the old complete MP4. | ||
| assert cache_path.read_bytes() == old_bytes | ||
| completed = source.read_bytes() | ||
| with av.open(io.BytesIO(completed)) as container: | ||
| assert len(list(container.decode(video=0))) == 6 | ||
| with av.open(io.BytesIO(completed)) as container: | ||
| assert sum(frame.samples for frame in container.decode(audio=0)) > 0 | ||
| published.append(completed) | ||
| replace(source, destination) | ||
|
|
||
| monkeypatch.setattr(media.os, "replace", observe_replace) | ||
| result = media.generate_synthetic_video(64, 64, 6, embed_audio=True, force_regenerate=True, cache_dir=tmp_path) | ||
|
|
||
| assert published == [cache_path.read_bytes()] | ||
| assert base64.b64decode(result["base64"]) == published[0] | ||
| assert list(tmp_path.iterdir()) == [cache_path] | ||
|
|
||
|
|
||
| def test_failed_cache_publication_preserves_old_file(mocker, synthetic_audio, tmp_path): | ||
| original = media.generate_synthetic_video(64, 64, 6, embed_audio=True, cache_dir=tmp_path) | ||
| cache_path = Path(original["file_path"]) | ||
| old_bytes = cache_path.read_bytes() | ||
| mocker.patch.object(media.os, "replace", side_effect=OSError("publication failed")) | ||
|
|
||
| with pytest.raises(OSError, match="publication failed"): | ||
| media.generate_synthetic_video(64, 64, 6, embed_audio=True, force_regenerate=True, cache_dir=tmp_path) | ||
|
|
||
| assert cache_path.read_bytes() == old_bytes | ||
| assert list(tmp_path.iterdir()) == [cache_path] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.