|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import argparse |
| 4 | +import json |
| 5 | +from datetime import datetime, timezone |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +from agents.memory_extractor import extract_memories |
| 9 | +from agents.semantic_confirmer import confirm_authority_change |
| 10 | + |
| 11 | +DEFAULT_FIXTURE = Path("tests/fixtures/path_a_authority_change_v3_carveout_additions_2026_07_12.json") |
| 12 | +DEFAULT_OUTPUT_DIR = Path("path_a_eval_artifacts") |
| 13 | + |
| 14 | +PREDICTIONS = { |
| 15 | + "path_a_v3_carveout_export_approval_eu": { |
| 16 | + "prediction_id": "C1-1", |
| 17 | + "expected_confirmed": False, |
| 18 | + "label": "bounded negative blocked by carve-out clause", |
| 19 | + }, |
| 20 | + "path_a_v3_universal_approval_all_regions": { |
| 21 | + "prediction_id": "C1-2", |
| 22 | + "expected_confirmed": True, |
| 23 | + "label": "universal positive survives carve-out clause", |
| 24 | + }, |
| 25 | +} |
| 26 | + |
| 27 | + |
| 28 | +def _utc_slug() -> str: |
| 29 | + return datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ") |
| 30 | + |
| 31 | + |
| 32 | +def main() -> int: |
| 33 | + parser = argparse.ArgumentParser() |
| 34 | + parser.add_argument("--fixture", default=str(DEFAULT_FIXTURE)) |
| 35 | + parser.add_argument("--output-dir", default=str(DEFAULT_OUTPUT_DIR)) |
| 36 | + args = parser.parse_args() |
| 37 | + |
| 38 | + fixture = json.loads(Path(args.fixture).read_text()) |
| 39 | + cases = fixture["cases"] |
| 40 | + if {case["id"] for case in cases} != set(PREDICTIONS): |
| 41 | + raise SystemExit("fixture cases do not match frozen carve-out C1 predictions") |
| 42 | + |
| 43 | + rows = [] |
| 44 | + for case in cases: |
| 45 | + items = [item.to_dict() for item in extract_memories(case["text"])] |
| 46 | + result = confirm_authority_change(case["c0_frozen_proposal"], items, require_relation_span=True) |
| 47 | + prediction = PREDICTIONS[case["id"]] |
| 48 | + confirmed = result["confirmed"] |
| 49 | + rows.append({ |
| 50 | + "case_id": case["id"], |
| 51 | + "class": case["class"], |
| 52 | + "prediction_id": prediction["prediction_id"], |
| 53 | + "label": prediction["label"], |
| 54 | + "expected_confirmed_after_patch": prediction["expected_confirmed"], |
| 55 | + "confirmed_after_patch": confirmed, |
| 56 | + "expectation_held": confirmed == prediction["expected_confirmed"], |
| 57 | + "confirmer_result": result, |
| 58 | + }) |
| 59 | + |
| 60 | + run_id = _utc_slug() |
| 61 | + artifact = { |
| 62 | + "run_id": run_id, |
| 63 | + "generated_at_utc": datetime.now(timezone.utc).isoformat(), |
| 64 | + "fixture": args.fixture, |
| 65 | + "preregistration_addendum": "PATH_A_V3_PREREGISTRATION_ADDENDUM_CARVEOUT_2026-07-12.md", |
| 66 | + "prereg_freeze_commit": "b1d44f9", |
| 67 | + "fixture_commit": "48507de", |
| 68 | + "c0_baseline_commit": "78d66a3", |
| 69 | + "gate_under_test": "patched confirmer with bounded customer carve-out clause", |
| 70 | + "boundary": ( |
| 71 | + "C1 only: the same two frozen c0_frozen_proposal objects are run after the " |
| 72 | + "carve-out defense. No fixture or prediction was changed after observing C0." |
| 73 | + ), |
| 74 | + "summary": { |
| 75 | + "cases": len(rows), |
| 76 | + "confirmed_after_patch": sum(int(row["confirmed_after_patch"]) for row in rows), |
| 77 | + "expectations_held": sum(int(row["expectation_held"]) for row in rows), |
| 78 | + "bounded_negative_blocked": not next( |
| 79 | + row["confirmed_after_patch"] |
| 80 | + for row in rows |
| 81 | + if row["case_id"] == "path_a_v3_carveout_export_approval_eu" |
| 82 | + ), |
| 83 | + "universal_positive_admitted": next( |
| 84 | + row["confirmed_after_patch"] |
| 85 | + for row in rows |
| 86 | + if row["case_id"] == "path_a_v3_universal_approval_all_regions" |
| 87 | + ), |
| 88 | + }, |
| 89 | + "cases": rows, |
| 90 | + } |
| 91 | + |
| 92 | + output_dir = Path(args.output_dir) |
| 93 | + output_dir.mkdir(parents=True, exist_ok=True) |
| 94 | + json_path = output_dir / f"path_a_v3_carveout_c1_regate_{run_id}.json" |
| 95 | + md_path = output_dir / f"path_a_v3_carveout_c1_regate_{run_id}.md" |
| 96 | + json_path.write_text(json.dumps(artifact, indent=2), encoding="utf-8") |
| 97 | + |
| 98 | + lines = [ |
| 99 | + "# Path A v3 Carve-Out C1 Re-Gate", |
| 100 | + "", |
| 101 | + f"Run ID: `{run_id}`", |
| 102 | + f"Pre-registration addendum: `PATH_A_V3_PREREGISTRATION_ADDENDUM_CARVEOUT_2026-07-12.md` (freeze `b1d44f9`)", |
| 103 | + f"Fixture additions: `{args.fixture}` (commit `48507de`)", |
| 104 | + "C0 baseline commit: `78d66a3`", |
| 105 | + "", |
| 106 | + "The same two frozen `c0_frozen_proposal` objects were run after the carve-out defense. " |
| 107 | + "The fixture and predictions were not changed after C0.", |
| 108 | + "", |
| 109 | + "| Case | Class | Expected after patch | Confirmed after patch | Held |", |
| 110 | + "| --- | --- | --- | --- | --- |", |
| 111 | + ] |
| 112 | + for row in rows: |
| 113 | + lines.append( |
| 114 | + f"| `{row['case_id']}` | {row['class']} | " |
| 115 | + f"{'CONFIRM' if row['expected_confirmed_after_patch'] else 'BLOCK'} | " |
| 116 | + f"{'CONFIRMED' if row['confirmed_after_patch'] else 'BLOCKED'} | " |
| 117 | + f"{'yes' if row['expectation_held'] else 'NO'} |" |
| 118 | + ) |
| 119 | + lines.extend([ |
| 120 | + "", |
| 121 | + "## Separate C1 Results", |
| 122 | + "", |
| 123 | + f"- EU-only bounded negative blocked: `{'yes' if artifact['summary']['bounded_negative_blocked'] else 'no'}`", |
| 124 | + f"- Universal all-regions positive admitted: `{'yes' if artifact['summary']['universal_positive_admitted'] else 'no'}`", |
| 125 | + "", |
| 126 | + "## Boundary", |
| 127 | + "", |
| 128 | + artifact["boundary"], |
| 129 | + "", |
| 130 | + ]) |
| 131 | + md_path.write_text("\n".join(lines), encoding="utf-8") |
| 132 | + |
| 133 | + print(json.dumps({ |
| 134 | + "json": str(json_path), |
| 135 | + "markdown": str(md_path), |
| 136 | + "summary": artifact["summary"], |
| 137 | + "cases": [ |
| 138 | + {k: row[k] for k in ("case_id", "confirmed_after_patch", "expectation_held")} |
| 139 | + for row in rows |
| 140 | + ], |
| 141 | + }, indent=2)) |
| 142 | + return 0 |
| 143 | + |
| 144 | + |
| 145 | +if __name__ == "__main__": |
| 146 | + raise SystemExit(main()) |
0 commit comments