This commit is contained in:
parent
3a6f2996cd
commit
837ef904f8
1 changed files with 1757 additions and 567 deletions
|
|
@ -6,10 +6,18 @@ the (transport, spec_version) cells via :func:`compute_cells`, applying arm excl
|
|||
bounds, and known-failure xfails declaratively.
|
||||
"""
|
||||
|
||||
from functools import partial
|
||||
from contextlib import AbstractAsyncContextManager
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from mcp_types import SERVER_INFO_META_KEY
|
||||
from mcp_types.version import MODERN_PROTOCOL_VERSIONS
|
||||
|
||||
from mcp.client.client import Client
|
||||
from mcp.server import Server
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
from tests._stamp import R, Unstamp
|
||||
from tests._stamp import unstamped as _strip_required_stamp
|
||||
from tests.interaction._connect import (
|
||||
Connect,
|
||||
connect_in_memory,
|
||||
|
|
@ -35,8 +43,23 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
|
|||
metafunc.parametrize("connect", compute_cells(requirements), indirect=True)
|
||||
|
||||
|
||||
class CellConnect:
|
||||
"""The cell's connection factory, also naming the cell's `spec_version`.
|
||||
|
||||
Callable exactly like the `Connect` factories it wraps; the attribute lets
|
||||
sibling fixtures (`unstamped`) key on the cell's era without re-deriving it.
|
||||
"""
|
||||
|
||||
def __init__(self, factory: Connect, spec_version: str) -> None:
|
||||
self._factory = factory
|
||||
self.spec_version = spec_version
|
||||
|
||||
def __call__(self, server: Server | MCPServer, **kwargs: Any) -> AbstractAsyncContextManager[Client]:
|
||||
return self._factory(server, spec_version=self.spec_version, **kwargs)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def connect(request: pytest.FixtureRequest) -> Connect:
|
||||
def connect(request: pytest.FixtureRequest) -> CellConnect:
|
||||
"""The transport-parametrized connection factory: a test using it runs once per matrix cell.
|
||||
|
||||
Tests that are tied to one transport (the wire-recording tests, the bare-ClientSession tests,
|
||||
|
|
@ -45,4 +68,24 @@ def connect(request: pytest.FixtureRequest) -> Connect:
|
|||
transport, spec_version = request.param
|
||||
assert isinstance(transport, str)
|
||||
assert isinstance(spec_version, str)
|
||||
return partial(_FACTORIES[transport], spec_version=spec_version)
|
||||
return CellConnect(_FACTORIES[transport], spec_version)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def unstamped(connect: CellConnect) -> Unstamp:
|
||||
"""The cell's era-aware serverInfo-stamp normalizer, for full-result comparisons.
|
||||
|
||||
On a modern cell the stamp MUST be present (asserted) and is stripped so
|
||||
one expected payload stays valid across eras; on a handshake-era cell the
|
||||
result must not be stamped at all. Either direction failing is a runner
|
||||
regression, so the same comparison line enforces both.
|
||||
"""
|
||||
if connect.spec_version in MODERN_PROTOCOL_VERSIONS:
|
||||
return _strip_required_stamp
|
||||
|
||||
def _assert_never_stamped(result: R) -> R:
|
||||
meta = result.meta
|
||||
assert meta is None or SERVER_INFO_META_KEY not in meta, "handshake-era results are never stamped"
|
||||
return result
|
||||
|
||||
return _assert_never_stamped
|
||||
|
|
|
|||
Loading…
Reference in a new issue