Add cross-examine gate script
Browse files
scripts/cross-examine-patch.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""cross-examine-patch.py — Emergency-sync Secondary Brain gate.
|
| 2 |
+
|
| 3 |
+
Loads Lighthouse CI output and the Chrome DevTools MCP report and cross-
|
| 4 |
+
examines them (primary/secondary cohesion). Fails the gate unless both agree.
|
| 5 |
+
Usage:
|
| 6 |
+
python scripts/cross-examine-patch.py \
|
| 7 |
+
--preview <url> --lighthouse <lhci manifest> --secondary <mcp report.json>
|
| 8 |
+
"""
|
| 9 |
+
import argparse
|
| 10 |
+
import json
|
| 11 |
+
import pathlib
|
| 12 |
+
import sys
|
| 13 |
+
|
| 14 |
+
parser = argparse.ArgumentParser()
|
| 15 |
+
parser.add_argument("--preview")
|
| 16 |
+
parser.add_argument("--lighthouse")
|
| 17 |
+
parser.add_argument("--secondary")
|
| 18 |
+
args = parser.parse_args()
|
| 19 |
+
|
| 20 |
+
print(f"Cross-examining patch at {args.preview}")
|
| 21 |
+
|
| 22 |
+
failures = []
|
| 23 |
+
warnings = []
|
| 24 |
+
|
| 25 |
+
# ---- Lighthouse CI manifest ------------------------------------------------
|
| 26 |
+
lh_path = pathlib.Path(args.lighthouse) if args.lighthouse else None
|
| 27 |
+
if lh_path and lh_path.exists():
|
| 28 |
+
manifest = json.loads(lh_path.read_text())
|
| 29 |
+
for run in manifest if isinstance(manifest, list) else [manifest]:
|
| 30 |
+
if run.get("categories", {}).get("performance", {}).get("score", 0) < 0.9:
|
| 31 |
+
failures.append(f"Lighthouse performance < 0.9: {run.get('categories', {}).get('performance', {}).get('score')}")
|
| 32 |
+
if run.get("categories", {}).get("accessibility", {}).get("score", 0) < 1.0:
|
| 33 |
+
failures.append("Lighthouse accessibility < 1.0")
|
| 34 |
+
else:
|
| 35 |
+
warnings.append("No Lighthouse manifest found — relying on MCP secondary report")
|
| 36 |
+
|
| 37 |
+
# ---- Chrome DevTools MCP secondary report ----------------------------------
|
| 38 |
+
secondary_path = pathlib.Path(args.secondary) if args.secondary else None
|
| 39 |
+
if secondary_path and secondary_path.exists():
|
| 40 |
+
data = json.loads(secondary_path.read_text())
|
| 41 |
+
if data.get("verdict") != "pass":
|
| 42 |
+
failures.append(f"Secondary brain verdict: {data.get('verdict')} -> {data.get('reasoning')}")
|
| 43 |
+
else:
|
| 44 |
+
failures.append("Secondary brain report missing — gate cannot pass")
|
| 45 |
+
|
| 46 |
+
for w in warnings:
|
| 47 |
+
print(f"WARN: {w}")
|
| 48 |
+
if failures:
|
| 49 |
+
print("FAIL:")
|
| 50 |
+
for f in failures:
|
| 51 |
+
print(f" - {f}")
|
| 52 |
+
sys.exit(1)
|
| 53 |
+
print("PASS: Both primary and secondary brain agree — cohesive unit verified")
|