The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(tui,cli): cover a refused delete leaving the closed session attached (currently failing)
yoniebansc92ca62a76ed
diff --git a/tests/hermes_cli/test_gateway_session_store.py b/tests/hermes_cli/test_gateway_session_store.pyindex f9c6d7b3661..0c2a08a61a9 100644--- a/tests/hermes_cli/test_gateway_session_store.py+++ b/tests/hermes_cli/test_gateway_session_store.py@@ -5,7 +5,7 @@ from contextlib import asynccontextmanagerimport pytest-from hermes_cli.gateway_client import GatewayClientError+from hermes_cli.gateway_client import GatewayClientError, GatewayRPCErrorfrom hermes_cli.gateway_connection import GatewayConnectionfrom hermes_cli.gateway_session_store import GatewaySessionStore@@ -113,6 +113,45 @@ def test_title_rename_delete_and_detach_are_gateway_verbs(store):assert delete["operation"] == "delete" and delete["expected_generation"] == 0+def test_a_refused_delete_of_a_closed_session_leaves_it_closed(store):+ """The delete reads its revision through ``session.resume``, which attaches this viewer again;+ a refusal must hand that attachment back, or the closed session stays in the live list with+ this CLI as its viewer."""+ db, client = store+ db.open_session(cli("local-old", resumed=True))+ db.end_session("local-old", "new_session")+ real_rpc = client.rpc++ async def refusing(method, *, _timeout=None, **params):+ if method == "session.mutate":+ client.calls.append((method, params))+ raise GatewayRPCError("session_busy")+ return await real_rpc(method, _timeout=_timeout, **params)++ client.rpc = refusing+ with pytest.raises(GatewayClientError):+ db.delete_session("local-old")+ # cli_close: the stamp main's classic CLI ends a session with; a row already ended keeps its own reason.+ assert client.calls[-1] == ("session.detach", {"session_id": "local-old", "subscription_id": "sub-local-old",+ "end_reason": "cli_close"})+++def test_a_refused_delete_keeps_a_session_this_cli_is_viewing(store):+ db, client = store+ db.open_session(cli("local-old", resumed=True))+ real_rpc = client.rpc++ async def refusing(method, *, _timeout=None, **params):+ if method == "session.mutate":+ raise GatewayRPCError("session_busy")+ return await real_rpc(method, _timeout=_timeout, **params)++ client.rpc = refusing+ with pytest.raises(GatewayClientError):+ db.delete_session("local-old")+ assert "session.detach" not in [method for method, _ in client.calls]++def test_gateway_owned_writes_are_noops_and_unknown_writes_refuse(store):db, client = storebefore = len(client.calls)diff --git a/ui-tui/src/__tests__/canonicalPickerDelete.test.tsx b/ui-tui/src/__tests__/canonicalPickerDelete.test.tsxindex cf28cd845fc..9465d26846c 100644--- a/ui-tui/src/__tests__/canonicalPickerDelete.test.tsx+++ b/ui-tui/src/__tests__/canonicalPickerDelete.test.tsx@@ -20,7 +20,17 @@ function mount(mutate: (params: any) => Promise<unknown>) {}if (method === 'session.resume') {- return { session_id: params.session_id, revision: 4, execution_generation: 2, messages: [] }+ return {+ session_id: params.session_id,+ revision: 4,+ execution_generation: 2,+ messages: [],+ subscription_id: 'cas-read'+ }+ }++ if (method === 'session.detach') {+ return { session_id: params.session_id, subscription_id: params.subscription_id, detached: true }}if (method === 'session.mutate') {@@ -120,3 +130,24 @@ it('keeps a refused delete on screen past the live-status poll', async () => {instance.unmount()}})++it('hands back the attachment its revision read made when the delete is refused', async () => {+ // The CAS read is a `session.resume`, which attaches this view to the closed session; left+ // attached, a refusal puts the closed session back in the live list until Ink exits.+ const { deleteStored, instance, request } = mount(async () => {+ throw Object.assign(new Error('session_busy'), { data: { reason: 'session_busy' } })+ })++ try {+ await deleteStored()+ await vi.waitFor(() =>+ expect(request).toHaveBeenCalledWith('session.detach', {+ session_id: 'old',+ subscription_id: 'cas-read',+ end_reason: 'tui_close'+ })+ )+ } finally {+ instance.unmount()+ }+})