test: align MCP transient reconnect coverage
maintainer edit: update the existing transient retry tests for reconnect-first behavior and keep structured retry-failure coverage in the focused MCP transient suite.
This commit is contained in:
@@ -16,6 +16,7 @@ from nanobot.agent.tools.mcp import (
|
||||
_is_session_terminated,
|
||||
_is_transient,
|
||||
)
|
||||
from nanobot.agent.tools.registry import is_tool_error_result
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# _is_transient helper
|
||||
@@ -134,6 +135,7 @@ async def test_tool_fails_after_retry_exhausted():
|
||||
|
||||
assert "failed after retry" in output
|
||||
assert "ClosedResourceError" in output
|
||||
assert is_tool_error_result(wrapper.name, output)
|
||||
assert session.call_tool.call_count == 2
|
||||
|
||||
|
||||
@@ -237,12 +239,10 @@ async def test_tool_retry_on_end_of_stream():
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_tool_reconnects_when_transient_retry_reveals_terminated_session():
|
||||
"""Tool should reconnect if a stale session reports termination after transient retry."""
|
||||
async def test_tool_reconnects_on_transient_failure():
|
||||
"""Tool should reconnect when a stale session reports a transient stream failure."""
|
||||
old_session = AsyncMock()
|
||||
old_session.call_tool = AsyncMock(
|
||||
side_effect=[_FakeClosedResourceError("closed"), _session_terminated_error()]
|
||||
)
|
||||
old_session.call_tool = AsyncMock(side_effect=_FakeClosedResourceError("closed"))
|
||||
new_session = AsyncMock()
|
||||
new_session.call_tool = AsyncMock(return_value=_make_tool_result("fresh"))
|
||||
|
||||
@@ -257,12 +257,13 @@ async def test_tool_reconnects_when_transient_retry_reveals_terminated_session()
|
||||
|
||||
wrapper.set_reconnect_handler(reconnect)
|
||||
|
||||
with patch("nanobot.agent.tools.mcp.asyncio.sleep", new_callable=AsyncMock):
|
||||
with patch("nanobot.agent.tools.mcp.asyncio.sleep", new_callable=AsyncMock) as mock_sleep:
|
||||
output = await wrapper.execute(foo="bar")
|
||||
|
||||
assert output == "fresh"
|
||||
assert old_session.call_tool.call_count == 2
|
||||
assert old_session.call_tool.call_count == 1
|
||||
assert new_session.call_tool.call_count == 1
|
||||
mock_sleep.assert_not_called()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user