Skip to content

The agent that grows with you

test(approval): align CI with transcript hosting and terminal scope

brooklyn!b4e4b9a65002
diff --git a/apps/desktop/src/components/assistant-ui/tool/tool-group.test.tsx b/apps/desktop/src/components/assistant-ui/tool/tool-group.test.tsx
index 3d3d2f818fc..9604e95543b 100644
--- a/apps/desktop/src/components/assistant-ui/tool/tool-group.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/tool/tool-group.test.tsx
@@ -15,12 +15,9 @@ import { formatTimelineRange } from '../thread/timestamp'
// Timeline timestamps render only when `display.timestamps` is enabled.
$displayTimestamps.set(true)
-// A run of tool calls collapses to a one-line summary once it has settled, but
-// a run with anything still pending always renders its rows. That rule is what
-// keeps the "approval must never be buried" bug fixed: an inline ApprovalBar
-// only ever exists on a pending tool, and a pending tool's run is never behind
-// a chevron. These cover both halves — the collapse itself, and the approval
-// staying in the visual flow.
+// Tool runs retain their own disclosure behavior. Approvals belong to a
+// persistent transcript host outside those runs, so collapsing or mounting a
+// tool row cannot hide or relocate the decision.
const createdAt = new Date('2026-06-03T00:00:00.000Z')
@@ -586,28 +583,37 @@ describe('tool run left unresolved', () => {
})
describe('flat tool list approval surfacing', () => {
- it('renders no inline approval bar when there is no live approval', async () => {
+ it('keeps the approval host empty when there is no live approval', async () => {
const { container } = render(<GroupHarness message={groupedPendingMessage()} />)
- // The pending terminal row mounts immediately, but its inline ApprovalBar
- // returns null while $approvalRequest is empty.
await waitFor(() => {
expect(container.querySelectorAll('[data-slot="tool-block"]').length).toBeGreaterThan(0)
})
- expect(container.querySelector('[data-slot="tool-approval-inline"]')).toBeNull()
+ expect(container.querySelector('[data-approval-stack]')).not.toBeNull()
+ expect(container.querySelector('[data-approval-stack] [data-approval-run]')).toBeNull()
})
- it('surfaces the approval inline and never under a hidden ancestor', async () => {
+ it('keeps the approval visible in the same host when tool rows arrive', async () => {
setApprovalRequest({ command: 'rm -rf /tmp/x', description: 'dangerous command', sessionId: 'sess-1' })
+ const message = groupedPendingMessage()
+ assert(message.role === 'assistant')
- const { container } = render(<GroupHarness message={groupedPendingMessage()} />)
+ const { container, rerender } = render(
+ <GroupHarness message={{ ...message, content: [{ type: 'text', text: 'Waiting for approval.' }] }} />
+ )
+ const run = await screen.findByRole('button', { name: /Run/ })
+ const host = run.closest('[data-approval-stack]')
+ expect(host).not.toBeNull()
+ expect(host?.parentElement?.getAttribute('data-slot')).toBe('aui_thread-content')
+ expect(host?.closest('[hidden], [inert], [data-tool-row], [data-tool-group]')).toBeNull()
+
+ rerender(<GroupHarness message={message} />)
await waitFor(() => {
- const bar = container.querySelector('[data-slot="tool-approval-inline"]')
- expect(bar).not.toBeNull()
- // Flat rows live directly in the flow — nothing should ever wrap the bar
- // in a `hidden` subtree.
- expect(bar?.closest('[hidden]')).toBeNull()
+ expect(container.querySelector('[data-approval-stack]')).toBe(host)
+ expect(screen.getByRole('button', { name: /Run/ })).toBe(run)
+ expect(run.closest('[hidden], [inert]')).toBeNull()
+ expect(screen.getByRole('button', { name: /Reject/ })).toBeTruthy()
})
})
diff --git a/tests/agent/test_terminal_approval_batch.py b/tests/agent/test_terminal_approval_batch.py
index 9bf1bd9a6c3..acc8c8b9e12 100644
--- a/tests/agent/test_terminal_approval_batch.py
+++ b/tests/agent/test_terminal_approval_batch.py
@@ -3,6 +3,7 @@
import json
import queue
import threading
+from contextlib import ExitStack
from types import SimpleNamespace
from unittest.mock import patch
@@ -38,7 +39,7 @@ def _agent():
@pytest.mark.parametrize("read_count", [0, 1, 2])
@pytest.mark.parametrize("threaded_middleware", [False, True])
def test_desktop_publishes_final_commands_before_wait_and_runs_in_order(tmp_path, monkeypatch, read_count, threaded_middleware):
- from tools.terminal_scope import terminal_scope
+ from tools.terminal_scope import reset_terminal_scope, set_terminal_scope
from tools.terminal_tool_lifecycle import cleanup_vm
monkeypatch.delenv("HERMES_DESKTOP", raising=False)
monkeypatch.setenv("HERMES_EXEC_ASK", "1")
@@ -110,9 +111,10 @@ def test_desktop_publishes_final_commands_before_wait_and_runs_in_order(tmp_path
except BaseException as exc:
errors.append(exc)
- with terminal_scope({"TERMINAL_ENV": "local", "TERMINAL_CWD": str(tmp_path)}), patch(
+ with ExitStack() as scope, patch(
"hermes_cli.plugins._dispatch_pre_tool_call_hooks", side_effect=pre_hook
):
+ scope.callback(reset_terminal_scope, set_terminal_scope({"TERMINAL_ENV": "local", "TERMINAL_CWD": str(tmp_path)}))
worker = threading.Thread(target=propagate_context_to_thread(run), daemon=True)
worker.start()
try:
@@ -145,7 +147,7 @@ def test_desktop_publishes_final_commands_before_wait_and_runs_in_order(tmp_path
def test_cancelled_preparation_drains_requests_without_reusing_once(tmp_path, monkeypatch):
- from tools.terminal_scope import terminal_scope
+ from tools.terminal_scope import reset_terminal_scope, set_terminal_scope
from tools.terminal_tool_lifecycle import cleanup_vm
monkeypatch.setenv("HERMES_EXEC_ASK", "1")
@@ -180,7 +182,8 @@ def test_cancelled_preparation_drains_requests_without_reusing_once(tmp_path, mo
"session_key": key, "source": "desktop", "agent": agent, "cwd": str(tmp_path),
}})
tokens = server._set_session_context(key)
- with terminal_scope({"TERMINAL_ENV": "local", "TERMINAL_CWD": str(tmp_path)}):
+ with ExitStack() as scope:
+ scope.callback(reset_terminal_scope, set_terminal_scope({"TERMINAL_ENV": "local", "TERMINAL_CWD": str(tmp_path)}))
worker = threading.Thread(target=propagate_context_to_thread(lambda: run(agent, calls, messages)), daemon=True)
retry_worker = None
retry_agent = None