"""Real HTTP check for the stateless synthetic Space, not a browser-render test.""" from pathlib import Path import json,os,socket,subprocess,sys,time,urllib.request,urllib.error ROOT=Path(__file__).resolve().parents[1] def main(): with socket.socket() as s:s.bind(('127.0.0.1',0));port=s.getsockname()[1] proc=subprocess.Popen([sys.executable,'-m','uvicorn','app:app','--host','127.0.0.1','--port',str(port)], cwd=ROOT/'space',env=dict(os.environ,PYTHONPATH=str(ROOT)),stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL) base=f'http://127.0.0.1:{port}' try: for _ in range(100): if proc.poll() is not None:raise RuntimeError('demo server exited') try: with urllib.request.urlopen(base+'/health',timeout=1) as r:health=json.load(r) break except OSError:time.sleep(.05) else:raise RuntimeError('demo startup timeout') with urllib.request.urlopen(base+'/',timeout=5) as r: html=r.read().decode();assert 'PHILLNET / RECALL' in html rows=[] for name in ('glossary','intersection','proof-budget','correction'): with urllib.request.urlopen(base+'/demo/'+name,timeout=10) as r: result=json.load(r);result.pop('evidence',None);rows.append(result) with urllib.request.urlopen(base+'/hero.png',timeout=5) as r:assert r.read(8)==b'\x89PNG\r\n\x1a\n' assert rows[0]['target_retrieved'] and rows[1]['answers']==[{'?service':'Beacon'}] assert rows[2]['after_bytes']