103 lines
3.5 KiB
Python
103 lines
3.5 KiB
Python
|
|
import pytest
|
||
|
|
|
||
|
|
from app.adapters.provider.continuity_media import parse_verdict
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize(
|
||
|
|
"raw, expected",
|
||
|
|
[
|
||
|
|
('{"verdict":"reject","reason":"subject disappeared"}', "reject"),
|
||
|
|
('{"verdict":"pass","reason":"subject and motion match"}', "pass"),
|
||
|
|
('{"verdict":"pass"}', "indeterminate"),
|
||
|
|
("model unavailable", "indeterminate"),
|
||
|
|
],
|
||
|
|
)
|
||
|
|
def test_quality_verdict(raw, expected):
|
||
|
|
assert parse_verdict(raw)["verdict"] == expected
|
||
|
|
|
||
|
|
|
||
|
|
async def test_actual_decoded_trimmed_anchor_and_uncertified_assessor(tmp_path, monkeypatch):
|
||
|
|
import json
|
||
|
|
import shutil
|
||
|
|
import subprocess
|
||
|
|
from types import SimpleNamespace
|
||
|
|
from unittest.mock import AsyncMock
|
||
|
|
from PIL import Image
|
||
|
|
from app.adapters.provider.continuity_media import inspect_continuity
|
||
|
|
|
||
|
|
ffmpeg = shutil.which("ffmpeg")
|
||
|
|
ffprobe = shutil.which("ffprobe")
|
||
|
|
if not ffmpeg or not ffprobe:
|
||
|
|
pytest.skip("FFmpeg and FFprobe required")
|
||
|
|
for i in range(8):
|
||
|
|
Image.new("RGB", (64, 48), (i * 30, 40, 10)).save(tmp_path / f"source-{i:02d}.png")
|
||
|
|
video = tmp_path / "video.mkv"
|
||
|
|
subprocess.run(
|
||
|
|
[
|
||
|
|
ffmpeg,
|
||
|
|
"-v",
|
||
|
|
"error",
|
||
|
|
"-framerate",
|
||
|
|
"24",
|
||
|
|
"-i",
|
||
|
|
str(tmp_path / "source-%02d.png"),
|
||
|
|
"-c:v",
|
||
|
|
"ffv1",
|
||
|
|
"-pix_fmt",
|
||
|
|
"bgr0",
|
||
|
|
str(video),
|
||
|
|
],
|
||
|
|
check=True,
|
||
|
|
)
|
||
|
|
|
||
|
|
def write_json(work, name, result):
|
||
|
|
path = work / name
|
||
|
|
path.write_text(json.dumps(result))
|
||
|
|
return path
|
||
|
|
|
||
|
|
provider = SimpleNamespace(
|
||
|
|
settings=SimpleNamespace(
|
||
|
|
workspace_root=tmp_path,
|
||
|
|
ffmpeg_bin=ffmpeg,
|
||
|
|
ffprobe_bin=ffprobe,
|
||
|
|
continuity_quality_certified=False,
|
||
|
|
),
|
||
|
|
_asset=lambda aid, assets: assets[aid],
|
||
|
|
_chat=AsyncMock(return_value='{"verdict":"pass","reason":"matches"}'),
|
||
|
|
_image_uri=AsyncMock(return_value="data:test"),
|
||
|
|
_json_file=write_json,
|
||
|
|
)
|
||
|
|
inputs = {
|
||
|
|
"asset_ids": ["v"],
|
||
|
|
"video_asset_id": "v",
|
||
|
|
"expected": {
|
||
|
|
"source_start_frame": 2,
|
||
|
|
"source_end_frame": 6,
|
||
|
|
"state_in": {},
|
||
|
|
"state_out": {},
|
||
|
|
"transition": "cut",
|
||
|
|
"expected_motion": True,
|
||
|
|
},
|
||
|
|
}
|
||
|
|
result = await inspect_continuity(provider, inputs, {"v": video}, tmp_path)
|
||
|
|
assert result.result["verdict"] == "indeterminate"
|
||
|
|
provider._chat.assert_not_awaited()
|
||
|
|
with Image.open(tmp_path / "join-anchor.png") as img:
|
||
|
|
assert img.getpixel((10, 10))[:3] == (150, 40, 10)
|
||
|
|
assert result.metadata["frame_indices"] == [2, 3, 4, 5]
|
||
|
|
provider.settings.continuity_quality_certified = True
|
||
|
|
result = await inspect_continuity(provider, inputs, {"v": video}, tmp_path)
|
||
|
|
assert result.result["verdict"] == "pass"
|
||
|
|
assert len(provider._chat.await_args.args[0][0]["content"]) == 5
|
||
|
|
|
||
|
|
inputs.update(previous_video_asset_id="v")
|
||
|
|
inputs["expected"].update(
|
||
|
|
transition="continue", previous_start_frame=0, previous_end_frame=3, dedup_frames=1
|
||
|
|
)
|
||
|
|
result = await inspect_continuity(provider, inputs, {"v": video}, tmp_path)
|
||
|
|
assert result.result["dedup_verified"] is True
|
||
|
|
assert result.result["frame_evidence"]["previous_indices"] == [0, 1, 2]
|
||
|
|
inputs["expected"]["previous_end_frame"] = 2
|
||
|
|
result = await inspect_continuity(provider, inputs, {"v": video}, tmp_path)
|
||
|
|
assert result.result["dedup_verified"] is False and result.result["verdict"] == "reject"
|