"""Read-only final artifact contract test. Exits nonzero on any unmet assertion."""
from pathlib import Path
import json,hashlib,struct
P=Path('/opt/creature-lib-20261017');entries=json.loads((P/'catalog_entries.json').read_text());extras=json.loads((P/'held_back_flyers.json').read_text());node=json.loads((P/'evidence/node-validation.json').read_text());audits=json.loads((P/'evidence/independent-glb-audit.json').read_text());reviews=json.loads((P/'scripts/review_notes.json').read_text())
assert len(entries)>=20 and len({d['id'] for d in entries})==len(entries)
assert node['models']==29 and node['clips']==169 and node['failures']==0
by_node={r['file']:r for r in node['results']};by_audit={r['file']:r for r in audits}
for d in entries+[x['candidate'] for x in extras]:
 raw=(P/'glb'/d['file']).read_bytes();sha=hashlib.sha256(raw).hexdigest();assert sha==by_node[d['file']]['sha256']==by_audit[d['file']]['sha256']
 assert len(raw)<=1500000 and not by_audit[d['file']]['findings'];assert 3000<=by_audit[d['file']]['triangles']<=20000
 jlen=struct.unpack_from('<I',raw,12)[0];g=json.loads(raw[20:20+jlen]);assert len(g['skins'])==1
 actual={a['name'] for a in g['animations']};assert set(d['clips'].values())<=actual
 assert d['licence']=='CC0-1.0' and 'https://' in d['credit'];assert d['id'].removeprefix('enemy-') in reviews['notes']
 for suffix in ['hero','clips']:assert (P/'renders'/(d['id']+'-'+suffix+'.png')).stat().st_size>1000
 assert isinstance(d['small'],bool) and d['small']==(d['height_m']<.5)
 assert set(d['tint'])<={m['name'] for m in g['materials']}
 if d in entries:
  assert all(k in d['clips'] for k in ['idle','walk','run','attack','die'])
  assert all(isinstance(d['speeds'][k],(int,float)) and d['speeds'][k]>0 for k in ['walk','run'])
  assert set(d)=={'id','role','about','good_for','names','file','height_m','clips','tint','licence','credit','speeds','style','mood','small'}
for f in ['REPORT.md','contact_sheet.png','renders/wolf-comparison-side-by-side.png','renders/wolf-head-side-by-side.png','renders/enemy-wolf-realistic-walk.png','renders/enemy-wolf-realistic-moving-walk.mp4']:
 assert (P/f).stat().st_size>1000
print(f'PASS: {len(entries)} exact-shape catalog entries, {len(extras)} explicit held-back flyers; 29 final hashes match both independent checks; every render and wolf proof exists.')
