#!/usr/bin/env python3 """#1357, checkable: the whole check, from served bytes only, as one command. Return #1357 (the audit-revision freshness triage) was not wrong, it was un-checkable, because its claim rests on the state of an input nobody else could obtain: a 1128-file snapshot taken with CRLF intact, while a fresh fetch of the corpus is LF and has a different file count. This script removes that dependency. Every input it reads is pinned by sha256, is served by the project's own store, and is fetched here by that sha -- so no live-corpus state can affect the result, and no local snapshot is assumed to exist. What it checks, and the failure it names at each step: (1) each served part downloads and hashes to its pinned sha256; they concatenate to the pinned archive sha256 -- a byte-level identity of the input, part by part; (2) the archive's 1128 members each hash to the manifest's `sha256_raw` for that relative path, so a truncated or substituted archive cannot pass; (2b) the four shas the instrument compares its snapshot against are NOT taken on trust: they are read out of its source and required to equal the `doc_sha256` values in #1354's own served artifact, `verdict-drift-live.json`. Without this step the q0 control is circular -- the instrument would be checking the snapshot against shas of its own choosing. (This matters because the instrument hard-codes them and never reads its second argument: running it with a NONEXISTENT second argument gives a byte-identical artifact, `bd9de6bb...`, so the `saved1354/` path in the published command is decorative. Demonstrated, not inferred: out-nosaved.json here and `stderr-nosaved.txt`.) (3) `freshness-triager.py` (#1357's own instrument, itself fetched by sha) is run on the pinned archive: its five summary lines are compared to #1357's, and its artifact is compared to #1357's `freshness-triage.json` field for field; (4) the reviewer's control: the same run over the newline-normalised copy of the same archive, requiring Q1/Q2/Q3 unchanged and `crlf_files=0`. Line 1 of the summary is `snapshot root: `, which cannot match across machines by construction, so the comparison is on the following lines and the artifact's `root` key is excluded -- both exclusions are stated here rather than applied silently. usage: python3 check-1357.py [--out DIR] [--token-file FILE] [--server URL] [--fetch-only] env: SOLVEATHOME_TOKEN_FILE or SOLVEATHOME_TOKEN exit: 0 when every step passes, 1 otherwise (with the first failing step printed). """ import argparse import base64 import hashlib import json import os import re import shutil import subprocess import sys import urllib.error import urllib.request import zipfile sys.stdout.reconfigure(encoding="utf-8", errors="replace") # ---- everything this check reads, pinned. No name here is resolved by search or by recency. ---- PARTS_MANIFEST = "89e164c2589a0a02d870e30c2e6b3d44e4bd295cd04e1a1e78498aad57b46946" PINNED = { "parts.json": PARTS_MANIFEST, "snapshot-2026-09-20-manifest.json": "852e3cf1b7567786e971dc2b0abfbafbc3a358207215b7c7848c35ec56e56b36", "freshness-triager.py": "b91f88a8db355c4114205a7f157ea2d99a49ae8cf007fbf5e2a8f4df0c6bf9da", "freshness-triage.json": # #1357's published artifact, the thing being reproduced "bd9de6bbaf5f6e8c2e14fdb25b5fb273b11b7cb4fef64dc85ab1bba23ef80698", "verdict-drift-live.json": # #1354's own artifact: the authority for the four shas "4b1885ea173cfdf52fd966b585b90386471e1e2dfbb9eb7835246c2e00aeb276", } # The four documents #1354 shipped (requirement (2) of the review), by the sha256 #1354 recorded. SAVED_1354 = { "fixed-endpoint-discrepancy.md": "19b6b12c228ec9decd4bd5328cf28b84c63e257ed04dbf55938ea687397f801d", "derive-0904-L7-transfer.md": "6ffd659cce7f0fe97069d8f2420c346916fdab2c32d92bf20e0d850511f245a9", "global-factor-signs.md": "0509638b58b7458b0eeddc0525745cafef5bd508d01ad65e74cc88b583ba72bb", "fold-arithmetic-bridge.md": "2d41665acfc82347f8ca9749e39e7e88f2ad842bb0de05f6b17d56ece84aca3c", } EXPECT = ["files: 1128", "Q0 control all_text_match=True byte_identical=0/4 crlf_files=1118", "Q1 any_hit=True outside=419", "Q2 blocks=602 ids=555 multi=22", "Q3 matched=554 mismatch=0 norow=1"] CONTROL = ["files: 1128", "Q0 control all_text_match=True byte_identical=4/4 crlf_files=0", "Q1 any_hit=True outside=419", "Q2 blocks=602 ids=555 multi=22", "Q3 matched=554 mismatch=0 norow=1"] def sha256(b): return hashlib.sha256(b).hexdigest() def token(args): for p in (args.token_file, os.environ.get("SOLVEATHOME_TOKEN_FILE")): if p and os.path.exists(p): t = open(p, encoding="utf-8").read().strip() return t.split("=", 1)[1].strip() if "=" in t else t if os.environ.get("SOLVEATHOME_TOKEN"): return os.environ["SOLVEATHOME_TOKEN"].strip() raise SystemExit("no credential: pass --token-file or set SOLVEATHOME_TOKEN_FILE") def get(args, tok, digest): """Fetch one store object by sha and require the bytes to hash to it.""" url = "%s/files/%s" % (args.server.rstrip("/"), digest) req = urllib.request.Request(url, method="GET") req.add_header("Authorization", "Bearer " + tok) with urllib.request.urlopen(req, timeout=300) as r: body = r.read() got = sha256(body) if got != digest: raise SystemExit("served bytes for %s hash to %s -- refusing to use them" % (digest, got)) return body def main(): ap = argparse.ArgumentParser() ap.add_argument("--out", default="pkg1357") ap.add_argument("--token-file", default=None) ap.add_argument("--server", default="https://solveathome.org") ap.add_argument("--fetch-only", action="store_true", help="download and verify every pinned input, but do not run the instrument") args = ap.parse_args() os.makedirs(args.out, exist_ok=True) tok = token(args) fails = [] # (1) the archive, part by part pm_raw = get(args, tok, PINNED["parts.json"]) pm = json.loads(pm_raw) print("parts manifest: %d parts, archive %d bytes, sha256 %s" % (len(pm["parts"]), pm["archive_bytes"], pm["archive_sha256"])) pieces = [] for p in pm["parts"]: blob = get(args, tok, p["sha256"]) if len(blob) != p["chars"]: fails.append("part %s is %d bytes, manifest says %d" % (p["name"], len(blob), p["chars"])) with open(os.path.join(args.out, p["name"]), "wb") as f: f.write(blob) pieces.append(blob) print("(1) %-44s %9d bytes %s OK" % (p["name"], len(blob), p["sha256"][:16])) raw = base64.b64decode(b"".join(pieces)) got = sha256(raw) ok = got == pm["archive_sha256"] print("(1) reassembled archive sha256 %s -> %s" % (got[:16], "PINNED" if ok else "MISMATCH")) if not ok: fails.append("reassembled archive does not hash to the pinned sha256") zpath = os.path.join(args.out, "snapshot-2026-09-20.zip") with open(zpath, "wb") as f: f.write(raw) # (2) every member against the per-file manifest man = json.loads(get(args, tok, PINNED["snapshot-2026-09-20-manifest.json"])) meta, rows = man["manifest"], man["files"] if meta["sha256_archive_raw"] != got: fails.append("the archive manifest pins a different archive sha256") snap = os.path.join(args.out, "snapshot") if os.path.isdir(snap): shutil.rmtree(snap) with zipfile.ZipFile(zpath) as z: z.extractall(snap) want = {r["path"]: r for r in rows} seen, bad = set(), [] for dirpath, _d, fns in os.walk(snap): for fn in fns: full = os.path.join(dirpath, fn) rel = os.path.relpath(full, snap).replace("\\", "/") seen.add(rel) r = want.get(rel) if r is None: bad.append((rel, "not in manifest")) elif sha256(open(full, "rb").read()) != r["sha256_raw"]: bad.append((rel, "raw sha mismatch")) missing = sorted(set(want) - seen) print("(2) members %d/%d, missing %d, mismatched %d" % (len(seen), meta["files"], len(missing), len(bad))) if missing or bad: fails.append("archive contents differ from the manifest") # (2b) the instrument's baked-in shas vs #1354's own artifact -- the non-circular part tri_raw0 = get(args, tok, PINNED["freshness-triager.py"]) src = tri_raw0.decode("utf-8") body = src.split("RECORDED_SHAS", 1)[-1].split("}", 1)[0] baked = dict(re.findall(r'"(research/[^"]+)":\s*\n?\s*"([0-9a-f]{64})"', body)) rec54 = json.loads(get(args, tok, PINNED["verdict-drift-live.json"])) claim = {c["doc"]: c["doc_sha256"] for c in rec54.get("cases", [])} print("(2b) instrument bakes %d shas; #1354's artifact records %d cases" % (len(baked), len(claim))) if len(baked) != 4: fails.append("expected 4 baked-in shas in the instrument, parsed %d" % len(baked)) for doc, h in sorted(baked.items()): ok = claim.get(doc) == h print(" %-46s %s %s" % (doc, h[:16], "MATCHES #1354" if ok else "DIFFERS from #1354 (%s)" % str(claim.get(doc))[:16])) if not ok: fails.append("the instrument pins %s to %s, #1354 recorded %s" % (doc, h, claim.get(doc))) # the pinned #1354 documents (served at exactly those shas) and instrument, by sha saved = os.path.join(args.out, "saved1354") os.makedirs(saved, exist_ok=True) for name, digest in SAVED_1354.items(): blob = get(args, tok, digest) open(os.path.join(saved, name), "wb").write(blob) tri_raw = tri_raw0 tri = os.path.join(args.out, "freshness-triager.py") open(tri, "wb").write(tri_raw) prior = json.loads(get(args, tok, PINNED["freshness-triage.json"])) print("(2) pinned: instrument %s, artifact %s, #1354's artifact %s, 4 documents served at their shas" % (sha256(tri_raw)[:16], PINNED["freshness-triage.json"][:16], PINNED["verdict-drift-live.json"][:16])) if args.fetch_only: print("\nFETCH-ONLY: every pinned input downloaded and verified." if not fails else "\nFAILED: " + "; ".join(fails)) return 1 if fails else 0 def run(root, out): p = subprocess.run([sys.executable, tri, root, saved, out], capture_output=True, text=True) lines = [l for l in p.stderr.replace("\r\n", "\n").splitlines() if l.startswith(("files:", "Q"))] return p.returncode, lines, json.load(open(out, encoding="utf-8")) # (3) the instrument on the pinned archive c1, l1, a1 = run(snap, os.path.join(args.out, "out-archive.json")) print("(3) exit %d; summary %s" % (c1, "MATCHES #1357" if l1 == EXPECT else "DIFFERS")) if c1 != 0: fails.append("the instrument exited %d on the pinned archive" % c1) if l1 != EXPECT: fails.append("summary lines differ from #1357's") for a, b in zip(l1 + [""] * 9, EXPECT + [""] * 9): if a != b: print(" got %r\n want %r" % (a, b)) drop = lambda d: {k: v for k, v in d.items() if k != "root"} same = json.dumps(drop(prior), sort_keys=True) == json.dumps(drop(a1), sort_keys=True) print("(4) artifact field-for-field vs #1357's: %s" % ("IDENTICAL" if same else "DIFFERS")) if not same: fails.append("the artifact differs from #1357's freshness-triage.json (besides `root`)") # (4) the control: newline-normalise a copy and re-run lf = os.path.join(args.out, "snapshot-lf") if os.path.isdir(lf): shutil.rmtree(lf) shutil.copytree(snap, lf) crlf = 0 for dirpath, _d, fns in os.walk(lf): for fn in fns: full = os.path.join(dirpath, fn) b = open(full, "rb").read() if b"\r\n" in b: crlf += 1 open(full, "wb").write(b.replace(b"\r\n", b"\n")) c2, l2, a2 = run(lf, os.path.join(args.out, "out-lf.json")) q = lambda d: {k: d.get(k) for k in ("q1_falsifier", "q2_capacity", "q3_fidelity")} print("(5) LF twin: %d files rewritten, exit %d, summary %s" % (crlf, c2, "MATCHES CONTROL" if l2 == CONTROL else "DIFFERS")) if l2 != CONTROL: fails.append("the newline-normalised control does not give crlf_files=0 with Q1-Q3 intact") if json.dumps(q(a1), sort_keys=True) != json.dumps(q(a2), sort_keys=True): fails.append("Q1/Q2/Q3 change under newline normalisation") print() if fails: print("FAILED: " + "; ".join(fails)) return 1 print("ALL STEPS PASS. #1357's numbers are reproduced from served, pinned bytes alone: Q1-Q3 and") print("all four q0 cases, with crlf_files=1118 as measured and crlf_files=0 on the normalised") print("copy. The counts do not depend on the CRLF state that made the original un-checkable.") return 0 if __name__ == "__main__": sys.exit(main())