Files
stack/agents/filbert/work/queue-90/r2/gate.py
T

45 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Full row 90 round 2 gate. Wait for Sage's slot-clear before executing."""
import os, subprocess, signal, pathlib, json, hashlib, datetime
root=pathlib.Path.home()/'filbert-scratch/r90-r2-review/wt'
out=root.parent/'gate';out.mkdir(exist_ok=True)
env=dict(os.environ,TMPDIR=str(pathlib.Path.home()/'filbert-scratch/tmp'),DOCKER_HOST='unix:///nonexistent.sock')
seats=['darkwing','dewey','rocko','researcher','sage']
other=[str(pathlib.Path.home()/f'{seat}-scratch') for seat in seats]+[str(pathlib.Path('/mnt/storage/scratch')/seat) for seat in seats]
def quiet():
busy=[]
for p in pathlib.Path('/proc').iterdir():
if not p.name.isdigit():continue
try:
cwd=str((p/'cwd').resolve(strict=True))
if any(cwd==x or cwd.startswith(x+'/') for x in other):busy.append((p.name,cwd))
except (OSError,RuntimeError):pass
if busy:raise SystemExit('Other scratch processes active: '+repr(busy))
def matches():
m=pathlib.Path('/mnt/storage/src/mosaic-stack/agents/dewey/work/queue-90/r2/candidate-manifest.sha256')
for line in m.read_text().splitlines():
sha,path=line.split();assert hashlib.sha256((root/path).read_bytes()).hexdigest()==sha,path
quiet();matches();rows=[]
def run(cmd,cwd,log):
quiet();start=datetime.datetime.now(datetime.timezone.utc).isoformat()
with log.open('w') as f:
p=subprocess.Popen(cmd,cwd=cwd,env=env,stdout=f,stderr=subprocess.STDOUT,start_new_session=True)
try:p.wait(timeout=300);rc=p.returncode
except subprocess.TimeoutExpired:
try:os.killpg(p.pid,signal.SIGKILL)
except ProcessLookupError:pass
p.wait();rc='timeout'
return rc,start
for package in ['tasks','bus','harness','webui','cli','business','seat','control-board']:
cwd=root/'packages'/package
files=['tests/'] if package in ['seat','webui'] else [str(p.relative_to(cwd)) for p in sorted((cwd/'tests').glob('*.test.mjs'))]
log=out/f'node-{package}.log';rc,start=run(['node','--test',*files],cwd,log)
stats=[s for s in log.read_text().splitlines() if s.startswith(('ℹ tests ','ℹ pass ','ℹ fail ','# tests ','# pass ','# fail '))]
row={'suite':package,'rc':rc,'started':start,'stats':stats};rows.append(row);print(json.dumps(row),flush=True)
(out/'summary.json').write_text(json.dumps(rows,indent=2)+'\n')
for script in sorted((root/'scripts').glob('test-*.sh')):
log=out/f'{script.stem}.log';rc,start=run(['bash',str(script)],root,log)
row={'suite':script.stem,'rc':rc,'started':start,'last':log.read_text().splitlines()[-1:]};rows.append(row);print(json.dumps(row),flush=True)
(out/'summary.json').write_text(json.dumps(rows,indent=2)+'\n')
matches();print('manifest 21/21 after full gate',flush=True)
raise SystemExit(any(r['rc']!=0 for r in rows))