main
John Lauer
Record unclipped current rework candidate and pending mesh/thermal checks
d9647fc
"""Inventory every saved geometry change; does not replace native DRC or electrical review."""
import json,sys,hashlib
from pathlib import Path
from sexp import parse,find,first
root=Path(__file__).resolve().parents[1]
base=root/'checkpoints/unclipped-hotspots-v1/baseline.kicad_pcb'
candidate=Path(sys.argv[1]);candidate=candidate if candidate.is_absolute() else root/candidate
def identity(x):return first(x,'uuid')[1]
def copper(b):
result={}
for kind in ['segment','via']:
for x in find(b,kind):
result[identity(x)]={'kind':kind,**{k:first(x,k)[1:] for k in ['start','end','at','width','size','drill','layer','layers','net'] if first(x,k)}}
return result
def footprints(b):
result={}
for fp in find(b,'footprint'):
ref=next(p[2] for p in find(fp,'property') if p[1]=='Reference')
result[ref]={'at':first(fp,'at')[1:],'pads':{str(p[1]):{'at':first(p,'at')[1:],'size':first(p,'size')[1:],'net':(first(p,'net') or ['net',''])[1:]} for p in find(fp,'pad')}}
return result
a=parse(base.read_text());b=parse(candidate.read_text());ca,cb=copper(a),copper(b);fa,fb=footprints(a),footprints(b)
changes=[]
for uid in sorted(set(ca)|set(cb)):
if ca.get(uid)!=cb.get(uid):changes.append({'uuid':uid,'before':ca.get(uid),'after':cb.get(uid)})
netchanges=[x for x in changes if x['before'] and x['after'] and x['before'].get('net')!=x['after'].get('net')]
fpchanges=[{'ref':k,'before':fa.get(k),'after':fb.get(k)} for k in sorted(set(fa)|set(fb)) if fa.get(k)!=fb.get(k)]
assert not netchanges,netchanges
assert fa.keys()==fb.keys(),'Footprint inventory changed'
for k in fa:assert fa[k]['pads']==fb[k]['pads'],f'{k} local pad geometry or connectivity changed'
report={'baselineSha256':hashlib.sha256(base.read_bytes()).hexdigest(),'candidateSha256':hashlib.sha256(candidate.read_bytes()).hexdigest(),'formalAcceptance':False,'existingCopperNetChanges':netchanges,'footprintChanges':fpchanges,'copperChanges':changes,'note':'All track/via changes inventoried by saved UUID. Native net invariant additionally checks newly created copper before and after connectivity/fill/save. Zone fill geometry and placement still require visual/native review.'}
out=candidate.with_suffix('.complete-diff.json');out.write_text(json.dumps(report,indent=2)+'\n');print(json.dumps({'report':str(out),'copperChanges':len(changes),'footprintChanges':[x['ref'] for x in fpchanges],'existingCopperNetChanges':0}))