79 lines
2.9 KiB
Python
79 lines
2.9 KiB
Python
"""新CPU任务必须经过统一提交合同与owner资产链。"""
|
|
|
|
import pytest
|
|
from app.adapters.provider.contracts import validate_arguments
|
|
from app.domain.errors import MediaError
|
|
from app.domain.tasks import CPU_TYPES
|
|
|
|
|
|
def test_new_audio_cpu_task_contract_is_strict():
|
|
assert {"audio.normalize", "audio.mix"} <= CPU_TYPES
|
|
validate_arguments("audio.normalize", {"asset_id": "audio1"}, {})
|
|
validate_arguments(
|
|
"audio.mix",
|
|
{
|
|
"total_frames": 25,
|
|
"segments": [
|
|
{
|
|
"asset_id": "audio1",
|
|
"source_start_sample": 0,
|
|
"source_end_sample": 50000,
|
|
"offset_sample": 0,
|
|
}
|
|
],
|
|
},
|
|
{},
|
|
)
|
|
with pytest.raises(MediaError):
|
|
validate_arguments("audio.normalize", {"asset_id": "C:/secret.wav"}, {})
|
|
|
|
|
|
async def test_audio_input_kind_and_owner_are_checked(system, other_client, png_bytes):
|
|
response = await system.client.post(
|
|
"/api/assets", files={"file": ("frame.png", png_bytes, "image/png")}
|
|
)
|
|
aid = response.json()["id"]
|
|
body = {"task_type": "audio.normalize", "input": {"asset_id": aid}, "parameters": {}}
|
|
rejected = await system.client.post(
|
|
"/api/jobs", json=body, headers={"Idempotency-Key": "normalize-image"}
|
|
)
|
|
assert rejected.status_code == 422, rejected.text
|
|
assert rejected.json()["detail"]["code"] == "wrong_asset_kind"
|
|
private = await other_client.post(
|
|
"/api/jobs", json=body, headers={"Idempotency-Key": "normalize-other-owner"}
|
|
)
|
|
assert private.status_code == 404, private.text
|
|
|
|
|
|
async def test_plan_checks_reference_budget_before_creating_jobs(system, png_bytes):
|
|
ids = []
|
|
for index in range(4):
|
|
response = await system.client.post(
|
|
"/api/assets", files={"file": (f"ref-{index}.png", png_bytes, "image/png")}
|
|
)
|
|
ids.append(response.json()["id"])
|
|
sid, entity, cast = "a" * 32, "b" * 32, "c" * 32
|
|
spec = {
|
|
"schema_version": 4,
|
|
"entities": [{"id": entity, "name": "旅人", "reference_asset_ids": ids}],
|
|
"shots": [
|
|
{
|
|
"id": sid,
|
|
"cast": [{"id": cast, "entity_id": entity}],
|
|
"visual_prompt": "旅人走向海边",
|
|
}
|
|
],
|
|
}
|
|
response = await system.client.post(
|
|
"/api/stories", json={"name": "Reference budget", "create_folder": False, "spec": spec}
|
|
)
|
|
assert response.status_code == 201, response.text
|
|
system.settings.reference_generation_enabled = True
|
|
plan = await system.client.post(
|
|
f"/api/editors/{response.json()['id']}/plan",
|
|
json={"expected_version": 1, "output_goal": "media", "targets": ["frame:" + sid]},
|
|
)
|
|
assert plan.status_code == 200, plan.text
|
|
assert any(issue["code"] == "reference_budget_exceeded" for issue in plan.json()["issues"])
|
|
assert (await system.client.get("/api/jobs")).json()["total"] == 0
|