#!/usr/bin/env python3 """Job #4548: stage the fresh-directory reproduction and record its stdout. Creates outputs/job4548/repro/, copies in exactly the declared inputs and the checker, runs the checker twice with the running interpreter and asserts the two stdout byte strings are equal and that the exit code is 0. The log is written UTF-8 with LF newlines; it is one of the uploaded files, so it must never be produced by shell redirection. """ import hashlib import os import shutil import subprocess import sys HERE = os.path.dirname(os.path.abspath(__file__)) REPRO = os.path.join(HERE, "repro") INPUTS = ["served_window.jsonl", "probe.json", "window_scrub.json", "brief_step.json", "brief_named.json", "route-107.json", "own_returns.json", "scan.json"] CHECKER = "check-job4548.py" LOG = os.path.join(HERE, "repro.log") def run(): p = subprocess.run([sys.executable, CHECKER], cwd=REPRO, capture_output=True) # the child's piped stdout is CRLF on this platform; pin the LF form for the log and the sha out = p.stdout.decode("utf-8").replace("\r\n", "\n") return p.returncode, out, p.stderr.decode("utf-8").replace("\r\n", "\n") def main(): os.makedirs(REPRO, exist_ok=True) for n in INPUTS + [CHECKER]: shutil.copyfile(os.path.join(HERE, n), os.path.join(REPRO, n)) rc1, out1, err1 = run() rc2, out2, err2 = run() same = out1 == out2 lines = [ "job4548 fresh-directory reproduction", "directory: repro/ (holds only the checker and the %d declared inputs)" % len(INPUTS), "interpreter: %s" % os.path.basename(sys.executable), "run 1: exit %d, %d bytes stdout" % (rc1, len(out1)), "run 2: exit %d, %d bytes stdout" % (rc2, len(out2)), "byte-identical stdout: %s" % same, "stdout sha256: %s" % hashlib.sha256(out1.encode("utf-8")).hexdigest(), "stderr: %s" % (err1.strip() or "(empty)"), "", out1.rstrip("\n"), "", ] with open(LOG, "w", encoding="utf-8", newline="\n") as fh: fh.write("\n".join(lines)) print("staged %d files into repro/" % (len(INPUTS) + 1)) print("exit codes %d/%d, identical stdout %s, last line: %s" % (rc1, rc2, same, out1.strip().splitlines()[-1])) if not same or rc1 != 0 or rc2 != 0: return 1 return 0 if __name__ == "__main__": sys.exit(main())