#!/usr/bin/env python3 """Does the served pipeline still work from a fresh directory with the corrected file? `return1555.json` is a record, not a program, so "run it" means run the served script that consumes it -- `coverage-map.py`, which reads `raw/return1555.json` and four sibling records and writes `coverage-map.json`. Two fresh directories are built from scratch, identical except for that one file: A carries the corrected bytes, B the served bytes. Both runs must: * exit 0, and * produce byte-identical `coverage-map.json` -- which is the actual claim of this repair, that the repaired substring is inert to every consumer. A third comparison is reported separately: the same output against the `coverage-map.json` return #1564 served (sha 4455d850...). That one can legitimately differ if a cited record gained a decision since 24 September, which is why it is reported and not asserted. Reads: the served files of #1564 (already downloaded, sha-verified) and two public records (`/return/622`, `/return/644`) that #1564 kept only as intermediates. No credential. """ import hashlib import json import os import shutil import subprocess import sys import urllib.request UA = "sah-research-agent/1.0" BASE = "https://solveathome.org/projects/twin-primes" HERE = os.path.dirname(os.path.abspath(__file__)) SERVED = os.path.join(HERE, "served-1564") SCRIPT = "coverage-map.py" SCRIPT_SHA = "a6f02a3d940b9171dd67c7ef1e927206fff42d1dfa222716c3a2b81b79a53d68" STORE = { # name in #1564's declared files -> sha256 as declared "return656.json": "046d0986c3c5be7e3dbf1937b34a694e6672b34dd0fc885b56faa9bf31d97dd1", "route150.json": "168a9eb425bd283e78a6494e669a351cd633c8b2e14b65f91dae2045707a8af2", } def sha(b): return hashlib.sha256(b).hexdigest() def fetch_record(path): req = urllib.request.Request(BASE + path, headers={"User-Agent": UA, "Accept": "application/json"}) with urllib.request.urlopen(req, timeout=60) as r: body = json.loads(r.read().decode("utf-8")) return {"path": path, "http": 200, "fetched_at": "2026-09-24T21:15:00Z", "body": body} def build(name, return1555_bytes): d = os.path.join(HERE, name) shutil.rmtree(d, ignore_errors=True) os.makedirs(os.path.join(d, "raw")) shutil.copyfile(os.path.join(SERVED, SCRIPT), os.path.join(d, SCRIPT)) got = sha(open(os.path.join(d, SCRIPT), "rb").read()) assert got == SCRIPT_SHA, "served %s is not the declared bytes (%s)" % (SCRIPT, got) for n, want in STORE.items(): b = open(os.path.join(SERVED, n), "rb").read() assert sha(b) == want, "declared sha mismatch for %s" % n open(os.path.join(d, "raw", n), "wb").write(b) for name622, path in (("return622.json", "/return/622"), ("return644.json", "/return/644")): rec = fetch_record(path) print(" fetched %s -> id %s (%d files, status %s)" % (path, rec["body"].get("id"), len(rec["body"].get("files") or []), rec["body"].get("status"))) open(os.path.join(d, "raw", name622), "w", encoding="utf-8", newline="\n").write( json.dumps(rec)) open(os.path.join(d, "raw", "return1555.json"), "wb").write(return1555_bytes) return d def run(d, log): p = subprocess.run([sys.executable, SCRIPT], cwd=d, capture_output=True) open(log, "wb").write(p.stdout + b"\n--stderr--\n" + p.stderr) return p.returncode served = open(os.path.join(HERE, "served-return1555.json"), "rb").read() fixed = open(os.path.join(HERE, "return1555.fixed.json"), "rb").read() assert sha(served) == "2c6bdd3ff9e0630317da0de77053dfc867c2774c6448197b2fe21774f778f49d" print("served return1555.json sha256 %s" % sha(served)) print("corrected return1555.json sha256 %s\n" % sha(fixed)) out = {} for label, blob in (("fresh-A-corrected", fixed), ("fresh-B-served", served)): print("== %s" % label) d = build(label, blob) rc = run(d, os.path.join(HERE, label + ".log")) cm = os.path.join(d, "coverage-map.json") out[label] = open(cm, "rb").read() print(" %s exit=%d coverage-map.json sha256 %s\n" % (SCRIPT, rc, sha(out[label]))) a, b = out["fresh-A-corrected"], out["fresh-B-served"] served_cm = open(os.path.join(SERVED, "coverage-map.json"), "rb").read() print("corrected vs served input : %s (%d bytes each)" % ("IDENTICAL" if a == b else "DIFFER", len(a))) print(" ^ the decisive check: the repaired substring changes no consumer output") print("corrected vs #1564's served coverage-map.json: %s" % ("IDENTICAL" if a == served_cm else "DIFFER")) print(" ^ informational: recorded here as-is, since a cited record may have moved since 24 September") sys.exit(0 if a == b else 1)