Files
ARCADIA-Studio/harness/experiments/focus-optical-20261001/evidence/helpers/run-focus-gates.py
T

26 lines
2.3 KiB
Python

from pathlib import Path
import subprocess,json,hashlib,datetime,sys
root=Path('C:/ar-focus-01a0d717');assert Path.cwd().resolve()==root
assert len(sys.argv)==2 and sys.argv[1].startswith('attempt')
out=root/'.local/focus-gates'/sys.argv[1];out.mkdir(parents=True,exist_ok=False)
head=subprocess.check_output(['git','rev-parse','HEAD'],text=True).strip()
assert not subprocess.check_output(['git','status','--porcelain'],text=True).strip()
files=subprocess.check_output(['git','ls-files','Cargo.toml','Cargo.lock','crates'],text=True).splitlines()
source={p:hashlib.sha256((root/p).read_bytes()).hexdigest() for p in files}
records={'source':head,'started':datetime.datetime.now(datetime.timezone.utc).isoformat(),'environment':'Rust1.98.1 gnullvm; LLVM-MinGW20260826UCRT; sharedtarget; jobs1/incremental0','source_inputs':source,'steps':[]}
(out/'initial.json').write_text(json.dumps(records,indent=2)+'\n',encoding='utf-8')
for label,command in [('fmt','cargo fmt --all -- --check'),('focused','cargo test --locked -p oa-desktop -- focus_optical diagram:: --test-threads=1'),('clippy','cargo clippy --locked -p oa-desktop --all-targets -- -D warnings'),('gui-build','cargo build --locked -p oa-desktop --bin arcadia-studio')]:
print(json.dumps({'running':label,'command':command,'source':head}),flush=True)
shell=". 'C:/Users/User/Documents/Git/ARCADIA-Studio/.local/toolchain/env.ps1'; $env:CARGO_BUILD_JOBS='1'; "+command+'; exit $LASTEXITCODE'
start=datetime.datetime.now(datetime.timezone.utc).isoformat()
with (out/(label+'.stdout')).open('xb') as a,(out/(label+'.stderr')).open('xb') as b:
r=subprocess.run(['pwsh','-NoLogo','-NoProfile','-NonInteractive','-Command',shell],cwd=root,stdout=a,stderr=b)
rec={'label':label,'command':command,'exit_code':r.returncode,'start':start,'finished':datetime.datetime.now(datetime.timezone.utc).isoformat(),'stdout_bytes':(out/(label+'.stdout')).stat().st_size,'stderr_bytes':(out/(label+'.stderr')).stat().st_size}
records['steps'].append(rec)
records['inputs_unchanged']=all(hashlib.sha256((root/p).read_bytes()).hexdigest()==h for p,h in source.items())
(out/'result.json').write_text(json.dumps(records,indent=2)+'\n',encoding='utf-8')
print(json.dumps(rec),flush=True)
if r.returncode:raise SystemExit(r.returncode)
assert records['inputs_unchanged']
print('All four declared gates pass on unchanged source inputs',flush=True)