Commit Graph
4 Commits
Author SHA1 Message Date
HermenixandClaude Opus 5 abf2c96ec1 test(mcp): pin the dependencies the http transport needs declared
`tests/pointer/test_vendored_protocol.py` asserts the root pyproject
names `pywayland` and `xkbcommon`, with a comment saying why neither may
be optional.  The MCP distribution had no equivalent, which left the
previous commit's argument resting on a comment.

So: `starlette` and `uvicorn` by name, and `anyio` beside them as the
precedent they follow.  The point of the test is that leaving them out
would *work* -- the SDK propagates all three today -- which is exactly
what makes a tripwire worth having rather than redundant.

Skipped outside a checkout, the same way its sibling is: the build
sandbox copies only `tests/`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KchcvnbfhhZhUHy83YL3Ya
2026-10-11 22:55:16 +00:00
HermenixandClaude Opus 5 8a0c9ca74d fix(mcp): declare the HTTP transport's dependencies, and forbid its tests to skip
`starlette` and `uvicorn` arrive through the MCP SDK today -- measured,
both of them -- and relying on that is exactly the trap this project
already wrote down twice.  `src/hhstream_mcp/pyproject.toml` declares
`anyio` rather than taking it for granted through the SDK because
`server.py` uses it by name; `http.py` imports `uvicorn` by name and sits
on Starlette's `Request` through the SDK's `TransportSecuritySettings`,
so both belong in the metadata on the same argument.  An SDK release that
moved its HTTP transport behind an optional extra would otherwise break
`serve --http` with an ImportError naming somebody else's package.
`nix/mcp.nix` carries them for the same reason.

The worse half was in the gate.  `tests/unit/test_mcp_http.py` opened
with `pytest.importorskip("starlette.testclient")`, which is the pattern
`checks/unit.nix`'s own comment argues against in as many words: "a file
that skipped when the SDK was absent would be green in exactly the build
where that mattered".  It would not skip today -- `mcp` propagates
starlette and httpx -- but the day it did, 43 tests would leave the gate
and nothing would say so, because pytest exits 0 when every test was
skipped.

So the import is unconditional now, `checks/unit.nix` declares `starlette`
and `httpx` explicitly, and the check proves them importable before
pytest runs, beside the lines that already do that for `hhstream` and the
tool table.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KchcvnbfhhZhUHy83YL3Ya
2026-10-11 22:49:44 +00:00
HermenixandClaude Opus 5 b2a683a560 fix(mcp): the endpoint is the exact path, and nothing redirects
`Starlette(routes=[Mount("/mcp", app=handle)])` serves `/mcp/` and
answers `/mcp` with a **307** -- or a 404 with `redirect_slashes` off.
Measured both ways.  Every MCP client configuration spells the URL
without the trailing slash, and a redirected POST has to be re-sent with
its body: `urllib` will not do that at all, and some clients get it
wrong.

So the routing is three lines of its own (`http.Endpoint`) instead: both
spellings are the endpoint, neither is a redirect to the other, and
anything else is a 404.  Starlette's router is gone from the request
path; the lifespan protocol is handled directly, which `manager.run()`
needs anyway because its task group must be exited by the task that
entered it.

This got through the unit suite once, and that is the more useful half of
this commit.  `starlette.testclient` follows redirects by default, so
every assertion in `test_mcp_http.py` passed against a server a real
client could not talk to -- the 307 only surfaced in
`checks/vm-mcp-http.nix`, from a `urllib` client over a real socket.
`post()` now passes `follow_redirects=False`, and
`test_the_exact_path_does_not_redirect` asserts both spellings answer
200 directly.  A test client that papers over a redirect is a test client
that cannot see one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KchcvnbfhhZhUHy83YL3Ya
2026-10-11 22:41:01 +00:00
HermenixandClaude Opus 5 fd6d48099b test(mcp): the store, the token verbs, and every way a request is refused
373 unit tests, up from 266.  Three files, split the way the modules are:
`test_mcp_authorizations.py` is standard library and touches no SDK,
`test_mcp_http.py` drives a real ASGI stack, and the additions to
`test_mcp_server.py` are about the command line now that it has
subcommands.

Four of these exist for properties that a refactor breaks silently rather
than loudly, which is the only reason they are worth their length:

* **the file never holds a token.**  A store that started writing the
  secret instead of its digest would pass every functional test here, so
  one test reads the bytes on disk and looks for the token and for a
  usable prefix of it.
* **a concurrent mint is not lost.**  Thirty threads mint into one table
  and all thirty tokens must still verify.  The atomic replace stops a
  torn read; it does nothing about two writers loading the same table and
  the second replacing the first's addition.  Without the flock this
  fails.
* **`--toolsets` before the subcommand survives it.**  argparse copies a
  subparser's namespace over the top-level one, so an ordinary default on
  the subcommand's copy would overwrite the value with `None` and
  `hhstream-mcp --toolsets=frames serve` would quietly serve all
  twenty-one tools.  `SUPPRESS` prevents it and this test notices if it
  goes.
* **a token verb never claims the transport.**  `mint` prints a secret on
  stdout, which on stdio *is* the transport, so `claim_transport` is
  monkeypatched to fail the test if it is ever reached.

The refusal tests assert the absence of information as much as the status
code: an empty body, no echo of the token in body or headers, and
unknown/revoked/expired arriving as one answer byte for byte -- telling
them apart would tell someone who guessed a real id that they had. An
unknown path is a 401 before a 404, so an unauthenticated caller does not
learn what is mounted; the token is checked before the Host, so it does
not learn the allowlist either.

`test_resources_are_not_narrowed_by_a_token` asserts a *limit*, on
purpose: a token scoped to `frames` can still read `hhstream://sessions`,
and that is written down rather than left for someone to discover.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KchcvnbfhhZhUHy83YL3Ya
2026-10-11 20:45:53 +00:00