53 lines
2.6 KiB
Python
53 lines
2.6 KiB
Python
"""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=os.environ.get('HEL732_PYTHON', 'python3')
|
|
logs=root/'e2e/shots/hel732'; 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'
|
|
reuse_fixture=os.environ.get('HEL732_REUSE_FIXTURE')=='1'
|
|
if reference.exists() and not reuse_fixture:reference.rename(reference.with_name('reference.previous-'+str(time.time_ns())))
|
|
mode_path=root/'e2e/fake_mode.json'
|
|
saved_mode=mode_path.read_bytes() if mode_path.exists() else None
|
|
processes=[]; handles=[]
|
|
try:
|
|
for name,cmd in [('api',[py,'e2e/reference/server.py']),('comfy',[py,'e2e/fake_comfy.py']),('llm',[py,'e2e/fake_agent_b4.py']),('web',['npm','--prefix',os.environ.get('HEL732_WEB_DIR',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)
|
|
if not reuse_fixture:
|
|
for cmd in [[py,'e2e/seed.py'],[py,'e2e/reference/seed.py']]:subprocess.run(cmd,env=env,check=True)
|
|
failures=[]
|
|
scripts=os.environ.get('HEL732_TESTS',os.environ.get('HEL729_TESTS','e2e/hel732.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()
|
|
print("STOPPED TEST CHILDREN", [{"pid":p.pid,"exit":p.returncode} for p in processes],flush=True)
|
|
for h in handles:h.close()
|
|
|
|
if saved_mode is not None:mode_path.write_bytes(saved_mode)
|
|
elif mode_path.exists():mode_path.unlink()
|