"""R5 FREEZE: point the registry entries synth_{hand,typed,clutter,pages}_{val,test} at their read-only copies in frozen_eval_v1/ (decision 4, 21 Nov 2026), so evaluation sets cannot change when GEN jobs rewrite manifests/. A path is changed only if the copy's sha256 equals the entry's manifest_sha256; the old path is kept in 'manifest_original'. Every other entry is unchanged. Note: DATA's r5_registry.py rewrites evalsets.json from manifests/; if it is ever run again, run this script and merge_evalsets.py again. usage: python -I repoint_evalsets.py REGISTRY_JSON FROZEN_EVAL_DIR LOG_JSON """ import hashlib import json import os import sys import time reg_p, fe, log_p = sys.argv[1:4] NAMES = ["synth_%s_%s" % (k, s) for k in ("hand", "typed", "clutter", "pages") for s in ("val", "test")] def sha(p): h = hashlib.sha256() with open(p, "rb") as f: for b in iter(lambda: f.read(1 << 20), b""): h.update(b) return h.hexdigest() now = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) reg = json.load(open(reg_p, encoding="utf-8")) log = {"written_utc": now, "registry": reg_p, "registry_sha256_before": sha(reg_p), "changed": [], "problems": []} by = {s["name"]: s for s in reg["sets"]} for n in NAMES: s = by.get(n) cp = os.path.join(fe, n + ".tsv") if s is None: log["problems"].append("registry has no " + n) continue h = sha(cp) if h != s.get("manifest_sha256"): log["problems"].append("%s: copy sha256 %s differs from the registry %s" % (n, h, s.get("manifest_sha256"))) continue if os.stat(cp).st_mode & 0o222: log["problems"].append(n + ": copy is writable") continue if s["manifest"] != cp: s["manifest_original"] = s["manifest"] s["manifest"] = cp s["frozen_copy"] = "read-only copy made by stage FREEZE %s; equal to GEN production_done.json stage 1" % now log["changed"].append({"name": n, "manifest": cp, "sha256": h, "locked": s.get("locked")}) if log["problems"]: json.dump(log, open(log_p, "w", encoding="utf-8"), indent=1) print("PROBLEMS", log["problems"]) sys.exit(3) reg["frozen_eval_note"] = "synth_*_val/test entries point to read-only copies in %s (stage FREEZE, %s)" % (fe, now) tmp = reg_p + ".tmp%d" % os.getpid() with open(tmp, "w", encoding="utf-8") as f: json.dump(reg, f, ensure_ascii=False, indent=1) os.replace(tmp, reg_p) log["registry_sha256_after"] = sha(reg_p) json.dump(log, open(log_p, "w", encoding="utf-8"), indent=1) print("OK", len(log["changed"]), "entries repointed", log["registry_sha256_after"])