The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(gateway): pin that a sibling answer needs the session's own attachment
unsupportedpastels7122521b9cee
diff --git a/tests/gateway/test_sibling_server_request_response.py b/tests/gateway/test_sibling_server_request_response.pyindex 746578f137d..1a11ebb8b79 100644--- a/tests/gateway/test_sibling_server_request_response.py+++ b/tests/gateway/test_sibling_server_request_response.py@@ -23,51 +23,76 @@ class _Transport:@pytest.mark.asyncioasync def test_host_socket_answers_a_sibling_profiles_sudo_request(tmp_path, monkeypatch):"""The Desktop's shared-primary socket chats on profile beta and answers beta's ``sudo`` request with- a response frame (which carries no profile): the waiting tool gets the password, not a timeout."""+ a response frame (which carries no profile): the waiting tool gets the password, not a timeout. A+ second socket's beta session stays its own: the first socket's beta sibling is not attached there,+ so its answer to that request id is refused and the owning socket's answer settles it."""from gateway.run_runtime import initialize_gateway_runtimefrom gateway.runtime_ownership import process_ownershipfrom gateway.session_authorities import authority_for_profile_id, owner_scopefrom gateway.session_controls import AuthorityConnection- from gateway.session_server_requests import ask_viewer+ from gateway.session_server_requests import ask_viewer, waitingroot, homes = _reserve_homes(tmp_path, monkeypatch)process_ownership.reserve([home for _, home in homes])- connection, runner = None, None+ connections, runner = [], Nonetry:runner = _runner(root, homes)await initialize_gateway_runtime(runner)store = runner.session_ticket_store- ticket = store.mint(profile_id=str(root.resolve()), subject='uid:desk', purpose='interactive', scope='host')- grant = store.redeem(ticket, profile_id=None, purpose='interactive')- launch = authority_for_profile_id(runner, grant['profile_id'])- identity = {'user_id': grant['subject'], 'provider': 'local', 'profile_id': grant['profile_id'],- 'instance_id': grant['instance_id'], 'capabilities': grant['capabilities'],- 'native_bootstrap': True, 'profile_scope': 'host'}- transport = _Transport()- with owner_scope(launch):- connection = AuthorityConnection(launch, transport, identity, operator=True)- created = await connection.dispatch({'id': 1, 'method': 'session.create', 'params': {- 'profile': 'beta', 'request_id': 'c0', 'source': 'cli', 'cwd': str(tmp_path), 'model': 'm',- 'toolsets': []}})- session_id = created['result']['session_id']beta = runner.session_authorities.for_home(homes[2][1])- assert beta is not launch and session_id in beta.sessions- events = beta.sessions[session_id].event_stream- out = {}- worker = threading.Thread(target=lambda: out.update(value=ask_viewer(- events, session_id, 'sudo', {'command': 'sudo true'}, timeout=5)), daemon=True)- worker.start()loop = asyncio.get_running_loop()- deadline = loop.time() + 5- while not any(f.get('method') == 'sudo' for f in transport.frames):- assert loop.time() < deadline, transport.frames- await asyncio.sleep(0.01)- rid = next(f['id'] for f in transport.frames if f.get('method') == 'sudo')- with owner_scope(launch):- await connection.dispatch({'jsonrpc': '2.0', 'id': rid, 'result': {'value': 'hunter2'}})++ async def open_beta_chat(request_id):+ ticket = store.mint(profile_id=str(root.resolve()), subject='uid:desk', purpose='interactive',+ scope='host')+ grant = store.redeem(ticket, profile_id=None, purpose='interactive')+ launch = authority_for_profile_id(runner, grant['profile_id'])+ identity = {'user_id': grant['subject'], 'provider': 'local', 'profile_id': grant['profile_id'],+ 'instance_id': grant['instance_id'], 'capabilities': grant['capabilities'],+ 'native_bootstrap': True, 'profile_scope': 'host'}+ transport = _Transport()+ with owner_scope(launch):+ connection = AuthorityConnection(launch, transport, identity, operator=True)+ connections.append(connection)+ created = await connection.dispatch({'id': 1, 'method': 'session.create', 'params': {+ 'profile': 'beta', 'request_id': request_id, 'source': 'cli', 'cwd': str(tmp_path),+ 'model': 'm', 'toolsets': []}})+ session_id = created['result']['session_id']+ assert beta is not launch and session_id in beta.sessions+ return connection, transport, session_id++ async def ask_sudo(transport, session_id):+ events = beta.sessions[session_id].event_stream+ out = {}+ worker = threading.Thread(target=lambda: out.update(value=ask_viewer(+ events, session_id, 'sudo', {'command': 'sudo true'}, timeout=5)), daemon=True)+ worker.start()+ deadline = loop.time() + 5+ while not any(f.get('method') == 'sudo' for f in transport.frames):+ assert loop.time() < deadline, transport.frames+ await asyncio.sleep(0.01)+ rid = next(f['id'] for f in transport.frames if f.get('method') == 'sudo')+ return worker, out, rid, events++ async def answer(connection, rid, value):+ with owner_scope(connection.authority):+ await connection.dispatch({'jsonrpc': '2.0', 'id': rid, 'result': {'value': value}})++ desk, desk_transport, desk_session = await open_beta_chat('c0')+ worker, out, rid, _ = await ask_sudo(desk_transport, desk_session)+ await answer(desk, rid, 'hunter2')await asyncio.to_thread(worker.join, 10)assert out == {'value': 'hunter2'}, out++ other, other_transport, other_session = await open_beta_chat('c1')+ worker, out, rid, events = await ask_sudo(other_transport, other_session)+ assert not any(f.get('id') == rid for f in desk_transport.frames)+ await answer(desk, rid, 'leaked')+ assert waiting(events, other_session, 'sudo') and worker.is_alive() and out == {}+ await answer(other, rid, 'mine')+ await asyncio.to_thread(worker.join, 10)+ assert out == {'value': 'mine'}, outfinally:- if connection is not None:+ for connection in connections:with owner_scope(connection.authority):await connection.close()for authority in getattr(runner, 'session_authorities', None) or []: