mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-30 09:14:03 +09:00
## Summary - Organised Dropbox track folders stopped containing the 5-second screen videos (`(Title).mov`/`(End).mov`) and the original input audio (`(flacfetch).flac` / `(uploaded).mp3`). Root cause: `_upload_to_dropbox` uploads the whole `output_dir`, and the monolith→distributed-GCE migration quietly narrowed what lands there. - Restores both file types for new jobs, adds an audio-only backfill for past jobs, and adds a daily-E2E guard so this regression class is caught automatically. - Bundles a CLI fix for an ffmpeg interactive-prompt hang in `--finalise-only` (found while regenerating the missing files locally). ## Changes **Screen `.mov`s (forward):** GCE encoder copies its generated `title/end.mov` into `outputs/` with canonical names → plumbed via `EncodingOutput.title_mov_path`/`end_mov_path`, the `GCEEncodingBackend` filename mapping, and `_download_gce_encoded_files` back into `output_dir`. **Original audio (forward):** new `backend/services/original_audio.py` (source tag `(uploaded)`/`(flacfetch)`/`(YouTube)` + GCS path + filename); orchestrator `_stage_original_audio_for_upload()` fetches it into `output_dir` before folder uploads (non-fatal, only when a folder upload will occur). **Backfill (audio only):** `backend/scripts/backfill_original_audio.py` — dry-run by default, `--live` to upload, skips when audio is gone from GCS or already present. `.mov` can't be backfilled (needs re-encode). Adds `DropboxService.file_exists` (re-raises non-not-found `ApiError`). **Daily E2E guard:** `audio_download_worker` records original audio in `file_urls['input']['audio']`; `_upload_results` registers `title_mov`/`end_mov` under `file_urls['finals']`; `happy-path-real-user.spec.ts` STEP 10.5 asserts the admin files manifest contains `finals/title_mov`, `finals/end_mov`, `input/audio`, `finals/lossless_4k_mp4`. **CLI ffmpeg-hang fix:** `karaoke_finalise` only added `-y` in non-interactive mode, so a pre-existing output made ffmpeg block on an invisible `Overwrite? [y/N]` prompt until the 600s timeout (silently aborting at step 2/6). `-y` is now unconditional + `stdin=subprocess.DEVNULL` on all ffmpeg `subprocess.run` calls. ## Testing - [x] 38 new/updated unit tests; all affected suites green (`encoding_interface`, `video_worker_orchestrator`, `gce_encoding_worker`, `original_audio`, `backfill_original_audio`, `dropbox_service`, `upload_results_screen_movs`, `audio_download_worker`, full `karaoke_finalise` suite) - [x] Full backend suite: +38 passing vs main, 0 new failures (12 pre-existing `asyncio.get_event_loop()` ordering failures on main, unrelated) - [x] Output-file completeness now verified by the daily GHA E2E (STEP 10.5) ## Review - [x] Local CodeRabbit review completed (scoped to this branch) — 1 major finding fixed (`file_exists` masking non-not-found errors), re-review clean (0 findings) @coderabbitai ignore --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
79 lines
2.8 KiB
Python
79 lines
2.8 KiB
Python
"""Tests for original-audio naming/location helpers (backend/services/original_audio.py).
|
|
|
|
These back the regression fix that restores the original input audio
|
|
(e.g. '<artist> - <title> (flacfetch).flac') to the Dropbox track folder.
|
|
"""
|
|
|
|
from types import SimpleNamespace
|
|
|
|
from backend.services.original_audio import (
|
|
original_audio_source_tag,
|
|
original_audio_gcs_path,
|
|
original_audio_output_filename,
|
|
)
|
|
|
|
|
|
def _job(**kwargs):
|
|
base = dict(
|
|
audio_source_type=None,
|
|
url=None,
|
|
filename=None,
|
|
input_media_gcs_path=None,
|
|
file_urls={},
|
|
)
|
|
base.update(kwargs)
|
|
return SimpleNamespace(**base)
|
|
|
|
|
|
class TestSourceTag:
|
|
def test_file_upload_maps_to_uploaded(self):
|
|
assert original_audio_source_tag(_job(audio_source_type="file_upload")) == "uploaded"
|
|
|
|
def test_youtube_url_maps_to_youtube(self):
|
|
assert original_audio_source_tag(_job(audio_source_type="youtube_url")) == "YouTube"
|
|
|
|
def test_audio_search_maps_to_flacfetch(self):
|
|
assert original_audio_source_tag(_job(audio_source_type="audio_search")) == "flacfetch"
|
|
|
|
def test_legacy_url_job_without_source_type(self):
|
|
assert original_audio_source_tag(_job(url="https://youtu.be/x")) == "YouTube"
|
|
|
|
def test_legacy_upload_without_source_type(self):
|
|
assert original_audio_source_tag(_job(filename="song.mp3")) == "uploaded"
|
|
|
|
def test_unknown_falls_back_to_input(self):
|
|
assert original_audio_source_tag(_job()) == "input"
|
|
|
|
|
|
class TestGcsPath:
|
|
def test_prefers_input_media_gcs_path(self):
|
|
job = _job(input_media_gcs_path="jobs/j1/input/song.mp3",
|
|
file_urls={"input": "jobs/j1/other.flac"})
|
|
assert original_audio_gcs_path(job) == "jobs/j1/input/song.mp3"
|
|
|
|
def test_file_urls_input_as_string(self):
|
|
job = _job(file_urls={"input": "jobs/j1/input.flac"})
|
|
assert original_audio_gcs_path(job) == "jobs/j1/input.flac"
|
|
|
|
def test_file_urls_input_as_dict(self):
|
|
job = _job(file_urls={"input": {"audio": "jobs/j1/input/song.flac"}})
|
|
assert original_audio_gcs_path(job) == "jobs/j1/input/song.flac"
|
|
|
|
def test_none_when_no_source(self):
|
|
assert original_audio_gcs_path(_job()) is None
|
|
|
|
|
|
class TestOutputFilename:
|
|
def test_flacfetch_flac(self):
|
|
job = _job(audio_source_type="audio_search",
|
|
input_media_gcs_path="jobs/j1/input/track.flac")
|
|
assert original_audio_output_filename(job, "Artist - Title") == "Artist - Title (flacfetch).flac"
|
|
|
|
def test_uploaded_mp3(self):
|
|
job = _job(audio_source_type="file_upload",
|
|
input_media_gcs_path="jobs/j1/input/My Song.mp3")
|
|
assert original_audio_output_filename(job, "Artist - Title") == "Artist - Title (uploaded).mp3"
|
|
|
|
def test_none_when_no_audio(self):
|
|
assert original_audio_output_filename(_job(), "Artist - Title") is None
|