166 lines
5.6 KiB
Python
166 lines
5.6 KiB
Python
|
|
from copy import deepcopy
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
from fastapi import HTTPException
|
||
|
|
|
||
|
|
from app.services.editors import sanitize_bindings
|
||
|
|
|
||
|
|
|
||
|
|
A = "a" * 32
|
||
|
|
|
||
|
|
|
||
|
|
def test_native_profile_requires_v4_exact_frame_contract():
|
||
|
|
from pydantic import ValidationError
|
||
|
|
from app.domain.stories import StorySpecV3, parse_story_spec
|
||
|
|
from app.domain.timeline import WorkflowSpec
|
||
|
|
|
||
|
|
profile = "minimax-h3-fl2va-bf16-v2"
|
||
|
|
with pytest.raises(ValidationError):
|
||
|
|
StorySpecV3.model_validate(
|
||
|
|
{"schema_version": 3, "shots": [{"id": A, "video_parameters": {"profile": profile}}]}
|
||
|
|
)
|
||
|
|
with pytest.raises(ValidationError):
|
||
|
|
WorkflowSpec.model_validate(
|
||
|
|
{
|
||
|
|
"schema_version": 2,
|
||
|
|
"shots": [{"key": "shot_1", "prompt": "海边", "parameters": {"profile": profile}}],
|
||
|
|
}
|
||
|
|
)
|
||
|
|
assert (
|
||
|
|
parse_story_spec(
|
||
|
|
{
|
||
|
|
"schema_version": 4,
|
||
|
|
"shots": [
|
||
|
|
{"id": A, "video_parameters": {"profile": profile, "source_frames": 124}}
|
||
|
|
],
|
||
|
|
}
|
||
|
|
)
|
||
|
|
.shots[0]
|
||
|
|
.video_parameters.source_frames
|
||
|
|
== 124
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
async def test_capabilities_advertise_both_versions_without_enabling_unverified_quality(system):
|
||
|
|
response = await system.client.get("/api/capabilities")
|
||
|
|
assert response.status_code == 200
|
||
|
|
caps = response.json()["editable_production"]
|
||
|
|
assert caps["schema_version"] == 1
|
||
|
|
assert caps["supported_schema_versions"] == [1, 2]
|
||
|
|
assert caps["story_schema_versions"] == [3, 4]
|
||
|
|
assert caps["continuity"]["available"] is False
|
||
|
|
|
||
|
|
|
||
|
|
async def test_internal_normalized_cache_does_not_fill_asset_pickers(system):
|
||
|
|
from app.models import Asset
|
||
|
|
|
||
|
|
owner = (await system.client.get("/api/auth/me")).json()["user"]["id"]
|
||
|
|
async with system.app.state.db.session() as session:
|
||
|
|
session.add(
|
||
|
|
Asset(
|
||
|
|
id="d" * 32,
|
||
|
|
owner_id=owner,
|
||
|
|
name="Normalized segment",
|
||
|
|
storage_key=f"{owner}/cache/normalized.mp4",
|
||
|
|
kind="video",
|
||
|
|
mime_type="video/mp4",
|
||
|
|
origin="normalized",
|
||
|
|
size_bytes=100,
|
||
|
|
sha256="e" * 64,
|
||
|
|
)
|
||
|
|
)
|
||
|
|
await session.commit()
|
||
|
|
response = await system.client.get("/api/assets", params={"kind": "video"})
|
||
|
|
assert response.status_code == 200
|
||
|
|
assert response.json()["items"] == []
|
||
|
|
assert response.json()["total"] == 0
|
||
|
|
|
||
|
|
|
||
|
|
def test_client_cannot_forge_actual_join_anchor_or_keep_it_after_new_selection():
|
||
|
|
m = {
|
||
|
|
"schema_version": 2,
|
||
|
|
"shot_ids": [A],
|
||
|
|
"spec": {"shots": [{"edit": {"start_frame": 0, "duration_frames": 124}}]},
|
||
|
|
"bindings": {
|
||
|
|
"video:" + A: {"asset_id": "video", "sha256": "1" * 64, "source": "manual"},
|
||
|
|
"join_anchor:" + A: {"asset_id": "image", "sha256": "2" * 64, "source": "manual"},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
with pytest.raises(HTTPException) as error:
|
||
|
|
sanitize_bindings(deepcopy(m), {"bindings": {}})
|
||
|
|
assert error.value.detail["code"] == "derived_binding_readonly"
|
||
|
|
original, modified = deepcopy(m), deepcopy(m)
|
||
|
|
modified["spec"]["shots"][0]["edit"]["duration_frames"] = 123
|
||
|
|
sanitize_bindings(modified, original)
|
||
|
|
assert "join_anchor:" + A not in modified["bindings"]
|
||
|
|
|
||
|
|
|
||
|
|
async def test_snapshot_exposes_quality_gate_not_just_successful_qa_job(system):
|
||
|
|
from sqlalchemy import select
|
||
|
|
from app.models import User, WorkflowDraft, WorkflowRun, WorkflowStep
|
||
|
|
from app.models.workflows import WorkflowVariant, QualityAssessment
|
||
|
|
|
||
|
|
async with system.app.state.db.session() as s:
|
||
|
|
owner = await s.scalar(select(User).where(User.username == "admin"))
|
||
|
|
draft = WorkflowDraft(
|
||
|
|
owner_id=owner.id,
|
||
|
|
name="Quality",
|
||
|
|
kind="story_v3",
|
||
|
|
spec={"schema_version": 4, "shots": [{"id": A}]},
|
||
|
|
)
|
||
|
|
s.add(draft)
|
||
|
|
await s.flush()
|
||
|
|
run = WorkflowRun(
|
||
|
|
owner_id=owner.id,
|
||
|
|
draft_id=draft.id,
|
||
|
|
draft_revision=1,
|
||
|
|
spec_hash="0" * 64,
|
||
|
|
spec_snapshot=draft.spec,
|
||
|
|
run_kind="story_auto",
|
||
|
|
state="blocked",
|
||
|
|
phase="production",
|
||
|
|
plan_snapshot={"steps": [{"key": "video_0001"}], "manifest": {"schema_version": 2}},
|
||
|
|
result_manifest={
|
||
|
|
"schema_version": 2,
|
||
|
|
"shot_ids": [A],
|
||
|
|
"bindings": {},
|
||
|
|
"spec": draft.spec,
|
||
|
|
},
|
||
|
|
)
|
||
|
|
s.add(run)
|
||
|
|
await s.flush()
|
||
|
|
s.add(
|
||
|
|
WorkflowStep(
|
||
|
|
run_id=run.id,
|
||
|
|
step_key="video_0001",
|
||
|
|
kind="video.generate",
|
||
|
|
dependencies=[],
|
||
|
|
semantic_input_hash="0" * 64,
|
||
|
|
state="blocked",
|
||
|
|
)
|
||
|
|
)
|
||
|
|
variant = WorkflowVariant(
|
||
|
|
run_id=run.id, step_key="video_0001", ordinal=1, resolved_input={}, state="reject"
|
||
|
|
)
|
||
|
|
s.add(variant)
|
||
|
|
await s.flush()
|
||
|
|
s.add(
|
||
|
|
QualityAssessment(
|
||
|
|
variant_id=variant.id,
|
||
|
|
job_id="b" * 32,
|
||
|
|
verdict="reject",
|
||
|
|
evidence={"reason": "动作不连贯"},
|
||
|
|
)
|
||
|
|
)
|
||
|
|
await s.commit()
|
||
|
|
rid = run.id
|
||
|
|
response = await system.client.get("/api/workflow-runs/" + rid)
|
||
|
|
assert response.status_code == 200, response.text
|
||
|
|
quality = response.json()["run"]["quality"]
|
||
|
|
assert (quality["accepted_shots"], quality["total_shots"], quality["total_repairs"]) == (
|
||
|
|
0,
|
||
|
|
1,
|
||
|
|
1,
|
||
|
|
)
|
||
|
|
assert quality["variants"][0]["assessment"]["verdict"] == "reject"
|