Files
nousresearch--hermes-agent/tests/cron/test_scheduler_mcp_init.py
T
wehub-resource-sync b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

54 lines
1.6 KiB
Python

"""Regression tests for MCP server availability in cron jobs.
Background
==========
``cron/scheduler.py:run_job()`` constructs ``AIAgent(...)`` directly without
calling ``discover_mcp_tools()`` — the initialization that CLI and gateway
paths do at startup. Cron jobs therefore never saw any MCP tools from
``mcp_servers`` in config.yaml. See #4219.
The fix inserts ``discover_mcp_tools()`` before the ``AIAgent(...)`` call,
wrapped in try/except so a broken MCP server can't kill an otherwise
working cron job. ``discover_mcp_tools`` is idempotent — subsequent ticks
short-circuit on already-connected servers.
"""
from __future__ import annotations
from unittest.mock import patch
def test_no_agent_cron_job_does_not_initialize_mcp():
"""Cron jobs with no_agent=True are script-only — no AIAgent, no MCP
tools needed. We must NOT pay the MCP init cost for those."""
from cron import scheduler
job = {
"id": "noagent-job",
"name": "noagent-job",
"no_agent": True,
"script": "/nonexistent/script.sh",
}
discover_called = []
def fake_discover():
discover_called.append(True)
return []
# _run_job_script returns (ok, output); make it fail cleanly so we
# don't need a real script file.
with patch("tools.mcp_tool.discover_mcp_tools", side_effect=fake_discover), \
patch("cron.scheduler._run_job_script", return_value=(False, "no such file")):
scheduler.run_job(job)
assert not discover_called, (
"discover_mcp_tools was called for a no_agent job — wasted MCP init "
"for a script-only cron tick"
)