84 lines
4.4 KiB
Python
84 lines
4.4 KiB
Python
"""LLM 总控台「等待在途任务」与「质检必须整批」两条红线。
|
||
|
||
现场来自项目 10《跨界斗地主》:用户先手动点了「生成镜头」,任务还在队列里,
|
||
总控台随后跑 full_delivery。generate_shots 因为「自己没新建任务」直接跳过,
|
||
质检也只质检了已经出图的那几镜,最后合成会静默产出一部**少镜头的成片**。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import pytest
|
||
|
||
from app.models import Project
|
||
from app.services import agent, storage
|
||
|
||
|
||
def _import_two_shots(api, studio, script_text, make_image_png):
|
||
pid = studio["project_id"]
|
||
api.post(f"/api/projects/{pid}/import",
|
||
data={"script_text": script_text, "default_duration": 2},
|
||
files=[("images", ("s01.png", make_image_png(480, 270, "0x226699"), "image/png")),
|
||
("images", ("s02.png", make_image_png(480, 270, "0x993355"), "image/png"))])
|
||
return pid
|
||
|
||
|
||
def test_generate_shots_waits_for_tasks_already_in_the_queue(api, db, studio, script_text,
|
||
make_image_png):
|
||
"""队列里已有这批镜头的任务:等它跑完,而不是「跳过」收工。"""
|
||
pid = _import_two_shots(api, studio, script_text, make_image_png)
|
||
enqueued = api.post(f"/api/projects/{pid}/tasks", json={"with_voiceover": True})
|
||
assert enqueued["result"]["created"]["count"] >= 2
|
||
# 故意不 dispatch:任务停在队列里,模拟「GPU 正忙,这一批还在排队」
|
||
counts = api.get(f"/api/projects/{pid}/queue")["counts"]
|
||
assert counts.get("queued", 0) == 4, counts # 2 画面 + 2 配音
|
||
|
||
project = db.get(Project, pid)
|
||
result = agent._step_generate_shots(db, project, {"action": "generate_shots"}, 240)
|
||
|
||
assert result["status"] == "succeeded", result
|
||
assert "在执行" in result["detail"] and "未重复提交" in result["detail"], result["detail"]
|
||
assert result["result"]["already_queued"] is True
|
||
db.expire_all()
|
||
project = db.get(Project, pid)
|
||
shots = sorted(project.shots or [], key=lambda row: row.order_index)
|
||
assert len(shots) == 2
|
||
assert all(shot.output_path and storage.exists(shot.output_path) for shot in shots), \
|
||
[(shot.order_index, shot.output_path) for shot in shots]
|
||
assert all(shot.voiceover_path and storage.exists(shot.voiceover_path) for shot in shots), \
|
||
[(shot.order_index, shot.voiceover_path) for shot in shots]
|
||
# 等归等,一条任务都不许多排:画面 2 + 配音 2,共 4 条,没有重复消耗
|
||
tasks = [row for row in api.get(f"/api/projects/{pid}/queue")["tasks"]
|
||
if row["kind"] in ("generate_shot", "voiceover")]
|
||
assert len(tasks) == 4, [(row["id"], row["kind"], row["status"]) for row in tasks]
|
||
assert {row["status"] for row in tasks} == {"succeeded"}, tasks
|
||
|
||
|
||
def test_quality_check_refuses_to_cover_only_part_of_the_shots(api, db, studio, script_text,
|
||
make_image_png):
|
||
"""有镜头还没出图时,质检必须报错,不能悄悄只检一半然后放行到合成。"""
|
||
pid = _import_two_shots(api, studio, script_text, make_image_png)
|
||
shots = api.get(f"/api/projects/{pid}/shots")["shots"]
|
||
first = shots[0]["id"]
|
||
api.post(f"/api/projects/{pid}/tasks", json={"shot_ids": [first], "with_voiceover": False})
|
||
assert api.drain(pid)["result"]["drained"]["remaining"] == 0
|
||
|
||
db.expire_all()
|
||
project = db.get(Project, pid)
|
||
with pytest.raises(agent.AgentStepError) as excinfo:
|
||
agent._step_quality_check(db, project, {"action": "quality_check"}, 120)
|
||
assert "还没有画面产物" in str(excinfo.value)
|
||
assert "#2" in str(excinfo.value)
|
||
|
||
|
||
def test_quality_check_still_passes_when_every_shot_has_output(api, db, studio, script_text,
|
||
make_image_png):
|
||
"""反向:镜头都出图后,质检照常整批通过(别把新校验变成新的卡死点)。"""
|
||
pid = _import_two_shots(api, studio, script_text, make_image_png)
|
||
api.post(f"/api/projects/{pid}/tasks", json={"with_voiceover": False})
|
||
assert api.drain(pid)["result"]["drained"]["remaining"] == 0
|
||
|
||
db.expire_all()
|
||
project = db.get(Project, pid)
|
||
result = agent._step_quality_check(db, project, {"action": "quality_check"}, 240)
|
||
assert result["status"] in ("succeeded", "skipped"), result
|
||
assert "还没有画面产物" not in str(result.get("detail", ""))
|