File size: 2,177 Bytes
4b56e86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa0cc1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/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

# Redacted incident bytes are checked locally, never against raw private profiles.
manifest = json.loads((root / "MANIFEST.json").read_text())
for entry in manifest["files"]:
    path = root / entry["path"]
    ok = path.is_file() and hashlib.sha256(path.read_bytes()).hexdigest() == entry["sha256"] and path.stat().st_size == entry["bytes"]
    print(f"{entry['path']}  {'MANIFEST-MATCH' if ok else 'MANIFEST-MISMATCH'}")
    bad += 0 if ok else 1
for line in (root / "incidents/incidents.jsonl").read_text().splitlines():
    row = json.loads(line)
    profile = json.loads((root / row["profile_file"]).read_text())
    ok = profile["id"] == row["profile_id"] and str(profile["runID"]) == row["run_id"]
    print(f"{row['run_id']}  {'INCIDENT-IDENTITY-MATCH' if ok else 'INCIDENT-IDENTITY-MISMATCH'}")
    bad += 0 if ok else 1

sys.exit(1 if bad else 0)