103 lines
4.1 KiB
Python
103 lines
4.1 KiB
Python
from copy import deepcopy
|
|
|
|
from test_native_two_person_turns import pair
|
|
|
|
|
|
def test_split_preserves_other_shots_caption_anchors_and_orders():
|
|
from app.services.dialogue_cuts import project_cuts
|
|
from app.domain.dialogue import StorySpecV6
|
|
|
|
m = pair()
|
|
m["schema_version"] = 4
|
|
old = m["shot_ids"][0]
|
|
seq = m["spec"]["dialogue"]["sequences"][0]
|
|
quiet = deepcopy(m["spec"]["shots"][0])
|
|
quiet.update(id="c" * 32, cast=[])
|
|
quiet["performance"] = dict(sequence_id=seq["id"], native_utterance_ids=[])
|
|
seq["shot_ids"].append(quiet["id"])
|
|
m["spec"]["shots"].append(quiet)
|
|
m["shot_ids"].append(quiet["id"])
|
|
m["bindings"] = {
|
|
"video:" + old: {"asset_id": "1" * 32},
|
|
"frame:" + quiet["id"]: {"asset_id": "3" * 32},
|
|
}
|
|
m["captions"]["cues"] = [
|
|
{
|
|
"id": "d" * 32,
|
|
"anchor": "shot",
|
|
"shot_id": old,
|
|
"text": "掌声",
|
|
"start_frame": 12,
|
|
"end_frame": 25,
|
|
"timing_override": True,
|
|
}
|
|
]
|
|
source = deepcopy(m)
|
|
projected, preview, locks = project_cuts(m, old, "双人切镜")
|
|
assert m == source
|
|
assert not locks
|
|
assert preview["shots"][0]["speaker_id"] == m["spec"]["dialogue"]["utterances"][0]["speaker_id"]
|
|
assert len(preview["shots"]) == 2 and preview["warnings"]
|
|
assert projected["shot_ids"][0] == old and projected["shot_ids"][2] == quiet["id"]
|
|
assert projected["spec"]["dialogue"]["sequences"][0]["shot_ids"] == projected["shot_ids"]
|
|
assert projected["captions"]["cues"] == m["captions"]["cues"]
|
|
assert projected["bindings"] == {"frame:" + quiet["id"]: {"asset_id": "3" * 32}}
|
|
assert [s["performance"].get("dialogue_staging") for s in projected["spec"]["shots"]] == [
|
|
None,
|
|
None,
|
|
None,
|
|
]
|
|
StorySpecV6.model_validate(projected["spec"])
|
|
|
|
|
|
def test_split_lists_irreplaceable_locked_video_and_keeps_it_in_source():
|
|
from app.services.dialogue_cuts import project_cuts
|
|
|
|
m = pair()
|
|
sid = m["shot_ids"][0]
|
|
m["bindings"]["video:" + sid] = {"locked": True}
|
|
_, preview, locks = project_cuts(m, sid, "切镜副本")
|
|
assert "video:" + sid in locks
|
|
assert any("锁" in w for w in preview["warnings"])
|
|
assert m["bindings"]["video:" + sid]["locked"]
|
|
|
|
|
|
async def test_confirm_forks_once_and_keeps_original(system):
|
|
from test_native_dialogue_workflow import native_story
|
|
from app.models import WorkflowDraft
|
|
from sqlalchemy import select, func
|
|
|
|
did, state = await native_story(system)
|
|
m = state["manifest"]
|
|
m.update(spec=pair()["spec"], schema_version=4)
|
|
for sp in m["spec"]["dialogue"]["speakers"]:
|
|
sp.pop("face_reference_asset_id")
|
|
sp.pop("voice_reference_asset_id")
|
|
saved = await system.client.post(
|
|
f"/api/editors/{did}/save",
|
|
json=dict(expected_version=state["version"], manifest=m),
|
|
headers={"Idempotency-Key": "save-pair-cuts"},
|
|
)
|
|
assert saved.status_code == 200, saved.text
|
|
body = dict(
|
|
expected_version=saved.json()["version"], shot_id=m["shot_ids"][0], name="切镜新故事"
|
|
)
|
|
url = f"/api/editors/{did}/dialogue/fork-cuts"
|
|
preview = await system.client.post(url, json={**body, "confirm": False})
|
|
assert preview.status_code == 200 and len(preview.json()["shots"]) == 2, preview.text
|
|
async with system.app.state.db.session() as s:
|
|
assert await s.scalar(select(func.count()).select_from(WorkflowDraft)) == 1
|
|
headers = {"Idempotency-Key": "new-cut-story"}
|
|
result = await system.client.post(url, json={**body, "confirm": True}, headers=headers)
|
|
assert result.status_code == 200, result.text
|
|
assert len(result.json()["manifest"]["shot_ids"]) == 2
|
|
replay = await system.client.post(url, json={**body, "confirm": True}, headers=headers)
|
|
assert replay.status_code == 200 and replay.json() == result.json()
|
|
async with system.app.state.db.session() as s:
|
|
assert await s.scalar(select(func.count()).select_from(WorkflowDraft)) == 2
|
|
source = await s.get(WorkflowDraft, did)
|
|
assert (
|
|
source.version == saved.json()["version"]
|
|
and source.editor_manifest == saved.json()["manifest"]
|
|
)
|