mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-18 18:10:37 +08:00
fix: resolve merge conflicts from upstream and fix tool conflict resolution
- ToolSet.add() now protects active tools from inactive overrides - Add missing _has_meaningful_content() method in RespondStage - Remove is_local=True from ExecuteShellTool (no longer supported) - Fix ToolSet() missing namespace argument in get_full_tool_set() - Rewrite tests to match new tool architecture (cron_tools, func_tool_manager, tool_conflict_resolution)
This commit is contained in:
@@ -1,40 +1,52 @@
|
||||
from astrbot.core import sp
|
||||
"""Tests for FunctionToolManager with new internal tools architecture."""
|
||||
|
||||
from astrbot.core.provider.func_tool_manager import FunctionToolManager
|
||||
from astrbot.core.tools.computer_tools.shell import ExecuteShellTool
|
||||
from astrbot.core.tools.message_tools import SendMessageToUserTool
|
||||
from astrbot.core.computer.computer_tool_provider import get_all_tools
|
||||
|
||||
|
||||
def test_get_builtin_tool_by_class_returns_cached_instance():
|
||||
def test_computer_tools_provider_returns_tools():
|
||||
"""ComputerToolProvider should return a list of computer tools."""
|
||||
tools = get_all_tools()
|
||||
|
||||
assert len(tools) > 0
|
||||
names = [t.name for t in tools]
|
||||
assert "astrbot_execute_shell" in names
|
||||
|
||||
|
||||
def test_register_internal_tools_adds_tools_to_manager():
|
||||
"""register_internal_tools should add computer tools to the manager."""
|
||||
manager = FunctionToolManager()
|
||||
|
||||
tool_by_class = manager.get_builtin_tool(SendMessageToUserTool)
|
||||
tool_by_name = manager.get_builtin_tool("send_message_to_user")
|
||||
# Should start empty
|
||||
assert manager.get_func("astrbot_execute_shell") is None
|
||||
|
||||
assert tool_by_class is tool_by_name
|
||||
assert manager.get_func("send_message_to_user") is tool_by_class
|
||||
assert tool_by_class.name == "send_message_to_user"
|
||||
|
||||
|
||||
def test_builtin_tool_ignores_inactivated_llm_tools():
|
||||
manager = FunctionToolManager()
|
||||
sp.put(
|
||||
"inactivated_llm_tools",
|
||||
["send_message_to_user"],
|
||||
scope="global",
|
||||
scope_id="global",
|
||||
)
|
||||
|
||||
try:
|
||||
tool = manager.get_builtin_tool(SendMessageToUserTool)
|
||||
assert tool.active is True
|
||||
finally:
|
||||
sp.put("inactivated_llm_tools", [], scope="global", scope_id="global")
|
||||
|
||||
|
||||
def test_computer_tools_are_registered_as_builtin_tools():
|
||||
manager = FunctionToolManager()
|
||||
|
||||
tool = manager.get_builtin_tool(ExecuteShellTool)
|
||||
# Register internal tools
|
||||
manager.register_internal_tools()
|
||||
|
||||
# Should now have the shell tool
|
||||
tool = manager.get_func("astrbot_execute_shell")
|
||||
assert tool is not None
|
||||
assert tool.name == "astrbot_execute_shell"
|
||||
assert manager.is_builtin_tool("astrbot_execute_shell") is True
|
||||
|
||||
|
||||
def test_manager_func_list_starts_empty():
|
||||
"""func_list should start empty in new architecture."""
|
||||
manager = FunctionToolManager()
|
||||
|
||||
assert manager.func_list == []
|
||||
|
||||
|
||||
def test_register_internal_tools_does_not_duplicate():
|
||||
"""Calling register_internal_tools twice should not duplicate tools."""
|
||||
manager = FunctionToolManager()
|
||||
manager.register_internal_tools()
|
||||
|
||||
first_tool = manager.get_func("astrbot_execute_shell")
|
||||
assert first_tool is not None
|
||||
|
||||
# Register again
|
||||
manager.register_internal_tools()
|
||||
|
||||
# Should still have the same tool (not duplicated)
|
||||
second_tool = manager.get_func("astrbot_execute_shell")
|
||||
assert second_tool is first_tool
|
||||
|
||||
Reference in New Issue
Block a user