"""reload_tools is a thin wrapper: it reports what reload_all() found.
The tool used to carry its own copy of the reload work, which is how the MCP
half drifted behind the admin reconnect route.
"""
from navi.core.reload import ReloadReport
from navi.core.registry import ToolRegistry
from navi.tools.reload_tools import ReloadToolsTool
async def test_success_follows_the_report(monkeypatch):
async def fake_reload_all(registry, cp_registry=None, mcp_manager=None):
return ReloadReport(tools=["alpha"], total_tools=4)
monkeypatch.setattr("navi.core.reload.reload_all", fake_reload_all)
result = await ReloadToolsTool(registry=ToolRegistry()).execute({})
assert result.success is True
assert "Tools (1): alpha." in result.output
async def test_errors_are_visible_in_the_output(monkeypatch):
async def fake_reload_all(registry, cp_registry=None, mcp_manager=None):
return ReloadReport(
tools=["alpha"],
tool_errors={"broken.py": "SyntaxError: bad"},
missing_enabled=["ghost"],
)
monkeypatch.setattr("navi.core.reload.reload_all", fake_reload_all)
result = await ReloadToolsTool(registry=ToolRegistry()).execute({})
assert result.success is False
assert "broken.py: SyntaxError: bad" in result.output
assert "ghost" in result.output
async def test_forwards_the_registries_it_was_built_with(monkeypatch):
seen = {}
async def fake_reload_all(registry, cp_registry=None, mcp_manager=None):
seen.update(registry=registry, cp=cp_registry, mcp=mcp_manager)
return ReloadReport()
monkeypatch.setattr("navi.core.reload.reload_all", fake_reload_all)
registry, cps, mcp = ToolRegistry(), object(), object()
await ReloadToolsTool(registry=registry, cp_registry=cps, mcp_manager=mcp).execute({})
assert seen == {"registry": registry, "cp": cps, "mcp": mcp}
async def test_no_registry_is_an_error_not_a_crash():
result = await ReloadToolsTool().execute({})
assert result.success is False
assert result.error == "no_registry"