Newer
Older
navi-1 / tests / unit / core / test_tool_executor.py
"""Unit tests for navi.core.tool_executor."""

from navi.core.registry import ToolRegistry
from navi.core.tool_executor import ToolExecutor
from navi.llm.base import ToolCallRequest
from tests.conftest_factory import FakeTool


class TestToolExecutorMcpAliases:
    async def test_executes_bare_mcp_tool_alias(self):
        registry = ToolRegistry()
        tool = FakeTool("mcp__gnexus_book__search_docs")
        registry.register(tool, builtin=True)
        executor = ToolExecutor(registry)

        messages, images = await executor._execute_tool_calls(
            [ToolCallRequest(id="1", name="search_docs", arguments={"query": "git"})],
            [tool],
        )

        assert images == []
        assert messages[0].name == "mcp__gnexus_book__search_docs"
        assert messages[0].content == "executed mcp__gnexus_book__search_docs"

    async def test_executes_mcp_tool_alias_with_dash_variant(self):
        registry = ToolRegistry()
        tool = FakeTool("mcp__gnexus_book__search_docs")
        registry.register(tool, builtin=True)
        executor = ToolExecutor(registry)

        messages, images = await executor._execute_tool_calls(
            [ToolCallRequest(id="1", name="mcp__gnexus-book__search_docs", arguments={"query": "git"})],
            [tool],
        )

        assert images == []
        assert messages[0].name == "mcp__gnexus_book__search_docs"
        assert messages[0].content == "executed mcp__gnexus_book__search_docs"

    async def test_executes_old_underscore_format_fallback(self):
        registry = ToolRegistry()
        tool = FakeTool("mcp__gnexus_book__search_docs")
        registry.register(tool, builtin=True)
        executor = ToolExecutor(registry)

        messages, images = await executor._execute_tool_calls(
            [ToolCallRequest(id="1", name="mcp_gnexus_book_search_docs", arguments={"query": "git"})],
            [tool],
        )

        assert images == []
        assert messages[0].name == "mcp__gnexus_book__search_docs"
        assert messages[0].content == "executed mcp__gnexus_book__search_docs"

    async def test_executes_legacy_colon_format_fallback(self):
        registry = ToolRegistry()
        tool = FakeTool("mcp__gnexus_book__search_docs")
        registry.register(tool, builtin=True)
        executor = ToolExecutor(registry)

        messages, images = await executor._execute_tool_calls(
            [ToolCallRequest(id="1", name="mcp:gnexus_book:search_docs", arguments={"query": "git"})],
            [tool],
        )

        assert images == []
        assert messages[0].name == "mcp__gnexus_book__search_docs"
        assert messages[0].content == "executed mcp__gnexus_book__search_docs"