#!/bin/sh
set -eu
HERE=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
CLI=${KICAD_CLI:-/Applications/KiCad/KiCad.app/Contents/MacOS/kicad-cli}
P="$HERE/board/lamp_safety_evt_a3_IR_PCB"
mkdir -p "$HERE/recheck"
"$CLI" sch erc --severity-all --format json --output "$HERE/recheck/erc.json" "$P.kicad_sch"
"$CLI" pcb drc --severity-all --all-track-errors --schematic-parity --refill-zones --format json --output "$HERE/recheck/drc.json" "$P.kicad_pcb"
python3 - "$HERE/recheck" <<'CHECK'
import json,sys
from pathlib import Path
r=Path(sys.argv[1]);e=json.loads((r/'erc.json').read_text());d=json.loads((r/'drc.json').read_text())
assert not [v for sh in e['sheets'] for v in sh.get('violations',[])]
assert not d['violations'] and not d['unconnected_items'] and not d['schematic_parity']
print('PASS: native ERC/DRC/connectivity/parity; no hardware qualification')
CHECK
