#!/usr/bin/env python3 """Job #4551: stage the fresh-directory reproduction of the shipped checker. Creates repro/ holding exactly the checker and its declared inputs, runs the checker twice there, and records both exit codes, the two stdouts and whether they are byte-identical. Discloses that the checker writes its own check.out.json into the staged directory, so after the first run the directory holds one self-generated extra file. """ import json import os import shutil import subprocess import sys import hashlib HERE = os.path.dirname(os.path.abspath(__file__)) REPRO = os.path.join(HERE, "repro") CHECKER = "check-job4551.py" INPUTS = [ "brief.md", "brief_step.json", "step.json", "newstep.json", "route1.json", "probe.json", "served_window.jsonl", "window_scrub.json", "screen962-L813.json", "selection749.json", "results751.json", "pilot749.json", "sweeper749.c", "report962.final.md", "recipe962.md", "gate_scan.json", "screen_facts.json", "price.json", ] def sha_lf(data): return hashlib.sha256(data.replace(b"\r\n", b"\n")).hexdigest() def main(): os.makedirs(REPRO, exist_ok=True) for name in [CHECKER] + INPUTS: shutil.copyfile(os.path.join(HERE, name), os.path.join(REPRO, name)) before = sorted(os.listdir(REPRO)) runs = [] for i in range(2): proc = subprocess.run([sys.executable, CHECKER], cwd=REPRO, capture_output=True) runs.append((proc.returncode, proc.stdout, proc.stderr)) same = runs[0][1] == runs[1][1] log = [] log.append("job #4551 fresh-directory reproduction") log.append("staged directory held, before the first run: %d files (%s)" % (len(before), ", ".join(before))) log.append("after the first run it holds one self-generated extra file: check.out.json") for i, (rc, out, err) in enumerate(runs, 1): log.append("run %d: exit %d, stdout %d bytes, sha256(lf) %s, stderr %d bytes" % (i, rc, len(out), sha_lf(out), len(err))) tail = out.decode("utf-8", "replace").strip().splitlines()[-1] log.append("run %d last stdout line: %s" % (i, tail)) log.append("byte-identical stdout: %s" % same) log.append("checks passed: %d/%d checks passed" % ( json.load(open(os.path.join(REPRO, "check.out.json")))["checks_passed"], json.load(open(os.path.join(REPRO, "check.out.json")))["checks_total"])) with open(os.path.join(HERE, "repro.log"), "w", encoding="utf-8", newline="\n") as fh: fh.write("\n".join(log) + "\n") print("\n".join(log)) return 0 if (same and runs[0][0] == 0 and runs[1][0] == 0) else 1 if __name__ == "__main__": sys.exit(main())