495 lines
25 KiB
Python
495 lines
25 KiB
Python
"""回归用例:锁定本轮端到端验证中发现并修复的缺陷。
|
||
|
||
覆盖
|
||
- 图2 节点 2 导入:Markdown 标题式镜号解析(`## 镜 1`)不得把文档标题当镜头、
|
||
重复镜号必须自动去重成唯一值,绝不能触发 UNIQUE 约束 500;
|
||
- 资产上传响应必须带回「本次新版本」,而不是提交前的过期版本列表;
|
||
- `黑场` 转场必须落到 Transition.FADE_THROUGH_BLACK 常量(曾因拼错常量名 AttributeError);
|
||
- 图2 节点 6「任务队列调度」:镜头驳回重做后同一镜头会有多条生成任务,
|
||
工作流节点必须按镜头计数,否则永远停在 active;
|
||
- 图2 节点 4「生成分镜任务清单」同样必须按镜头计数(曾出现 5/4 的分母),
|
||
并且任何流程节点的 done 都不得大于 total;
|
||
- `review_state` 的取值是 pending/pass/fail(与审核记录 verdict 同源),前端分镜卡片依赖它
|
||
显示人工审核结论;且镜头没有产物时不允许直接审核通过(图2 节点 9 必须先于 10);
|
||
- 局部失败不得被整体成功掩盖:失败镜头的旧产物还在磁盘上时,
|
||
节点 8「调用视频模型」/节点 9「下载并保存视频」依然要转红,可用产物数要扣掉它。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
from app.constants import Transition, ReviewVerdict
|
||
from app.db import SessionLocal
|
||
from app.models import Task
|
||
from app.providers import registry as model_registry
|
||
from app.providers.base import AssetGenResult
|
||
from app.services import dispatch
|
||
|
||
DOC_TITLE_SCRIPT = """# 分镜脚本 · 雨夜站台
|
||
## 镜 1
|
||
- 景别: 全景
|
||
- 运镜: 推镜
|
||
- 时长: 3
|
||
- 镜头描述: 空荡的站台被霓虹染成蓝色
|
||
- 台词: 这座城市从不等人。
|
||
|
||
## 镜 2
|
||
- 景别: 中景
|
||
- 时长: 3
|
||
- 镜头描述: 林墨收起伞走进画面
|
||
- 台词: 末班列车,还有两分钟。
|
||
|
||
## 镜 3
|
||
- 景别: 特写
|
||
- 时长: 2
|
||
- 镜头描述: 车窗上的雨滴把站台扭成光斑
|
||
- 台词: 有些人一转身就是一辈子。
|
||
"""
|
||
|
||
DUP_SCRIPT = """## 镜头 01
|
||
画面: 重复镜号的第一条
|
||
时长: 2
|
||
|
||
## 镜头 01
|
||
画面: 重复镜号的第二条
|
||
时长: 2
|
||
|
||
## 镜头 01
|
||
画面: 重复镜号的第三条
|
||
时长: 2
|
||
"""
|
||
|
||
|
||
def test_markdown_headings_skip_document_title_and_yield_unique_codes(api, studio):
|
||
pid = studio["project_id"]
|
||
body = api.post(f"/api/projects/{pid}/import",
|
||
data={"script_text": DOC_TITLE_SCRIPT, "script_name": "storyboard.md",
|
||
"default_duration": 3})
|
||
result = body["result"]
|
||
assert result["created"] == 3, "文档标题《分镜脚本 · 雨夜站台」不应成为一个镜头"
|
||
|
||
shots = api.get(f"/api/projects/{pid}/shots")["shots"]
|
||
assert [s["code"] for s in shots] == ["1", "2", "3"]
|
||
assert [s["order_index"] for s in shots] == [1, 2, 3]
|
||
assert {s["title"] for s in shots} != {""}
|
||
assert shots[0]["dialogue"] == "这座城市从不等人。"
|
||
|
||
|
||
def test_duplicate_shot_codes_are_deduplicated_instead_of_raising_500(api, studio):
|
||
"""同一份脚本里出现重复镜号时,过去会撞 shots(project_id, code) 唯一约束返回 500。"""
|
||
pid = studio["project_id"]
|
||
body = api.post(f"/api/projects/{pid}/import",
|
||
data={"script_text": DUP_SCRIPT, "default_duration": 2})
|
||
assert body["result"]["created"] == 3
|
||
|
||
codes = [s["code"] for s in api.get(f"/api/projects/{pid}/shots")["shots"]]
|
||
assert len(codes) == len(set(codes)) == 3, f"镜号必须唯一,实际 {codes}"
|
||
|
||
|
||
def test_reimport_without_replace_or_keep_returns_readable_400(api, studio, script_text):
|
||
"""既不替换现有分镜、又要求保留,重复导入应给出 400 可读提示而非 500。"""
|
||
pid = studio["project_id"]
|
||
first = api.post(f"/api/projects/{pid}/import",
|
||
data={"script_text": script_text, "default_duration": 2})
|
||
assert first["result"]["created"] == 2
|
||
|
||
again = api.post(f"/api/projects/{pid}/import",
|
||
data={"script_text": script_text, "default_duration": 2,
|
||
"keep_existing": "false", "replace": "false"}, expect=400)
|
||
detail = again["detail"]
|
||
assert "镜号" in detail and "冲突" in detail, detail
|
||
|
||
# 失败的那次导入必须整体回滚,不能留下半截数据
|
||
assert api.get(f"/api/projects/{pid}/shots")["count"] == 2
|
||
|
||
|
||
def test_reimport_with_replace_succeeds(api, studio, script_text):
|
||
pid = studio["project_id"]
|
||
api.post(f"/api/projects/{pid}/import",
|
||
data={"script_text": script_text, "default_duration": 2})
|
||
replaced = api.post(f"/api/projects/{pid}/import",
|
||
data={"script_text": script_text, "default_duration": 2, "replace": "true"})
|
||
assert replaced["result"]["created"] == 2
|
||
|
||
|
||
def test_asset_upload_response_carries_the_new_version(api, studio, make_image_png):
|
||
"""曾因 expire_on_commit=False 让第二次上传的响应回吐过期版本列表。"""
|
||
pid = studio["project_id"]
|
||
character = api.post(f"/api/projects/{pid}/characters",
|
||
json={"name": "林墨", "role": "主角"})["result"]["id"]
|
||
|
||
def upload(note: str) -> dict:
|
||
return api.post(f"/api/projects/{pid}/characters/{character}/assets",
|
||
data={"kind": "portrait", "note": note},
|
||
files={"file": ("portrait.png", make_image_png(), "image/png")})["result"]
|
||
|
||
first = upload("初版定妆")
|
||
assert first["version"] == 1 and first["checksum"]
|
||
assert [v["version_no"] for v in first["versions"]] == [1]
|
||
|
||
second = upload("换装后")
|
||
assert second["id"] == first["id"], "同名资产应追加版本而不是新建资产"
|
||
assert second["version"] == 2, f"上传响应必须返回新版本,实际 v{second['version']}"
|
||
assert [v["version_no"] for v in second["versions"]] == [2, 1], second["versions"]
|
||
|
||
listed = [a for a in api.get(f"/api/projects/{pid}/assets")["assets"]
|
||
if a["id"] == second["id"]][0]
|
||
assert listed["version"] == 2 and [v["version_no"] for v in listed["versions"]] == [2, 1]
|
||
|
||
|
||
def test_black_field_transition_label_maps_to_constant(api, studio):
|
||
assert Transition.FADE_THROUGH_BLACK == "fade_through_black"
|
||
assert Transition.LABELS[Transition.FADE_THROUGH_BLACK] == "黑场过渡"
|
||
|
||
pid = studio["project_id"]
|
||
script = """## 镜 1
|
||
画面: 主角转身离去
|
||
时长: 3
|
||
转场: 黑场
|
||
|
||
## 镜 2
|
||
画面: 空无一人的站台
|
||
时长: 3
|
||
转场: 淡出
|
||
"""
|
||
api.post(f"/api/projects/{pid}/import", data={"script_text": script, "default_duration": 3})
|
||
shots = api.get(f"/api/projects/{pid}/shots")["shots"]
|
||
assert shots[0]["transition_out"] == Transition.FADE_THROUGH_BLACK
|
||
assert shots[1]["transition_out"] == Transition.FADE_OUT
|
||
|
||
|
||
def test_dispatch_node_completes_even_after_regeneration(api, studio, script_text, make_image_png):
|
||
"""驳回重做会让同一镜头产生第二条生成任务;按任务数比较会让节点 6 永远 active。"""
|
||
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"))])
|
||
api.post(f"/api/projects/{pid}/tasks", json={"with_voiceover": True})
|
||
api.drain(pid)
|
||
|
||
shots = api.get(f"/api/projects/{pid}/shots")["shots"]
|
||
for shot in shots:
|
||
api.post(f"/api/projects/{pid}/shots/{shot['id']}/approve", json={})
|
||
|
||
target = shots[-1]
|
||
rejected = api.post(f"/api/projects/{pid}/shots/{target['id']}/reject",
|
||
json={"notes": "脸部不一致", "regenerate": True,
|
||
"prompt": target["prompt"] + ",正脸清晰"})
|
||
assert rejected["result"]["shot"]["status"] == "rejected"
|
||
assert rejected["result"]["requeue"]["created"]["count"] == 1
|
||
api.drain(pid)
|
||
|
||
workflow = {n["key"]: n for n in api.get(f"/api/projects/{pid}/summary")["result"]["workflow"]}
|
||
assert workflow["dispatch"]["state"] == "done", workflow["dispatch"]
|
||
assert workflow["generate"]["state"] == "done", workflow["generate"]
|
||
# 生成任务确实多于镜头数,证明这次断言测到了「按镜头计数」而不是巧合
|
||
gen_tasks = [t for t in api.get(f"/api/tasks?project_id={pid}")["tasks"]
|
||
if t["kind"] == "generate_shot"]
|
||
assert len(gen_tasks) > len(shots)
|
||
|
||
|
||
def test_workflow_counters_never_exceed_shot_totals(api, studio, script_text, make_image_png):
|
||
"""「生成分镜任务清单」节点曾按任务数比镜头数,界面露出 5/4。"""
|
||
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"))])
|
||
api.post(f"/api/projects/{pid}/tasks", json={"with_voiceover": True})
|
||
api.drain(pid)
|
||
|
||
shots = api.get(f"/api/projects/{pid}/shots")["shots"]
|
||
for shot in shots:
|
||
api.post(f"/api/projects/{pid}/shots/{shot['id']}/approve", json={})
|
||
target = shots[-1]
|
||
api.post(f"/api/projects/{pid}/shots/{target['id']}/reject",
|
||
json={"notes": "构图太满", "regenerate": True, "prompt": target["prompt"] + ",留出头顶空间"})
|
||
api.drain(pid)
|
||
|
||
workflow = {n["key"]: n for n in api.get(f"/api/projects/{pid}/summary")["result"]["workflow"]}
|
||
plan = workflow["plan_tasks"]
|
||
assert plan["total"] == len(shots), plan
|
||
assert plan["done"] == len(shots), plan
|
||
assert plan["state"] == "done", plan
|
||
# 分母不变量的通用防线:任何节点的进度都不得超过总数
|
||
for node in workflow.values():
|
||
if node["done"] is not None and node["total"] is not None:
|
||
assert node["done"] <= node["total"], node
|
||
|
||
|
||
def test_project_queue_does_not_leak_tasks_from_other_projects(api, db):
|
||
"""项目调度页必须只看到本项目任务;旧实现把最近 200 条全局任务混进来。"""
|
||
first = api.project(name="排队隔离 A")
|
||
second = api.project(name="排队隔离 B")
|
||
mine = Task(project_id=first, kind="asset", name="A 的任务", stage="asset", status="failed")
|
||
other = Task(project_id=second, kind="asset", name="B 的任务", stage="asset", status="running")
|
||
db.add_all([mine, other])
|
||
db.commit()
|
||
|
||
queue = api.get(f"/api/projects/{first}/queue")
|
||
assert [row["id"] for row in queue["tasks"]] == [mine.id]
|
||
assert all(row["project_id"] == first for row in queue["tasks"])
|
||
|
||
|
||
def test_negative_prompt_reassembly_does_not_duplicate_terms(api):
|
||
"""绑定/编辑镜头会多次重算提示词,反向词不能每次再叠加一份。"""
|
||
pid = api.project(global_negative_prompt="闪烁,水印,角色漂移")
|
||
shot = api.post(f"/api/projects/{pid}/shots", json={
|
||
"title": "提示词去重", "description": "主角走过雨夜站台", "duration": 5,
|
||
})["result"]
|
||
for _ in range(5):
|
||
shot = api.patch(f"/api/projects/{pid}/shots/{shot['id']}",
|
||
json={"lens_note": f"35mm-{_}"})["result"]
|
||
|
||
negative = shot["negative_prompt"]
|
||
assert negative.count("闪烁") == 1, negative
|
||
assert negative.count("水印") == 1, negative
|
||
assert negative.count("角色漂移") == 1, negative
|
||
|
||
|
||
def test_project_prompt_changes_resync_shots_without_sticky_old_terms(api):
|
||
"""项目级提示词更新后,已有分镜必须重算,且不能保留上一次组装的旧反向词。"""
|
||
pid = api.project(style_guide="旧风格", global_negative_prompt="鲸鱼比例错误,角色漂移")
|
||
shot = api.post(f"/api/projects/{pid}/shots", json={
|
||
"title": "提示词重算", "description": "主角站在落地窗前", "duration": 5,
|
||
})["result"]
|
||
assert "旧风格" in shot["prompt"]
|
||
assert "鲸鱼比例错误" in shot["negative_prompt"]
|
||
|
||
api.patch(f"/api/projects/{pid}", json={
|
||
"style_guide": "新风格,清晨海面",
|
||
"global_negative_prompt": "怪兽卡通化,场景跳变",
|
||
})
|
||
updated = api.get(f"/api/projects/{pid}/shots/{shot['id']}")["shot"]
|
||
assert "新风格" in updated["prompt"] and "旧风格" not in updated["prompt"]
|
||
assert "怪兽卡通化" in updated["negative_prompt"]
|
||
assert "鲸鱼比例错误" not in updated["negative_prompt"]
|
||
|
||
|
||
def test_cancelled_asset_result_is_not_persisted(api, studio, make_image_png, tmp_path, monkeypatch):
|
||
"""供应商调用返回前已被取消的任务,不能把迟到的图片写回资产库。"""
|
||
pid, character_id = studio["project_id"], studio["character_id"]
|
||
queued = api.post(f"/api/projects/{pid}/assets/generate", json={
|
||
"target_type": "human", "target_id": character_id, "kind": "costume",
|
||
"provider": "mock", "model": "mock-image-1", "prompt": "测试取消",
|
||
"width": 320, "height": 180, "drain": False,
|
||
})["result"]["task"]
|
||
task_id = queued["id"]
|
||
produced = tmp_path / "late.png"
|
||
produced.write_bytes(make_image_png(320, 180, "0x664422"))
|
||
|
||
def generate_then_cancel(*_args, **_kwargs):
|
||
session = SessionLocal()
|
||
try:
|
||
task = session.get(Task, task_id)
|
||
dispatch.cancel_task(session, task, reason="用户在供应商返回前取消")
|
||
finally:
|
||
session.close()
|
||
return AssetGenResult(file_path=str(produced))
|
||
|
||
monkeypatch.setattr(model_registry, "generate_asset", generate_then_cancel)
|
||
api.drain(pid, timeout=20)
|
||
|
||
task = api.get(f"/api/tasks/{task_id}")["task"]
|
||
assert task["status"] == "cancelled"
|
||
assets = api.get(f"/api/projects/{pid}/assets")["assets"]
|
||
assert not any((row.get("metadata") or {}).get("task_id") == task_id for row in assets)
|
||
|
||
|
||
def test_review_state_uses_pass_fail_verdicts(api, studio, script_text, make_image_png):
|
||
"""前端分镜卡片按 pass/fail 判定;后端若改成 approved 会显示成「人工不合格」。"""
|
||
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"))])
|
||
shots = api.get(f"/api/projects/{pid}/shots")["shots"]
|
||
assert [s["review_state"] for s in shots] == [ReviewVerdict.PENDING] * len(shots)
|
||
|
||
# 人工审核在生成+质检之后(图2 节点 9→10);没有产物时不得凭空放行
|
||
too_early = api.post(f"/api/projects/{pid}/shots/{shots[0]['id']}/approve", json={}, expect=400)
|
||
assert "产物" in too_early["detail"]
|
||
|
||
api.post(f"/api/projects/{pid}/tasks", json={"with_voiceover": False})
|
||
assert api.drain(pid)["result"]["drained"]["remaining"] == 0
|
||
|
||
shots = api.get(f"/api/projects/{pid}/shots")["shots"]
|
||
api.post(f"/api/projects/{pid}/shots/{shots[0]['id']}/approve", json={})
|
||
approved = next(s for s in api.get(f"/api/projects/{pid}/shots")["shots"]
|
||
if s["id"] == shots[0]["id"])
|
||
assert approved["review_state"] == ReviewVerdict.PASS and approved["status"] == "approved"
|
||
|
||
api.post(f"/api/projects/{pid}/shots/{shots[1]['id']}/reject",
|
||
json={"notes": "穿帮", "regenerate": False})
|
||
rejected = next(s for s in api.get(f"/api/projects/{pid}/shots")["shots"]
|
||
if s["id"] == shots[1]["id"])
|
||
assert rejected["review_state"] == ReviewVerdict.FAIL and rejected["status"] == "rejected"
|
||
|
||
# 审核记录与 review_state 共用同一套 pass/fail 取值,前端两处判定不会互相打架
|
||
manual = api.get(f"/api/projects/{pid}/reviews", params={"kind": "manual"})["reviews"]
|
||
assert {r["verdict"] for r in manual} == {ReviewVerdict.PASS, ReviewVerdict.FAIL}
|
||
|
||
|
||
FOUR_SHOT_SCRIPT = """## 镜头 01
|
||
- 景别: 全景
|
||
- 运镜: 推镜
|
||
- 时长: 2
|
||
- 镜头描述: 末班列车驶入空荡的站台
|
||
- 台词: 这座城市从不等人。
|
||
|
||
## 镜头 02
|
||
- 景别: 中景
|
||
- 运镜: 跟镜
|
||
- 时长: 2
|
||
- 镜头描述: 林澈收起伞走向车门
|
||
- 台词: 还有两分钟。
|
||
|
||
## 镜头 03
|
||
- 景别: 特写
|
||
- 时长: 2
|
||
- 镜头描述: 车窗上的雨滴把灯光扭成光斑
|
||
- 台词: 有些人一转身就是一辈子。
|
||
|
||
## 镜头 04
|
||
- 景别: 远景
|
||
- 运镜: 拉镜
|
||
- 时长: 2
|
||
- 镜头描述: 列车驶离站台,站台上只剩一个人
|
||
- 台词: 那就再等一班。
|
||
"""
|
||
|
||
|
||
def test_partial_regeneration_failure_still_turns_generation_node_red(
|
||
api, studio, make_image_png):
|
||
"""局部失败不得被整体成功掩盖:4 个镜头已出片,其中 1 个重做失败 → 节点 8/9 必须转红。
|
||
|
||
失败镜头的旧产物仍留在磁盘上,而 `generated` 是按产物是否存在计数的,
|
||
曾经因此算出「生成成功 4/4 且 state=done」,只在 detail 里留一句「1 个任务失败」,
|
||
界面上完全看不出图2 节点 8 走了「否」分支。
|
||
"""
|
||
pid = studio["project_id"]
|
||
api.post(f"/api/projects/{pid}/import",
|
||
data={"script_text": FOUR_SHOT_SCRIPT, "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")),
|
||
("images", ("s03.png", make_image_png(480, 270, "0x3a7d44"), "image/png")),
|
||
("images", ("s04.png", make_image_png(480, 270, "0x6b4a2f"), "image/png"))])
|
||
api.post(f"/api/projects/{pid}/tasks", json={"with_voiceover": False, "actor": "回归测试"})
|
||
assert api.drain(pid)["result"]["drained"]["remaining"] == 0
|
||
|
||
shots = api.get(f"/api/projects/{pid}/shots")["shots"]
|
||
assert len(shots) == 4
|
||
for shot in shots:
|
||
api.post(f"/api/projects/{pid}/shots/{shot['id']}/approve", json={})
|
||
green = {n["key"]: n for n in api.get(f"/api/projects/{pid}/summary")["result"]["workflow"]}
|
||
assert green["generate"]["state"] == "done" and green["save_output"]["state"] == "done"
|
||
|
||
# 注入供应商故障,只重做第 1 个镜头(其余 3 个镜头的成功产物原样保留)
|
||
spec = next(r for r in api.get("/api/providers")["providers"]
|
||
if r["provider"] == "mock" and r["media_type"] == "video")
|
||
api.patch(f"/api/providers/{spec['id']}", json={"config": {"failure_rate": 1.0}})
|
||
victim = shots[0]
|
||
api.post(f"/api/projects/{pid}/tasks", json={"shot_ids": [victim["id"]], "force": True,
|
||
"allow_unready": True, "with_voiceover": False})
|
||
assert api.drain(pid)["result"]["drained"]["remaining"] == 0
|
||
|
||
broken_shot = next(s for s in api.get(f"/api/projects/{pid}/shots")["shots"]
|
||
if s["id"] == victim["id"])
|
||
assert broken_shot["status"] == "failed" and broken_shot["error_code"]
|
||
|
||
workflow = {n["key"]: n for n in api.get(f"/api/projects/{pid}/summary")["result"]["workflow"]}
|
||
assert workflow["generate"]["state"] == "failed", workflow["generate"]
|
||
assert "失败" in workflow["generate"]["detail"], workflow["generate"]
|
||
assert workflow["save_output"]["state"] == "failed", workflow["save_output"]
|
||
# 可用产物只剩 3 个:失败镜头的旧产物不能继续冒充「这一镜已经好了」
|
||
assert workflow["generate"]["done"] == 3 and workflow["generate"]["total"] == 4, workflow["generate"]
|
||
assert workflow["save_output"]["done"] == 3, workflow["save_output"]
|
||
assert workflow["review"]["state"] != "done", workflow["review"]
|
||
|
||
# 修好故障 → 一键重跑 → 复核,节点重新转绿(失败不该是终态)
|
||
api.patch(f"/api/providers/{spec['id']}", json={"config": {"failure_rate": 0}})
|
||
requeued = api.post(f"/api/projects/{pid}/tasks/retry-failed", json={"reset_attempts": True})["result"]
|
||
assert requeued["count"] >= 1
|
||
assert api.drain(pid)["result"]["drained"]["remaining"] == 0
|
||
api.post(f"/api/projects/{pid}/shots/{victim['id']}/approve", json={"notes": "重做后复核合格"})
|
||
|
||
healed = {n["key"]: n for n in api.get(f"/api/projects/{pid}/summary")["result"]["workflow"]}
|
||
for key in ("generate", "save_output", "quality_check", "review"):
|
||
assert healed[key]["state"] == "done", (key, healed[key])
|
||
|
||
|
||
def test_capacity_rows_follow_the_model_spec_media_type(api, studio, script_text, make_image_png):
|
||
"""限流容量行必须「一个 (provider, model) 一行」,且媒体类型跟着模型规格走。
|
||
|
||
曾因任务派生出的容量键一律写成 media_type="video",配音模型 mock/mock-tts-1 凭空多出
|
||
一行默认限额(2 并发 / 30 RPM)的幽灵记录;而派发用的 `headroom()` 和
|
||
`GET /api/providers` 的 load 都按 `provider|model` 取行,幽灵行把真正的 TTS 行
|
||
(4 并发 / 120 RPM)盖掉,配音任务的限流被悄悄降级,限流面板还多显示一行假模型。
|
||
模型管理中心加入图像与文本生成后,容量视图应展示注册表中的全部四类模型,而不是
|
||
只在出现过任务后才显示,也不能为同一模型派生重复行。
|
||
"""
|
||
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"))])
|
||
api.post(f"/api/projects/{pid}/tasks", json={"with_voiceover": True, "actor": "回归测试"})
|
||
assert api.drain(pid)["result"]["drained"]["remaining"] == 0
|
||
kinds = {t["kind"] for t in api.get(f"/api/tasks?project_id={pid}")["tasks"]}
|
||
assert {"generate_shot", "voiceover"} <= kinds # 视频与配音都真的调过模型
|
||
|
||
specs = {(s["provider"], s["model"]): s for s in api.get("/api/providers")["providers"]}
|
||
rows = api.get(f"/api/projects/{pid}/queue")["capacity"]
|
||
pairs = [(r["provider"], r["model"]) for r in rows]
|
||
assert len(pairs) == len(set(pairs)), rows # 一个模型只允许占一行
|
||
assert set(pairs) == set(specs), rows # 注册表中的四类模型都应进入容量视图
|
||
assert {r["media_type"] for r in rows} == {s["media_type"] for s in specs.values()}, rows
|
||
for row in rows:
|
||
spec = specs[(row["provider"], row["model"])] # 不得凭空多出没登记过的模型行
|
||
assert row["media_type"] == spec["media_type"], row
|
||
assert row["concurrency_limit"] == spec["max_concurrency"], row
|
||
assert row["rpm_limit"] == spec["requests_per_minute"], row
|
||
assert row["enabled"] == spec["enabled"], row
|
||
assert spec["load"]["media_type"] == spec["media_type"], (spec["model"], spec["load"])
|
||
|
||
|
||
def test_shot_provider_follows_project_default_not_hardcoded_mock(api, studio, script_text, make_image_png):
|
||
"""镜头的 provider 留空必须跟随项目默认模型(历史上 Shot.provider 列默认写死 "mock")。
|
||
|
||
曾出现:项目已切到自建 ComfyUI/真实供应商,导入的镜头 provider 仍是 "mock",
|
||
任务于是静默走 mock 适配器,界面与生成记录全都显示 mock,用户以为在跑真实模型。
|
||
"""
|
||
pid = studio["project_id"]
|
||
api.post("/api/providers", json={
|
||
"provider": "selfhost", "model": "h3-local", "display_name": "自建 ComfyUI(用例替身)",
|
||
"media_type": "video", "adapter": "mock", "max_concurrency": 1, "requests_per_minute": 6,
|
||
"modes": ["t2v", "i2v", "fl"], "resolutions": ["480p", "720p"], "min_duration": 1.0,
|
||
"max_duration": 20.0, "max_reference_images": 6})
|
||
|
||
api.patch(f"/api/projects/{pid}", json={"default_provider": "selfhost", "default_model": "h3-local"})
|
||
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"))])
|
||
|
||
shots = api.get(f"/api/projects/{pid}/shots")["shots"]
|
||
assert shots and all(s["effective_provider"] == "selfhost" for s in shots), \
|
||
[(s["provider"], s["effective_provider"]) for s in shots]
|
||
|
||
plan = api.get(f"/api/projects/{pid}/tasklist?force=true")["plan"]
|
||
assert {s["provider"] for s in plan["shots"]} == {"selfhost"}, plan["shots"]
|
||
|
||
api.post(f"/api/projects/{pid}/tasks", json={"with_voiceover": False, "actor": "回归测试"})
|
||
tasks = [t for t in api.get(f"/api/tasks?project_id={pid}")["tasks"] if t["kind"] == "generate_shot"]
|
||
assert tasks and {t["provider"] for t in tasks} == {"selfhost"}, \
|
||
[(t["id"], t["provider"], t["model"]) for t in tasks]
|
||
assert api.drain(pid)["result"]["drained"]["remaining"] == 0
|
||
for shot in api.get(f"/api/projects/{pid}/shots")["shots"]:
|
||
assert shot["provider"] == "selfhost", (shot["order_index"], shot["provider"])
|
||
# 限流容量表也按真实模型出行:既不能只剩 mock,也不能长出 model='' 的幽灵行
|
||
rows = api.get(f"/api/projects/{pid}/queue")["capacity"]
|
||
pairs = {(r["provider"], r["model"]) for r in rows}
|
||
assert ("selfhost", "h3-local") in pairs, rows
|
||
assert ("selfhost", "") not in pairs, rows
|
||
limits = {(r["provider"], r["model"]): (r["concurrency_limit"], r["rpm_limit"]) for r in rows}
|
||
assert limits[("selfhost", "h3-local")] == (1, 6), limits # 用模型自己的限额,不是平台默认 2/30
|