Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion astrbot/core/provider/func_tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ async def init_mcp_clients(
name=name,
cfg=cfg,
shutdown_event=shutdown_event,
timeout=init_timeout,
timeout_seconds=init_timeout,
),
name=f"mcp-init:{name}",
)
Expand Down
46 changes: 46 additions & 0 deletions tests/unit/test_func_tool_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import json

import pytest

from astrbot.core.provider import func_tool_manager
from astrbot.core.provider.func_tool_manager import FunctionToolManager


@pytest.mark.asyncio
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): 添加一个测试,用于验证在使用非默认的 init_timeout 值时的行为。

为了更好地覆盖此次回归,请同时测试一个非默认的超时时间(例如 await manager.init_mcp_clients(init_timeout=3.5)),并断言 called["demo"]["timeout_seconds"] 等于该值。这样可以验证当调用方覆盖超时时间时,该参数能够被正确传递。

Original comment in English

suggestion (testing): Add a test that exercises a non-default init_timeout value

To better cover the regression, please also test a non-default timeout (e.g. await manager.init_mcp_clients(init_timeout=3.5)) and assert that called["demo"]["timeout_seconds"] equals that value. This will validate the parameter is correctly forwarded when callers override the timeout.

async def test_init_mcp_clients_passes_timeout_seconds_keyword(
monkeypatch: pytest.MonkeyPatch,
tmp_path,
):
manager = FunctionToolManager()
data_dir = tmp_path / "data"
data_dir.mkdir()

(data_dir / "mcp_server.json").write_text(
json.dumps({"mcpServers": {"demo": {"active": True}}}),
encoding="utf-8",
)
monkeypatch.setattr(
func_tool_manager,
"get_astrbot_data_path",
lambda: data_dir,
)

called = {}

async def fake_start_mcp_server(*, name, cfg, shutdown_event, timeout_seconds):
called[name] = {
"cfg": cfg,
"shutdown_event_type": type(shutdown_event).__name__,
"timeout_seconds": timeout_seconds,
}

monkeypatch.setattr(manager, "_start_mcp_server", fake_start_mcp_server)

summary = await manager.init_mcp_clients()

assert summary.total == 1
assert summary.success == 1
assert summary.failed == []
assert called["demo"]["cfg"] == {"active": True}
assert called["demo"]["shutdown_event_type"] == "Event"
assert called["demo"]["timeout_seconds"] == manager._init_timeout_default