forked from HomeLab/unraid-mcp
feat(elicitation): auto-elicit credentials on CredentialsNotConfiguredError in unraid_info
This commit is contained in:
@@ -174,3 +174,42 @@ async def test_make_graphql_request_raises_sentinel_when_unconfigured():
|
||||
finally:
|
||||
settings_mod.UNRAID_API_URL = original_url
|
||||
settings_mod.UNRAID_API_KEY = original_key
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_auto_elicitation_triggered_on_credentials_not_configured():
|
||||
"""Any tool call with missing creds auto-triggers elicitation before erroring."""
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from conftest import make_tool_fn
|
||||
from fastmcp import FastMCP
|
||||
|
||||
from unraid_mcp.core.exceptions import CredentialsNotConfiguredError
|
||||
from unraid_mcp.tools.info import register_info_tool
|
||||
|
||||
test_mcp = FastMCP("test")
|
||||
register_info_tool(test_mcp)
|
||||
tool_fn = make_tool_fn("unraid_mcp.tools.info", "register_info_tool", "unraid_info")
|
||||
|
||||
mock_ctx = MagicMock()
|
||||
|
||||
# First call raises CredentialsNotConfiguredError, second returns data
|
||||
call_count = 0
|
||||
|
||||
async def side_effect(*args, **kwargs):
|
||||
nonlocal call_count
|
||||
call_count += 1
|
||||
if call_count == 1:
|
||||
raise CredentialsNotConfiguredError()
|
||||
return {"info": {"os": {"hostname": "tootie"}}}
|
||||
|
||||
with (
|
||||
patch("unraid_mcp.tools.info.make_graphql_request", side_effect=side_effect),
|
||||
patch(
|
||||
"unraid_mcp.tools.info.elicit_and_configure", new=AsyncMock(return_value=True)
|
||||
) as mock_elicit,
|
||||
):
|
||||
result = await tool_fn(action="overview", ctx=mock_ctx)
|
||||
|
||||
mock_elicit.assert_called_once_with(mock_ctx)
|
||||
assert result is not None
|
||||
|
||||
Reference in New Issue
Block a user