Skip to content

The agent that grows with you

test: pin /browser connect as browser.manage in Desktop and LOCAL for API-created sessions

Tekniumbea0df016674
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/browser-manage.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/browser-manage.test.tsx
new file mode 100644
index 00000000000..ab3d90ed178
--- /dev/null
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/browser-manage.test.tsx
@@ -0,0 +1,58 @@
+import { cleanup } from '@testing-library/react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+
+import { $connection, setSessions } from '@/store/session'
+
+import { actRender, Harness, type HarnessHandle, RUNTIME_SESSION_ID, sessionInfo } from './index-test-utils'
+import { clearSingleFlightSessionResumeState } from './single-flight-resume'
+
+vi.mock('@/hermes', () => ({
+ getLatestSessionMessages: vi.fn(async () => ({ messages: [], session_id: 'session' })),
+ getProfiles: vi.fn(async () => ({ profiles: [] })),
+ getSession: vi.fn(),
+ PROMPT_SUBMIT_REQUEST_TIMEOUT_MS: 1_800_000,
+ setApiRequestProfile: vi.fn(),
+ transcribeAudio: vi.fn()
+}))
+
+vi.mock('@/store/gateway', async importOriginal => ({
+ ...(await importOriginal<Record<string, unknown>>()),
+ requestGatewayForAgent: vi.fn()
+}))
+
+describe('usePromptActions /browser connect|disconnect', () => {
+ beforeEach(() => {
+ clearSingleFlightSessionResumeState()
+ setSessions(() => [sessionInfo()])
+ })
+
+ afterEach(() => {
+ cleanup()
+ $connection.set(null)
+ vi.restoreAllMocks()
+ })
+
+ // #134889 TUI-14: on a local connection /browser connect|disconnect go to the gateway as
+ // browser.manage (never slash.exec); the gateway owns any refusal.
+ it.each([
+ ['/browser connect', { action: 'connect', session_id: RUNTIME_SESSION_ID, url: 'http://127.0.0.1:9222' }],
+ ['/browser disconnect', { action: 'disconnect', session_id: RUNTIME_SESSION_ID }]
+ ])('%s on a local connection is sent as browser.manage', async (text, params) => {
+ $connection.set({ connectionId: 'local', mode: 'local' } as never)
+ const requestGateway = vi.fn(async () => ({ connected: false }) as never)
+
+ let handle: HarnessHandle | null = null
+ await actRender(
+ <Harness
+ onReady={h => (handle = h)}
+ refreshSessions={vi.fn(async () => undefined)}
+ requestGateway={requestGateway}
+ />
+ )
+
+ await handle!.submitText(text)
+
+ expect(requestGateway).toHaveBeenCalledWith('browser.manage', expect.objectContaining(params))
+ expect(requestGateway).not.toHaveBeenCalledWith('slash.exec', expect.anything())
+ })
+})
diff --git a/tests/gateway/test_gateway_api_session_platform.py b/tests/gateway/test_gateway_api_session_platform.py
new file mode 100644
index 00000000000..167ecaf7db4
--- /dev/null
+++ b/tests/gateway/test_gateway_api_session_platform.py
@@ -0,0 +1,50 @@
+"""#134889 T22: a session created over the gateway's own API is platform ``LOCAL`` whether the client
+is on this host or remote (Desktop -> remote gateway). The platform is not renamed (stored rows and
+shipped client filters read ``LOCAL``); the connection's mode is what tells a remote client apart:
+``AuthorityConnection.native_owner`` (a ticket minted over the private control socket), carried
+into the frozen policy as ``client_local`` / ``client_env_remote``. Real SessionStore /
+SessionAuthority / AuthorityConnection."""
+import json
+
+import pytest
+
+from tests.gateway.test_finite_unattended_wire_grant import CAPS
+from tests.gateway.test_session_follow_profile_config import _owner
+
+
+def _connection(authority, user, *, native):
+ from gateway.session_controls import AuthorityConnection
+ identity = {'user_id': user, 'provider': 'local' if native else 'fixture', 'profile_id': authority.profile_id,
+ 'instance_id': authority.instance_id, 'capabilities': CAPS}
+ if native:
+ identity['native_bootstrap'] = True
+ return AuthorityConnection(authority, object(), identity)
+
+
+async def test_api_created_sessions_are_local_and_the_connection_mode_marks_remote(monkeypatch):
+ from gateway import run
+ from gateway.config import Platform
+ from hermes_constants import get_hermes_home
+ home = get_hermes_home()
+ home.mkdir(parents=True, exist_ok=True)
+ monkeypatch.setattr(run, '_hermes_home', home)
+ (home / 'config.yaml').write_text(json.dumps({'model': {'provider': 'custom', 'default': 'm',
+ 'base_url': 'http://127.0.0.1:1/v1'}}))
+ _store, _runner, authority, _dashboard = _owner(home)
+ monkeypatch.setattr(authority, '_schedule', lambda ref: None)
+ local, remote = _connection(authority, 'here', native=True), _connection(authority, 'away', native=False)
+ assert (local.native_owner, remote.native_owner) == (True, False)
+ created = {}
+ for name, connection in (('local', local), ('remote', remote)):
+ reply = await connection.dispatch({'id': name, 'method': 'session.create', 'params': {
+ 'request_id': name, 'source': 'gui', 'cwd': str(home), 'toolsets': [],
+ 'client_env': {'PATH': '/usr/bin'}}})
+ assert 'result' in reply, reply
+ sid = reply['result']['session_id']
+ source = authority.sessions[sid].source
+ from gateway.session_local_recovery import local_adapter_map
+ policy = local_adapter_map(authority)[Platform.LOCAL].policies[source.chat_id]
+ created[name] = (source.platform, policy.client_env_remote)
+ # Same platform either way; only the connection-derived policy flag differs.
+ assert created == {'local': (Platform.LOCAL, False), 'remote': (Platform.LOCAL, True)}