#!/usr/bin/env python3 """Sage's owner-gate runner. Rocko has not run this without the test slot.""" import pathlib,subprocess,os,signal,sys,json root=pathlib.Path(sys.argv[1] if len(sys.argv)>1 else '/mnt/storage/src/mosaic-stack-rocko-147-r1') out=pathlib.Path(__file__).resolve().parent/'gate';out.mkdir(exist_ok=True) steps=[] # Touched packages; Sage may use the repository-wide landing gate instead. for name in ['project','business','cli']: files=[str(f.relative_to(root)) for f in sorted((root/'packages'/name/'tests').glob('*.test.mjs'))] steps.append(('pkg-'+name,['node','--test','--test-concurrency=1','--test-reporter=spec',*files])) for file in sorted((root/'scripts').glob('test-*.sh')):steps.append(('script-'+file.stem,['bash',str(file.relative_to(root))])) results=[] for name,command in steps: env={**os.environ,'DOCKER_HOST':'unix:///nonexistent.sock'} if name in ['script-test-task','script-test-release']:env.pop('DOCKER_HOST',None) with (out/(name+'.log')).open('w') as log: p=subprocess.Popen(command,cwd=root,env=env,stdout=log,stderr=subprocess.STDOUT,start_new_session=True) try:rc=p.wait(timeout=1200) except subprocess.TimeoutExpired:os.killpg(p.pid,signal.SIGKILL);p.wait();rc='timeout' results.append(dict(suite=name,exit=rc,command=command));(out/'results.json').write_text(json.dumps(results,indent=2)+'\n');print(name,rc,flush=True) if rc!=0:sys.exit(1)