mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-01 16:51:53 +03:00
refactor(agent): load MyTool through tool loader
This commit is contained in:
@@ -59,6 +59,7 @@ def test_tool_context_has_required_fields():
|
||||
"config", "workspace", "bus", "subagent_manager",
|
||||
"cron_service", "exec_session_manager", "file_state_store",
|
||||
"provider_snapshot_loader", "image_generation_provider_configs", "timezone",
|
||||
"runtime_control",
|
||||
}
|
||||
assert required <= field_names
|
||||
|
||||
@@ -71,6 +72,7 @@ def test_tool_context_defaults():
|
||||
assert ctx.exec_session_manager is None
|
||||
assert ctx.provider_snapshot_loader is None
|
||||
assert ctx.image_generation_provider_configs is None
|
||||
assert ctx.runtime_control is None
|
||||
assert ctx.timezone == "UTC"
|
||||
|
||||
|
||||
@@ -91,6 +93,7 @@ def test_discover_finds_concrete_tools():
|
||||
assert "ExecTool" in class_names
|
||||
assert "CliAppsTool" in class_names
|
||||
assert "MessageTool" in class_names
|
||||
assert "MyTool" in class_names
|
||||
assert "SpawnTool" in class_names
|
||||
assert "ExecSessionTool" in class_names
|
||||
|
||||
@@ -373,12 +376,26 @@ def test_my_tool_enabled():
|
||||
from nanobot.agent.tools.self import MyTool
|
||||
mock_config = MagicMock()
|
||||
mock_config.my.enable = True
|
||||
ctx = ToolContext(config=mock_config, workspace="/tmp")
|
||||
ctx = ToolContext(
|
||||
config=mock_config,
|
||||
workspace="/tmp",
|
||||
runtime_control=MagicMock(),
|
||||
)
|
||||
assert MyTool.enabled(ctx) is True
|
||||
mock_config.my.enable = False
|
||||
assert MyTool.enabled(ctx) is False
|
||||
|
||||
|
||||
def test_my_tool_requires_runtime_control():
|
||||
from nanobot.agent.tools.self import MyTool
|
||||
|
||||
mock_config = MagicMock()
|
||||
mock_config.my.enable = True
|
||||
ctx = ToolContext(config=mock_config, workspace="/tmp")
|
||||
|
||||
assert MyTool.enabled(ctx) is False
|
||||
|
||||
|
||||
def test_mcp_wrappers_not_discoverable():
|
||||
from nanobot.agent.tools.mcp import MCPPromptWrapper, MCPResourceWrapper, MCPToolWrapper
|
||||
assert MCPToolWrapper._plugin_discoverable is False
|
||||
@@ -411,6 +428,7 @@ def test_loader_registers_same_tools_as_old_hardcoded():
|
||||
mock_config.web.user_agent = None
|
||||
mock_config.image_generation.enabled = False
|
||||
mock_config.my.enable = True
|
||||
mock_config.my.allow_set = False
|
||||
|
||||
ctx = ToolContext(
|
||||
config=mock_config,
|
||||
@@ -419,6 +437,7 @@ def test_loader_registers_same_tools_as_old_hardcoded():
|
||||
subagent_manager=MagicMock(),
|
||||
cron_service=MagicMock(),
|
||||
timezone="UTC",
|
||||
runtime_control=MagicMock(),
|
||||
)
|
||||
registry = ToolRegistry()
|
||||
loader = ToolLoader()
|
||||
@@ -429,6 +448,7 @@ def test_loader_registers_same_tools_as_old_hardcoded():
|
||||
"find_files", "grep", "exec", "exec_session", "list_exec_sessions",
|
||||
"web_search", "web_fetch",
|
||||
"message", "spawn", "cron",
|
||||
"my",
|
||||
}
|
||||
actual = set(registered)
|
||||
assert expected <= actual, f"Missing tools: {expected - actual}"
|
||||
|
||||
Reference in New Issue
Block a user