| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/usr/bin/env python3
- """Run the public Qt-clean validator against an in-process simulated server."""
- import asyncio
- import os
- from pathlib import Path
- import sys
- import tempfile
- ROOT = Path(__file__).resolve().parents[1]
- sys.path.insert(0, str(ROOT / "src"))
- from stl_backend.config import load_settings
- from stl_backend.server import start_server
- from stl_backend.web_gateway import WebGateway
- async def main():
- with tempfile.TemporaryDirectory(prefix="qt-clean-smoke-") as directory:
- settings = load_settings(ROOT / "config/simulated.json")
- settings.update(listen="127.0.0.1:0", data_dir=directory, telemetry_interval_s=.1)
- settings["stations"] = settings["stations"][:1]
- server, bench, grpc_port = await start_server(settings)
- gateway = WebGateway(bench.grpc_service, "127.0.0.1", 0,
- ROOT / "src/stl_backend/web")
- try:
- await gateway.start()
- port = gateway.server.sockets[0].getsockname()[1]
- output = Path(directory) / "protocol.json"
- child = await asyncio.create_subprocess_exec(sys.executable, "-B",
- str(ROOT / "validation/validate_qt_clean.py"), "--url",
- f"ws://127.0.0.1:{port}/ws?view=qt-clean", "--station", "S1",
- "--output", str(output), "--grpc-address", f"127.0.0.1:{grpc_port}",
- "--backend-source", str(ROOT),
- stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT,
- cwd=ROOT, env=os.environ.copy())
- stdout, _ = await asyncio.wait_for(child.communicate(), timeout=45)
- print(stdout.decode("utf-8", errors="replace"), end="")
- raise SystemExit(child.returncode)
- finally:
- await gateway.stop()
- await server.stop(0)
- await bench.grpc_service.drain()
- await bench.close()
- if __name__ == "__main__":
- asyncio.run(main())
|