The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(webapp): run the gateway launch checks on the macOS launch path on every host
emozilla7fc531ca6a8a
diff --git a/tests/gateway/fixtures/webapp_listener_peer.py b/tests/gateway/fixtures/webapp_listener_peer.pyindex f21800b325f..52d6b607323 100644--- a/tests/gateway/fixtures/webapp_listener_peer.py+++ b/tests/gateway/fixtures/webapp_listener_peer.py@@ -1,6 +1,7 @@"""Start the gateway listener with the Webapp on or off; report what a browser and a native client get.-Run as ``python webapp_listener_peer.py on|off <port> <dist>`` with an isolated ``HERMES_HOME``. Writes+Run as ``python webapp_listener_peer.py on|off <port> <dist> [macos]`` with an isolated ``HERMES_HOME``;+``macos`` takes the launch path of macOS and the BSDs on any host. Writes``receipt.json`` there (the gateway redirects stdout). No external inference: the model points at a closedport and no turn is submitted."""@@ -14,6 +15,17 @@ import tracebackSEEDED_TOKEN = "seeded-browser-credential-from-an-earlier-0" # 43 URL-safe characters+def follow_launch_path(platform: str) -> None:+ """Have this gateway take *platform*'s launch path: ``macos`` stands in for macOS and the BSDs,+ where nothing identifies who owns the browser's connection; anything else keeps the host's own."""+ if platform == "macos":+ from gateway import webapp_listener+ from hermes_cli.web_routers import webapp++ webapp_listener._one_use_links_work = lambda: False+ webapp._peer_is_server_user = lambda _request: False++async def _upgrade_refusal(url, **kwargs):"""The HTTP status a refused upgrade answers, or ``"accepted"``."""from websockets.asyncio.client import connect@@ -86,10 +98,11 @@ async def sockets_across_sign_out(runner, client, origin, ask):return report-async def probe(mode, port, dist):+async def probe(mode, port, dist, platform):import httpxfrom websockets.asyncio.client import connect+ from gateway import webapp_listenerfrom gateway.control_socket import GatewayControlServerfrom gateway.run import GatewayRunnerfrom gateway.run_api import stop_gateway_api@@ -99,6 +112,7 @@ async def probe(mode, port, dist):import hermes_cli.webappfrom tests.gateway.fixtures.local_recovery_probe import rpc+ follow_launch_path(platform)home = Path(os.environ["HERMES_HOME"])webapp_block = f"webapp:\n enabled: true\n port: {port}\n" if mode == "on" else ""(home / "config.yaml").write_text(@@ -153,6 +167,7 @@ async def probe(mode, port, dist):url = launched["result"]["url"]report["launch_page"] = url.split("#", 1)[0] == origin + "/webapp/launch"report["launch_private"] = launched["result"]["private"]+ report["launch_printed_for_the_user"] = not webapp_listener._one_use_links_work()ticket = url.split("#ticket=", 1)[1]handoff = {"X-Hermes-Window-Ticket": ticket, "Origin": origin}redeemed = await client.post("/webapp/window-session", headers=handoff)@@ -175,7 +190,8 @@ async def probe(mode, port, dist):def main():receipt = Path(os.environ["HERMES_HOME"]) / "receipt.json"try:- receipt.write_text(json.dumps(asyncio.run(probe(sys.argv[1], int(sys.argv[2]), sys.argv[3]))))+ receipt.write_text(json.dumps(asyncio.run(probe(+ sys.argv[1], int(sys.argv[2]), sys.argv[3], sys.argv[4] if len(sys.argv) > 4 else "this platform"))))except BaseException:receipt.write_text(json.dumps({"error": traceback.format_exc()}))raise SystemExit(1)diff --git a/tests/gateway/test_gateway_serves_webapp.py b/tests/gateway/test_gateway_serves_webapp.pyindex c02959fdf90..cfbeb2c93d1 100644--- a/tests/gateway/test_gateway_serves_webapp.py+++ b/tests/gateway/test_gateway_serves_webapp.py@@ -3,7 +3,9 @@With it on, the dashboard mount serves the Webapp bundle without the session token in the page, thebrowser credential is the one kept in the gateway home (so it survives a restart), the host terminalregistry runs, and a browser holding that credential gets a socket ticket and opens a gateway session-on the same origin. The launcher's link comes over the control socket and spends once; signing out+on the same origin. The launcher's link comes over the control socket and spends once, on this host's+launch path and on that of macOS and the BSDs (taken here on any host), where the link is printed for+the user to open by hand; signing outreplaces the credential and closes the browser sockets it opened, while native clients stayconnected. Each browser socket ticket opens only its own socket. With it off, the listener is main'sprivate one: no Webapp surface, no ticket route, no credential file, no launch link.@@ -25,7 +27,7 @@ def _free_port() -> int:return probe.getsockname()[1]-def _run(tmp_path, mode):+def _run(tmp_path, mode, platform="this platform"):root = Path(__file__).resolve().parents[2]home, user, dist = tmp_path / "state", tmp_path / "user", tmp_path / "dist-webapp"for path in (home, user, dist):@@ -36,16 +38,19 @@ def _run(tmp_path, mode):env.update(HOME=str(user), USERPROFILE=str(user), HERMES_HOME=str(home), PYTHONPATH=str(root),PYTHONUNBUFFERED="1")result = subprocess.run(- [sys.executable, str(root / "tests/gateway/fixtures/webapp_listener_peer.py"), mode, str(port), str(dist)],+ [sys.executable, str(root / "tests/gateway/fixtures/webapp_listener_peer.py"), mode, str(port), str(dist),+ platform],cwd=root, env=env, capture_output=True, text=True, timeout=120, check=False)receipt = home / "receipt.json"assert result.returncode == 0, result.stdout + result.stderr + (receipt.read_text() if receipt.exists() else "")return port, json.loads(receipt.read_text())[email protected](scope="module")-def webapp_on(tmp_path_factory):- return _run(tmp_path_factory.mktemp("webapp-on"), "on")+# Every check runs on this host's launch path and on that of macOS and the BSDs, where nothing tells who+# owns the browser's connection and the launch link is printed for the user to open by hand.[email protected](scope="module", params=["this platform", "macos"])+def webapp_on(request, tmp_path_factory):+ return _run(tmp_path_factory.mktemp("webapp-on"), "on", request.param)@pytest.fixture(scope="module")@@ -85,7 +90,10 @@ def test_a_browser_with_the_credential_opens_a_gateway_session(webapp_on):def test_the_launch_link_from_the_control_socket_hands_over_the_credential_once(webapp_on):port, report = webapp_onassert report["status"] == {"state": "serving", "url": f"http://127.0.0.1:{port}", "reason": None}- assert (report["launch_ok"], report["launch_page"], report["launch_private"]) == (True, True, False)+ assert (report["launch_ok"], report["launch_page"]) == (True, True)+ # Marked private (printed, never handed to a browser launcher) exactly where the platform cannot+ # check who redeems it.+ assert report["launch_private"] is report["launch_printed_for_the_user"]assert (report["handoff_status"], report["handoff_gives_credential"]) == (200, True)assert report["handoff_reuse_status"] == 403