File size: 2,098 Bytes
350f4fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""cross-examine-patch.py — Emergency-sync Secondary Brain gate.

Loads Lighthouse CI output and the Chrome DevTools MCP report and cross-
examines them (primary/secondary cohesion). Fails the gate unless both agree.
Usage:
  python scripts/cross-examine-patch.py \
      --preview <url> --lighthouse <lhci manifest> --secondary <mcp report.json>
"""
import argparse
import json
import pathlib
import sys

parser = argparse.ArgumentParser()
parser.add_argument("--preview")
parser.add_argument("--lighthouse")
parser.add_argument("--secondary")
args = parser.parse_args()

print(f"Cross-examining patch at {args.preview}")

failures = []
warnings = []

# ---- Lighthouse CI manifest ------------------------------------------------
lh_path = pathlib.Path(args.lighthouse) if args.lighthouse else None
if lh_path and lh_path.exists():
    manifest = json.loads(lh_path.read_text())
    for run in manifest if isinstance(manifest, list) else [manifest]:
        if run.get("categories", {}).get("performance", {}).get("score", 0) < 0.9:
            failures.append(f"Lighthouse performance < 0.9: {run.get('categories', {}).get('performance', {}).get('score')}")
        if run.get("categories", {}).get("accessibility", {}).get("score", 0) < 1.0:
            failures.append("Lighthouse accessibility < 1.0")
else:
    warnings.append("No Lighthouse manifest found — relying on MCP secondary report")

# ---- Chrome DevTools MCP secondary report ----------------------------------
secondary_path = pathlib.Path(args.secondary) if args.secondary else None
if secondary_path and secondary_path.exists():
    data = json.loads(secondary_path.read_text())
    if data.get("verdict") != "pass":
        failures.append(f"Secondary brain verdict: {data.get('verdict')} -> {data.get('reasoning')}")
else:
    failures.append("Secondary brain report missing — gate cannot pass")

for w in warnings:
    print(f"WARN: {w}")
if failures:
    print("FAIL:")
    for f in failures:
        print(f"  - {f}")
    sys.exit(1)
print("PASS: Both primary and secondary brain agree — cohesive unit verified")