"""Run the isolated regression stack in the foreground and always stop children.""" import os, signal, socket, subprocess, time, urllib.request from pathlib import Path root=Path(__file__).resolve().parents[1] os.chdir(root) py=str(root/'calliope-backend/.venv/bin/python') logs=root/'e2e/shots/hel729'; logs.mkdir(parents=True,exist_ok=True) env=os.environ.copy() env['PYTHONPATH']=str(root/'calliope-backend/src') for port in [8247,5173,18188,18189]: with socket.socket() as probe: assert probe.connect_ex(('127.0.0.1',port)) != 0, f'Test port {port} is already in use' # Every run gets fresh disposable state; retain prior evidence instead of deleting it. reference=root/'e2e/shots/reference' if reference.exists():reference.rename(reference.with_name('reference.previous-'+str(time.time_ns()))) processes=[]; handles=[] try: for name,cmd in [('api',[py,'e2e/reference/server.py']),('comfy',[py,'e2e/fake_comfy.py']),('llm',[py,'e2e/reference/fake_llm.py']),('web',['npm','--prefix',os.environ.get('HEL729_WEB_DIR','calliope-web'),'run','dev'])]: h=open(logs/(name+'.log'),'w');handles.append(h);processes.append(subprocess.Popen(cmd,stdout=h,stderr=subprocess.STDOUT,env=env,start_new_session=True)) for url in ['http://127.0.0.1:8247/api/health','http://127.0.0.1:5173']: for i in range(100): try: urllib.request.urlopen(url,timeout=2); break except Exception: if any(p.poll() is not None for p in processes): raise RuntimeError('A test service failed') if i==99:raise time.sleep(.2) for cmd in [[py,'e2e/seed.py'],[py,'e2e/reference/seed.py']]:subprocess.run(cmd,env=env,check=True) failures=[] scripts=os.environ.get('HEL729_TESTS','e2e/hel729.cjs').split(',') for script in scripts: print('RUN',script,flush=True) result=subprocess.run(['node',script],env=env) if result.returncode:failures.append(script) print('FAILED SCRIPTS',failures,flush=True) if failures:raise SystemExit(1) finally: for p in processes: if p.poll() is None:os.killpg(p.pid,signal.SIGTERM) for p in processes: try:p.wait(timeout=10) except subprocess.TimeoutExpired:os.killpg(p.pid,signal.SIGKILL);p.wait() for h in handles:h.close()