interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / evidence / text-parent-qualification / emitdiff.py

43 lines · 2405 bytes Raw Blame History
1#!/usr/bin/env python3
2"""L555 delta check: compare two converter binaries over every committed .om file and every mode.
3
4Usage: emitdiff.py OLD_BRIDGE NEW_BRIDGE OUT.json
5Every source in the repository (tests/, evidence/, examples/, src/ excluded) is fed with each mode
6byte the converter recognises. Output bytes and exit status must be identical, except (a) where the
7new converter refuses a unit the old one accepted and the pinned seed also refuses it, or (b) where
8both refuse with different codes (seeded-mode text: 24 now, before tokenizing). Each changed row is
9listed with both statuses and the seed's status for the same unit.
10"""
11import hashlib, json, pathlib, subprocess, sys
12
13old, new, out = sys.argv[1:4]
14root = pathlib.Path('.')
15seed = 'build/bootstrap/omc'
16srcs = 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)
17modes = b'CPDQHRSEJWYLMV' # every mode byte main() in src/toc.om recognises
18def run(exe, data):
19 r = subprocess.run([exe], input=data, capture_output=True, timeout=120)
20 return r.returncode, r.stdout
21rows, same, changed = [], 0, []
22for 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]))
34for c in changed:
35 c['kind'] = 'new-refusal' if c['old'] == 0 else 'refusal-code'
36ok = all(c['new_is_refusal'] and (c['old'] != 0 or c['seed'] != 0) for c in changed)
37res = 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())
40pathlib.Path(out).write_text(json.dumps(res, indent=1) + '\n')
41kinds = {k: sum(c['kind'] == k for c in changed) for k in ('new-refusal', 'refusal-code')}
42print(f"L555 EMITDIFF sources={len(srcs)} runs={res['runs']} identical={same} changed={len(changed)} {kinds} ok={ok}")
43sys.exit(0 if ok else 1)