import asyncio
import sys
from types import SimpleNamespace
import pytest
from domin8 import server
from mcp.types import TextContent
@pytest.mark.asyncio
async def test_call_tool_fallback_normalized(monkeypatch):
# Make a handler that returns a message
async def fake_req(args):
return "OK"
# Patch the module and function to ensure fallback finds it
monkeypatch.setattr('domin8.tools.request_change.handle_request_change', fake_req)
res = await server.call_tool('prefix.request_change', {'repo_relative_path': 'x'})
assert isinstance(res, list)
assert isinstance(res[0], TextContent)
assert res[0].text == 'OK'
@pytest.mark.asyncio
async def test_call_tool_unknown_raises():
with pytest.raises(ValueError):
await server.call_tool('totally_unknown_tool', {})
def test_create_initialization_options_with_tools(monkeypatch):
# Create a fake Tool object
class FakeTool:
def __init__(self, name):
self.name = name
self.description = 'd'
self.inputSchema = {'x': 1}
async def fake_list_tools():
return [FakeTool('t1'), FakeTool('t2')]
monkeypatch.setattr('domin8.server.list_tools', fake_list_tools)
# call the coroutine
init_opts = asyncio.get_event_loop().run_until_complete(server.create_initialization_options_with_tools())
assert hasattr(init_opts.capabilities, 'tools')
assert hasattr(init_opts.capabilities.tools, 'tool_list')
# The initialization options should include the standard tool names
names = [t['name'] for t in init_opts.capabilities.tools.tool_list]
assert 't1' in names and 't2' in names