Files
ARCADIA-Studio/harness/experiments/connection-layout-reference-20260925/run-reference-local.py
T

53 lines
2.8 KiB
Python

"""Bound each frozen reference case in a separate process and preserve all outcomes."""
from pathlib import Path
import datetime, hashlib, json, subprocess, sys, time
local = Path(__file__).resolve().parent
root = local / 'elk-reference-20260925'
node = Path('C:/Users/User/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node.exe')
script = root / 'reference_probe.cjs'
source = local / 'routing-corpus-runs-20260925/geometry-released/stdout.jsonl'
manifest = local / 'auto-layout-20260925/harness/experiments/routing-independent-20260925/corpus/manifest.json'
output = root / sys.argv[1]
assert output.parent == root and output.name == sys.argv[1]
output.mkdir(exist_ok=False)
def record(path):
return {'path':str(path), 'bytes':path.stat().st_size,
'sha256':hashlib.sha256(path.read_bytes()).hexdigest()}
bound = [node, script, source, manifest, root/'lib/elk.bundled.js', root/'dependency-receipt.json',
local/'connection-layout-reference-plan-20260925.md', Path(__file__)]
before = [record(p) for p in bound]
assert before[2]['sha256'] == '9a31a676f23dea2f41daec39497f569d68231fa0fd66e5a1a476be97d5d61ac2'
assert before[3]['sha256'] == 'a58a6956e26b414e88fafd4fdb92e006050653a4149178f08df84128e3917717'
assert before[4]['sha256'] == '1222e44f953ce7746af23801e723708f8e6f436b8b377a6a5fc7552f34a307b3'
cases = [c['name'] for c in json.loads(manifest.read_text())['cases']]
receipts = []
for case in cases:
case_output = output / case
stdout = output / (case+'.stdout.log')
stderr = output / (case+'.stderr.log')
argv = [str(node), str(script), case, str(case_output)]
started = datetime.datetime.now(datetime.timezone.utc).isoformat()
start = time.perf_counter()
timed_out = False
with stdout.open('xb') as out, stderr.open('xb') as err:
try:
completed = subprocess.run(argv, cwd=root, stdout=out, stderr=err, timeout=90)
code = completed.returncode
except subprocess.TimeoutExpired:
timed_out = True
code = None
receipt = {'case':case, 'argv':argv, 'started_utc':started,
'elapsed_seconds':time.perf_counter()-start, 'timeout_seconds':90,
'timed_out':timed_out, 'exit_code':code, 'stdout':record(stdout), 'stderr':record(stderr)}
receipts.append(receipt)
(output/(case+'.receipt.json')).write_text(json.dumps(receipt,indent=2)+'\n')
print(json.dumps(receipt), flush=True)
after = [record(p) for p in bound]
receipt = {'inputs_before':before, 'inputs_after':after, 'inputs_unchanged':before==after,
'cases':receipts, 'scope':'Reference-engine adapter execution; exit0 is not geometry or production acceptance.'}
(output/'receipt.json').write_text(json.dumps(receipt,indent=2)+'\n')
assert before == after, 'Bound inputs changed during experiment'