Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/cortex/blob/main/tests/json/cmp.py # cortex aien-dev/cortex Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `cortex / tests / json / cmp.py` 24 lines ยท 1092 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Compare framed (u32 LE length + bytes) expected vs observed records. Verification tooling only. 3 usage: cmp.py NAME EXPECTED OBSERVED [SHOW] -> prints 'NAME records E observed G match M mismatch X' 4 exit 0 only when every expected record is matched byte for byte and counts agree.""" 5 import sys 6 def recs(b): 7 i, o = 0, [] 8 while i < len(b): 9 n = int.from_bytes(b[i:i + 4], 'little'); o.append(b[i + 4:i + 4 + n]); i += 4 + n 10 return o 11 name, ef, gf = sys.argv[1:4] 12 show = int(sys.argv[4]) if len(sys.argv) > 4 else 3 13 exp, got = recs(open(ef, 'rb').read()), recs(open(gf, 'rb').read()) 14 ok = bad = 0 15 for k, e in enumerate(exp): 16 g = got[k] if k < len(got) else None 17 if g == e: 18 ok += 1 19 else: 20 bad += 1 21 if bad <= show: 22 print(' mismatch record %d\n expected %r\n observed %r' % (k, e[:160], None if g is None else g[:160])) 23 print('%s records %d observed %d match %d mismatch %d' % (name, len(exp), len(got), ok, bad + max(0, len(got) - len(exp)))) 24 sys.exit(0 if bad == 0 and len(got) == len(exp) else 1)