"""Serve built frontend with a read-only proxy to verify progress; no DB writes.""" import http.server,json,pathlib,subprocess,threading,urllib.request,urllib.error,sys root=pathlib.Path(__file__).resolve().parent.parent public=root/'huobao-source/frontend/.output/public' upstream=json.loads((root/'huobao-data/last-launch.json').read_text())['api'].removesuffix('/api/v1') class ReadOnly(http.server.SimpleHTTPRequestHandler): def __init__(self,*args,**kw):super().__init__(*args,directory=str(public),**kw) def log_message(self,*args):pass def do_GET(self): if self.path.startswith(('/api/','/static/')): try: with urllib.request.urlopen(upstream+self.path,timeout=15) as r: data=r.read();self.send_response(r.status);self.send_header('Content-Type',r.headers.get('Content-Type','application/json'));self.end_headers();self.wfile.write(data) except urllib.error.HTTPError as e:self.send_error(e.code) except (ConnectionAbortedError, BrokenPipeError):pass else: if not pathlib.Path(self.translate_path(self.path)).exists():self.path='/index.html' super().do_GET() server=http.server.ThreadingHTTPServer(('127.0.0.1',18938),ReadOnly) threading.Thread(target=server.serve_forever,daemon=True).start() script = sys.argv[1] if len(sys.argv)>1 else 'verify_progress_ui.cjs' if script not in {'verify_progress_ui.cjs','verify_cancel_ui.cjs','verify_english_ui.cjs','verify_video_action_ui.cjs'}:raise ValueError('Unknown UI test') try:subprocess.run(['node',str(root/'integration-work/browser-test'/script)],cwd=root,check=True) finally:server.shutdown()