"""画面验收应与画内、画外及静默对白的实际口型意图保持一致。""" from copy import deepcopy import pytest from app.models import WorkflowDraft from app.services.orchestration import native_dialogue_engine as engine from test_native_dialogue_workflow import capabilities, native_story @pytest.mark.parametrize("mode", ["visible", "offscreen", "lip_off", "silent"]) async def test_native_review_mouth_expectation_tracks_visible_speech(system, mode): capabilities(system) system.settings._native_av_upstream = await system.provider.upstream_capabilities() did, editor = await native_story(system) manifest = deepcopy(editor["manifest"]) shot = manifest["spec"]["shots"][0] if mode == "offscreen": shot["performance"]["visible_speaker_ids"] = [] if mode == "lip_off": shot["performance"]["lip_sync"] = "off" if mode == "silent": manifest["spec"]["dialogue"]["utterances"] = [] manifest["spec"]["dialogue"]["sequences"][0]["utterance_ids"] = [] async with system.app.state.db.session() as session: draft = await session.get(WorkflowDraft, did) plan = await engine.plan_editor( session, draft, manifest, {"output_goal": "film"}, system.settings ) review = next(r for r in plan["_recipes"] if r["kind"] == "video.dialogue.review") expected = review["input"]["expected"] if mode == "visible": assert expected["mouth_expectation"] == "说话人自然发音,其他人物保持嘴部放松" else: assert ( "所有人物" in expected["mouth_expectation"] and "闭唇" in expected["mouth_expectation"] ) assert expected["native_dialogue"] == ("" if mode == "silent" else "你好。") assert review["context_hash"] == engine._review_context(None, {}, expected) def test_native_review_context_binds_complete_expectation(): expected = dict(source_start_frame=0, source_end_frame=124, mouth_expectation="自然闭唇") digest = engine._review_context("a" * 64, {"r": "b" * 64}, expected) assert engine._review_context("a" * 64, {"r": "b" * 64}, deepcopy(expected)) == digest assert ( engine._review_context( "a" * 64, {"r": "b" * 64}, {**expected, "mouth_expectation": "说话人自然发音"} ) != digest ) assert ( engine._review_context("a" * 64, {"r": "b" * 64}, {**expected, "source_end_frame": 141}) != digest ) @pytest.mark.parametrize("text", ["你好。", "她住五号楼。"]) def test_native_consensus_requires_both_real_transcripts_and_normalized_fields(text): from app.domain.native_av import normalize_native_text normalized = normalize_native_text(text) report = dict( content_verification_policy="whisper-sensevoice-consensus-v1", content_decision_source="whisper_sensevoice_consensus", content_error_rate=0, transcript=text, normalized_expected_text=normalized, normalized_transcript=normalized, secondary_status="completed", secondary_content_error_rate=0, secondary_asr_revision="90c1c61912018b70ada0fcc024ea24aca62f2e63", secondary_runtime_revision="6991744856587fa44379e8b5dcc432debffeb1be", secondary_transcript=text, normalized_secondary_transcript=normalized, ) assert engine._content_consensus(report, text) assert not engine._content_consensus({**report, "secondary_transcript": "不一致"}, text) assert not engine._content_consensus({**report, "transcript": "不一致"}, text) assert not engine._content_consensus({**report, "normalized_expected_text": "伪造"}, text) assert not engine._content_consensus({**report, "secondary_status": "unavailable"}, text) assert not engine._content_consensus({**report, "secondary_transcript": None}, text) if text == "她住五号楼。": assert engine._content_consensus({**report, "secondary_transcript": "他住5号楼"}, text)