#!/usr/bin/env python3 """Verify job #3001's revision of paper/anchored-note.md, from the network, with no state. Run from a fresh directory. Needs python3 and network access to the project server; no credential (every input is a public content address or a served document). V1 the served document's bytes hash to the `base` this revision names -- so the diff is against the text actually being edited. If they hash to the revision's own `file` instead, the revision is already integrated: reported as such, exit 0; V2 applying apply-revision.py to those exact bytes reproduces the filed `file` sha256, byte for byte; V3 the invariants the two findings asked for, re-derived from the revised text: the dimension-2 floor in §6 and in Appendix A, no surviving floor-2 reading, the §9.1 Theorem 1 constant written out, the abstract's Proposition 1 part label, the orphan Appendix A row gone, the Appendix B item 7 residual, and Lemma 3 marked corrected by return #1537 in both places -- plus the two structural invariants (no heading added or removed, and no line whose math became newly bare); V4 the EXTERNAL premises of those edits, which is where a revision of this kind can quietly lie: (a) paper/wall-note.md §2 Face 1 really carries the dimension-2 reading that §6 now quotes -- floor 8, Selberg's Lambda-squared at kappa = 2, Riesel-Vaughan Lemma 5, the 6.25x margin, and the withdrawal of the floor-2 reading; (b) the served research/natal-cap-19-calm-lemma.md still carries the OLD Lemma 3 step and none of return #1537's patch markers, which is why the revision says corrected-but-not-applied rather than simply corrected; V5 the served producer still runs and its stdout reproduces byte for byte elsewhere: draft2-checks.py (content address from return #1060) re-run with the stdout newline pinned prints exactly the served draft2-checks-out.txt, and that stdout carries the two numbers the revision touches -- c' = 0.604502 and the @13 residual +0.017269. Usage: verify-revision.py --apply apply-revision.py --base --file [--workdir .] [--instrument-] Exit 0 only when every check performed passes. """ import argparse import hashlib import json import os import re import subprocess import sys import urllib.request # Documents are served under the project path; the file store is at the ORIGIN root # (/files/). Measured: /projects/twin-primes/files/ is a 404 while # https://solveathome.org/files/ returns the bytes -- the #488/#1384 transport defect in # its other direction, so the two bases are kept separate here rather than assumed equal. ORIGIN = "https://solveathome.org" BASE_URL = ORIGIN + "/projects/twin-primes" DOC = "paper/anchored-note.md" WALL = "paper/wall-note.md" LEMMA = "research/natal-cap-19-calm-lemma.md" PRODUCER_SHA = "97f845fbe6aadfab8fa8f4d9119159314d2794e1a7aec808b33588a767427a1c" PRODUCER_OUT_SHA = "3f370c3cb8b491c0076ae22b27684f9433ff6793335bcc73184ce9151c756c01" BARE = re.compile(r"(? int: ap = argparse.ArgumentParser() ap.add_argument("--apply", required=True) ap.add_argument("--base", required=True) ap.add_argument("--file", required=True) ap.add_argument("--workdir", default=".") a = ap.parse_args() sys.stdout.reconfigure(newline="\n", encoding="utf-8", errors="replace") checks, notes = {}, [] served = doc(DOC) served_sha = hashlib.sha256(served).hexdigest() notes.append({"served_path": DOC, "served_sha256": served_sha, "bytes": len(served)}) if served_sha == a.file: print(json.dumps({"ok": True, "already_integrated": True, "checks": {"V1_served_is_the_revision": True}, "notes": notes}, indent=1, sort_keys=True)) return 0 checks["V1_served_bytes_are_the_base"] = (served_sha == a.base) if not checks["V1_served_bytes_are_the_base"]: print(json.dumps({"ok": False, "checks": checks, "notes": notes, "why": "served bytes are neither this revision nor the base it names: " "the document moved since the base was taken"}, indent=1)) return 1 src, out = os.path.join(a.workdir, "served.base.md"), os.path.join(a.workdir, "revised.md") with open(src, "wb") as fh: fh.write(served) p = subprocess.run([sys.executable, a.apply, "--in", src, "--out", out], capture_output=True, text=True) checks["V2_apply_exit_0"] = (p.returncode == 0) if p.returncode != 0: print(json.dumps({"ok": False, "checks": checks, "stdout": p.stdout[-1500:], "stderr": p.stderr[-1500:]}, indent=1)) return 1 revised = open(out, "rb").read() got = hashlib.sha256(revised).hexdigest() checks["V2_result_is_the_filed_revision"] = (got == a.file) notes.append({"reproduced_sha256": got, "filed_sha256": a.file, "bytes": len(revised)}) base_text, text = served.decode("utf-8"), revised.decode("utf-8") checks["V3_dimension2_floor_in_s6"] = "operative parity floor is 8" in text checks["V3_floor2_reading_withdrawn"] = ( "the floor-2 reading is withdrawn" in text and "carry a parity floor of 2 against" not in text and "parity floor 2, needed 1.28" not in text) checks["V3_theorem1_constant_written_out"] = ( "written out numerically as c′ = 0.6045 (§3)" in text and "not written out numerically" not in text) checks["V3_abstract_labelled_prop1_ii"] = ( "(Proposition 1(ii))" in text and text.count("Proposition 1(i)") == 1) checks["V3_orphan_appendix_a_row_gone"] = "3025" not in text and "1,682" not in text checks["V3_appendix_b7_residual_0173"] = ( "the residuals at @7 through @19 are −0.1005, +0.0686, +0.0173" in text and text.count("0.0172") == 1) # the surviving one is §9's record of Draft 1's error checks["V3_lemma3_corrected_by_1537"] = ( text.count("#1537") == 2 and "needs correction (Appendix B, item 6)" not in text and "corrected by return #1537" in text) checks["V3_no_heading_added_or_removed"] = ( sum(1 for l in text.splitlines() if l.startswith("#")) == sum(1 for l in base_text.splitlines() if l.startswith("#"))) checks["V3_no_line_made_newly_bare"] = ( len(BARE.findall(text)) <= len(BARE.findall(base_text))) notes.append({"bare_math_marks_base": len(BARE.findall(base_text)), "bare_math_marks_revised": len(BARE.findall(text))}) # Anchor on a short phrase and take a window: the markdown wraps the sentence across lines, so # a long literal would silently find nothing (it did, at 0 bytes, before this was fixed). wall = doc(WALL).decode("utf-8") at = wall.find("operative floor is 8") face1 = wall[max(0, at - 900):at + 1500] if at >= 0 else "" checks["V4a_wallnote_face1_is_the_source"] = at >= 0 and all(s in face1 for s in ( "operative floor is 8", "Λ² at κ = 2", "Riesel–Vaughan Lemma 5", "6.25×", "the dimension-1, whole-range figure")) checks["V4a_wallnote_says_position_uniform"] = "position-uniform" in face1 notes.append({"wall_note_face1_quote_bytes": len(face1.encode("utf-8"))}) lemma = doc(LEMMA).decode("utf-8") patched = any(m in lemma for m in ("exactly one fixed point", "no self-pairing", "which no scour prime")) checks["V4b_lemma3_still_unpatched"] = ( "self-paired iff 2t ≡ 0 (mod W)" in lemma and not patched) notes.append({"lemma3_served_sha256": hashlib.sha256(doc(LEMMA)).hexdigest(), "lemma3_patch_applied": patched}) producer, recorded = blob(PRODUCER_SHA), blob(PRODUCER_OUT_SHA) checks["V5_producer_served_bytes_match_declared_sha"] = ( hashlib.sha256(producer).hexdigest() == PRODUCER_SHA and hashlib.sha256(recorded).hexdigest() == PRODUCER_OUT_SHA) pdir = os.path.join(a.workdir, "producer") os.makedirs(pdir, exist_ok=True) # absolute: the run below changes the working directory, and a relative script path would then # be resolved against the new one and silently not exist ppath = os.path.abspath(os.path.join(pdir, "draft2-checks.py")) with open(ppath, "wb") as fh: fh.write(producer) r = subprocess.run([sys.executable, "-c", HARNESS, ppath], capture_output=True, cwd=pdir) checks["V5_producer_exit_0"] = (r.returncode == 0) checks["V5_stdout_reproduces_byte_for_byte"] = (hashlib.sha256(r.stdout).hexdigest() == PRODUCER_OUT_SHA) checks["V5_stdout_carries_the_two_edited_numbers"] = ( b"= 0.604502;" in r.stdout and b"+0.017269" in r.stdout) notes.append({"producer_stdout_sha256": hashlib.sha256(r.stdout).hexdigest(), "producer_stderr_bytes": len(r.stderr), "producer_stderr": r.stderr.decode("utf-8", "replace")[-400:] if r.returncode else ""}) ok = all(checks.values()) print(json.dumps({"ok": ok, "checks": checks, "notes": notes}, indent=1, sort_keys=True)) return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())