116 lines
4.4 KiB
Python
116 lines
4.4 KiB
Python
|
|
"""原生模型的可用性只覆盖证书实际验收的画布。"""
|
||
|
|
|
||
|
|
from copy import deepcopy
|
||
|
|
from types import SimpleNamespace
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from app.adapters.provider import native_av
|
||
|
|
from app.services.orchestration.native_dialogue_engine import _capability
|
||
|
|
from test_native_av_contract import TP2, certificate
|
||
|
|
|
||
|
|
|
||
|
|
def landscape_certificate():
|
||
|
|
return {**certificate(TP2), "canvases": [[1344, 768]]}
|
||
|
|
|
||
|
|
|
||
|
|
def test_single_audited_canvas_certificate_does_not_imply_the_other_canvas():
|
||
|
|
evidence = landscape_certificate()
|
||
|
|
assert native_av.certified(evidence, TP2)
|
||
|
|
assert native_av.canvas_certified(evidence, TP2, 1344, 768)
|
||
|
|
assert not native_av.canvas_certified(evidence, TP2, 768, 1344)
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize(
|
||
|
|
"canvases",
|
||
|
|
[[], None, [[1344, 768]] * 2, [[1344, True]], [[1024, 1024]], [[768, 1344], [1344, 768]]],
|
||
|
|
)
|
||
|
|
def test_malformed_or_unordered_canvas_scope_is_not_a_certificate(canvases):
|
||
|
|
assert not native_av.certified({**certificate(TP2), "canvases": canvases}, TP2)
|
||
|
|
|
||
|
|
|
||
|
|
async def test_provider_and_frozen_phase_check_exact_geometry():
|
||
|
|
evidence = landscape_certificate()
|
||
|
|
snapshot = dict(video_generation=dict(native_av_tp2=evidence))
|
||
|
|
settings = SimpleNamespace(
|
||
|
|
inference_base_url="http://example.test",
|
||
|
|
native_dialogue_tp2_enabled=True,
|
||
|
|
_native_av_upstream=snapshot,
|
||
|
|
)
|
||
|
|
|
||
|
|
async def caps():
|
||
|
|
return deepcopy(snapshot)
|
||
|
|
|
||
|
|
provider = SimpleNamespace(settings=settings, upstream_capabilities=caps)
|
||
|
|
assert await native_av.available(provider, TP2, canvas=[1344, 768])
|
||
|
|
assert not await native_av.available(provider, TP2, canvas=[768, 1344])
|
||
|
|
assert _capability("video.generate", dict(profile=TP2, width=1344, height=768), settings)
|
||
|
|
assert not _capability("video.generate", dict(profile=TP2, width=768, height=1344), settings)
|
||
|
|
|
||
|
|
|
||
|
|
async def test_provider_dispatch_does_not_upload_or_submit_uncertified_canvas(tmp_path):
|
||
|
|
from app.adapters.provider.gpu import prepare_gpu_payload
|
||
|
|
from app.domain.errors import MediaError
|
||
|
|
|
||
|
|
async def caps():
|
||
|
|
return dict(video_generation=dict(native_av_tp2=landscape_certificate()))
|
||
|
|
|
||
|
|
def forbidden(*args):
|
||
|
|
raise AssertionError("未认证的画布不应进入素材上传或模型调用")
|
||
|
|
|
||
|
|
provider = SimpleNamespace(
|
||
|
|
settings=SimpleNamespace(
|
||
|
|
inference_base_url="http://example.test", native_dialogue_tp2_enabled=True
|
||
|
|
),
|
||
|
|
upstream_capabilities=caps,
|
||
|
|
_work=lambda work: tmp_path,
|
||
|
|
_asset=forbidden,
|
||
|
|
)
|
||
|
|
with pytest.raises(MediaError) as caught:
|
||
|
|
await prepare_gpu_payload(
|
||
|
|
provider,
|
||
|
|
"video.generate",
|
||
|
|
dict(prompt="你好", first_frame_asset_id="a" * 32),
|
||
|
|
dict(profile=TP2, num_frames=158, width=768, height=1344),
|
||
|
|
{},
|
||
|
|
tmp_path,
|
||
|
|
)
|
||
|
|
assert caught.value.code == "capability_unavailable"
|
||
|
|
|
||
|
|
|
||
|
|
async def test_http_exposes_only_audited_canvas_and_rejects_portrait_without_creating_job(
|
||
|
|
system, png_bytes
|
||
|
|
):
|
||
|
|
system.settings.inference_base_url = "http://example.test"
|
||
|
|
system.settings.native_dialogue_tp2_enabled = True
|
||
|
|
|
||
|
|
async def caps():
|
||
|
|
return dict(video_generation=dict(native_av_tp2=landscape_certificate()))
|
||
|
|
|
||
|
|
system.provider.upstream_capabilities = caps
|
||
|
|
response = await system.client.get("/api/capabilities")
|
||
|
|
row = next(item for item in response.json()["items"] if item["task_type"] == "video.generate")
|
||
|
|
option = next(item for item in row["video_profiles"] if item["profile"] == TP2)
|
||
|
|
assert option["available"] is True
|
||
|
|
assert option["canvases"] == [[1344, 768]]
|
||
|
|
frame = await system.client.post(
|
||
|
|
"/api/assets", files={"file": ("frame.png", png_bytes, "image/png")}
|
||
|
|
)
|
||
|
|
assert frame.status_code == 201
|
||
|
|
body = dict(
|
||
|
|
task_type="video.generate",
|
||
|
|
input=dict(prompt="你好", first_frame_asset_id=frame.json()["id"]),
|
||
|
|
parameters=dict(profile=TP2, num_frames=158, width=768, height=1344),
|
||
|
|
)
|
||
|
|
rejected = await system.client.post(
|
||
|
|
"/api/jobs", json=body, headers={"Idempotency-Key": "portrait-uncertified"}
|
||
|
|
)
|
||
|
|
assert rejected.status_code == 422, rejected.text
|
||
|
|
assert rejected.json()["detail"]["code"] == "native_canvas_uncertified"
|
||
|
|
assert (await system.client.get("/api/jobs")).json()["total"] == 0
|
||
|
|
body["parameters"].update(width=1344, height=768)
|
||
|
|
accepted = await system.client.post(
|
||
|
|
"/api/jobs", json=body, headers={"Idempotency-Key": "landscape-certified"}
|
||
|
|
)
|
||
|
|
assert accepted.status_code == 202, accepted.text
|