fix(agent): redact private recovery and reconnect diagnostics

This commit is contained in:
Xubin Ren committed 2026-09-21 15:24:38 +08:00
1 parent 2640251076
commit d37d7c07c0
6 files changed
+160 -14

No files matched your search

+19 -3
View File
@@ -5,9 +5,11 @@ from unittest.mock import AsyncMock, MagicMock
import pytest
from nanobot.agent.loop import AgentLoop
from nanobot.agent.tools.context import current_request_context
from nanobot.bus.events import INBOUND_META_USER_SHELL, InboundMessage, OutboundMessage
from nanobot.command.builtin import cmd_user_shell
from nanobot.command.router import CommandContext
from nanobot.session.manager import Session, SessionPolicy
def _context(loop: MagicMock, *, trusted: bool, command: str = "pwd") -> CommandContext:
@@ -44,22 +46,36 @@ async def test_user_shell_rejects_untrusted_transport_metadata() -> None:
@pytest.mark.asyncio
async def test_user_shell_uses_exec_tool_with_workspace_scope(tmp_path: Path) -> None:
@pytest.mark.parametrize("log_content", [True, False])
@pytest.mark.parametrize("context_session", [True, False])
async def test_user_shell_uses_exec_tool_with_workspace_scope(
tmp_path: Path, log_content: bool, context_session: bool,
) -> None:
async def execute(**kwargs):
request = current_request_context()
assert request is not None
assert request.log_content is log_content
assert request.workspace == tmp_path
return f"{tmp_path}\n\nExit code: 0"
tool = MagicMock()
tool.execute = AsyncMock(return_value=f"{tmp_path}\n\nExit code: 0")
session = SimpleNamespace(metadata={})
tool.execute = AsyncMock(side_effect=execute)
session = Session(key="websocket:chat", policy=SessionPolicy(log_content=log_content))
scope = SimpleNamespace(project_path=tmp_path)
loop = MagicMock()
loop.tools.get.return_value = tool
loop.sessions.get_or_create.return_value = session
loop.workspace_scopes.for_turn.return_value = scope
ctx = _context(loop, trusted=True)
if context_session:
ctx.session = session
response = await AgentLoop.execute_user_shell_command(loop, ctx)
tool.execute.assert_awaited_once_with(command="pwd", working_dir=str(tmp_path))
assert response.content.endswith("Exit code: 0")
assert response.metadata["render_as"] == "text"
assert current_request_context() is None
@pytest.mark.asyncio