mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-04 02:01:48 +03:00
fix(gateway): retry MCP readiness before turns (#5535)
This commit is contained in:
@@ -3697,6 +3697,7 @@ def test_gateway_agent_task_owns_initial_mcp_provider_close(
|
||||
return cls(**extra)
|
||||
|
||||
def __init__(self, **_kwargs) -> None:
|
||||
seen["hooks"] = _kwargs.get("hooks")
|
||||
self.model = "test-model"
|
||||
self.provider = object()
|
||||
self.sessions = _FakeSessionManager()
|
||||
@@ -3809,6 +3810,11 @@ def test_gateway_agent_task_owns_initial_mcp_provider_close(
|
||||
assert mcp_provider.connect_task is seen["agent_task"]
|
||||
assert mcp_provider.close_tasks[0] is mcp_provider.connect_task
|
||||
assert len(mcp_provider.close_tasks) == 2
|
||||
hooks = seen["hooks"]
|
||||
assert isinstance(hooks, list)
|
||||
assert len(hooks) == 1
|
||||
hook = hooks[0]
|
||||
assert isinstance(hook, cli_gateway_runtime._MCPReadinessHook)
|
||||
|
||||
|
||||
def test_gateway_shutdown_event_exits_forever_runtime_tasks(
|
||||
|
||||
@@ -11,7 +11,10 @@ import asyncio
|
||||
import time
|
||||
from contextlib import suppress
|
||||
|
||||
from nanobot.cli.gateway_runtime import _close_gateway_runtime
|
||||
from nanobot.agent.hook import AgentRunHookContext
|
||||
from nanobot.agent.tools.mcp import MCPProvider
|
||||
from nanobot.agent.tools.registry import ToolRegistry
|
||||
from nanobot.cli.gateway_runtime import _close_gateway_runtime, _MCPReadinessHook
|
||||
|
||||
|
||||
class _FakeAgent:
|
||||
@@ -53,6 +56,24 @@ class _FakeMCPProvider:
|
||||
self.events.append("mcp_closed")
|
||||
|
||||
|
||||
class _TrackingMCPProvider(MCPProvider):
|
||||
def __init__(self) -> None:
|
||||
super().__init__({}, ToolRegistry())
|
||||
self.connect_calls = 0
|
||||
|
||||
async def connect(self) -> None:
|
||||
self.connect_calls += 1
|
||||
|
||||
|
||||
async def test_mcp_readiness_hook_delegates_to_application_provider() -> None:
|
||||
provider = _TrackingMCPProvider()
|
||||
hook = _MCPReadinessHook(provider)
|
||||
|
||||
await hook.before_run(AgentRunHookContext(messages=[]))
|
||||
|
||||
assert provider.connect_calls == 1
|
||||
|
||||
|
||||
async def _cancellable_task(events: list[str]) -> None:
|
||||
try:
|
||||
await asyncio.sleep(3600)
|
||||
|
||||
Reference in New Issue
Block a user