feat: add explicit media review workflow
CI / backend-and-migrations (push) Canceled after 0s
CI / astro-build (push) Canceled after 0s
CI / dependency-audit (push) Canceled after 0s
CI / compose-e2e (push) Canceled after 0s

This commit is contained in:
ik
2026-09-12 15:55:39 +07:00
parent 26724c7675
commit 215af73388
5 changed files with 54 additions and 4 deletions
+15 -1
View File
@@ -5,7 +5,7 @@ import io
import pytest
from PIL import Image
from rf4_research.media_assets import extract_media_candidates, inspect_image, merge_manifest, store_asset
from rf4_research.media_assets import extract_media_candidates, inspect_image, merge_manifest, review_asset, store_asset
def test_extracts_and_classifies_unique_https_media() -> None:
@@ -45,3 +45,17 @@ def test_image_inspection_rejects_invalid_body_and_mime_mismatch(tmp_path: Path)
Image.new("RGB", (1, 1)).save(image, format="PNG")
with pytest.raises(ValueError, match="MIME mismatch"):
store_asset(tmp_path, image.getvalue(), content_type="image/jpeg", source_url="https://example.test/a.jpg")
def test_review_requires_stored_asset_and_canonical_mapping(tmp_path: Path) -> None:
item = extract_media_candidates('<img src="/fish/pike.png" alt="Щука">', source_page="https://example.test")[0]
path = tmp_path / "manifest.json"
manifest = merge_manifest(path, [item])
with pytest.raises(ValueError, match="stored"):
review_asset(path, asset_url=item.asset_url, decision="approved", entity_type="fish", entity_key="pike")
manifest["assets"][0]["status"] = "stored"
path.write_text(__import__("json").dumps(manifest), encoding="utf-8")
with pytest.raises(ValueError, match="canonical key"):
review_asset(path, asset_url=item.asset_url, decision="approved", entity_type="fish")
reviewed = review_asset(path, asset_url=item.asset_url, decision="approved", entity_type="fish", entity_key="pike", note="matched by name")
assert (reviewed["status"], reviewed["entity_key"]) == ("approved", "pike")