86 lines
3.2 KiB
Python
86 lines
3.2 KiB
Python
|
|
import pytest
|
||
|
|
|
||
|
|
from app.adapters.provider.video_generation import normalize
|
||
|
|
from app.domain.errors import MediaError
|
||
|
|
from app.domain.video_generation import required_output_frames
|
||
|
|
|
||
|
|
PROFILE = "minimax-h3-fl2va-bf16-v2"
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize("frames", [124, 345])
|
||
|
|
def test_full_native_output(frames):
|
||
|
|
params = normalize(
|
||
|
|
{"profile": PROFILE, "num_frames": frames, "conditioning_mode": "first_last_frame"},
|
||
|
|
{"prompt": "shot", "first_frame_asset_id": "a", "last_frame_asset_id": "b"},
|
||
|
|
)
|
||
|
|
assert required_output_frames(params) == frames
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize("frames", [123, 125, 346, True])
|
||
|
|
def test_native_grid_rejected(frames):
|
||
|
|
with pytest.raises(MediaError):
|
||
|
|
normalize(
|
||
|
|
{"profile": PROFILE, "num_frames": frames},
|
||
|
|
{"prompt": "shot", "first_frame_asset_id": "a"},
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize("field", ["first_frame_asset_id", "last_frame_asset_id"])
|
||
|
|
def test_both_endpoints_required(field):
|
||
|
|
with pytest.raises(MediaError):
|
||
|
|
normalize(
|
||
|
|
{"profile": PROFILE, "conditioning_mode": "first_last_frame"},
|
||
|
|
{"prompt": "shot", field: "a"},
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize("foreign_field", ["first_frame_asset_id", "last_frame_asset_id"])
|
||
|
|
async def test_foreign_endpoint_denied(system, other_client, png_bytes, foreign_field):
|
||
|
|
fields = {}
|
||
|
|
for field in ("first_frame_asset_id", "last_frame_asset_id"):
|
||
|
|
client = other_client if field == foreign_field else system.client
|
||
|
|
response = await client.post(
|
||
|
|
"/api/assets", files={"file": ("frame.png", png_bytes, "image/png")}
|
||
|
|
)
|
||
|
|
fields[field] = response.json()["id"]
|
||
|
|
response = await system.client.post(
|
||
|
|
"/api/jobs",
|
||
|
|
json={
|
||
|
|
"task_type": "video.generate",
|
||
|
|
"input": {"prompt": "shot", **fields},
|
||
|
|
"parameters": {"profile": PROFILE, "conditioning_mode": "first_last_frame"},
|
||
|
|
},
|
||
|
|
)
|
||
|
|
assert response.status_code == 404
|
||
|
|
|
||
|
|
|
||
|
|
async def test_remote_endpoints_uploaded_in_role_order(system, tmp_path, png_bytes, monkeypatch):
|
||
|
|
from unittest.mock import AsyncMock
|
||
|
|
from app.adapters.provider.client import Provider
|
||
|
|
|
||
|
|
provider = Provider(system.settings)
|
||
|
|
work = system.settings.job_work_root / "v2-remote"
|
||
|
|
work.mkdir(parents=True)
|
||
|
|
first, last = work / "first.png", work / "last.png"
|
||
|
|
first.write_bytes(png_bytes)
|
||
|
|
last.write_bytes(png_bytes)
|
||
|
|
monkeypatch.setattr(system.settings, "inference_remote_files", True)
|
||
|
|
upload = AsyncMock(side_effect=["/inputs/first.png", "/inputs/last.png"])
|
||
|
|
monkeypatch.setattr(provider, "_upload_input", upload)
|
||
|
|
try:
|
||
|
|
payload = await provider.prepare_gpu_payload(
|
||
|
|
"video.generate",
|
||
|
|
{"prompt": "shot", "first_frame_asset_id": "f", "last_frame_asset_id": "l"},
|
||
|
|
{"profile": PROFILE, "conditioning_mode": "first_last_frame"},
|
||
|
|
{"f": first, "l": last},
|
||
|
|
work,
|
||
|
|
)
|
||
|
|
finally:
|
||
|
|
await provider.aclose()
|
||
|
|
assert [call.args[0] for call in upload.await_args_list] == [first, last]
|
||
|
|
assert payload["input"] == {
|
||
|
|
"prompt": "shot",
|
||
|
|
"image_path": "/inputs/first.png",
|
||
|
|
"last_image_path": "/inputs/last.png",
|
||
|
|
}
|