omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / evidence / text-parent-qualification / emitdiff.py
| 1 | #!/usr/bin/env python3 |
| 2 | """L555 delta check: compare two converter binaries over every committed .om file and every mode. |
| 3 | |
| 4 | Usage: emitdiff.py OLD_BRIDGE NEW_BRIDGE OUT.json |
| 5 | Every source in the repository (tests/, evidence/, examples/, src/ excluded) is fed with each mode |
| 6 | byte the converter recognises. Output bytes and exit status must be identical, except (a) where the |
| 7 | new converter refuses a unit the old one accepted and the pinned seed also refuses it, or (b) where |
| 8 | both refuse with different codes (seeded-mode text: 24 now, before tokenizing). Each changed row is |
| 9 | listed with both statuses and the seed's status for the same unit. |
| 10 | """ |
| 11 | import hashlib, json, pathlib, subprocess, sys |
| 12 | |
| 13 | old, new, out = sys.argv[1:4] |
| 14 | root = pathlib.Path('.') |
| 15 | seed = 'build/bootstrap/omc' |
| 16 | srcs = sorted(p for p in root.rglob('*.om') if 'build' not in p.parts and p.parts[0] != 'src' and '.git' not in p.parts) |
| 17 | modes = b'CPDQHRSEJWYLMV' # every mode byte main() in src/toc.om recognises |
| 18 | def run(exe, data): |
| 19 | r = subprocess.run([exe], input=data, capture_output=True, timeout=120) |
| 20 | return r.returncode, r.stdout |
| 21 | rows, same, changed = [], 0, [] |
| 22 | for p in srcs: |
| 23 | body = p.read_bytes() |
| 24 | sr = subprocess.run([seed], input=body, capture_output=True, timeout=120).returncode |
| 25 | for m in modes: |
| 26 | data = bytes([m]) + body |
| 27 | a, b = run(old, data), run(new, data) |
| 28 | if a == b: |
| 29 | same += 1 |
| 30 | continue |
| 31 | changed.append(dict(file=str(p), mode=chr(m), seed=sr, old=a[0], new=b[0], |
| 32 | old_sha=hashlib.sha256(a[1]).hexdigest(), new_sha=hashlib.sha256(b[1]).hexdigest(), |
| 33 | new_is_refusal=b[0] != 0 and not b[1])) |
| 34 | for c in changed: |
| 35 | c['kind'] = 'new-refusal' if c['old'] == 0 else 'refusal-code' |
| 36 | ok = all(c['new_is_refusal'] and (c['old'] != 0 or c['seed'] != 0) for c in changed) |
| 37 | res = dict(sources=len(srcs), runs=len(srcs) * len(modes), identical=same, changed=changed, ok=ok, |
| 38 | old=hashlib.sha256(pathlib.Path(old).read_bytes()).hexdigest(), |
| 39 | new=hashlib.sha256(pathlib.Path(new).read_bytes()).hexdigest()) |
| 40 | pathlib.Path(out).write_text(json.dumps(res, indent=1) + '\n') |
| 41 | kinds = {k: sum(c['kind'] == k for c in changed) for k in ('new-refusal', 'refusal-code')} |
| 42 | print(f"L555 EMITDIFF sources={len(srcs)} runs={res['runs']} identical={same} changed={len(changed)} {kinds} ok={ok}") |
| 43 | sys.exit(0 if ok else 1) |