#!/usr/bin/env python3 """Job #1054 -- negative controls for the immutable package e94c275d (return #430). Each control is a fresh copy of the clean package with ONE mutation, run with the unmodified checker (no --replay-all, so the direct-replay assertion fires on values[0] only: fast and targeted). Records exit code and the first assertion line. The clean package is never modified. """ import json import math import shutil import subprocess import sys from pathlib import Path BASE = Path("job1054/pkg") OUT = Path("job1054/controls") OUT.mkdir(parents=True, exist_ok=True) def run(tag, mutate): d = OUT / tag if d.exists(): shutil.rmtree(d) shutil.copytree(BASE, d) mutate(d) p = subprocess.run([sys.executable, "check1050.py", "--input", "input.json", "--result", "reflection1050.json"], cwd=d, capture_output=True, text=True) first = "" for ln in (p.stderr or "").splitlines(): if "Error" in ln or "assert" in ln.lower(): first = ln.strip() break print("%-26s exit=%d %s" % (tag, p.returncode, first[:150])) return dict(tag=tag, exit_code=p.returncode, first_error_line=first[:300], stdout=(p.stdout or "").strip()[:200]) def c1_value_conflict(d): t = json.loads((d / "reflection1050.json").read_text()) t["batches"][0]["values"][0] += 6 # value changed, summary left alone (d / "reflection1050.json").write_text(json.dumps(t)) def c2_rotated_input(d): t = json.loads((d / "input.json").read_text()) for r in t["levels"]: if r["x"] == 19: r["A2_reported"] += 6 # input's A2 moved: the target's z must no longer match (d / "input.json").write_text(json.dumps(t)) def c3_missing_record(d): t = json.loads((d / "reflection1050.json").read_text()) t["batches"] = t["batches"][:3] # drop the second 19# record (d / "reflection1050.json").write_text(json.dumps(t)) def c4_inconsistent_summary(d): t = json.loads((d / "reflection1050.json").read_text()) t["batches"][1]["summary"]["sample_sd"] *= 1.0 + 1e-6 # 1e-6 > the declared 1e-10 tolerance (d / "reflection1050.json").write_text(json.dumps(t)) def c5_bad_draw_all_metadata_consistent(d): """The decisive control: one draw changed AND every derived field recomputed, so only the direct replay of the seeded shuffle can detect it.""" inp = json.loads((d / "input.json").read_text()) t = json.loads((d / "reflection1050.json").read_text()) b = t["batches"][3] # 19#, seed 104519, 500 values b["values"][0] += 6 A2 = next(r["A2_reported"] for r in inp["levels"] if r["x"] == b["x"]) v = b["values"] n = len(v) mean = sum(v) / n sd = math.sqrt(sum((q - mean) ** 2 for q in v) / (n - 1)) s = b["summary"] s["n"] = n s["sum"] = sum(v) s["square_sum"] = sum(q * q for q in v) s["min"] = min(v) s["max"] = max(v) s["mean"] = mean s["sample_sd"] = sd s["z_ref"] = (A2 - mean) / sd s["strictly_below_observed"] = sum(q < A2 for q in v) s["equal_observed"] = sum(q == A2 for q in v) s["at_or_below_observed"] = sum(q <= A2 for q in v) b["first_direct_mirror_max"] = v[0] (d / "reflection1050.json").write_text(json.dumps(t)) if __name__ == "__main__": res = [run("c1_value_conflict", c1_value_conflict), run("c2_rotated_input", c2_rotated_input), run("c3_missing_record", c3_missing_record), run("c4_inconsistent_summary", c4_inconsistent_summary), run("c5_bad_draw_all_meta_ok", c5_bad_draw_all_metadata_consistent)] Path("job1054/controls.json").write_text(json.dumps(res, indent=1)) print("all controls detected:", all(r["exit_code"] != 0 for r in res))