Files
ARCADIA-Studio/harness/experiments/behavior-creation-native-20260911/verify.py
T

94 lines
5.2 KiB
Python

"""Read only frozen checkpoints; run the existing v2 oracle without compiling."""
from pathlib import Path
import datetime
import hashlib
import json
import os
import subprocess
import time
ROOT = Path(__file__).resolve().parents[3]
OUT = Path(__file__).resolve().parent
STAGE = ROOT / '.local/native-qa/behavior-20260911-v4'
BASE = ROOT / '.local/native-qa/palette-20260910-v3/checkpoint-transition-reopen'
EXE = ROOT / '.local/behavior-creation-oracle-20260911/behavior-creation-contract-v2.exe'
def record(path):
data = path.read_bytes()
return {'path': path.relative_to(ROOT).as_posix(), 'bytes': len(data),
'sha256': hashlib.sha256(data).hexdigest()}
def inventory(directory):
return {p.relative_to(directory).as_posix(): {
'bytes': p.stat().st_size, 'sha256': hashlib.sha256(p.read_bytes()).hexdigest()
} for p in sorted(directory.rglob('*')) if p.is_file()}
def entry(directory):
return str(directory / 'project.arcadia')
checkpoints = {'baseline': BASE}
for family in ('process', 'scenario', 'machine'):
for suffix in ('', '-undo', '-redo'):
checkpoints[family + suffix] = STAGE / ('checkpoint-' + family + suffix)
checkpoints['creation-reopen'] = STAGE / 'checkpoint-creation-reopen'
before = {name: inventory(path) for name, path in checkpoints.items()}
artifacts = [record(p) for p in (
EXE, ROOT / 'harness/behavior-creation-contract.rs', Path(__file__),
STAGE / 'bin/arcadia-studio.exe', STAGE / 'bin/libunwind.dll',
STAGE / 'bin/manifest.json', STAGE / 'baseline-source-manifest.json',
STAGE / 'cancel-save-verification.json', STAGE / 'scenario-empty-saved.png',
STAGE / 'machine-created-saved.png')]
assert artifacts[0]['sha256'] == '056eefd444924916bf6ac3c4897ab2ff4a8a4bb892e1dbc16adad32e59bf6a36'
assert artifacts[1]['sha256'] == '51ab2ffa1826dd949b79f3a9690042a2f9e38daf9ed91517cade3861482117ba'
commands = [('self-check', ['self-check', entry(BASE)]),
('baseline', ['check', 'baseline', entry(BASE), entry(BASE), entry(BASE)])]
previous = BASE
for family in ('process', 'scenario', 'machine'):
first = checkpoints[family]
commands.extend([
(family, ['check', family, entry(BASE), entry(first), entry(first)]),
(family + '-undo', ['same', entry(previous), entry(checkpoints[family + '-undo']), entry(first)]),
(family + '-redo', ['check', family, entry(BASE), entry(checkpoints[family + '-redo']), entry(first)])])
previous = first
commands.extend([
('reopen-contract', ['check', 'machine', entry(BASE), entry(checkpoints['creation-reopen']), entry(checkpoints['machine'])]),
('reopen-exact-redo', ['same', entry(checkpoints['machine-redo']), entry(checkpoints['creation-reopen'])])])
env = os.environ.copy()
env['PATH'] = str(STAGE / 'bin') + os.pathsep + env.get('PATH', '')
started = datetime.datetime.now(datetime.timezone.utc).isoformat()
results = []
for label, args in commands:
t = time.perf_counter()
command = [str(EXE), *args]
run = subprocess.run(command, cwd=ROOT, env=env, capture_output=True, text=True, encoding='utf-8', errors='replace', timeout=60)
results.append({'label': label, 'command_argv': command, 'exit_code': run.returncode,
'elapsed_seconds': round(time.perf_counter() - t, 6),
'stdout': run.stdout, 'stderr': run.stderr})
after = {name: inventory(path) for name, path in checkpoints.items()}
redo_files = checkpoints['machine-redo']
reopen_files = checkpoints['creation-reopen']
same_names = set(before['machine-redo']) == set(before['creation-reopen'])
byte_results = {name: (redo_files / name).read_bytes() == (reopen_files / name).read_bytes()
for name in before['machine-redo'] if (reopen_files / name).is_file()}
success = (all(r['exit_code'] == 0 for r in results) and before == after
and same_names and all(byte_results.values()))
log = '\n\n'.join(f"[{r['label']}] argv={json.dumps(r['command_argv'])}\nexit={r['exit_code']} elapsed={r['elapsed_seconds']}s\nstdout:\n{r['stdout']}stderr:\n{r['stderr']}" for r in results)
(OUT / 'commands-results.log').write_text(log + '\n', encoding='utf-8', newline='\n')
manifest = {'reviewer': 'Codex-9e8r6t /root/palette_finish', 'started_utc': started,
'finished_utc': datetime.datetime.now(datetime.timezone.utc).isoformat(),
'scope': 'Frozen checkpoints only; no live work/profile/UI access or compilation.',
'artifacts': artifacts, 'checkpoints': {name: {'path': path.relative_to(ROOT).as_posix(), 'files': before[name]} for name, path in checkpoints.items()},
'commands': results, 'all_checkpoint_files_unchanged': before == after,
'machine_redo_reopen_inventory_equal': same_names,
'machine_redo_reopen_direct_byte_comparisons': byte_results,
'log': record(OUT / 'commands-results.log'), 'pass': success}
(OUT / 'manifest.json').write_text(json.dumps(manifest, indent=2) + '\n', encoding='utf-8', newline='\n')
print(json.dumps({'pass': success, 'commands_passed': sum(r['exit_code'] == 0 for r in results),
'commands_total': len(results), 'unchanged_checkpoints': before == after,
'reopen_exact_files': len(byte_results), 'manifest': record(OUT / 'manifest.json')}))
raise SystemExit(0 if success else 1)