main
John Lauer
Adopt native-reviewed Board31 library corrections and publish process clip
17c4685
"""Synchronize Board31 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/library-label-review';run=R/'aiflow/run';r=json.loads((run/'run.json').read_text());assert Path(r['boards'][-1]).name=='board-31.kicad_pcb'
b=R/r['boards'][-1];h=hashlib.sha256(b.read_bytes()).hexdigest();assert h=='a2b7fda1783e8b519a8819d93837c8d6fa5acb57dfde4f43abd2b3fd1b405bc5'
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)==40,len(changes)
assert {c['reference'] for c in changes if c['reference'] in ['Q1','J11']}=={'Q1','J11'}
(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='# Board31 manufacturer land-pattern adoption; source review in checkpoints/library-label-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/library-label-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/library-label-candidate/library-label-candidate.kicad_pcb';r['liveBoardBinding']={'board':r['boards'][-1],'remoteBoard':r['remoteBoard'],'previousRemoteBoard':prev,'evidence':'checkpoints/library-label-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':40,'priorCanonicalBindingCorrections':['Q1','J11'],'qualificationGatesChanged':False},indent=2)+'\n');print('Board31: 38 new and 2 previously stale canonical footprint bindings synchronized; gates unchanged.')