File size: 3,060 Bytes
7ff74f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/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+|<gateway>')
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'(?<![0-9a-f])[0-9a-f]{64}(?![0-9a-f])', t)):
        h = h.decode()
        if h in old_digests: stale[rel.split('/')[0] + '/' + rel.split('/')[-1]] += 1
        elif h in new_digests: good += 1
print('embedded digests updated:', good, '| stale old digests left:', dict(stale) or 0)
# (4) facts fingerprints
canon = lambda o: json.dumps(o, sort_keys=True, ensure_ascii=False).encode()
fp = C.Counter()
for rel in d['order']:
    if not rel.endswith('/facts.json'): continue
    f = json.loads(where(rel).read_bytes())['fingerprint']; seg = rel.rsplit('/', 1)[0]
    s = json.loads(where(seg + '/script.json').read_bytes())
    fp['script ok'] += f['script'] == sha(canon(s))
    cap = f'assets/capability/{s["world_id"]}'
    fp['capability ok'] += f['capability'] == sha(where(cap + '/capability.json').read_bytes() + where(cap + '/static-bands.npz').read_bytes())
    fp['n'] += 1
print('facts fingerprints:', dict(fp))
sys.exit(1 if bad or left or stale or fp['script ok'] != fp['n'] or fp['capability ok'] != fp['n'] else 0)