fix(ci): guard the MCP SDK import so pytest can collect the suite

`tests/test_project_context_mcp_template.py` imported `mcp` at module scope,
but the SDK is a runtime dependency (requirements.txt) and is deliberately
absent from requirements-test.txt — the only thing CI installs. Collection
therefore aborted for the ENTIRE suite before a single test ran.

The guard now sits inside the one test that touches the SDK, so the other
cases in the file (pure-Python contract checks) keep running on CI instead
of being skipped along with it.

Unrelated to the R04 refactor; kept as its own commit so it can be cherry-
picked to main on its own.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-23 13:13:42 +09:00
co-authored by Claude Opus 5
parent f61c5474b0
commit 176e6aef79
+8 -1
View File
@@ -14,7 +14,6 @@ from cowork_local.mcp_servers.project_context.registry import (
) )
from cowork_local.mcp_servers.project_context.runtime import require_supported_python from cowork_local.mcp_servers.project_context.runtime import require_supported_python
from cowork_local.mcp_servers.project_context.server import dispatch from cowork_local.mcp_servers.project_context.server import dispatch
from mcp import types
EXPECTED_TOOLS = { EXPECTED_TOOLS = {
"get_project_issue_context", "get_project_issue_context",
@@ -88,6 +87,14 @@ def source() -> dict[str, str]:
def test_template_exposes_exactly_three_provider_neutral_tools() -> None: def test_template_exposes_exactly_three_provider_neutral_tools() -> None:
# The MCP SDK is a RUNTIME dependency (requirements.txt) and is deliberately
# absent from requirements-test.txt, which is all CI installs. Importing it at
# module scope aborted collection for the ENTIRE suite, so the guard lives here,
# inside the only test that touches the SDK. Guarding per-test rather than
# per-module keeps the other cases -- pure-Python contract checks that need no
# SDK -- running on CI instead of silently skipping with it.
types = pytest.importorskip("mcp.types")
assert set(TOOL_NAMES) == EXPECTED_TOOLS assert set(TOOL_NAMES) == EXPECTED_TOOLS
declarations = tool_declarations() declarations = tool_declarations()
assert {item["name"] for item in declarations} == EXPECTED_TOOLS assert {item["name"] for item in declarations} == EXPECTED_TOOLS