main
John Lauer
Preserve board29, component assets and scaffold-fit correction candidate with reviewed footage
c54169e
"""Review the explicit PowerDI5 substitution and copper diff without losing repeated pads."""
from pathlib import Path
import hashlib,json,sys
from sexp import parse,find,first
root=Path(__file__).resolve().parents[1];folder=root/'checkpoints/unclipped-hotspots-v1'
a=parse((folder/'baseline.kicad_pcb').read_text());b=parse((folder/'candidate-v84.kicad_pcb').read_text())
def props(x):return {p[1]:p[2] for p in find(x,'property')}
def fps(x):return {props(f)['Reference']:f for f in find(x,'footprint')}
def pads(fp):
return sorted([{'number':str(p[1]),'at':first(p,'at')[1:],'size':first(p,'size')[1:],'net':first(p,'net')[1:] if first(p,'net') else [],'drill':first(p,'drill')[1:] if first(p,'drill') else []} for p in find(fp,'pad')],key=lambda p:(p['number'],p['at']))
fa,fb=fps(a),fps(b);assert fa.keys()==fb.keys()
changes=[]
for ref in fa:
pa,pb=pads(fa[ref]),pads(fb[ref]);oldpos,newpos=first(fa[ref],'at'),first(fb[ref],'at')
assert first(fa[ref],'uuid')==first(fb[ref],'uuid'),ref+' identity changed'
if pa!=pb:
assert ref in ['Q1','D1'],ref+' unexpected pad change'
if ref=='Q1':
for x,y in zip(pa,pb):
z=dict(x)
if x['number']=='2':z['size']=['1.6','2']
assert z==y,(ref,x,y)
else:
assert {p['number']:p['net'] for p in pa}=={p['number']:p['net'] for p in pb}
assert [p['number'] for p in pb]==['1','2','2']
if oldpos!=newpos:assert ref in ['Q2','R7','U3'],ref+' unexpected placement'
if pa!=pb or oldpos!=newpos or props(fa[ref]).get('Value')!=props(fb[ref]).get('Value'):
changes.append({'ref':ref,'beforePads':pa,'afterPads':pb,'beforeAt':oldpos,'afterAt':newpos,'beforeValue':props(fa[ref]).get('Value'),'afterValue':props(fb[ref]).get('Value')})
def copper(x):
return {first(y,'uuid')[1]:y for k in ['segment','via'] for y in find(x,k)}
ca,cb=copper(a),copper(b)
for u in ca.keys()&cb.keys():assert first(ca[u],'net')==first(cb[u],'net'),u
cc=[{'uuid':u,'before':ca.get(u),'after':cb.get(u)} for u in sorted(ca.keys()|cb.keys()) if ca.get(u)!=cb.get(u)]
report={'status':'reviewed explicit substitution, not live adoption','footprintCount':len(fa),'footprintChanges':changes,'copperChanges':cc,'existingCopperNetChanges':0,'repeatedPhysicalPadsPreserved':True,'baselineSha256':hashlib.sha256((folder/'baseline.kicad_pcb').read_bytes()).hexdigest(),'candidateSha256':hashlib.sha256((folder/'candidate-v84.kicad_pcb').read_bytes()).hexdigest(),'limits':['Zone fill and full native 3D still require visual review','D1 replaces package; schematic/BOM synchronization required','Full thermal qualification not established']}
(folder/'candidate-v84.complete-diff.json').write_text(json.dumps(report,indent=2)+'\n')
print(json.dumps({'footprints':len(fa),'changedRefs':[p['ref'] for p in changes],'copperChanges':len(cc),'existingNetChanges':0}))