119 lines
6.3 KiB
Python
119 lines
6.3 KiB
Python
"""「定妆照 vs 文字设定」谁是准绳,以及文案点名人物的参照物缺口。
|
||
|
||
项目 9《自检-异步调度验证》实测两处根因:
|
||
|
||
1. 紫小慧的定妆照是深蓝西装,人物描述卡还写着「白色T恤、透肤黑丝」。视频模型
|
||
照定妆照出图(这正是用户要的),画面质检却拿那段旧文字判定「服装严重错误」,
|
||
于是每一镜都判返工、返工又改不掉——**无限返工**。现在形象准绳是定妆参考照,
|
||
文字设定只在没有定妆照时才作为依据。
|
||
2. 俊杰只出现在画面描述里(「俊杰坐在服务台后」),没挂进本镜出镜名单,
|
||
于是他的定妆照一张都没进视频模型,每一镜都凭文字臆造一套长相与服装。
|
||
现在文案点名的人物同样收集定妆图/三视图,并出现在提示词的出镜角色里。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import pytest
|
||
|
||
from app.models import Character, Project, Shot
|
||
from app.services import prompt, storage, visual_qc
|
||
|
||
|
||
def _p9_like_rows():
|
||
"""项目 9 的真实形状:镜头只绑紫小慧,画面描述里点名要俊杰。"""
|
||
lead = Character(id=71, project_id=9, name="紫小慧", gender="female",
|
||
appearance="白色T恤、透肤黑丝")
|
||
extra = Character(id=72, project_id=9, name="俊杰", gender="male", appearance="深蓝西装、领带")
|
||
project = Project(id=9, name="自检-异步调度验证")
|
||
project.characters = [lead, extra]
|
||
shot = Shot(id=91, project_id=9, order_index=1, code="s01", title="求助",
|
||
description="紫小慧神色焦急地跑入画面,来到俊杰面前", dialogue="我的电脑坏了",
|
||
speaker_character_id=71)
|
||
shot.characters = [lead]
|
||
return project, shot, lead, extra
|
||
|
||
|
||
# ---------------------------------------------------------------- 质检准绳
|
||
def test_prompt_marks_who_actually_has_a_reference_photo():
|
||
"""模型必须知道每个人该拿照片核对还是拿文字核对。"""
|
||
project, shot, lead, extra = _p9_like_rows()
|
||
cast = visual_qc.expected_cast(None, project, shot)
|
||
text = visual_qc.build_prompt(shot, cast, 4, [{"name": "紫小慧", "kind": "portrait",
|
||
"path": "/tmp/a.png"}])
|
||
line = next(l for l in text.split("\n") if l.strip().startswith("1. 紫小慧"))
|
||
other = next(l for l in text.split("\n") if l.strip().startswith("1. 俊杰"))
|
||
assert "已附定妆照,形象以照片为准" in line
|
||
assert "无定妆照" in other
|
||
|
||
|
||
def test_reference_photo_outranks_the_stale_text_setting():
|
||
"""判定纪律里必须写明「文字设定可能过时,照片才是准绳」,否则会无限返工。"""
|
||
project, shot, lead, extra = _p9_like_rows()
|
||
cast = visual_qc.expected_cast(None, project, shot)
|
||
text = visual_qc.build_prompt(shot, cast, 4, [{"name": "紫小慧", "kind": "portrait",
|
||
"path": "/tmp/a.png"}])
|
||
assert "准绳是随附的该人物定妆参考照" in text
|
||
assert "仅因「与文字设定里的衣着/发型不符」而报 identity_drift" in text
|
||
assert "定妆参考照**用来认人" not in text # 参考照不只是用来认人
|
||
assert "形象的唯一准绳" in text
|
||
|
||
|
||
def test_identity_rule_points_at_photo_not_text():
|
||
project, shot, lead, extra = _p9_like_rows()
|
||
cast = visual_qc.expected_cast(None, project, shot)
|
||
text = visual_qc.build_prompt(shot, cast, 4, [])
|
||
rule = next(l for l in text.split("\n") if l.startswith("F 形象"))
|
||
assert "定妆参考照" in rule and "【无定妆照】的人物才对照文字设定" in rule
|
||
|
||
|
||
# ---------------------------------------------------------------- 参照物缺口
|
||
@pytest.fixture
|
||
def scene_with_two_people(api, db, studio):
|
||
"""项目里两个角色都有定妆图,镜头只绑了其中一个,文案点名另一个。"""
|
||
pid = studio["project_id"]
|
||
junjie = api.post(f"/api/projects/{pid}/characters",
|
||
json={"name": "俊杰", "role": "配角", "appearance": "高大、和蔼,穿着整洁"})["result"]["id"]
|
||
from tests.conftest import _make_image_png
|
||
|
||
api.post(f"/api/projects/{pid}/characters/{junjie}/assets",
|
||
files={"file": ("jj.png", _make_image_png(480, 270, "0x334455"), "image/png")},
|
||
data={"kind": "portrait", "name": "俊杰定妆图"})
|
||
lead = db.get(Character, studio["character_id"])
|
||
sid = api.post(f"/api/projects/{pid}/shots",
|
||
json={"title": "安抚", "description": f"{lead.name}跑到柜台前,俊杰坐在服务台后",
|
||
"mode": "i2v", "duration": 2, "dialogue": "别慌"})["result"]["id"]
|
||
shot = db.get(Shot, sid)
|
||
shot.characters = [lead]
|
||
shot.speaker_character_id = lead.id
|
||
db.commit()
|
||
return {"pid": pid, "sid": sid, "lead": lead, "junjie_id": junjie}
|
||
|
||
|
||
def test_script_mentioned_character_portrait_joins_references(db, scene_with_two_people):
|
||
ctx = scene_with_two_people
|
||
shot = db.get(Shot, ctx["sid"])
|
||
owners = {(row["owner_type"], row["owner_id"]) for row in prompt.collect_reference_details(db, shot)}
|
||
assert ("human", ctx["junjie_id"]) in owners, "文案点名的俊杰必须带上自己的定妆照"
|
||
paths = [row["path"] for row in prompt.collect_reference_details(db, shot)]
|
||
assert all(p.endswith(".png") for p in paths)
|
||
assert prompt.portrait_bound_ids(db, shot) >= {ctx["lead"].id, ctx["junjie_id"]}
|
||
|
||
|
||
def test_compose_prompt_names_mentioned_character_without_his_old_costume(db, scene_with_two_people):
|
||
"""俊杰进了出镜角色,且形象交给定妆照,不再复述描述卡里的旧文字。"""
|
||
ctx = scene_with_two_people
|
||
project = db.get(Project, ctx["pid"])
|
||
shot = db.get(Shot, ctx["sid"])
|
||
text = prompt.compose_prompt(project, shot, db=db)
|
||
assert "出镜角色(保持造型一致)" in text and "俊杰" in text
|
||
assert "定妆图" in text and "不得按文字另行改写衣着" in text
|
||
|
||
|
||
def test_unmentioned_character_does_not_leak_into_references(db, scene_with_two_people):
|
||
ctx = scene_with_two_people
|
||
shot = db.get(Shot, ctx["sid"])
|
||
shot.description = f"{ctx['lead'].name}独自坐在柜台前"
|
||
db.commit()
|
||
owners = {row["owner_id"] for row in prompt.collect_reference_details(db, shot)
|
||
if row["owner_type"] == "human"}
|
||
assert ctx["junjie_id"] not in owners
|