59 lines
3.4 KiB
Python
59 lines
3.4 KiB
Python
"""Preserve a real GUI Save checkpoint and run the unchanged independent oracle."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('trial', choices=['lifeline', 'machine'])
|
|
parser.add_argument('checkpoint', choices=['first', 'undo', 'redo', 'reopen', 'cancelled'])
|
|
args = parser.parse_args()
|
|
root = Path(__file__).resolve().parents[2]
|
|
stage = root/'.local/native-qa/contextual-source-20260911-v2'/args.trial
|
|
prior = root/'.local/native-qa/contextual-source-20260911-v1'
|
|
base = root/'harness/fixtures/staged-source-authoring/base'
|
|
oracle = root/'.local/staged-source-oracle-20260911/staged-source-authoring-contract.exe'
|
|
runtime = prior/'bin'
|
|
digest = lambda p: hashlib.sha256(p.read_bytes()).hexdigest().upper()
|
|
assert digest(oracle) == '967D9BA3C6FB3A7EFB410833903EC94556CA2D48A67D5072C8BB160F40A00F9C'
|
|
assert digest(runtime/'libunwind.dll') == 'F45604A12E8BCD839FD86F667C1BE1CC7C4F9DA2B3C69FF381AC708F0E1AE7D4'
|
|
destination = stage/('checkpoint-'+args.checkpoint)
|
|
assert not destination.exists(), 'Refuse to overwrite a checkpoint'
|
|
source = stage/('cancelled-copy' if args.checkpoint == 'cancelled' else 'work')
|
|
assert source.is_dir() and (source/'project.arcadia').is_file()
|
|
assert all(not p.is_symlink() for p in source.rglob('*'))
|
|
shutil.copytree(source, destination)
|
|
entry = lambda p:str(p/'project.arcadia')
|
|
first = stage/'checkpoint-first'
|
|
commands = []
|
|
if args.checkpoint == 'cancelled':
|
|
assert args.trial == 'lifeline'
|
|
commands.append(['same', entry(base), entry(destination)])
|
|
elif args.checkpoint == 'undo':
|
|
commands.append(['same', entry(base if args.trial == 'lifeline' else prior/'checkpoint-chain'), entry(destination), entry(first)])
|
|
elif args.trial == 'lifeline':
|
|
commands.append(['check', 'lifeline', entry(base), entry(destination), entry(first)])
|
|
else:
|
|
commands.append(['check', 'machine', entry(base), entry(destination), entry(prior/'checkpoint-lifeline'), entry(prior/'checkpoint-chain'), entry(first)])
|
|
if args.checkpoint == 'reopen':
|
|
commands.append(['same', entry(stage/'checkpoint-redo'), entry(destination)])
|
|
env = dict(os.environ)
|
|
system_root = next(v for k,v in env.items() if k.upper() == 'SYSTEMROOT')
|
|
env['PATH'] = str(runtime)+';'+system_root+'\\System32;'+system_root
|
|
results = []
|
|
for index, command in enumerate(commands, 1):
|
|
log = stage/(args.checkpoint+'-check-'+str(index)+'.log')
|
|
assert not log.exists()
|
|
result = subprocess.run([str(oracle), *command],env=env,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
|
|
log.write_bytes(result.stdout)
|
|
results.append({'args':command, 'exitCode':result.returncode, 'log':log.name})
|
|
record = {'scope':'Independent complete model, raw source, original identity and physical-file contract', 'trial':args.trial,'checkpoint':args.checkpoint,'oracleSha256':digest(oracle),'checks':results,'files':[{'path':p.relative_to(destination).as_posix(),'bytes':p.stat().st_size,'sha256':digest(p)} for p in sorted(destination.rglob('*')) if p.is_file()]}
|
|
(stage/(args.checkpoint+'-result.json')).write_text(json.dumps(record,indent=2)+'\n',encoding='utf8')
|
|
for result in results:
|
|
print((stage/result['log']).read_text(encoding='utf8'), end='')
|
|
assert all(result['exitCode'] == 0 for result in results), 'Oracle failure preserved'
|
|
print(json.dumps({'state':'pass','trial':args.trial,'checkpoint':args.checkpoint,'files':len(record['files']),'checks':len(results)}))
|