The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: prove fresh local clarify survives complete viewer detachment
Teknium1044867be6a6
diff --git a/docs/gateway-local-sessions.md b/docs/gateway-local-sessions.mdindex fd7a64a4eb3..a7603a02beb 100644--- a/docs/gateway-local-sessions.md+++ b/docs/gateway-local-sessions.md@@ -56,4 +56,8 @@ tickets, a loopback OpenAI-compatible model, the real TurnRunner/AIAgent, and thterminal tool. It proves persisted identity and same-agent reattachment; closes bothviewers while approval is pending; reconnects and consents before deleting only an ownedtemporary directory; checks canonical history; and rejects forged authentication/source/-profile and unsupported launch fields. No native messaging allow-all credential is used.+profile and unsupported launch fields. A second case runs the real clarify tool,+reattaches after all viewers close, and verifies the answer reaches the next loopback+model request. No native messaging allow-all credential authorizes the execution; a+separate negative control enables messaging allow-all only while proving reconstructed+local source/profile objects still fail closed.diff --git a/tests/gateway/fixtures/local_session_peer.py b/tests/gateway/fixtures/local_session_peer.pyindex e6f675012a2..206ccd510c9 100644--- a/tests/gateway/fixtures/local_session_peer.py+++ b/tests/gateway/fixtures/local_session_peer.py@@ -5,13 +5,14 @@ import jsonimport osfrom pathlib import Pathimport shlex+import sysimport threadingimport tracebackfrom authority_controls_peer import ModelPeer-async def probe(peer, target):+async def probe(peer, target, kind):import websocketsfrom gateway.run import GatewayRunnerfrom gateway.session_authority import initialize_session_authority@@ -102,6 +103,7 @@ async def probe(peer, target):agent = authority.agent(ref)assert isinstance(agent, AIAgent)prompt = snapshot['result']['prompts'][0]+ assert prompt['kind'] == kind, promptawait a.close()await b.close()assert target.exists()@@ -109,14 +111,19 @@ async def probe(peer, target):snapshot = await rpc(c, 'session.resume', session_id=sid)assert snapshot['result']['prompts'][0]['prompt_id'] == prompt['prompt_id']assert authority.agent(ref) is agent- answer = await rpc(c, 'approval.respond', session_id=sid,- prompt_id=prompt['prompt_id'], execution_generation=prompt['execution_generation'], choice='once')+ response = {'choice': 'once'} if kind == 'approval' else {'answer': 'green'}+ answer = await rpc(c, kind + '.respond', session_id=sid,+ prompt_id=prompt['prompt_id'], execution_generation=prompt['execution_generation'], **response)assert answer.get('result', {}).get('status') == 'resolved', answerawait asyncio.wait_for(authority.sessions[sid].task, 25)- assert not target.exists(), 'real owned terminal effect missing'+ if kind == 'approval':+ assert not target.exists(), 'real owned terminal effect missing'+ else:+ assert any('green' in json.dumps(m) for messages in peer.requests+ for m in messages if m['role'] == 'tool'), peer.requestsfinal = await rpc(c, 'session.resume', session_id=sid)assert final['result']['session_id'] == sid- assert any(m.get('content') == 'APPROVAL_FINISHED' for m in final['result']['messages']), final+ assert any(m.get('content') == kind.upper() + '_FINISHED' for m in final['result']['messages']), finalassert authority.agent(ref) is agentpong = await rpc(c, 'ping')assert pong.get('result', {}).get('pong') is True, pong@@ -132,11 +139,14 @@ async def probe(peer, target):else:raise AssertionError('unauthenticated socket accepted')Path(os.environ['HERMES_HOME'], 'receipt.json').write_text(json.dumps({- 'terminal_effect': True, 'same_agent': True, 'detached_pending': True,+ 'terminal_effect': not target.exists(), 'human_response': True,+ 'same_agent': True, 'detached_pending': True,'negative_controls': True, 'reconnected_identity': sid, 'model_requests': len(peer.requests)}))finally:if sid is not None:resolve_gateway_approval(authority.sessions[sid].route, 'deny', resolve_all=True)+ from tools import clarify_gateway+ clarify_gateway.clear_session(authority.sessions[sid].route)task = authority.sessions[sid].taskif task is not None:await asyncio.wait_for(task, 30)@@ -149,7 +159,9 @@ def main():target = Path(os.environ['HERMES_HOME'], 'owned-removal')target.mkdir()(target / 'owned.txt').write_text('disposable')- peer = ThreadingHTTPServer(('127.0.0.1', 0), ModelPeer)+ kind = sys.argv[1] if len(sys.argv) > 1 else 'approval'+ from authority_clarify_peer import ModelPeer as ClarifyPeer+ peer = ThreadingHTTPServer(('127.0.0.1', 0), ModelPeer if kind == 'approval' else ClarifyPeer)peer.requests = []peer.command = 'rm -r -- ' + shlex.quote(str(target))threading.Thread(target=peer.serve_forever, daemon=True).start()@@ -161,7 +173,7 @@ def main():'streaming:\n enabled: false\n''auxiliary:\n title_generation:\n enabled: false\n')try:- asyncio.run(probe(peer, target))+ asyncio.run(probe(peer, target, kind))finally:peer.shutdown()peer.server_close()diff --git a/tests/gateway/test_local_session.py b/tests/gateway/test_local_session.pyindex 215c1aa912e..8234de3f33c 100644--- a/tests/gateway/test_local_session.py+++ b/tests/gateway/test_local_session.py@@ -5,8 +5,11 @@ from pathlib import Pathimport subprocessimport sys+import pytest-def test_fresh_local_session_owns_execution_across_viewers(tmp_path):+[email protected]('kind', ['approval', 'clarify'])+def test_fresh_local_session_owns_execution_across_viewers(tmp_path, kind):repo = Path(__file__).resolve().parents[2]home, state = tmp_path / 'home', tmp_path / 'state'home.mkdir()@@ -14,10 +17,12 @@ def test_fresh_local_session_owns_execution_across_viewers(tmp_path):env = {k: os.environ[k] for k in ('PATH', 'SYSTEMROOT', 'LANG', 'TZ') if k in os.environ}env.update(HOME=str(home), USERPROFILE=str(home), HERMES_HOME=str(state), PYTHONPATH=str(repo))result = subprocess.run(- [sys.executable, str(Path(__file__).parent / 'fixtures' / 'local_session_peer.py')],+ [sys.executable, str(Path(__file__).parent / 'fixtures' / 'local_session_peer.py'), kind],cwd=repo, env=env, stdin=subprocess.DEVNULL, capture_output=True, text=True, timeout=100)assert result.returncode == 0, result.stdout + '\n' + result.stderrreceipt = json.loads((state / 'receipt.json').read_text())- assert receipt['terminal_effect'] and receipt['same_agent'] and receipt['detached_pending']+ assert receipt['human_response'] and receipt['same_agent'] and receipt['detached_pending']+ if kind == 'approval':+ assert receipt['terminal_effect']assert receipt['negative_controls'] and receipt['reconnected_identity']print(json.dumps(receipt))