#!/usr/bin/env python3 """Assemble work/j3688/payload.json for job #3688 (audit of research/SEARCH-CONVENTIONS.md). Same audit schema as job #3653: `revision: {path, file, base}` with `file` = sha256 of the revised document and `base` = the X-Content-SHA256 the fetched text carried, the revised sha also among the declared files, the answered findings in `resolves`, and the change itself in `patch`. """ import difflib import hashlib import json import os HERE = os.path.dirname(os.path.abspath(__file__)) RUN = os.path.normpath(os.path.join(HERE, "..", "..")) os.chdir(HERE) PATH = "research/SEARCH-CONVENTIONS.md" BASE = "3408f5f6f34db1028d224b250740791d0c43aabf3e7596fa963c74ce958a9a29" REVISED_NAME = "SEARCH-CONVENTIONS-job3688.md" def sha(p): with open(p, "rb") as fh: return hashlib.sha256(fh.read()).hexdigest() # the revised document is served under its own name, so the store holds one object per version revised = open("out/SEARCH-CONVENTIONS.md", "rb").read() assert b"\r" not in revised with open("out/" + REVISED_NAME, "wb") as fh: fh.write(revised) REVISED = hashlib.sha256(revised).hexdigest() assert sha("out/" + REVISED_NAME) == REVISED # the served base must be the bytes the finding numbering refers to assert sha("doc/SEARCH-CONVENTIONS.md") == BASE, "served base drifted since the fetch" # the patch is served v5 -> this revision, so a reviewer reads what moved without diffing shas old = open("doc/SEARCH-CONVENTIONS.md", encoding="utf-8", newline="").read().split("\n") new = revised.decode("utf-8").split("\n") diff = "\n".join(difflib.unified_diff(old, new, "a/" + PATH, "b/" + PATH, n=3, lineterm="")) with open("out/SEARCH-CONVENTIONS.md.diff", "wb") as fh: fh.write(diff.encode("utf-8")) DIFF = sha("out/SEARCH-CONVENTIONS.md.diff") # every blob this revision's evidence rests on (all fetched and sha-checked, see fetch_sha.py) CITED_FILES = [ "47c10f0a5d7c78a982708270b4aecc5b6eb97d6dfd2b47cbce69f78c74aa15cb", # v2, #796 "bc7639925683d96a41b5f7ee2ce3b471bb209f7d6c03c6a90d3297d5a453a841", # v3, #1099 rev4 "6778292c1b085c7f12b08020d4f8ea530b4756489e032e0cf10909cd990580e9", # v4, #1350 "295310d7a3cf5fd52d41b59240546f6a27a3184a43326a9bb930c786204d87c4", # #1350's patch "56757e0b815ad2e23de80afe117ecc2e9779f153c51be3737211d881dbc16910", # #1659 rev (rejected) ] payload = { "job_id": 3688, "attempt_id": "c0199296543ff44e97ce6f2ed053e5ab", "type": "audit", "revision": {"path": PATH, "file": REVISED, "base": BASE}, "patch": diff, "resolves": [33, 205, 748, 753, 761, 762, 767, 2567, 2568], "hashes": {REVISED_NAME: REVISED, "SEARCH-CONVENTIONS.md.diff": DIFF}, "cites": {"returns": [1253], "handles": [], "files": CITED_FILES, "messages": []}, "cpu_hours": 0.1, "author_rung": "verified", "transcript_approved": True, } with open("payload.json", "w", encoding="utf-8", newline="\n") as f: json.dump(payload, f, indent=1, ensure_ascii=False) print(json.dumps({ "wrote": "payload.json", "bytes": os.path.getsize("payload.json"), "revision": payload["revision"], "resolves": payload["resolves"], "patch_lines": diff.count("\n"), "diff_bytes": len(diff.encode("utf-8")), "served_copy": REVISED_NAME, "revised_bytes": len(revised)}, indent=1))