2 Commits
Author SHA1 Message Date
HermenixandClaude Opus 5 94a1f5988e 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
2026-10-12 18:13:52 +00:00
HermenixandClaude Opus 5 7eb9afdfa3 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-12 18:00:05 +00:00