Files
hermes-agent/tests/tools/test_mcp_reconnect_signal.py
红尘 d73ff9b0fb
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
Docker / shell lint / Lint Dockerfile (hadolint) (push) Has been cancelled
Docker / shell lint / Lint docker/ shell scripts (shellcheck) (push) Has been cancelled
Docker Build and Publish / build-amd64 (push) Has been cancelled
Docker Build and Publish / build-arm64 (push) Has been cancelled
Lint (ruff + ty) / ruff + ty diff (push) Has been cancelled
Lint (ruff + ty) / ruff enforcement (blocking) (push) Has been cancelled
Lint (ruff + ty) / Windows footguns (blocking) (push) Has been cancelled
Nix Lockfile Fix / auto-fix-main (push) Has been cancelled
Nix Lockfile Fix / fix (push) Has been cancelled
Nix / nix (macos-latest) (push) Has been cancelled
Nix / nix (ubuntu-latest) (push) Has been cancelled
OSV-Scanner / Scan lockfiles (push) Has been cancelled
Build Skills Index / build-index (push) Has been cancelled
Tests / test (1) (push) Has been cancelled
Tests / test (2) (push) Has been cancelled
Tests / test (3) (push) Has been cancelled
Tests / test (4) (push) Has been cancelled
Tests / test (5) (push) Has been cancelled
Tests / test (6) (push) Has been cancelled
Tests / e2e (push) Has been cancelled
uv.lock check / uv lock --check (push) Has been cancelled
Docker Build and Publish / merge (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
Tests / save-durations (push) Has been cancelled
Initial import of NousResearch/hermes-agent
2026-05-31 09:36:58 +08:00

58 lines
2.0 KiB
Python

"""Tests for the MCPServerTask reconnect signal.
When the OAuth layer cannot recover in-place (e.g., external refresh of a
single-use refresh_token made the SDK's in-memory refresh fail), the tool
handler signals MCPServerTask to tear down the current MCP session and
reconnect with fresh credentials. This file exercises the signal plumbing
in isolation from the full stdio/http transport machinery.
"""
import asyncio
import pytest
@pytest.mark.asyncio
async def test_reconnect_event_attribute_exists():
"""MCPServerTask has a _reconnect_event alongside _shutdown_event."""
from tools.mcp_tool import MCPServerTask
task = MCPServerTask("test")
assert hasattr(task, "_reconnect_event")
assert isinstance(task._reconnect_event, asyncio.Event)
assert not task._reconnect_event.is_set()
@pytest.mark.asyncio
async def test_wait_for_lifecycle_event_returns_reconnect():
"""When _reconnect_event fires, helper returns 'reconnect' and clears it."""
from tools.mcp_tool import MCPServerTask
task = MCPServerTask("test")
task._reconnect_event.set()
reason = await task._wait_for_lifecycle_event()
assert reason == "reconnect"
# Should have cleared so the next cycle starts fresh
assert not task._reconnect_event.is_set()
@pytest.mark.asyncio
async def test_wait_for_lifecycle_event_returns_shutdown():
"""When _shutdown_event fires, helper returns 'shutdown'."""
from tools.mcp_tool import MCPServerTask
task = MCPServerTask("test")
task._shutdown_event.set()
reason = await task._wait_for_lifecycle_event()
assert reason == "shutdown"
@pytest.mark.asyncio
async def test_wait_for_lifecycle_event_shutdown_wins_when_both_set():
"""If both events are set simultaneously, shutdown takes precedence."""
from tools.mcp_tool import MCPServerTask
task = MCPServerTask("test")
task._shutdown_event.set()
task._reconnect_event.set()
reason = await task._wait_for_lifecycle_event()
assert reason == "shutdown"