main
John Lauer Adopt native-verified amplifier and comparator TI lands as Board32 98249e8
"""Synchronize Board32 prototype library corrections, preserving acceptance gates."""
from pathlib import Path
import json,hashlib,shutil
import sexp
R=Path(__file__).resolve().parents[1];O=R/'checkpoints/amplifier-comparator-land-review';run=R/'aiflow/run';r=json.loads((run/'run.json').read_text());assert Path(r['boards'][-1]).name=='board-32.kicad_pcb'
b=R/r['boards'][-1];h=hashlib.sha256(b.read_bytes()).hexdigest();assert h=='ea37ce6db20bae331bf41b6638fe9149a17c484e01bc2a0d7fd34917203b7fc3'
backup=O/'before-adoption';assert not backup.exists(),'One-shot synchronization already attempted; inspect before rerun';backup.mkdir()
for name in ['design/netlist.json','design/spec.json','tools/netlist.py','aiflow/run/run.json']:
 p=R/name;q=backup/name;q.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(p,q)
shutil.copytree(R/'kicad',backup/'kicad',ignore=shutil.ignore_patterns('3d','*.step','*.glb'))
intent=json.loads((R/'design/netlist.json').read_text());fps={}
for f in sexp.find(sexp.parse(b.read_text()),'footprint'):
 props={p[1]:p[2]for p in sexp.find(f,'property')};fps[props['Reference']]=f[1]
changes=[]
for c in intent['components']:
 if c['fp']!=fps[c['ref']]:changes.append({'reference':c['ref'],'before':c['fp'],'after':fps[c['ref']]});c['fp']=fps[c['ref']]
assert len(changes)==2,len(changes)
assert {c['reference'] for c in changes}=={'U3','U7'}
(R/'design/netlist.json').write_text(json.dumps(intent,indent=2)+'\n')
for p in O.glob('*.kicad_sch'):shutil.copy2(p,R/'kicad'/p.name)
shutil.copytree(O/'lib',R/'kicad/lib',dirs_exist_ok=True)
# Keep generator regeneration from silently restoring superseded generic footprints.
p=R/'tools/netlist.py';s=p.read_text();marker="out={'design':'adom-custom-electronic-load'";assert s.count(marker)==1
mapping={c['reference']:c['after']for c in changes}
block='# Board32 manufacturer land-pattern adoption; source review in checkpoints/amplifier-comparator-land-review.\nland_pattern_overrides = '+repr(mapping)+'\nfor component in C:\n if component[\'ref\'] in land_pattern_overrides: component[\'fp\'] = land_pattern_overrides[component[\'ref\']]\n'
p.write_text(s.replace(marker,block+marker))
spec=json.loads((R/'design/spec.json').read_text());spec['adoptedGeometryEvidence']={'board':r['boards'][-1],'sha256':h,'source':'checkpoints/amplifier-comparator-land-review/adoption-evidence.json','limits':'Prototype library and label corrections only; copper process, thermal and physical qualification remain open.'};(R/'design/spec.json').write_text(json.dumps(spec,indent=2)+'\n')
prev=r['remoteBoard'];r['remoteBoard']='C:/Users/john/adom-projects/adom-custom-electronic-load/review/ic-land-candidate/ic-land-candidate.kicad_pcb';r['liveBoardBinding']={'board':r['boards'][-1],'remoteBoard':r['remoteBoard'],'previousRemoteBoard':prev,'evidence':'checkpoints/amplifier-comparator-land-review/adoption-evidence.json','note':'Native-saved prototype correction; no qualification implied.'};(run/'run.json').write_text(json.dumps(r,indent=2)+'\n')
(O/'adoption-sync.json').write_text(json.dumps({'board':str(b.relative_to(R)),'sha256':h,'footprintChanges':changes,'schematicSynchronized':True,'generatorOverridesAdded':2,'priorCanonicalBindingCorrections':[],'qualificationGatesChanged':False},indent=2)+'\n');print('Board32: 2 TI example-land bindings synchronized; gates unchanged.')