497 lines
22 KiB
Python
497 lines
22 KiB
Python
|
|
import pytest
|
||
|
|
|
||
|
|
from app.services.orchestration.continuity_engine import quality_action
|
||
|
|
|
||
|
|
|
||
|
|
def test_reject_budget():
|
||
|
|
assert [quality_action("reject", i, 0, {}, False) for i in range(3)] == [
|
||
|
|
"repair",
|
||
|
|
"repair",
|
||
|
|
"blocked",
|
||
|
|
]
|
||
|
|
assert quality_action("reject", 0, 12, {}, False) == "blocked"
|
||
|
|
assert quality_action("reject", 0, 0, {}, True) == "blocked"
|
||
|
|
assert quality_action("indeterminate", 0, 0, {}, False) == "blocked"
|
||
|
|
assert quality_action("pass", 2, 12, {}, True) == "accept"
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize(
|
||
|
|
("cancel", "trimmed"), [(False, False), (True, False), (False, True), (False, "dedup")]
|
||
|
|
)
|
||
|
|
async def test_restart_after_each_reject_keeps_one_variant_and_blocks_publication(
|
||
|
|
system, monkeypatch, cancel, trimmed
|
||
|
|
):
|
||
|
|
from sqlalchemy import select
|
||
|
|
from app.models import User, Job, WorkflowDraft, WorkflowRun, WorkflowStep
|
||
|
|
from app.models.workflows import WorkflowVariant, QualityAssessment
|
||
|
|
from app.services.orchestration import editor_engine
|
||
|
|
from app.services.orchestration.workflow_engine import advance_run
|
||
|
|
|
||
|
|
parameters = {"seed": 42}
|
||
|
|
if trimmed is True:
|
||
|
|
parameters.update(conditioning_mode="first_last_frame", num_frames=124)
|
||
|
|
|
||
|
|
async def resolve(*args):
|
||
|
|
return {"input": {"image_asset_id": "test"}, "parameters": parameters, "input_sha256": {}}
|
||
|
|
|
||
|
|
monkeypatch.setattr(editor_engine, "_resolve", resolve)
|
||
|
|
# Observe the committed repair before allowing the next dispatch.
|
||
|
|
monkeypatch.setattr("app.services.orchestration.workflow_engine.child_capacity", no_capacity)
|
||
|
|
db = system.app.state.db
|
||
|
|
async with db.session() as session:
|
||
|
|
owner = await session.scalar(select(User.id))
|
||
|
|
m = {"schema_version": 2, "shot_ids": ["shot"], "bindings": {}, "production": {}}
|
||
|
|
if trimmed is True:
|
||
|
|
m["spec"] = {"shots": [{"edit": {"start_frame": 4, "duration_frames": 120}}]}
|
||
|
|
draft = WorkflowDraft(owner_id=owner, name="Test")
|
||
|
|
session.add(draft)
|
||
|
|
await session.flush()
|
||
|
|
run = WorkflowRun(
|
||
|
|
owner_id=owner,
|
||
|
|
draft_id=draft.id,
|
||
|
|
draft_revision=1,
|
||
|
|
spec_hash="h",
|
||
|
|
phase="production",
|
||
|
|
plan_snapshot={"steps": [{"key": "video"}]},
|
||
|
|
result_manifest=m,
|
||
|
|
run_kind="story_auto",
|
||
|
|
)
|
||
|
|
session.add(run)
|
||
|
|
await session.flush()
|
||
|
|
rid = run.id
|
||
|
|
step = WorkflowStep(
|
||
|
|
run_id=rid,
|
||
|
|
step_key="video",
|
||
|
|
kind="video.generate",
|
||
|
|
semantic_input_hash="x",
|
||
|
|
recipe_json={"unit_id": "shot", "parameters": parameters},
|
||
|
|
)
|
||
|
|
session.add_all(
|
||
|
|
[
|
||
|
|
step,
|
||
|
|
WorkflowVariant(
|
||
|
|
run_id=rid,
|
||
|
|
step_key="video",
|
||
|
|
ordinal=0,
|
||
|
|
resolved_input=await resolve(),
|
||
|
|
state="assessing",
|
||
|
|
candidate={"asset_id": "src"},
|
||
|
|
),
|
||
|
|
]
|
||
|
|
)
|
||
|
|
await session.commit()
|
||
|
|
for ordinal in range(3):
|
||
|
|
async with db.session() as session:
|
||
|
|
run = await session.get(WorkflowRun, rid)
|
||
|
|
step = await session.scalar(select(WorkflowStep).where(WorkflowStep.run_id == rid))
|
||
|
|
latest = await session.scalar(
|
||
|
|
select(WorkflowVariant).where(
|
||
|
|
WorkflowVariant.run_id == rid, WorkflowVariant.ordinal == ordinal
|
||
|
|
)
|
||
|
|
)
|
||
|
|
latest.candidate = {"asset_id": "src", "source": "manual", "locked": False}
|
||
|
|
latest.state = "assessing"
|
||
|
|
j = Job(
|
||
|
|
owner_id=owner,
|
||
|
|
run_id=rid,
|
||
|
|
step_key="video",
|
||
|
|
explicit_attempt=ordinal + 1,
|
||
|
|
task_type="video.continuity.inspect",
|
||
|
|
state="succeeded",
|
||
|
|
phase="done",
|
||
|
|
input_json={},
|
||
|
|
parameters={},
|
||
|
|
request_hash="x",
|
||
|
|
upstream_key=f"qa-{ordinal}",
|
||
|
|
result_json={
|
||
|
|
"verdict": "reject",
|
||
|
|
"reason": "bad motion",
|
||
|
|
**({"dedup_verified": False} if trimmed == "dedup" else {}),
|
||
|
|
},
|
||
|
|
)
|
||
|
|
session.add(j)
|
||
|
|
await session.flush()
|
||
|
|
step.selected_job_id = j.id
|
||
|
|
step.explicit_attempt = ordinal + 1
|
||
|
|
run.desired_state = "pause"
|
||
|
|
await advance_run(session, rid, system.settings)
|
||
|
|
assert run.state == "paused" and latest.state == "assessing"
|
||
|
|
if cancel:
|
||
|
|
run.desired_state = "cancel"
|
||
|
|
await advance_run(session, rid, system.settings)
|
||
|
|
assert run.state == "cancelled" and run.result_manifest["bindings"] == {}
|
||
|
|
assert not (await session.scalars(select(QualityAssessment))).all()
|
||
|
|
await session.commit()
|
||
|
|
await advance_run(session, rid, system.settings)
|
||
|
|
assert not (await session.scalars(select(QualityAssessment))).all()
|
||
|
|
return
|
||
|
|
run.desired_state = "run"
|
||
|
|
await advance_run(session, rid, system.settings)
|
||
|
|
await session.commit()
|
||
|
|
async with db.session() as session:
|
||
|
|
await advance_run(session, rid, system.settings)
|
||
|
|
run = await session.get(WorkflowRun, rid)
|
||
|
|
assert run.result_manifest["bindings"] == {}
|
||
|
|
assessments = (await session.scalars(select(QualityAssessment))).all()
|
||
|
|
variants = (await session.scalars(select(WorkflowVariant))).all()
|
||
|
|
if trimmed:
|
||
|
|
assert [v.ordinal for v in variants] == [0]
|
||
|
|
assert len(assessments) == 1 and assessments[0].verdict == "reject"
|
||
|
|
assert run.state == "blocked" and run.error_json["code"] == (
|
||
|
|
"dedup_mismatch" if trimmed == "dedup" else "endpoint_trim_conflict"
|
||
|
|
)
|
||
|
|
return
|
||
|
|
assert len(assessments) == ordinal + 1 and len(variants) == min(ordinal + 2, 3)
|
||
|
|
assert run.state == ("blocked" if ordinal == 2 else "running")
|
||
|
|
await session.commit()
|
||
|
|
|
||
|
|
|
||
|
|
async def no_capacity(*args):
|
||
|
|
return False
|
||
|
|
|
||
|
|
|
||
|
|
async def test_v4_run_freezes_plan_and_dispatches_child_of_parent(system, png_bytes):
|
||
|
|
from sqlalchemy import select
|
||
|
|
from app.models import Job, WorkflowRun, WorkflowStep
|
||
|
|
from app.services.orchestration.workflow_engine import advance_run
|
||
|
|
from app.domain.continuity import upgrade_story_spec
|
||
|
|
from test_story_studio import story_spec
|
||
|
|
|
||
|
|
system.settings.continuity_quality_certified = True
|
||
|
|
spec = upgrade_story_spec(story_spec())
|
||
|
|
spec["shots"][0]["video_parameters"] = {
|
||
|
|
"profile": "minimax-h3-fl2va-bf16-v2",
|
||
|
|
"source_frames": 124,
|
||
|
|
}
|
||
|
|
spec["shots"][0]["edit"]["duration_frames"] = 124
|
||
|
|
spec["render"]["total_frames"] = 124
|
||
|
|
spec["shots"][0]["continuity"]["endpoint_mode"] = "first_last_frame"
|
||
|
|
spec["shots"][0]["continuity"]["end_prompt"] = "The tree at sunset"
|
||
|
|
spec["shots"][0]["continuity"]["state_in"]["summary"] = "Tree at noon"
|
||
|
|
spec["shots"][0]["continuity"]["state_out"]["summary"] = "Tree at sunset"
|
||
|
|
c = system.client
|
||
|
|
response = await c.post("/api/stories", json={"name": "Continuity", "spec": spec})
|
||
|
|
assert response.status_code == 201, response.text
|
||
|
|
did = response.json()["id"]
|
||
|
|
response = await c.get("/api/editors/" + did)
|
||
|
|
assert response.status_code == 200, response.text
|
||
|
|
manifest = response.json()["manifest"]
|
||
|
|
assert manifest["schema_version"] == 2
|
||
|
|
body = {"expected_version": 1, "output_goal": "film"}
|
||
|
|
response = await c.post("/api/editors/" + did + "/plan", json=body)
|
||
|
|
assert response.status_code == 200, response.text
|
||
|
|
system.settings.continuity_quality_certified = False
|
||
|
|
disabled = await c.post("/api/editors/" + did + "/plan", json=body)
|
||
|
|
assert any(issue["code"] == "capability_unavailable" for issue in disabled.json()["issues"])
|
||
|
|
frame_only = await c.post(
|
||
|
|
"/api/editors/" + did + "/plan",
|
||
|
|
json={
|
||
|
|
"expected_version": 1,
|
||
|
|
"output_goal": "media",
|
||
|
|
"targets": ["frame:" + manifest["shot_ids"][0]],
|
||
|
|
},
|
||
|
|
)
|
||
|
|
assert not any(
|
||
|
|
issue["code"] == "capability_unavailable" for issue in frame_only.json()["issues"]
|
||
|
|
)
|
||
|
|
system.settings.continuity_quality_certified = True
|
||
|
|
body["expected_plan_hash"] = response.json()["plan_hash"]
|
||
|
|
response = await c.post(
|
||
|
|
"/api/editors/" + did + "/runs", json=body, headers={"Idempotency-Key": "v4"}
|
||
|
|
)
|
||
|
|
assert response.status_code == 202, response.text
|
||
|
|
rid = response.json()["run"]["id"]
|
||
|
|
async with system.app.state.db.session() as session:
|
||
|
|
run = await session.get(WorkflowRun, rid)
|
||
|
|
assert run.phase == "preparation" and run.prepared_plan is None
|
||
|
|
await advance_run(session, rid, system.settings)
|
||
|
|
jobs = (await session.scalars(select(Job).where(Job.run_id == rid))).all()
|
||
|
|
assert {j.step_key for j in jobs} == {"frame_0001", "end_0001"}
|
||
|
|
assert all(j.owner_id == run.owner_id for j in jobs)
|
||
|
|
video = await session.scalar(
|
||
|
|
select(WorkflowStep).where(
|
||
|
|
WorkflowStep.run_id == rid, WorkflowStep.kind == "video.generate"
|
||
|
|
)
|
||
|
|
)
|
||
|
|
assert video.recipe_json["parameters"]["num_frames"] == 124
|
||
|
|
assert video.resolved_input_json is None
|
||
|
|
from app.models import Asset
|
||
|
|
import hashlib
|
||
|
|
|
||
|
|
endpoints = {}
|
||
|
|
for j in jobs:
|
||
|
|
key = f"mock/{j.id}.png"
|
||
|
|
path = system.settings.asset_root / key
|
||
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||
|
|
path.write_bytes(png_bytes)
|
||
|
|
a = Asset(
|
||
|
|
owner_id=run.owner_id,
|
||
|
|
name="frame",
|
||
|
|
storage_key=key,
|
||
|
|
kind="image",
|
||
|
|
mime_type="image/png",
|
||
|
|
size_bytes=len(png_bytes),
|
||
|
|
sha256=hashlib.sha256(png_bytes).hexdigest(),
|
||
|
|
width=1280,
|
||
|
|
height=704,
|
||
|
|
source_job_id=j.id,
|
||
|
|
source_output_index=0,
|
||
|
|
)
|
||
|
|
session.add(a)
|
||
|
|
await session.flush()
|
||
|
|
endpoints[j.step_key] = a.id
|
||
|
|
j.state = "succeeded"
|
||
|
|
await advance_run(session, rid, system.settings)
|
||
|
|
assert run.state != "blocked", run.error_json
|
||
|
|
video_job = await session.get(Job, video.selected_job_id)
|
||
|
|
assert video_job.task_type == "video.generate" and video_job.run_id == rid
|
||
|
|
assert video_job.parameters["num_frames"] == 124
|
||
|
|
assert video_job.input_json["first_frame_asset_id"] == endpoints["frame_0001"]
|
||
|
|
assert video_job.input_json["last_frame_asset_id"] == endpoints["end_0001"]
|
||
|
|
assert "image_asset_id" not in video_job.input_json
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize(("locked", "seed_edit"), [(False, False), (True, False), (True, True)])
|
||
|
|
async def test_v4_pass_promotes_anchor_then_final_cas_once(
|
||
|
|
system, monkeypatch, png_bytes, locked, seed_edit
|
||
|
|
):
|
||
|
|
import hashlib
|
||
|
|
from uuid import uuid4
|
||
|
|
from unittest.mock import AsyncMock
|
||
|
|
from sqlalchemy import select
|
||
|
|
from app.models import Asset, Job, WorkflowRun, WorkflowDraft
|
||
|
|
from app.services.orchestration.workflow_engine import advance_run
|
||
|
|
from app.domain.continuity import upgrade_story_spec
|
||
|
|
from test_story_studio import story_spec
|
||
|
|
from copy import deepcopy
|
||
|
|
|
||
|
|
system.settings.continuity_quality_certified = True
|
||
|
|
spec = upgrade_story_spec(story_spec())
|
||
|
|
first = spec["shots"][0]
|
||
|
|
first["edit"].update(start_frame=4, duration_frames=26)
|
||
|
|
second = deepcopy(first)
|
||
|
|
second.update(id="2" * 32)
|
||
|
|
second["continuity"]["transition"] = "continue"
|
||
|
|
second["edit"].update(start_frame=1, duration_frames=28, dedup_frames=1)
|
||
|
|
spec["shots"].append(second)
|
||
|
|
spec["render"]["total_frames"] = 53
|
||
|
|
monkeypatch.setattr("app.services.stories.candidates.validate_video", AsyncMock())
|
||
|
|
monkeypatch.setattr(
|
||
|
|
"app.adapters.media.inspect_video_track",
|
||
|
|
AsyncMock(return_value={"fps": 24, "frames": 120, "width": 1280, "height": 704}),
|
||
|
|
)
|
||
|
|
c = system.client
|
||
|
|
response = await c.post("/api/stories", json={"name": "Continuity", "spec": spec})
|
||
|
|
assert response.status_code == 201, response.text
|
||
|
|
did = response.json()["id"]
|
||
|
|
initial = (await c.get("/api/editors/" + did)).json()["manifest"]
|
||
|
|
target = "video:" + initial["shot_ids"][0]
|
||
|
|
body = {"force": [target], "expected_version": 1, "output_goal": "film"}
|
||
|
|
response = await c.post("/api/editors/" + did + "/plan", json=body)
|
||
|
|
assert response.status_code == 200, response.text
|
||
|
|
body["expected_plan_hash"] = response.json()["plan_hash"]
|
||
|
|
response = await c.post(
|
||
|
|
"/api/editors/" + did + "/runs", json=body, headers={"Idempotency-Key": "v4-follow"}
|
||
|
|
)
|
||
|
|
assert response.status_code == 202, response.text
|
||
|
|
rid = response.json()["run"]["id"]
|
||
|
|
anchors = []
|
||
|
|
dispatched_seeds = []
|
||
|
|
for _ in range(14):
|
||
|
|
async with system.app.state.db.session() as session:
|
||
|
|
await advance_run(session, rid, system.settings)
|
||
|
|
run = await session.get(WorkflowRun, rid)
|
||
|
|
draft = await session.get(WorkflowDraft, did)
|
||
|
|
assert run.state != "blocked", run.error_json
|
||
|
|
if run.state == "succeeded":
|
||
|
|
assert run.apply_state == "applied" and draft.current_run_id == rid
|
||
|
|
assert draft.version == 2
|
||
|
|
await advance_run(session, rid, system.settings)
|
||
|
|
assert draft.version == 2 and len(anchors) == 2
|
||
|
|
await session.commit()
|
||
|
|
break
|
||
|
|
assert draft.version == 1
|
||
|
|
jobs = (
|
||
|
|
await session.scalars(
|
||
|
|
select(Job).where(Job.run_id == rid, Job.state != "succeeded")
|
||
|
|
)
|
||
|
|
).all()
|
||
|
|
for j in jobs:
|
||
|
|
key = "mock/" + uuid4().hex + ".bin"
|
||
|
|
path = system.settings.asset_root / key
|
||
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||
|
|
path.write_bytes(png_bytes)
|
||
|
|
kind = (
|
||
|
|
"json"
|
||
|
|
if j.task_type == "text.story.plan"
|
||
|
|
else "image"
|
||
|
|
if j.task_type in ("image.generate", "video.continuity.inspect")
|
||
|
|
else "video"
|
||
|
|
)
|
||
|
|
if j.task_type == "text.story.plan":
|
||
|
|
prepared = deepcopy(j.input_json["spec"])
|
||
|
|
for index, shot in enumerate(prepared["shots"]):
|
||
|
|
shot["continuity"]["state_in"]["summary"] = f"scene state {index}"
|
||
|
|
shot["continuity"]["state_out"]["summary"] = f"scene state {index + 1}"
|
||
|
|
j.result_json = {"spec": prepared}
|
||
|
|
if j.task_type == "image.generate":
|
||
|
|
assert "scene state 0" in j.input_json["prompt"]
|
||
|
|
if j.task_type == "video.generate":
|
||
|
|
if j.step_key == "video_0001":
|
||
|
|
dispatched_seeds.append(j.parameters["seed"])
|
||
|
|
assert "scene state" in j.input_json["prompt"]
|
||
|
|
assert run.prepared_plan["prepared_hash"]
|
||
|
|
assert "story_plan" in run.prepared_plan["preparation"]
|
||
|
|
assert not run.spec_snapshot["shots"][0]["continuity"]["state_in"]["summary"]
|
||
|
|
a = Asset(
|
||
|
|
owner_id=run.owner_id,
|
||
|
|
name="mock",
|
||
|
|
storage_key=key,
|
||
|
|
kind=kind,
|
||
|
|
mime_type="application/octet-stream",
|
||
|
|
size_bytes=len(png_bytes),
|
||
|
|
sha256=hashlib.sha256(png_bytes).hexdigest(),
|
||
|
|
width=1280,
|
||
|
|
height=704,
|
||
|
|
duration_seconds=5 if kind == "video" else None,
|
||
|
|
source_job_id=j.id,
|
||
|
|
source_output_index=0,
|
||
|
|
)
|
||
|
|
session.add(a)
|
||
|
|
await session.flush()
|
||
|
|
if j.task_type == "video.continuity.inspect":
|
||
|
|
if locked and not anchors and len(dispatched_seeds) == 1:
|
||
|
|
j.result_json = {"verdict": "reject", "reason": "motion drift"}
|
||
|
|
j.state = "succeeded"
|
||
|
|
continue
|
||
|
|
anchors.append(a.id)
|
||
|
|
if len(anchors) == 1:
|
||
|
|
assert j.input_json["expected"]["source_end_frame"] == 30
|
||
|
|
assert "previous_video_asset_id" not in j.input_json
|
||
|
|
else:
|
||
|
|
assert j.input_json["expected"]["previous_end_frame"] == 30
|
||
|
|
j.result_json = {
|
||
|
|
"verdict": "pass",
|
||
|
|
"reason": "Subject and motion consistent",
|
||
|
|
"dedup_verified": True
|
||
|
|
if j.input_json["expected"]["dedup_frames"]
|
||
|
|
else None,
|
||
|
|
}
|
||
|
|
if j.task_type == "video.generate" and j.step_key == "video_0002":
|
||
|
|
assert j.input_json["image_asset_id"] == anchors[0]
|
||
|
|
if j.task_type == "video.compose":
|
||
|
|
clips = j.parameters["render_inputs"]["clips"]
|
||
|
|
assert [(x["start_frame"], x["duration_frames"]) for x in clips] == [
|
||
|
|
(4, 26),
|
||
|
|
(2, 27),
|
||
|
|
]
|
||
|
|
j.state = "succeeded"
|
||
|
|
await session.commit()
|
||
|
|
else:
|
||
|
|
raise AssertionError("workflow did not finish")
|
||
|
|
|
||
|
|
current = (await c.get("/api/editors/" + did)).json()
|
||
|
|
manifest = current["manifest"]
|
||
|
|
accepted = manifest["bindings"][target]
|
||
|
|
assert len(dispatched_seeds) == (2 if locked else 1)
|
||
|
|
assert accepted["generation_parameters"]["seed"] == dispatched_seeds[-1] != 42
|
||
|
|
accepted["locked"] = locked
|
||
|
|
if seed_edit:
|
||
|
|
manifest["spec"]["shots"][0].setdefault("video_parameters", {})["seed"] = 12345
|
||
|
|
manifest["captions"] = dict(
|
||
|
|
mode="manual",
|
||
|
|
cues=[dict(id="a" * 32, anchor="absolute", start_frame=0, end_frame=12, text=str(locked))],
|
||
|
|
)
|
||
|
|
saved = await c.post(
|
||
|
|
"/api/editors/" + did + "/save",
|
||
|
|
json={"expected_version": current["version"], "manifest": manifest},
|
||
|
|
headers={"Idempotency-Key": "save-" + str(locked)},
|
||
|
|
)
|
||
|
|
assert saved.status_code == 200, saved.text
|
||
|
|
body = dict(expected_version=saved.json()["version"], output_goal="film")
|
||
|
|
planned = await c.post("/api/editors/" + did + "/plan", json=body)
|
||
|
|
body["expected_plan_hash"] = planned.json()["plan_hash"]
|
||
|
|
started = await c.post(
|
||
|
|
"/api/editors/" + did + "/runs",
|
||
|
|
json=body,
|
||
|
|
headers={"Idempotency-Key": "edited-" + str(locked)},
|
||
|
|
)
|
||
|
|
assert started.status_code == 202, started.text
|
||
|
|
edited_id = started.json()["run"]["id"]
|
||
|
|
for _ in range(14):
|
||
|
|
async with system.app.state.db.session() as session:
|
||
|
|
await advance_run(session, edited_id, system.settings)
|
||
|
|
edited_run = await session.get(WorkflowRun, edited_id)
|
||
|
|
if seed_edit and edited_run.state == "blocked":
|
||
|
|
assert edited_run.error_json["code"] == "locked_dependency_changed"
|
||
|
|
return
|
||
|
|
assert edited_run.state != "blocked", edited_run.error_json
|
||
|
|
jobs = (await session.scalars(select(Job).where(Job.run_id == edited_id))).all()
|
||
|
|
assert all(j.task_type != "video.generate" for j in jobs)
|
||
|
|
if edited_run.state == "succeeded":
|
||
|
|
assert not seed_edit
|
||
|
|
assert (
|
||
|
|
edited_run.result_manifest["bindings"][target]["asset_id"]
|
||
|
|
== accepted["asset_id"]
|
||
|
|
)
|
||
|
|
assert any(j.task_type == "video.compose" for j in jobs)
|
||
|
|
break
|
||
|
|
for j in jobs:
|
||
|
|
if j.state != "succeeded":
|
||
|
|
previous = await session.scalar(
|
||
|
|
select(Job)
|
||
|
|
.where(
|
||
|
|
Job.run_id == rid,
|
||
|
|
Job.step_key == j.step_key,
|
||
|
|
Job.task_type == j.task_type,
|
||
|
|
)
|
||
|
|
.order_by(Job.created_at.desc())
|
||
|
|
)
|
||
|
|
source = await session.scalar(
|
||
|
|
select(Asset).where(Asset.source_job_id == previous.id)
|
||
|
|
)
|
||
|
|
if source:
|
||
|
|
key = "mock/" + uuid4().hex + ".bin"
|
||
|
|
(system.settings.asset_root / key).write_bytes(png_bytes)
|
||
|
|
session.add(
|
||
|
|
Asset(
|
||
|
|
owner_id=source.owner_id,
|
||
|
|
name="mock",
|
||
|
|
storage_key=key,
|
||
|
|
kind=source.kind,
|
||
|
|
mime_type=source.mime_type,
|
||
|
|
size_bytes=source.size_bytes,
|
||
|
|
duration_seconds=source.duration_seconds,
|
||
|
|
sha256=source.sha256,
|
||
|
|
width=source.width,
|
||
|
|
height=source.height,
|
||
|
|
source_job_id=j.id,
|
||
|
|
source_output_index=0,
|
||
|
|
)
|
||
|
|
)
|
||
|
|
j.result_json = deepcopy(previous.result_json)
|
||
|
|
j.state = "succeeded"
|
||
|
|
await session.commit()
|
||
|
|
else:
|
||
|
|
raise AssertionError("edited run did not finish")
|
||
|
|
|
||
|
|
|
||
|
|
def test_forced_and_repaired_video_track_requested_and_actual_identity():
|
||
|
|
from copy import deepcopy
|
||
|
|
from app.services.orchestration import continuity_engine as engine
|
||
|
|
|
||
|
|
requested = {"input": {"prompt": "walk"}, "parameters": {"seed": 42}, "input_sha256": {}}
|
||
|
|
forced = deepcopy(requested)
|
||
|
|
forced["parameters"]["seed"] = 173
|
||
|
|
repaired = deepcopy(forced)
|
||
|
|
repaired["parameters"]["seed"] += 1
|
||
|
|
repaired["input"]["prompt"] += " repair"
|
||
|
|
for actual in (forced, repaired):
|
||
|
|
binding = engine.generated_candidate({}, actual, forced, {"seed": 42})
|
||
|
|
assert binding["context_hash"] == engine.model_hash(actual)
|
||
|
|
assert binding["provenance"]["requested_context_hash"] == engine.model_hash(requested)
|
||
|
|
for locked in (False, True):
|
||
|
|
binding["locked"] = locked
|
||
|
|
assert engine.matches_request(binding, requested)
|
||
|
|
assert not engine.matches_request(binding, forced)
|