PROCITY/pipeline/validate_manifest.py
m3ultra 84e0a1b764 Lane E R23 (v5.0-alpha): the atlas validator + toowoomba retired (ledger #4)
1. validate_atlas (the G2a format gate). pipeline/validate_atlas.py, wired into validate_manifest so it
   runs in qa gate 3. Judges Lane G's tier-1 atlases from the COMMITTED FILES ALONE -- no dealgod DB, no
   network. No atlases yet => clean pass, so it's in place before G's lands. Enforces: provenance
   {license, attribution, generator, snapshot} (charter law #3 + determinism); NO private-individual item
   fields (law #3); 1 atlas/shop hard cap 2 (C §7.1); <=1024², 2048² only for a 60+ item shop (C §7.2);
   declared atlas_px == the atlas's REAL pixels + every listed atlas exists; schema/UV/bands/dup-ids
   (C §7.3). The licence string is PRINTED, not pattern-matched -- clearing photos for public release is
   a human call, so the gate surfaces it. Dependency-free PNG/WebP header parser. Tested against a
   10-case matrix (real 2048² WebP + 1024² PNG): good passes clean, all 9 violations caught.

2. toowoomba RETIRED (my call, counted). Tried the re-bbox FIRST: 3.0km CBD-wide -> 1.6km on the Ruthven
   St heart. It fixed the named metric (median NN 395.7 -> 89.4m raw, 'passes') but made the real thing
   WORSE: hub density 3/12 -> 2/12 within 160m, the pack's worst (D's alive-darwin is 7/12). Its shops
   are PAIRS strung along a road, not a high street; densest 300m cluster is 3 shops (< MIN_TOWN_SHOPS),
   so no tighter box exists. Shipping it would have gamed the number while leaving a town nobody shops in
   (D: 0 finds / 1417 checks). Config entry kept commented with the rationale. Pack: 21 real + 1 godverse
   = 22 rostered, 1180 shops, all 8 states/territories (QLD keeps westend). selfcheck ALL GREEN 152015.

-> Lane A, before you freeze the spacing warn (#5): (a) your validator sees the CACHE (raw lat/lon) but
   D's numbers are SEATED (post-lift) -- darwin is 27m seated vs 68.3m RAW, so a threshold picked off D's
   table would FALSE-WARN darwin; calibrate on the raw spread (daylesford 11.6 ... braddon 119.2,
   ballarat 254.6 -- a ~200m line has daylight). (b) median NN alone is GAMEABLE: my re-bbox improved it
   4.4x while the town got worse -- the hub fraction is the discriminator, and my raw hub metric
   reproduces D's darwin exactly (7/12), so it's directly encodable (alive ~38-75%, dead <=20%).
   (c) ballarat is a SECOND spread town D's two-town comparison missed (NN 254.6m, hub 4/20 = 20%) -- it
   will trip your warn, correctly. Not retired: the ledger named toowoomba only.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-16 23:14:00 +10:00

180 lines
6.8 KiB
Python

#!/usr/bin/env python3
"""Validate web/assets/manifest.json — runs in Lane F's integration gate.
Checks: JSON parses; every referenced skin exists locally; every fitting/furniture GLB
exists locally (pipeline/_normalized) OR HEADs 200 on the depot; every thumb exists;
footprints & heights are sane; every registry shop type has >=2 facades.
python3 pipeline/validate_manifest.py # local + soft depot check
python3 pipeline/validate_manifest.py --depot # require GLBs live on the depot (post-publish)
Exit 0 = green, 1 = fail. Plain stdlib (no deps), so it runs anywhere.
"""
import json, os, sys, urllib.request, urllib.error
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ASSETS = os.path.join(ROOT, "web", "assets")
NORM = os.path.join(ROOT, "pipeline", "_normalized")
MANIFEST = os.path.join(ASSETS, "manifest.json")
REGISTRY_TYPES = ["record", "opshop", "toy", "book", "video", "pawn", "milkbar", "dept", "stall"]
STRICT_DEPOT = "--depot" in sys.argv
errors, warnings = [], []
def err(m): errors.append(m)
def warn(m): warnings.append(m)
def head_ok(url):
# The depot contract documents GET only, not HEAD — probe with a 1-byte Range GET so we don't
# download the whole GLB and don't depend on HEAD being supported by the CDN/cache.
try:
# custom UA: Cloudflare 403s the default Python-urllib agent on the public path
req = urllib.request.Request(url, headers={"Range": "bytes=0-0",
"User-Agent": "procity-validator/1.0"})
with urllib.request.urlopen(req, timeout=12) as r:
return r.status in (200, 206)
except urllib.error.HTTPError as e:
if e.code == 416: # range not satisfiable but the file exists
return True
return False
except Exception:
return False
def check_skin(file):
p = os.path.join(ASSETS, file)
if not os.path.isfile(p):
err(f"skin missing: {file}")
def check_glb(entry, depot):
file = entry["file"]
local = os.path.join(NORM, file)
on_disk = os.path.isfile(local)
live = head_ok(f"{depot}/a/{file}")
if STRICT_DEPOT and not live:
err(f"GLB not live on depot: {file}")
elif not on_disk and not live:
err(f"GLB missing (not local, not on depot): {file}")
elif not live:
warn(f"GLB not yet published to depot (local only): {file}")
# thumb
thumb = entry.get("thumb")
if thumb and not os.path.isfile(os.path.join(ASSETS, thumb)):
err(f"thumb missing: {thumb}")
# footprint / height sanity
fp = entry.get("footprint")
if not (isinstance(fp, list) and len(fp) == 2 and all(0 < x < 12 for x in fp)):
err(f"insane footprint for {file}: {fp}")
h = entry.get("height")
if not (isinstance(h, (int, float)) and 0 < h < 8):
err(f"insane height for {file}: {h}")
def main():
try:
m = json.load(open(MANIFEST))
except Exception as e:
print(f"FAIL: manifest does not parse: {e}")
sys.exit(1)
# GOD3_DEPOT overrides for the direct tailnet path (same env publish.py uses)
depot = os.environ.get("GOD3_DEPOT", m.get("depot", "https://digalot.fyi/3god")).rstrip("/")
sk = m.get("skins", {})
# facades + type coverage
facade = sk.get("facade", {})
for k, v in facade.items():
check_skin(v["file"])
for t in REGISTRY_TYPES:
n = sum(1 for v in facade.values() if t in v.get("types", []))
if n < 2:
err(f"shop type '{t}' has only {n} facade(s) (need >=2)")
# other skin groups
for s in sk.get("sky", []):
check_skin(s["file"])
for g in sk.get("ground", {}).values():
check_skin(g["file"])
for w in sk.get("wall", []):
check_skin(w["file"])
interior = sk.get("interior", {})
for grp in ("floor", "surface"):
for it in interior.get(grp, []):
check_skin(it["file"])
for a in sk.get("awning", []):
check_skin(a["file"])
# fittings + furniture GLBs
n_glb = 0
manifest_files = set()
for grp in ("fittings", "furniture"):
for entry in m.get(grp, {}).values():
check_glb(entry, depot)
manifest_files.add(entry["file"])
n_glb += 1
# audio pack (round-11): if the manifest names an audio file it must ship locally (both the
# ogg primary and the m4a fallback). Silent-happy is a runtime rule, not a licence to dangle refs.
n_audio = 0
def _chk_audio(e):
for key in ("file", "fallback"):
if key in e:
check_skin(e[key])
for grp in m.get("audio", {}).values():
for v in grp.values():
if isinstance(v, dict) and "file" in v:
_chk_audio(v); n_audio += 1
elif isinstance(v, dict): # footstep {surface:[variants]}
for arr in v.values():
for e in arr:
_chk_audio(e); n_audio += 1
# provenance-drift gate: every manifest depot GLB must be recorded in _published.json, so a
# clobbered/stale provenance record (the R5 bug) fails QA loudly instead of hiding.
recpath = os.path.join(ROOT, "pipeline", "_published.json")
try:
record = set(json.load(open(recpath)))
except Exception as e:
err(f"_published.json unreadable: {e}")
record = set()
for f in sorted(manifest_files):
if f.startswith("procity_") and f not in record:
err(f"manifest GLB not in _published.json (provenance drift): {f}")
# pack-index QA (round-8 E2): a bad stock-pack bake fails the same gate as the manifest
try:
import validate_pack
if validate_pack.main() != 0:
err("stock-pack index validation failed (see pack-QA errors above)")
except Exception as e:
warn(f"pack-QA skipped: {e}")
# per-shop atlas QA (v5 G2a, ROUND23 E #4): Lane G's tier-1 atlases are gate-checked from the
# committed files alone — no dealgod DB, no network. No atlases yet ⇒ clean pass.
try:
import validate_atlas
if validate_atlas.main() != 0:
err("per-shop atlas validation failed (see atlas-QA errors above)")
except Exception as e:
warn(f"atlas-QA skipped: {e}")
print(f"manifest v{m.get('version')} — facades {len(facade)}, "
f"skins {sum(len(v) if isinstance(v, list) else (len(v) if isinstance(v, dict) else 0) for v in sk.values())} groups, "
f"GLBs {n_glb}, audio {n_audio}")
for w in warnings:
print(f" WARN {w}")
if errors:
for e in errors:
print(f" ERR {e}")
print(f"\nFAIL — {len(errors)} error(s), {len(warnings)} warning(s)")
sys.exit(1)
print(f"\nOK — 0 errors, {len(warnings)} warning(s)")
sys.exit(0)
if __name__ == "__main__":
main()