42 lines
2.5 KiB
Python
42 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
# Invoke only after Sage CLEAR; each process runs whole files, serially.
|
|
import json, os, pathlib, subprocess, sys, time
|
|
REPO = pathlib.Path(__file__).resolve().parents[4]
|
|
OUT = REPO / 'agents/magica/work/queue-329/gate'
|
|
OUT.mkdir(exist_ok=True)
|
|
# One short shell-created scratch root per runner invocation, never Python tempfile.
|
|
TMP = subprocess.check_output(['mktemp', '-d', '/mnt/storage/scratch/tmp/XXXXXX'], text=True).strip()
|
|
env = dict(os.environ, TMPDIR=TMP, npm_config_offline='true', MOSAIC_REQUIRE_EDITOR_BUILD='1')
|
|
def nice19(): os.setpriority(os.PRIO_PROCESS, 0, 19)
|
|
def run(label, cmd, cwd=REPO, seconds=1800):
|
|
log = OUT / (label + '.txt')
|
|
start = time.monotonic()
|
|
with log.open('w') as f:
|
|
f.write('command: '+json.dumps(cmd)+'\nTMPDIR: '+TMP+'\n'); f.flush()
|
|
proc = subprocess.Popen(['timeout','-k','10',str(seconds),*cmd], cwd=cwd, env=env, stdout=f, stderr=subprocess.STDOUT, preexec_fn=nice19)
|
|
observed = os.getpriority(os.PRIO_PROCESS, proc.pid)
|
|
f.write('launch nice: '+str(observed)+'\n'); f.flush()
|
|
rc=proc.wait()
|
|
receipt={'label':label,'rc':rc,'nice':observed,'seconds':round(time.monotonic()-start,2),'log':str(log.relative_to(REPO))}
|
|
with (OUT/'runs.jsonl').open('a') as f: f.write(json.dumps(receipt)+'\n')
|
|
print(json.dumps(receipt),flush=True)
|
|
return rc
|
|
mode=sys.argv[1] if len(sys.argv)>1 else ''
|
|
if mode=='install':
|
|
for label,cwd in [('npm-root',REPO),('npm-webui',REPO/'packages/webui')]:
|
|
if run(label,['npm','ci','--offline','--ignore-scripts','--no-audit','--no-fund'],cwd,600): sys.exit(1)
|
|
elif mode=='new':
|
|
for p in sorted((REPO/'packages/model-proxy/tests').glob('*.test.mjs')):
|
|
if run('model-proxy-'+p.stem,['node','--test',str(p)]): sys.exit(1)
|
|
for suite in ['bus','cli']:
|
|
p=REPO/f'packages/{suite}/tests/model-proxy.test.mjs'
|
|
if run(suite+'-model-proxy.test',['node','--test',str(p)]): sys.exit(1)
|
|
elif mode=='gate':
|
|
for suite in ['model-proxy','bus','cli']:
|
|
for p in sorted((REPO/f'packages/{suite}/tests').glob('*.test.mjs')):
|
|
if run(suite+'-'+p.stem,['node','--test',str(p)]): sys.exit(1)
|
|
if run('webui-pinned-copy.test',['node','--test',str(REPO/'packages/webui/tests/pinned-copy.test.mjs')]):sys.exit(1)
|
|
for script in ['test-config.sh','test-federation-acceptance.sh']:
|
|
if run(script,['bash',str(REPO/'scripts'/script)],seconds=600):sys.exit(1)
|
|
else: raise SystemExit('choose install, new or gate only after CLEAR')
|