test(mcp): the http transport, its unit and its token, in a guest
`checks.vm-mcp-http` -- the sibling of `vm-mcp`, on the same session machine. That one proves the *surface* over a pipe; this one proves the two things stdio does not have: a unit systemd supervises, and a credential on the way in. So there is one tool call and one resource read here, just enough to show a request reached the broker through an authenticated session, and the weight is on the refusals, the state directory's permissions, and the unit's lifecycle. **The first subtest is the one that justifies the file.** The server exits 2 while the authorization table is empty, which leaves a freshly provisioned machine in a failed state on purpose -- and that trade is only sound because the unit retries, so the first `token mint` brings it up with no `systemctl start`. That self-heal lives in `StartLimitIntervalSec = 0` and nothing in Python can test it. If it regresses, every machine that enables the option comes up dead and stays dead, and this is the only thing that would notice. Also asserted, and each for a reason rather than for coverage: the state directory is 0700 and owned by the account that mints tokens (which is also the proof an operator *can* mint one on a machine configured this way); the table is 0600 and does not contain the token; the port is on loopback and **not** in the firewall, because neither default may become implied; the refusals are 401 with an empty body and no echo; two tokens served by one process see different tool budgets, which is the whole argument for putting toolsets on a token; a revocation takes effect on the next request with no restart, because an operator who must restart a service to lock someone out does not have revocation; and revoking *every* token does not stop the process, since the startup refusal exists to catch a forgotten mint rather than to police a deliberate one. `lib/mcp_http_client.py` is raw JSON-RPC over `urllib` and deliberately not the SDK's client, for the reason `lib/mcp_client.py` is not either -- the SDK on both ends would agree with itself about a framing and a header neither side had to get right, and the header is half of what this file is about. It earned that choice immediately: it is what caught the 307 on the exact path that the SDK-shaped test client had been following silently. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KchcvnbfhhZhUHy83YL3Ya
This commit is contained in:
1 parent
10176356b6
commit
94a1f5988e
4 files changed
+619
No files matched your search
@@ -23,6 +23,7 @@ would 421 them, which is the behaviour ``test_rebinding_protection_*`` asserts.
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import pathlib
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -471,3 +472,35 @@ def test_offered_for_returns_everything_without_a_grant():
|
||||
|
||||
chooser = http_transport.offered_for(Server("probe"), tools.TOOLS)
|
||||
assert chooser() == tools.TOOLS
|
||||
|
||||
|
||||
# ── the dependencies this transport needs declared ─────────────────────────
|
||||
|
||||
|
||||
#: `src/hhstream_mcp/pyproject.toml`, when the suite is run from a checkout.
|
||||
#: Absent in the build sandbox, which copies only `tests/`.
|
||||
MCP_PYPROJECT = (
|
||||
pathlib.Path(__file__).resolve().parents[2] / "src" / "hhstream_mcp" / "pyproject.toml"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not MCP_PYPROJECT.is_file(), reason="not running from a checkout")
|
||||
def test_the_distribution_declares_what_this_module_imports():
|
||||
"""`starlette` and `uvicorn` by name, not by way of the SDK.
|
||||
|
||||
The same assertion `tests/pointer/test_vendored_protocol.py` makes about
|
||||
`pywayland` and `xkbcommon`, and for the same kind of reason. The MCP SDK
|
||||
propagates both of these today, so leaving them out of the metadata would
|
||||
*work* — which is exactly what makes it worth pinning. `http.py` imports
|
||||
`uvicorn` by name and the SDK's `TransportSecuritySettings` sits on
|
||||
Starlette's `Request`, so an SDK release that moved its HTTP transport
|
||||
behind an optional extra would break `serve --http` with an ImportError
|
||||
naming somebody else's package.
|
||||
"""
|
||||
|
||||
pyproject = MCP_PYPROJECT.read_text()
|
||||
assert "starlette" in pyproject
|
||||
assert "uvicorn" in pyproject
|
||||
# And `anyio`, which was already declared on this argument before the HTTP
|
||||
# transport existed — the precedent this follows.
|
||||
assert "anyio" in pyproject
|
||||
Reference in new issue
Block a user