import pathlib,json,hashlib,struct,re,subprocess,shutil
P=pathlib.Path(__file__).resolve().parent
checks=[]
def good(name,condition):
 if not condition:raise ValueError(name)
 checks.append(name)
manifest=json.loads((P/'manifest.json').read_text())
for item in manifest:
 f=P/item['file'];good('sha256 '+item['file'],f.is_file() and hashlib.sha256(f.read_bytes()).hexdigest()==item['sha256'])
for f in P.glob('*.glb'):
 b=f.read_bytes();magic,version,length=struct.unpack('<4sII',b[:12]);good('GLB header '+f.name,magic==b'glTF' and version==2 and length==len(b));size,kind=struct.unpack('<II',b[12:20]);doc=json.loads(b[20:20+size]);good('GLB mesh '+f.name,bool(doc.get('meshes')))
for f in P.glob('*.obj'):
 text=f.read_text();good('OBJ vertices and UV '+f.name,'\nv ' in text and '\nvt ' in text and '\nf ' in text)
 for lib in re.findall(r'^mtllib\s+(.+)$',text,re.M):good('OBJ material file '+lib,(P/lib).is_file())
for f in P.glob('*.mtl'):
 for target in re.findall(r'^map_Kd\s+(.+)$',f.read_text(),re.M):good('MTL texture '+target,(P/target).is_file())
for f in (P/'vendor').rglob('*.js') if (P/'vendor').exists() else []:
 for dep in re.findall(r'from\s+[\'\"]([^\'\"]+)[\'\"]',f.read_text()):
  if dep.startswith('.'):good('module '+str(f.relative_to(P))+' -> '+dep,(f.parent/dep).resolve().is_file())
if (P/'input.mp4').exists() and shutil.which('ffprobe'):
 data=json.loads(subprocess.check_output(['ffprobe','-v','error','-show_streams','-show_format','-of','json',str(P/'input.mp4')],text=True));s=next(x for x in data['streams']if x['codec_type']=='video');good('input 36 frames',int(s['nb_frames'])==36);good('input 12fps',s['r_frame_rate']=='12/1');good('input 3 seconds',abs(float(data['format']['duration'])-3)<.02)
try:
 import numpy as np
 from PIL import Image
 for f in P.glob('*.png'):
  with Image.open(f) as im:im.load();good('image decode '+f.name,im.width>0 and im.height>0)
 for f in P.glob('geometry-reference-depth.npy'):
  a=np.load(f,allow_pickle=False);good('known geometry depth shape',a.shape==(360,640) and np.isfinite(a).all() and (a>0).any())
except ImportError:checks.append('NumPy/Pillow unavailable: optional image/depth decode skipped')
runtime=json.loads((P/'runtime.json').read_text());good('model status remains explicit',runtime['model_status']=='not-executed')
print(json.dumps({'status':'passed','identity':'offline input/reference file checks, not model inference','checks':checks,'model_status':runtime['model_status']},ensure_ascii=False,indent=2))
