main
John Lauer Bind shunt connector discrete and IC library evidence to board30 without relaxing gates d84da78
"""Compare adopted connector pads by identity and location; retain exact variants."""
from pathlib import Path
import json,hashlib
import sexp
R=Path(__file__).resolve().parents[1];O=R/'checkpoints/connector-library-review';O.mkdir(exist_ok=True);board=R/'aiflow/run/board-30.kicad_pcb';b=sexp.parse(board.read_text());intent={c['ref']:c for c in json.loads((R/'design/netlist.json').read_text())['components']};rows=[]
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
slugs={'J8':'usb4105-gf-a','J9':'m20-9990346','J11':'fts-105-01-l-s'}
def pads(f):
 return {(p[1],*map(float,sexp.first(p,'at')[1:3])):{'size':list(map(float,sexp.first(p,'size')[1:3])),'drill':sexp.first(p,'drill'),'type':p[2],'shape':p[3]}for p in sexp.find(f,'pad')}
for f in sexp.find(b,'footprint'):
 props={p[1]:p[2]for p in sexp.find(f,'property')};ref=props['Reference']
 if ref not in slugs:continue
 slug=slugs[ref];cat=R/'components'/slug;assert props['MPN']==intent[ref]['mpn'];cp=pads(sexp.parse((cat/(slug+'.kicad_mod')).read_text()));bp=pads(f);assert set(cp)==set(bp),(ref,'pad identities/positions mismatch')
 differences=[{'pad':key,'board':bp[key],'catalog':cp[key]}for key in bp if bp[key]!=cp[key]]
 for p in sexp.find(f,'pad'):
  if not p[1]:continue
  expected=intent[ref]['pins'].get(p[1]);n=sexp.first(p,'net');actual=n[-1]if n else None;assert actual==expected,(ref,p[1],actual,expected)
 model=Path(sexp.first(f,'model')[1].replace('${KIPRJMOD}',str(board.parent)));assert sha(model)==sha(cat/(slug+'.step'))
 rows.append({'reference':ref,'mpn':props['MPN'],'pinNets':intent[ref]['pins'],'padVariants':differences,'selectedModelMatchesCatalog':True,'modelSha256':sha(model)})
report={'boardSha256':sha(board),'references':rows,'limits':['J9 uses1.00mm nominal holes; catalog target1.02+/-0.05mm. Nominal1.00 lies within drawing range but finished-hole process tolerance is unconfirmed; not a manufacturing pass.','J11 uses1.05mm pads versus catalog1.00mm, retaining0.71mm hole target. Project variant requires fab annular-ring and spacing acceptance.','USB shared/duplicate power contacts and four SH pads are retained; SBU pins remain explicit no-connect.','Nominal model matching and pin membership do not establish mating, physical reliability or visual acceptance.']};(O/'review.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report,indent=2))
p=R/'aiflow/run/components.json';reg=json.loads(p.read_text())
for c in reg['components']:
 if c['reference']in slugs:
  c['review']['classification']='purchased';e=c['review'].setdefault('geometryEvidence',[])
  if 'checkpoints/connector-library-review/review.json'not in e:e.append('checkpoints/connector-library-review/review.json')
p.write_text(json.dumps(reg,indent=2)+'\n')