#!/usr/bin/env python3 """Decision136 builder gate. No live files or services; processes isolated by group.""" import os,pathlib,signal,subprocess,sys,json root=pathlib.Path(sys.argv[1] if len(sys.argv)>1 else '/mnt/storage/src/mosaic-stack-rocko-122');out=pathlib.Path(__file__).resolve().parent/'gate';out.mkdir(exist_ok=True) env={**os.environ,'DOCKER_HOST':'unix:///nonexistent.sock'} steps=[('pkg-'+p,['node','--test','--test-concurrency=1','--test-reporter=spec',*map(str,sorted(pathlib.Path('packages',p,'tests').glob('*.test.mjs')))]) for p in []] # Discover paths from the candidate, not the directory from which the runner is invoked. steps=[] for p in ['business','bus','seat','harness','cli','webui','control-board','conversation','ledger','tasks']: files=[str(f.relative_to(root)) for f in sorted((root/'packages'/p/'tests').glob('*.test.mjs'))] steps.append(('pkg-'+p,['node','--test','--test-concurrency=1','--test-reporter=spec',*files])) # The changed script dispatcher is read by queue and discord; task resolves changed business code. for p in ['queue','discord','task']: steps.append(('script-'+p,['bash','scripts/test-'+p+'.sh'])) results=[] if os.environ.get('GATE_ONLY'): names=set(os.environ['GATE_ONLY'].split(','));steps=[s for s in steps if s[0] in names];results=[r for r in json.loads((out/'results.json').read_text()) if r['suite'] not in names] if len(sys.argv)>2: start=next(i for i,s in enumerate(steps) if s[0]==sys.argv[2]); prior=json.loads((out/'results.json').read_text()); names={s[0] for s in steps[start:]};results=[r for r in prior if r['suite'] not in names];steps=steps[start:] for name,cmd in steps: with (out/(name+'.log')).open('w') as log: step_env=dict(env) if name=='script-task':step_env.pop('DOCKER_HOST',None) child=subprocess.Popen(cmd,cwd=root,env=step_env,stdout=log,stderr=subprocess.STDOUT,start_new_session=True) try:rc=child.wait(timeout=1200) except subprocess.TimeoutExpired:os.killpg(child.pid,signal.SIGKILL);child.wait();rc='timeout' results.append(dict(suite=name,exit=rc,command=cmd));(out/'results.json').write_text(json.dumps(results,indent=2)+'\n');print(name,rc,flush=True) if rc!=0:sys.exit(1)