#!/usr/bin/env python3 """After normalize.py: (1) originals unchanged, (2) no local paths / hosts left, (3) every embedded sha256 that names a repo file matches that file, (4) facts.json fingerprints match the rewritten script / capability.""" import hashlib, json, os, re, sys, collections as C from pathlib import Path H = Path('${LOCAL}/simulation-workspace/runs/hf-release-20261120') DISK = H / 'stage'; SHM = Path('${LOCAL}/shm/ent400/hf-release-20261120/stage') scan = {x['rel']: x for x in json.load(open(H / 'work/scan.json'))} d = json.load(open(H / 'work/normalize-digests.json')) sha = lambda b: hashlib.sha256(b).hexdigest() bad = C.Counter() def where(rel): for r in (DISK, SHM): if (r / rel).is_file(): return r / rel # (1) originals: each rewritten file's old digest must still exist as the source file the stage linked to. # stage.py LINKED inode map is gone, so check via the evaluated packs / source trees named in the rel path orig_ok = 0 for rel in d['order']: if (DISK / rel).exists() and (SHM / rel).exists(): bad['in both roots'] += 1 if where(rel) is None: bad['missing'] += 1 print('rewritten files', len(d['order'])) # (2) leftovers ABS = re.compile(rb'${LOCAL}|${LOCAL}|${LOCAL}/shm/ent400|dsw-\d+|') left = C.Counter() for rel, x in scan.items(): if rel.startswith('code/evaluation-code/') and not rel.endswith(('endpoints.example.json', 'api-final.endpoints.json')): continue p = where(rel) if p is None: continue if ABS.search(p.read_bytes()): left[rel.split('/')[0] + '/' + rel.split('/')[-1]] += 1 print('files still containing local paths / hosts (outside eval-code snapshots):', dict(left) or 0) # (3) embedded digests -> repo files cur = {} for rel in scan: p = where(rel) if p is not None and scan[rel]['size'] < 60_000_000: cur[sha(p.read_bytes())] = rel new_digests = set(d['rep'].values()); old_digests = set(d['rep']) stale = C.Counter(); good = 0 for rel in d['order']: t = where(rel).read_bytes() for h in set(re.findall(rb'(?