cmvr-visual/backend/tests/test_continuity_review.py

104 lines
3.6 KiB
Python
Raw Normal View History

from types import SimpleNamespace
import pytest
from app.domain.continuity import upgrade_story_spec
from app.domain.stories import compile_story
from app.services.editor_media import audio_segment_ranges
from app.services.orchestration.editor_engine import build_recipes
from test_story_studio import story_spec
def manifest():
spec = upgrade_story_spec(story_spec())
sid = spec["shots"][0]["id"]
return dict(
schema_version=2,
spec=spec,
shot_ids=[sid],
bindings={},
audio={
"mode": "generated_narration",
"segments": [{"id": sid, "shot_id": sid, "text": "hello"}],
},
captions={},
)
def test_normalize_new_speech():
rows = build_recipes(manifest(), {}, {}, SimpleNamespace())
assert any(r["kind"] == "audio.normalize" and "speech_0001" in r["dependencies"] for r in rows)
def test_first_hash_ignores_end():
spec = manifest()["spec"]
before = compile_story(spec, {})["shots"][0]["context_hash"]
spec["shots"][0]["continuity"]["end_prompt"] = "sunset"
assert compile_story(spec, {})["shots"][0]["context_hash"] == before
def test_silent_absolute_cue():
m = manifest()
m["audio"]["mode"] = "silent"
seg = m["audio"]["segments"][0]
seg.update(anchor="absolute", shot_id=None, offset_sample=4000)
assert audio_segment_ranges(m, {})[seg["id"]] == (2, 120)
def test_new_dual_frame_requires_full_edit():
m = manifest()
shot = m["spec"]["shots"][0]
shot["continuity"]["endpoint_mode"] = "first_last_frame"
shot["video_parameters"].update(profile="minimax-h3-fl2va-bf16-v2", source_frames=124)
rows = build_recipes(m, {}, {}, SimpleNamespace())
assert any(r.get("issue", {}).get("code") == "endpoint_trim_conflict" for r in rows)
def test_historical_sample_count_still_needs_actual_normalization():
m = manifest()
sid = m["shot_ids"][0]
binding = {
"source": "manual",
"kind": "audio",
"asset_id": "voice",
"sha256": "a" * 64,
"sample_count": 48003,
}
rows = build_recipes(m, {"audio:" + sid: binding}, {}, SimpleNamespace())
norm = next(r for r in rows if r["kind"] == "audio.normalize")
assert (
norm["dependencies"] == ["speech_0001"]
and norm["key"] in next(r for r in rows if r["kind"] == "audio.mix")["dependencies"]
)
def test_silent_scene_cues_share_scene_bounds():
from copy import deepcopy
m = manifest()
first = m["spec"]["shots"][0]
first["scene_id"] = "a" * 32
m["spec"]["scenes"] = [{"id": first["scene_id"], "name": "Scene"}]
m["spec"]["render"]["total_frames"] = 240
second = deepcopy(first)
second["id"] = "2" * 32
m["spec"]["shots"].append(second)
m["shot_ids"].append(second["id"])
m["audio"] = {
"mode": "silent",
"segments": [
{"id": "3" * 32, "text": "one", "anchor": "scene", "scene_id": first["scene_id"]},
{"id": "4" * 32, "text": "two", "anchor": "scene", "scene_id": first["scene_id"]},
],
}
assert list(audio_segment_ranges(m, {}).values()) == [(0, 120), (120, 240)]
def test_dual_frame_manual_video_keeps_trim():
m = manifest()
shot = m["spec"]["shots"][0]
shot["continuity"]["endpoint_mode"] = "first_last_frame"
shot["video_parameters"].update(profile="minimax-h3-fl2va-bf16-v2", source_frames=124)
binding = {"source": "manual", "kind": "video", "asset_id": "manual", "sha256": "a" * 64}
rows = build_recipes(m, {"video:" + shot["id"]: binding}, {}, SimpleNamespace())
video = next(r for r in rows if r["kind"] == "video.generate")
assert video["candidate"] == binding and "issue" not in video