master
John Lauer 1.1.13: balanced grouped 2-column, 15 mm icon lane, body-centred designators, stroke_mm; widget gains a parity-tested JS engine for CSP-blocked wasm 47c81ac 1mo ago
// Parity check: symgen.js must produce byte-identical .kicad_sym to the Rust CLI.
// usage: node widget/parity.js <adom-symbol binary> <create.json>...
const fs = require('fs'), path = require('path'), os = require('os'), cp = require('child_process');
const gen = require('./symgen.js');
const [bin, ...files] = process.argv.slice(2);
let bad = 0;
for (const f of files) {
  const input = JSON.parse(fs.readFileSync(f, 'utf8'));
  const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'parity-'));
  try { cp.execFileSync(bin, ['create', '--file', f, '--out', tmp], { stdio: 'pipe' }); }
  catch (e) { console.log('SKIP', f, '(cli failed:', String(e.stderr).trim().slice(0, 80) + ')'); continue; }
  const rust = fs.readFileSync(path.join(tmp, input.symbolName + '.kicad_sym'), 'utf8');
  const js = gen.generateFromCreateJson(input);
  if (rust === js) console.log('OK  ', f);
  else {
    bad++;
    const a = rust.split('\n'), b = js.split('\n');
    for (let i = 0; i < Math.max(a.length, b.length); i++) if (a[i] !== b[i]) { console.log('DIFF', f, 'line', i + 1, '\n  rust:', a[i], '\n  js:  ', b[i]); break; }
  }
}
process.exit(bad ? 1 : 0);