Skip to content

Your lightweight open-source personal agent.

test(agent): cover disabled subagent exec tool

Xubin Ren351e3720b6c6
diff --git a/tests/agent/test_task_cancel.py b/tests/agent/test_task_cancel.py
index 8894cd973..4902a4c80 100644
--- a/tests/agent/test_task_cancel.py
+++ b/tests/agent/test_task_cancel.py
@@ -3,6 +3,7 @@
from __future__ import annotations
import asyncio
+from types import SimpleNamespace
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
@@ -222,6 +223,39 @@ class TestSubagentCancellation:
assert assistant_messages[0]["reasoning_content"] == "hidden reasoning"
assert assistant_messages[0]["thinking_blocks"] == [{"type": "thinking", "thinking": "step"}]
+ @pytest.mark.asyncio
+ async def test_subagent_exec_tool_not_registered_when_disabled(self, tmp_path):
+ from nanobot.agent.subagent import SubagentManager
+ from nanobot.bus.queue import MessageBus
+ from nanobot.config.schema import ExecToolConfig
+
+ bus = MessageBus()
+ provider = MagicMock()
+ provider.get_default_model.return_value = "test-model"
+ mgr = SubagentManager(
+ provider=provider,
+ workspace=tmp_path,
+ bus=bus,
+ exec_config=ExecToolConfig(enable=False),
+ )
+ mgr._announce_result = AsyncMock()
+
+ async def fake_run(spec):
+ assert spec.tools.get("exec") is None
+ return SimpleNamespace(
+ stop_reason="done",
+ final_content="done",
+ error=None,
+ tool_events=[],
+ )
+
+ mgr.runner.run = AsyncMock(side_effect=fake_run)
+
+ await mgr._run_subagent("sub-1", "do task", "label", {"channel": "test", "chat_id": "c1"})
+
+ mgr.runner.run.assert_awaited_once()
+ mgr._announce_result.assert_awaited_once()
+
@pytest.mark.asyncio
async def test_subagent_announces_error_when_tool_execution_fails(self, monkeypatch, tmp_path):
from nanobot.agent.subagent import SubagentManager