Files
ARCADIA-Studio/harness/experiments/text-workspace-initial-20260913/helpers/verify_saved.py
T
sorokin.oleg.edu 2df7f580aa Make the Text workspace compact and preserve editing context
Replace the oversized header and reference rail with stable editor slots and a retained supporting drawer. Bind diagnostic, result and menu actions to their original publication and visit; preserve effective selections on navigation and dismiss Actions, Find and the drawer one surface per Escape.

Retain exact Windows source captures, eight final gates (871 desktop passes), independent reviews, native selection/rename/recovery trials and the original failures. All 526 tested inputs and staged evidence were byte-checked before commit. Combined preview integration and packaging remain with issue 27; Linux remains paused.
2026-09-12 22:00:36 -07:00

81 lines
4.0 KiB
Python

"""Read-only full saved-model/source and physical-byte comparison after a GUI step."""
from datetime import datetime, timezone
import hashlib
import json
import os
from pathlib import Path
import re
import subprocess
import sys
import time
BASE = Path(__file__).resolve().parent
ROOT = BASE.parents[1]
trial, case, expected, step = sys.argv[1:]
if not re.fullmatch(r'trial-text-[0-9]+', trial):
raise RuntimeError('Invalid trial')
if case not in ['simple', 'representative'] or expected not in ['baseline', 'expected']:
raise RuntimeError('Invalid fixture or expectation')
if not re.fullmatch(r'[a-z0-9-]+', step):
raise RuntimeError('Invalid step')
TRIAL = BASE / trial
launch = json.loads((TRIAL / 'launch.json').read_text(encoding='utf-8'))
def sha(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def inventory(folder):
return {p.relative_to(folder).as_posix(): {'sha256': sha(p), 'bytes': p.stat().st_size}
for p in sorted(folder.rglob('*')) if p.is_file()}
def now():
return datetime.now(timezone.utc).isoformat()
manifest_path = BASE / 'fixture-manifest.json'
if sha(manifest_path) != 'a25651305b23da985eb6d8c637a687a0c4261b5a8c0d8ef84dda95a51fbed931':
raise RuntimeError('Authored fixture manifest changed')
manifest = json.loads(manifest_path.read_text(encoding='utf-8'))
for label, record in manifest['cases'].items():
for variant, key in [('baseline', 'original_files'), ('expected', 'expected_files')]:
if inventory(BASE / label / variant) != record[key]:
raise RuntimeError('Authored expectation changed')
oracle = ROOT / '.local/staged-source-oracle-20260911/staged-source-authoring-contract.exe'
dll = BASE / 'runtime/libunwind.dll'
if sha(oracle) != manifest['oracle_sha256'] or sha(dll) != manifest['dll_sha256']:
raise RuntimeError('Oracle or DLL changed')
if sha(Path(launch['executable'])) != launch['binary']['sha256']:
raise RuntimeError('Native executable changed')
destination = TRIAL / ('verification-' + case + '-' + step)
destination.mkdir()
actual = BASE / case / 'work'
before = inventory(actual)
expectation = manifest['cases'][case]['original_files' if expected == 'baseline' else 'expected_files']
system = os.environ['SystemRoot']
env = {'SystemRoot': system, 'SystemDrive': os.environ['SystemDrive'], 'WINDIR': system,
'PATH': str(dll.parent) + ';' + system + '\\System32;' + system, 'RUST_BACKTRACE': '0'}
command = [str(oracle), 'same', str(BASE / case / expected / 'project.arcadia'), str(actual / 'project.arcadia')]
started, timer = now(), time.perf_counter()
failure = None
code = None
with (destination / 'stdout.log').open('xb') as out, (destination / 'stderr.log').open('xb') as err:
try:
result = subprocess.run(command, cwd=BASE, env=env, stdout=out, stderr=err, timeout=55)
code = result.returncode
except (subprocess.TimeoutExpired, OSError) as error:
failure = {'type': type(error).__name__, 'message': str(error)}
after = inventory(actual)
receipt = {'startedUtc': started, 'finishedUtc': now(), 'seconds': time.perf_counter() - timer,
'command': command, 'environment': env, 'exitCode': code, 'failure': failure,
'scope': 'Saved disk state only; does not inspect the live unsaved GUI model.',
'binarySha256': launch['binary']['sha256'], 'oracleSha256': sha(oracle), 'dllSha256': sha(dll),
'expectedVariant': expected, 'actualFiles': after, 'physicalBytesMatch': before == expectation,
'actualUnchangedByOracle': before == after,
'stdoutSha256': sha(destination / 'stdout.log'), 'stderrSha256': sha(destination / 'stderr.log')}
receipt['passed'] = code == 0 and failure is None and before == expectation and after == before
(destination / 'result.json').write_text(json.dumps(receipt, indent=2) + '\n', encoding='utf-8')
print(json.dumps({'passed': receipt['passed'], 'receipt': str(destination / 'result.json'),
'stdout': (destination / 'stdout.log').read_text(encoding='utf-8', errors='replace')}), flush=True)
if not receipt['passed']:
raise SystemExit(1)