File size: 1,345 Bytes
4b56e86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Re-fetch every public profile named in data/receipts.jsonl and compare it with the committed copy.

Usage: python scripts/verify.py            (from the dataset root)
Exit 0 when every live body matches profile_sha256; 1 otherwise. Standard library only.
"""
import hashlib, json, sys, urllib.request, pathlib, datetime

root = pathlib.Path(__file__).resolve().parent.parent
bad = 0
for line in open(root / "data/receipts.jsonl"):
    row = json.loads(line)
    local = (root / row["profile_file"]).read_bytes()
    local_sha = hashlib.sha256(local).hexdigest()
    req = urllib.request.Request(row["garnet_profile_api_url"], headers={"User-Agent": "agent-execution-receipts-verify"})
    try:
        with urllib.request.urlopen(req, timeout=60) as r:
            live = r.read(); status = r.status
    except Exception as e:  # network or HTTP error: report, do not guess
        print(f"{row['run_id']}  FETCH-ERROR {e}"); bad += 1; continue
    live_sha = hashlib.sha256(live).hexdigest()
    now = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
    ok = local_sha == row["profile_sha256"] == live_sha
    print(f"{row['run_id']}  HTTP {status}  committed={local_sha[:12]}  live={live_sha[:12]}  {'MATCH' if ok else 'DRIFT'}  {now}")
    bad += 0 if ok else 1
sys.exit(1 if bad else 0)