The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(webapp): assert the sign-out summary the gateway prints now
Tekniume5ebf04f3a4d
diff --git a/apps/desktop/e2e/core/webapp-gateway-attach.spec.ts b/apps/desktop/e2e/core/webapp-gateway-attach.spec.tsindex 190209b5082..b7bd44a7a40 100644--- a/apps/desktop/e2e/core/webapp-gateway-attach.spec.ts+++ b/apps/desktop/e2e/core/webapp-gateway-attach.spec.ts@@ -456,7 +456,7 @@ test('signing out of a Webapp behind sign-in signs the browser out', async () =>.poll(() => open.every(socket => socket.closed), { timeout: 30_000, message: "sign-out closed the tab's socket" }).toBe(true)expect(signedOut.output).toMatch(/closed [1-9]\d* browser connections?\./)- expect(signedOut.output).toContain('Browsers behind sign-in must sign in again')+ expect(signedOut.output).toContain('Every browser login behind sign-in has ended')expect((await page.request.get(`${origin}/api/sessions`)).status()).toBe(401)await page.reload()await expect(page).toHaveURL(/\/login/, { timeout: 60_000 })diff --git a/tests/hermes_cli/test_webapp_ticket_profile.py b/tests/hermes_cli/test_webapp_ticket_profile.pynew file mode 100644index 00000000000..00c73ce6ea1--- /dev/null+++ b/tests/hermes_cli/test_webapp_ticket_profile.py@@ -0,0 +1,81 @@+"""A Webapp tab's socket answers for the profile its gateway ticket names.++A tab opened on ``?profile=<name>`` mints its ``/api/ws`` ticket with that profile. The socket must+answer a request that names no profile (the sidebar's ``session.active_list``, the silence probe)+for that profile, as a native ticket does, not for the gateway's launch profile: otherwise the tab+cannot see its own running turn and reads it as ended. Its host scope survives, so a request that+names another served profile still reaches it.+"""+from pathlib import Path+from types import SimpleNamespace++import pytest+from fastapi.testclient import TestClient++_TOKEN = "b" * 43+++def two_profiles(monkeypatch, tmp_path):+ from gateway.session_authorities import SessionAuthorities+ from gateway.session_authority import SessionAuthority+ from hermes_cli import web_server as server+ from hermes_state import SessionDB+ from hermes_state_runtime import begin_runtime_epoch++ launch = tmp_path / ".hermes"+ beta = launch / "profiles" / "beta"+ beta.mkdir(parents=True)+ for home in (launch, beta):+ (home / "config.yaml").write_text("{}", encoding="utf-8")+ monkeypatch.setattr(Path, "home", lambda: tmp_path)+ monkeypatch.setenv("HERMES_HOME", str(launch))+ registry = SessionAuthorities(launch, multiplexed=True)+ runner = SimpleNamespace(_draining=False, session_authorities=registry)+ authorities, dbs = {}, []+ for name, home in (("default", launch), ("beta", beta)):+ db = SessionDB(home / "state.db")+ dbs.append(db)+ authorities[name] = SessionAuthority(runner, profile_id=str(home), instance_id="ticket-profile", db=db,+ epoch=begin_runtime_epoch(db, instance_id="ticket-profile"))+ registry.add(home, authorities[name], name=name)+ runner.session_authority = authorities["default"]+ monkeypatch.setattr(server.app.state, "session_authority", authorities["default"], raising=False)+ monkeypatch.setattr(server.app.state, "ui_surface", "webapp", raising=False)+ monkeypatch.setattr(server.app.state, "auth_required", False, raising=False)+ monkeypatch.setattr(server.app.state, "bound_host", "127.0.0.1", raising=False)+ monkeypatch.setattr(server, "_SESSION_TOKEN", _TOKEN)+ try:+ yield TestClient(server.app, base_url="http://127.0.0.1"), launch, beta+ finally:+ for db in dbs:+ db.close()+++def _answering_home(client, profile=None, request_profile=None):+ """The profile home ``runtime.describe`` answers from on a tab socket opened for *profile*."""+ query = f"?profile={profile}" if profile else ""+ minted = client.post(f"/api/webapp/gateway-ticket{query}", headers={"X-Hermes-Session-Token": _TOKEN})+ assert minted.status_code == 200, minted.text+ ticket = minted.json()["ticket"]+ socket_query = f"&profile={profile}" if profile else ""+ params = {"profile": request_profile} if request_profile else {}+ with client.websocket_connect(f"/api/ws?native_dial=browser&ticket={ticket}{socket_query}") as ws:+ ws.send_json({"jsonrpc": "2.0", "id": "describe", "method": "runtime.describe", "params": params})+ while True:+ frame = ws.receive_json()+ if frame.get("id") == "describe":+ assert "result" in frame, frame+ return Path(frame["result"]["profile_id"])+++def test_a_tab_opened_on_a_profile_is_answered_for_it_and_keeps_its_host_scope(two_profiles):+ client, launch, beta = two_profiles+ assert _answering_home(client, profile="beta") == beta+ # The ticket keeps the dashboard gate's host scope: naming the launch profile still reaches it.+ assert _answering_home(client, profile="beta", request_profile="default") == launch+++def test_a_tab_opened_without_a_profile_is_answered_for_the_launch_profile(two_profiles):+ client, launch, _beta = two_profiles+ assert _answering_home(client) == launch