"""Snapshot a native acceptance copy and compare its complete source/model.""" from pathlib import Path from datetime import datetime, timezone import hashlib import json import os import shutil import subprocess import sys root = Path(__file__).resolve().parent.parent trial = root / '.local/native-qa/lifecycle-palette-20260913-01' name, fixture = sys.argv[1:] assert name.replace('-', '').isalnum() entries = {'compact': 'project.arcadia', 'lifecycle': 'lifecycle-native.arcadia', 'topology': 'project.arcadia'} entry = entries[fixture] source, baseline = (trial / (fixture + suffix) for suffix in ('-work', '-baseline')) dest = trial / 'checkpoints' / name receipt = trial / 'evidence' / (name + '.json') log = trial / 'evidence' / (name + '.log') assert not dest.exists() and not receipt.exists() and not log.exists() launch = json.loads((trial / 'launch.json').read_bytes()) assert launch['source'] == 'dd39e1fdc13f04f18975a70736d2ed7f752a6df2' checker = root / '.local/native-qa/delete-oracle-warning-fix-42511f0/delete-oracle-warning-fix-42511f0.exe' assert hashlib.sha256(checker.read_bytes()).hexdigest() == '9796aa73544c6414003e6230a668a6cf1435978a310187ef2560af67e35f3466' runtime = root / '.local/toolchain/llvm-mingw-20260908-ucrt-x86_64/bin' assert hashlib.sha256((runtime / 'libunwind.dll').read_bytes()).hexdigest() == 'aa282fa47bb2c4e210cea5e470cdbdca58568f0be0bc73e404d86ab9cd95ef6a' scoped = json.loads((trial / 'topology-admission-42511f0-r1/verified-current-core-config-inputs.json').read_bytes()) assert len(scoped) == 110 for item in scoped: raw = (root / item['path']).read_bytes() assert len(raw) == item['bytes'] and hashlib.sha256(raw).hexdigest() == item['sha256'] shutil.copytree(source, dest) command = [str(checker), 'same', str(baseline / entry), str(dest / entry)] env = os.environ.copy() env['PATH'] = str(runtime) + os.pathsep + env.get('PATH', '') start = datetime.now(timezone.utc).isoformat() run = subprocess.run(command, cwd=root, env=env, capture_output=True) files = [] for path in sorted(dest.rglob('*')): if path.is_file(): relative = path.relative_to(dest) raw = path.read_bytes() assert (source / relative).read_bytes() == raw files.append({'path': relative.as_posix(), 'bytes': len(raw), 'sha256': hashlib.sha256(raw).hexdigest(), 'baseline_equal': (baseline / relative).read_bytes() == raw}) with log.open('xb') as stream: stream.write(run.stdout + run.stderr) record = {'start': start, 'end': datetime.now(timezone.utc).isoformat(), 'gui_source': launch['source'], 'gui_sha256': launch['sha256'], 'snapshot': str(dest), 'command': command, 'exit': run.returncode, 'oracle_sha256': hashlib.sha256(checker.read_bytes()).hexdigest(), 'runtime_directory': str(runtime), 'verified_core_inputs': len(scoped), 'files': files, 'scope': 'Whole Project and exact SourceBundle comparison. Native actions are recorded separately.'} with receipt.open('x', encoding='utf-8', newline='\n') as stream: stream.write(json.dumps(record, indent=2) + '\n') print(run.stdout.decode('utf-8', errors='replace')) print(json.dumps({'receipt': str(receipt), 'exit': run.returncode, 'files': len(files), 'all_baseline_equal': all(item['baseline_equal'] for item in files)})) sys.exit(run.returncode)