Files
intervalsicu-mcp/tests/test_server_setup.py
T
Chris Farhood 43bbbb6bbb
build-image / test (push) Failing after 53s
build-image / build (push) Has been skipped
test: raise coverage 64% -> 90% with behavior-focused tests + enforced gate
New suites assert real behavior, not just that code runs:
- test_types: workout serialization round-trips (recursive steps, camelCase
  keys, enum conversion) + __str__ formatting.
- test_api_client: request construction (URL/method/auth/body) and the full
  HTTP status-code -> message mapping.
- test_auth: RS256 JWT verification — valid -> AccessToken; expired/wrong-aud/
  wrong-issuer/wrong-key/missing-claim -> None; audience slash variants.
- test_server_setup: transport selection + start_server dispatch.
- test_events / test_activities / test_custom_items: request payloads
  (create vs update, POST/PUT/DELETE), delete accounting, JSON-content parsing,
  and error/empty branches.

Enforce >=90 via pytest --cov-fail-under=90; CI test job now gates the build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-04 18:39:20 -04:00

75 lines
2.4 KiB
Python

"""
Tests for intervals_mcp_server.server_setup — transport selection and startup.
Verifies MCP_TRANSPORT parsing (including the http -> streamable-http mapping and
the invalid-value error) and that start_server dispatches to mcp.run with the
correct transport arguments for each mode.
"""
from unittest.mock import MagicMock
import pytest
from intervals_mcp_server import server_setup
from intervals_mcp_server.utils.types import TransportAliases
# --------------------------------------------------------------------------- #
# setup_transport
# --------------------------------------------------------------------------- #
def test_default_is_stdio(monkeypatch):
monkeypatch.delenv("MCP_TRANSPORT", raising=False)
assert server_setup.setup_transport() == TransportAliases.STDIO
@pytest.mark.parametrize(
"value,expected",
[
("sse", TransportAliases.SSE),
("http", TransportAliases.STREAMABLE_HTTP), # http is an alias for streamable-http
("streamable-http", TransportAliases.STREAMABLE_HTTP),
("STDIO", TransportAliases.STDIO), # case-insensitive
],
)
def test_transport_mapping(monkeypatch, value, expected):
monkeypatch.setenv("MCP_TRANSPORT", value)
assert server_setup.setup_transport() == expected
def test_invalid_transport_raises(monkeypatch):
monkeypatch.setenv("MCP_TRANSPORT", "carrier-pigeon")
with pytest.raises(ValueError, match="Unsupported MCP_TRANSPORT"):
server_setup.setup_transport()
# --------------------------------------------------------------------------- #
# start_server
# --------------------------------------------------------------------------- #
def _mock_mcp():
m = MagicMock()
m.settings.host = "0.0.0.0"
m.settings.port = 8080
m.settings.sse_path = "/sse"
m.settings.message_path = "/messages"
m.settings.streamable_http_path = "/mcp"
return m
def test_start_server_stdio():
m = _mock_mcp()
server_setup.start_server(m, TransportAliases.STDIO)
m.run.assert_called_once_with()
def test_start_server_streamable_http():
m = _mock_mcp()
server_setup.start_server(m, TransportAliases.STREAMABLE_HTTP)
m.run.assert_called_once_with(transport="streamable-http")
def test_start_server_sse_uses_mount_path(monkeypatch):
monkeypatch.setenv("MCP_SSE_MOUNT_PATH", "/custom")
m = _mock_mcp()
server_setup.start_server(m, TransportAliases.SSE)
m.run.assert_called_once_with(transport="sse", mount_path="/custom")