feat: extend media roles and acceptance coverage
CI / backend-and-migrations (push) Waiting to run
CI / astro-build (push) Waiting to run
CI / dependency-audit (push) Waiting to run
CI / compose-e2e (push) Waiting to run

This commit is contained in:
ik
2026-09-20 18:30:16 +07:00
parent e94d247096
commit a547d09fcd
6 changed files with 42 additions and 7 deletions
+13 -2
View File
@@ -18,6 +18,13 @@ DERIVATIVE_TARGETS = {"card": 256, "detail": 1024}
WATERBODY_MEDIA_ROLES = frozenset({
"waterbody_cover", "waterbody_map", "waterbody_depth_map", "waterbody_screenshot",
})
TACKLE_MEDIA_ROLES = frozenset({
"tackle_card", "tackle_detail", "rig_diagram", "tackle_screenshot",
})
MEDIA_ROLES_BY_ENTITY = {
"waterbody": WATERBODY_MEDIA_ROLES,
"tackle": TACKLE_MEDIA_ROLES,
}
@dataclass(frozen=True, slots=True)
@@ -276,8 +283,8 @@ def review_asset(
item = next((asset for asset in manifest.get("assets", []) if asset["asset_url"] == asset_url), None)
if item is None:
raise ValueError("asset URL is not present in manifest")
if media_role is not None and (entity_type != "waterbody" or media_role not in WATERBODY_MEDIA_ROLES):
raise ValueError("media role is only valid for a waterbody and must be a known waterbody role")
if media_role is not None and media_role not in MEDIA_ROLES_BY_ENTITY.get(entity_type or "", set()):
raise ValueError(f"media role is only valid for {entity_type}; use a known {entity_type} role")
if decision == "approved":
if item.get("status") != "stored":
raise ValueError("only a stored asset can be approved")
@@ -345,6 +352,10 @@ def audit_media_catalog(root: Path) -> dict:
issues.append(f"{item['asset_url']}: derivative {exc}")
if status == "approved" and (not item.get("entity_key") or item.get("entity_type") not in {"fish", "waterbody", "tackle", "reference"}):
issues.append(f"{item['asset_url']}: approved asset has no valid canonical mapping")
if item.get("media_role") not in {None, *WATERBODY_MEDIA_ROLES, *TACKLE_MEDIA_ROLES}:
issues.append(f"{item['asset_url']}: unknown media role")
elif item.get("media_role") is not None and item.get("media_role") not in MEDIA_ROLES_BY_ENTITY.get(item.get("entity_type"), set()):
issues.append(f"{item['asset_url']}: media role does not match entity type")
files_root = root / "files"
orphaned = sorted(str(path.relative_to(root)) for path in files_root.rglob("*") if path.is_file() and str(path.relative_to(root)) not in referenced) if files_root.exists() else []
return {"total": sum(statuses.values()), "statuses": statuses, "issues": issues, "orphaned_files": orphaned}