#!/usr/bin/env python3 """Job 975 negative controls for checkcert959.py (stdlib): each tampered copy must FAIL. python3 controls975.py > controls975.out """ import json, os, subprocess, sys, tempfile def run(n, lines): with tempfile.NamedTemporaryFile('w', suffix='.jsonl', delete=False) as f: f.write(''.join(l + '\n' for l in lines)) p = subprocess.run([sys.executable, 'checkcert959.py', '9409', str(n), f.name], capture_output=True, text=True) os.unlink(f.name) return 'PASS' if p.returncode == 0 else 'FAIL' L = open('tree975-101.cert.jsonl').read().splitlines() uni = [json.dumps({**r, 'w': [1] * len(r['w'])}, separators=(',', ':')) if r.get('path') == [[101, 60]] else json.dumps(r, separators=(',', ':')) for r in map(json.loads, L)] cases = [('original n=52', 52, L, 'PASS'), ('leaf b=60 weights replaced by uniform', 52, uni, 'FAIL'), ('child b=17 deleted', 52, [l for l in L if '[[101,17]]' not in l], 'FAIL'), ('wrong prefix n=47 (coverable per #1840)', 47, L, 'FAIL'), ('extra unreferenced record', 52, L + ['{"path":[[103,0]],"w":[1]}'], 'FAIL')] bad = 0 for name, n, lines, want in cases: got = run(n, lines) bad += got != want print(f'{name}: {got} (expected {want})') print('ALL CONTROLS AS EXPECTED' if bad == 0 else f'{bad} CONTROLS WRONG')