Files
aigc-home/e2e/run-hel849.py
T
2026-10-25 20:26:23 +08:00

54 lines
3.0 KiB
Python

"""Own a loopback-only API, static web and fake model for one foreground check."""
import json, os, signal, socket, subprocess, sys, tempfile, time, urllib.request
from pathlib import Path
root = Path(__file__).resolve().parents[1]
os.chdir(root)
out = root.parent / 'evidence/hel849'
out.mkdir(parents=True, exist_ok=True)
phase = os.environ.get('HEL849_PHASE', 'after')
for port in [18259, 15259, 19259]:
with socket.socket() as s:
assert s.connect_ex(('127.0.0.1', port)) != 0, f'Port occupied: {port}'
processes, handles = [], []
cleanup = []
with tempfile.TemporaryDirectory(prefix='runtime-', dir=out) as tmp:
env = {**os.environ, 'PYTHONPATH': str(root/'calliope-backend/src'), 'HEL849_DATA': tmp}
api = """import os
from pathlib import Path
from calliope import config
root=Path(os.environ['HEL849_DATA'])
config.CONFIG_FILE=root/'settings.json'
config.settings=config.Settings(data_dir=root/'data',assets_dir=root/'data/assets',llm_base_url='http://127.0.0.1:19259/v1',llm_model='isolated',comfyui_base_url='http://127.0.0.1:1',dry_run=False)
config.settings.ensure_storage_dirs();config.settings.ensure_llm_profiles();config.settings.save_config_file()
from calliope.main import create_app
import uvicorn
uvicorn.run(create_app(),host='127.0.0.1',port=18259)
"""
web = (root/'e2e/hel818-web.cjs').read_text().replace('18247','18259').replace('15173','15259')
model = (root/'e2e/reference/fake_llm.py').read_text().replace("root=Path(__file__).resolve().parents[1]/'shots/reference'", 'root=Path('+repr(tmp)+')').replace('18189','19259')
try:
for name, cmd in [('api',[sys.executable,'-c',api]),('web',['node','-e',web]),('model',[sys.executable,'-c',model])]:
h=(out/f'{phase}-{name}.log').open('w');handles.append(h)
processes.append(subprocess.Popen(cmd, env=env, stdout=h, stderr=subprocess.STDOUT))
for url in ['http://127.0.0.1:18259/api/health','http://127.0.0.1:15259']:
for attempt in range(100):
try: urllib.request.urlopen(url,timeout=1);break
except Exception:
if any(p.poll() is not None for p in processes):raise RuntimeError('Service failed')
if attempt==99:raise
time.sleep(.1)
subprocess.run(['node','e2e/hel849.cjs'],env=env,check=True)
finally:
daemon=json.loads(subprocess.check_output(['multica','daemon','status','--output','json']))['pid']
for p in processes:
assert p.pid != daemon
if p.poll() is None:p.send_signal(signal.SIGTERM)
for p in processes:
try:p.wait(timeout=10)
except subprocess.TimeoutExpired:p.kill();p.wait()
cleanup.append({'pid':p.pid,'exit':p.returncode,'daemon':daemon})
for h in handles:h.close()
(out/f'{phase}-cleanup.json').write_text(json.dumps({'children':cleanup,'isolated_data_removed':not Path(tmp).exists()},indent=2))
print('CLEANUP',cleanup,'isolated data removed',not Path(tmp).exists(),flush=True)