Download scripts/space_smoke.py from ayjays132/PhillNet_Recall: direct link, hf CLI and curl.
- Browser
- Download file 2.08 kB
-
https://huggingface.co/ayjays132/PhillNet_Recall/resolve/main/scripts/space_smoke.py
- Command line
-
hf download hf://ayjays132/PhillNet_Recall/scripts/space_smoke.py
-
curl -L -o space_smoke.py https://huggingface.co/ayjays132/PhillNet_Recall/resolve/main/scripts/space_smoke.py
2.08 kB
| """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']<rows[2]['before_bytes'] and not rows[3]['old_certificate_valid_now'] | |
| finally:proc.terminate();proc.wait(10) | |
| report={'transport':'actual localhost HTTP','health':health,'four_scenarios_executed':True,'hero_served':True, | |
| 'private_memory_writes_exposed':False,'server_left_running':False,'browser_rendered':False, | |
| 'docker_built':False,'results':rows} | |
| (ROOT/'reports/space_http.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report,indent=2)) | |
| if __name__=='__main__':main() | |