test_mcp_docs.py
python
sha256:0a2400b8017d871bff9916bfa6d3898b74b0dcce7f8e4d6e842365133f21090a
fix(coord): a task claim is one conditional UPDATE — exactl…
Opus 5.5
minor
⚠ breaking
1 day ago
| 1 | """DOC_MCD — /mcp/docs contract (musehub#261, QA contract v2). |
| 2 | |
| 3 | Every claim on the page was checked on 2026-11-09 against musehub ``dev`` 259e6968 (the real ``/mcp`` router, dispatcher, |
| 4 | scope policy and registry) and Muse 0.2.1rc20. The tool groups, counts, auth / scope / hint matrix and every card come from |
| 5 | the live registry (``ui_docs._mcp_catalogue()`` + ``MCP_TOOLS``); these tests re-derive each from the gates the server |
| 6 | enforces and from ``tools/list``, offline and database-free: the HTTP transport runs in-process on a bare FastAPI app with |
| 7 | the database dependencies stubbed, and the page is rendered by the real app. Known product defects stay documented as |
| 8 | contract plus warning (#241 defect-preservation rule): each is pinned by a strict xfail that flips when its ticket is fixed. |
| 9 | |
| 10 | DOC_MCD_01 (commands parse) is ``TestPageClaims::test_documented_commands_parse``; _02 (anchors) is |
| 11 | ``test_in_page_and_docs_links_resolve``; _03 (URL scheme) is ``test_served_over_https_has_no_http_urls`` (musehub#276, |
| 12 | fixed); _04 (every registry tool once, with the group and auth the server enforces) is ``TestRegistry``; |
| 13 | _05 is ``TestMachineTwin`` (docs.json equals tools/list); _06 is ``TestQuickStart``; _07 is ``TestKnownDefects``. |
| 14 | """ |
| 15 | |
| 16 | from __future__ import annotations |
| 17 | |
| 18 | import argparse |
| 19 | import html as html_lib |
| 20 | import re |
| 21 | import time |
| 22 | from collections.abc import Iterator |
| 23 | from pathlib import Path |
| 24 | from typing import Any |
| 25 | |
| 26 | import pytest |
| 27 | from fastapi import FastAPI |
| 28 | from fastapi.testclient import TestClient |
| 29 | |
| 30 | from tests.docs_contract import cli_check as cc |
| 31 | from tests.docs_contract import mcp_session_table |
| 32 | from tests.docs_contract import registry_check as rc |
| 33 | from tests.docs_contract import scheme_check as sc |
| 34 | from tests.docs_contract.pages import BRIDGE_GATEWAY_PEER, render_behind_proxy |
| 35 | from tests.docs_contract.test_doc_inf_scheme import trusted_proxies # noqa: F401 - fixture reused |
| 36 | |
| 37 | pytestmark = pytest.mark.no_db |
| 38 | |
| 39 | PAGE = "/mcp/docs" |
| 40 | HUB_ISSUES = "https://staging.musehub.ai/gabriel/musehub/issues/" |
| 41 | _REPO = Path(__file__).resolve().parents[2] |
| 42 | _TEMPLATE = _REPO / "musehub" / "templates" / "musehub" / "pages" / "mcp_docs.html" |
| 43 | _KNOWN = {"289", "300"} |
| 44 | XFAIL = dict(strict=True, raises=AssertionError) |
| 45 | |
| 46 | INIT = { |
| 47 | "jsonrpc": "2.0", |
| 48 | "id": 1, |
| 49 | "method": "initialize", |
| 50 | "params": { |
| 51 | "protocolVersion": "2025-11-25", |
| 52 | "capabilities": {"elicitation": {"form": {}, "url": {}}}, |
| 53 | "clientInfo": {"name": "doc-mcd", "version": "1"}, |
| 54 | }, |
| 55 | } |
| 56 | |
| 57 | |
| 58 | # ── Fixtures ──────────────────────────────────────────────────────────────── |
| 59 | |
| 60 | |
| 61 | @pytest.fixture(scope="module") |
| 62 | def page() -> str: |
| 63 | from musehub.main import app |
| 64 | |
| 65 | r = TestClient(app).get(PAGE) |
| 66 | assert r.status_code == 200 and r.headers["content-type"].startswith("text/html") |
| 67 | return r.text |
| 68 | |
| 69 | |
| 70 | @pytest.fixture(scope="module") |
| 71 | def html(page: str) -> str: |
| 72 | """The raw markup with only quote entities decoded: attribute values keep their ``>`` so tags stay parseable.""" |
| 73 | return page.replace("'", "'").replace(""", '"').replace(""", '"') |
| 74 | |
| 75 | |
| 76 | @pytest.fixture(scope="module") |
| 77 | def text(html: str) -> str: |
| 78 | return " ".join(html_lib.unescape(re.sub(r"<[^>]+>", "", html)).split()) |
| 79 | |
| 80 | |
| 81 | @pytest.fixture(scope="module") |
| 82 | def client() -> Iterator[TestClient]: |
| 83 | from musehub.api.routes import mcp as route |
| 84 | from musehub.auth.request_signing import optional_signed_request |
| 85 | from musehub.rate_limits import limiter |
| 86 | |
| 87 | app = FastAPI() |
| 88 | app.state.limiter = limiter |
| 89 | app.include_router(route.router) |
| 90 | app.dependency_overrides[optional_signed_request] = lambda: None # anonymous caller |
| 91 | with mcp_session_table.installed(), TestClient(app) as c: # the session table every worker shares, in memory (#289) |
| 92 | yield c |
| 93 | |
| 94 | |
| 95 | @pytest.fixture(scope="module") |
| 96 | def sid(client: TestClient) -> str: |
| 97 | r = client.post("/mcp", json=INIT) |
| 98 | assert r.status_code == 200 |
| 99 | return r.headers["Mcp-Session-Id"] |
| 100 | |
| 101 | |
| 102 | @pytest.fixture(scope="module") |
| 103 | def initialize(client: TestClient) -> dict[str, Any]: |
| 104 | return client.post("/mcp", json=INIT).json()["result"] |
| 105 | |
| 106 | |
| 107 | @pytest.fixture(scope="module") |
| 108 | def docs_json(client: TestClient) -> tuple[dict[str, Any], Any]: |
| 109 | r = client.get("/mcp/docs.json") |
| 110 | assert r.status_code == 200 |
| 111 | return r.json(), r |
| 112 | |
| 113 | |
| 114 | def _rpc(client: TestClient, sid: str, method: str, params: dict[str, Any] | None = None) -> Any: |
| 115 | body = {"jsonrpc": "2.0", "id": 7, "method": method, **({"params": params} if params else {})} |
| 116 | return client.post("/mcp", json=body, headers={"Mcp-Session-Id": sid}) |
| 117 | |
| 118 | |
| 119 | @pytest.fixture(scope="module") |
| 120 | def tools_list(client: TestClient, sid: str) -> list[dict[str, Any]]: |
| 121 | return _rpc(client, sid, "tools/list").json()["result"]["tools"] |
| 122 | |
| 123 | |
| 124 | def _section(html: str, anchor: str) -> str: |
| 125 | return html.split(f'id="{anchor}"', 1)[1].split("</section>", 1)[0] |
| 126 | |
| 127 | |
| 128 | def _cards(html: str) -> dict[str, dict[str, str]]: |
| 129 | out: dict[str, dict[str, str]] = {} |
| 130 | for m in re.finditer(r'<div class="tool-card tool-card--([a-z-]+)" id="tool-([a-z_]+)"[^>]*data-auth="([a-z]+)"', html): |
| 131 | assert m.group(2) not in out, f"{m.group(2)} rendered twice" |
| 132 | out[m.group(2)] = {"group": m.group(1), "auth": m.group(3)} |
| 133 | return out |
| 134 | |
| 135 | |
| 136 | def _matrix_rows(html: str) -> list[dict[str, str]]: |
| 137 | table = html.split('id="tool-matrix-table"', 1)[1].split("</table>", 1)[0] |
| 138 | return [dict(re.findall(r'data-([a-z-]+)="([^"]*)"', m)) for m in re.findall(r"<tr data-tool=[^>]*>", table)] |
| 139 | |
| 140 | |
| 141 | # ── DOC_MCD_04: every registry tool once, with the group and auth the server enforces ───────────────────── |
| 142 | |
| 143 | |
| 144 | class TestRegistry: |
| 145 | def test_hero_counts_are_the_registry_counts(self, html: str) -> None: |
| 146 | from musehub.mcp.prompts import PROMPT_CATALOGUE |
| 147 | from musehub.mcp.resources import RESOURCE_TEMPLATES, STATIC_RESOURCES |
| 148 | from musehub.mcp.tools import MCP_TOOLS |
| 149 | |
| 150 | nums = re.findall(r'<span class="stat-pill__num">(\d+)</span>\s*<span class="stat-pill__label">([A-Za-z]+)</span>', html) |
| 151 | assert dict((label, int(n)) for n, label in nums) == { |
| 152 | "Tools": len(MCP_TOOLS), |
| 153 | "Resources": len(STATIC_RESOURCES), |
| 154 | "Templates": len(RESOURCE_TEMPLATES), |
| 155 | "Prompts": len(PROMPT_CATALOGUE), |
| 156 | } |
| 157 | assert len(MCP_TOOLS) == len({t["name"] for t in MCP_TOOLS}) |
| 158 | |
| 159 | def test_every_registry_tool_has_exactly_one_card_in_the_group_its_registry_list_says(self, html: str) -> None: |
| 160 | from musehub.api.routes.musehub.ui_docs import _mcp_catalogue |
| 161 | from musehub.mcp.tools import MCP_TOOLS |
| 162 | |
| 163 | cards = _cards(html) |
| 164 | assert set(cards) == {t["name"] for t in MCP_TOOLS} |
| 165 | for g in _mcp_catalogue()["groups"]: # type: ignore[attr-defined] |
| 166 | for t in g.tools: |
| 167 | assert cards[t.name]["group"] == g.key, t.name |
| 168 | # each card sits inside its own group's section |
| 169 | for g in _mcp_catalogue()["groups"]: # type: ignore[attr-defined] |
| 170 | body = _section(html, f"tools-{g.key}") |
| 171 | assert {n for n in re.findall(r'id="tool-([a-z_]+)"', body)} == {t.name for t in g.tools}, g.key |
| 172 | |
| 173 | def test_card_auth_equals_the_gate_the_dispatcher_enforces(self, html: str) -> None: |
| 174 | from musehub.mcp.tools import MUSEHUB_WRITE_TOOL_NAMES |
| 175 | |
| 176 | for name, c in _cards(html).items(): |
| 177 | assert (c["auth"] == "msign") == (name in MUSEHUB_WRITE_TOOL_NAMES), name |
| 178 | assert sum(c["auth"] == "msign" for c in _cards(html).values()) == len(MUSEHUB_WRITE_TOOL_NAMES) == 75 |
| 179 | |
| 180 | def test_matrix_rows_equal_cards_scope_policy_and_tools_list_hints(self, html: str, tools_list: list[dict[str, Any]]) -> None: |
| 181 | from musehub.mcp import scope_policy |
| 182 | from musehub.mcp.tools import MUSEHUB_WRITE_TOOL_NAMES |
| 183 | |
| 184 | rows = _matrix_rows(html) |
| 185 | listed = {t["name"]: t for t in tools_list} |
| 186 | assert len(rows) == len(listed) == 127 and {r["tool"] for r in rows} == set(listed) |
| 187 | for r in rows: |
| 188 | n, ann = r["tool"], listed[r["tool"]]["annotations"] |
| 189 | assert (r["auth"] == "msign") == (n in MUSEHUB_WRITE_TOOL_NAMES), n |
| 190 | assert (r["readonly"] == "true") == bool(ann.get("readOnlyHint")), n |
| 191 | assert (r["destructive"] == "true") == bool(ann.get("destructiveHint")), n |
| 192 | want_scope = "" if n in scope_policy.READ_TOOLS else scope_policy.REQUIRED_SCOPE.get(n, "not for agent identities" if n in scope_policy.SCOPED_CALLER_DENIED else "") |
| 193 | assert r["scope"] == want_scope, n |
| 194 | |
| 195 | def test_group_summary_counts_and_totals(self, html: str) -> None: |
| 196 | from musehub.mcp.tools import MCP_TOOLS, MUSEHUB_WRITE_TOOL_NAMES |
| 197 | |
| 198 | table = html.split('id="tool-groups"', 1)[1].split("</table>", 1)[0] |
| 199 | rows = {m[0]: (int(m[1]), int(m[2])) for m in re.findall(r'<tr data-group="([a-z-]+)" data-count="(\d+)" data-auth="(\d+)"', table)} |
| 200 | assert sum(c for c, _ in rows.values()) == len(MCP_TOOLS) and sum(a for _, a in rows.values()) == len(MUSEHUB_WRITE_TOOL_NAMES) |
| 201 | assert set(rows) == {"read", "write", "elicitation", "coord-read", "coord-write", "workspace"} |
| 202 | assert f"{len(MCP_TOOLS)} tools in 6 registry groups: {len(MUSEHUB_WRITE_TOOL_NAMES)} need an MSign signature" in html |
| 203 | |
| 204 | def test_no_hand_written_tool_lists_remain_in_the_template(self) -> None: |
| 205 | src = _TEMPLATE.read_text(encoding="utf-8") |
| 206 | assert not re.search(r"\b(read_names|cli_names|mist_names|elicit_names)\b", src) |
| 207 | assert not re.findall(r"'(?:musehub|muse)_[a-z_]*[a-z]'", src), "a tool name is typed into the template" |
| 208 | assert "{% for t in tools if" not in src |
| 209 | |
| 210 | def test_the_server_and_deprecated_badges_are_gone_and_nothing_is_deprecated(self, html: str) -> None: |
| 211 | from musehub.mcp.prompts import PROMPT_CATALOGUE |
| 212 | from musehub.mcp.resources import RESOURCE_TEMPLATES, STATIC_RESOURCES |
| 213 | from musehub.mcp.tools import MCP_TOOLS |
| 214 | |
| 215 | assert "badge--server" not in html and "badge--deprecated" not in html |
| 216 | blob = repr((MCP_TOOLS, STATIC_RESOURCES, RESOURCE_TEMPLATES, PROMPT_CATALOGUE)).lower() |
| 217 | assert "deprecat" not in blob, "the no-legacy rule: delete a deprecated tool instead of badging it" |
| 218 | assert all(t.get("server_side") for t in MCP_TOOLS), "every tool carried the 'server' badge, so it said nothing" |
| 219 | |
| 220 | def test_anonymous_calls_to_every_signed_tool_are_refused_by_the_gate( |
| 221 | self, client: TestClient, sid: str, monkeypatch: pytest.MonkeyPatch |
| 222 | ) -> None: |
| 223 | from musehub.api.routes import mcp as route |
| 224 | from musehub.mcp.tools import MUSEHUB_WRITE_TOOL_NAMES |
| 225 | |
| 226 | # One anonymous call per signed tool, far more than the anonymous per-IP budget: lift that budget for this sweep |
| 227 | # only (the limit itself is pinned by TestKnownDefects::test_an_anonymous_caller_is_held_to_the_anonymous_limit). |
| 228 | monkeypatch.setitem(route._CALLER_LIMITS, "anonymous", f"{len(MUSEHUB_WRITE_TOOL_NAMES) + 10}/minute") |
| 229 | for name in sorted(MUSEHUB_WRITE_TOOL_NAMES): |
| 230 | r = _rpc(client, sid, "tools/call", {"name": name, "arguments": {}}) |
| 231 | assert r.status_code == 401 and r.json()["error"]["code"] == -32001, name |
| 232 | assert "MSign signature" in r.json()["error"]["message"], name |
| 233 | |
| 234 | def test_resources_templates_and_prompts_equal_the_jsonrpc_lists(self, client: TestClient, sid: str, html: str) -> None: |
| 235 | uris = [x["uri"] for x in _rpc(client, sid, "resources/list").json()["result"]["resources"]] |
| 236 | tpls = [x["uriTemplate"] for x in _rpc(client, sid, "resources/templates/list").json()["result"]["resourceTemplates"]] |
| 237 | names = [x["name"] for x in _rpc(client, sid, "prompts/list").json()["result"]["prompts"]] |
| 238 | assert [html.count(f'<code class="resource-card__uri">{u}</code>') for u in uris] == [1] * len(uris) |
| 239 | assert [html.count(f'<code class="resource-card__uri">{u}</code>') for u in tpls] == [1] * len(tpls) |
| 240 | assert [html.count(f'<code class="prompt-card__name">{n}</code>') for n in names] == [1] * len(names) |
| 241 | |
| 242 | |
| 243 | # ── DOC_MCD_05: the machine twin ───────────────────────────────────────────── |
| 244 | |
| 245 | |
| 246 | class TestMachineTwin: |
| 247 | def test_docs_json_equals_tools_list_resources_templates_and_prompts(self, client: TestClient, sid: str, docs_json: tuple[dict[str, Any], Any], tools_list: list[dict[str, Any]]) -> None: |
| 248 | d, _ = docs_json |
| 249 | assert d["tools"] == tools_list |
| 250 | assert [x["uri"] for x in d["resources"]] == [x["uri"] for x in _rpc(client, sid, "resources/list").json()["result"]["resources"]] |
| 251 | assert [x["uriTemplate"] for x in d["resourceTemplates"]] == [x["uriTemplate"] for x in _rpc(client, sid, "resources/templates/list").json()["result"]["resourceTemplates"]] |
| 252 | assert [x["name"] for x in d["prompts"]] == [x["name"] for x in _rpc(client, sid, "prompts/list").json()["result"]["prompts"]] |
| 253 | assert {k: len(d[k]) for k in ("tools", "resources", "resourceTemplates", "prompts")} == {"tools": 127, "resources": 9, "resourceTemplates": 19, "prompts": 11} |
| 254 | |
| 255 | def test_server_block_is_the_served_one_and_public_cacheable(self, docs_json: tuple[dict[str, Any], Any], initialize: dict[str, Any]) -> None: |
| 256 | from musehub.api.routes.mcp import _PROTOCOL_VERSION |
| 257 | |
| 258 | d, r = docs_json |
| 259 | assert d["server"]["version"] == initialize["serverInfo"]["version"] and d["server"]["name"] == initialize["serverInfo"]["name"] |
| 260 | assert d["server"]["protocolVersion"] == initialize["protocolVersion"] == _PROTOCOL_VERSION == "2025-11-25" |
| 261 | assert r.headers["cache-control"] == "public, max-age=300" |
| 262 | src = (_REPO / "musehub" / "api" / "routes" / "mcp.py").read_text(encoding="utf-8") |
| 263 | assert '"version": "0.2.0"' not in src, "the version is read from the dispatcher, not typed twice" |
| 264 | |
| 265 | def test_the_page_links_the_machine_twin_and_the_spec_for_the_served_version(self, html: str) -> None: |
| 266 | assert html.count('href="/mcp/docs.json"') >= 2 |
| 267 | assert "modelcontextprotocol.io/specification/2025-11-25" in html |
| 268 | |
| 269 | |
| 270 | # ── DOC_MCD_06: the quick-start is the server's own onboarding sequence ───────────────────────────────────── |
| 271 | |
| 272 | |
| 273 | class TestQuickStart: |
| 274 | def test_every_tool_and_prompt_named_in_the_quick_start_exists(self, html: str) -> None: |
| 275 | from musehub.mcp.prompts import PROMPT_CATALOGUE |
| 276 | from musehub.mcp.tools import MCP_TOOLS |
| 277 | |
| 278 | body = _section(html, "quickstart") |
| 279 | names = set(re.findall(r"<code>((?:musehub|muse)_[a-z_]+)</code>", body)) |
| 280 | assert names >= {"musehub_set_context", "musehub_list_domains", "musehub_search_repos", "musehub_read_context", "musehub_read_coord_swarm", "muse_push", "musehub_read_prompt"} |
| 281 | assert names <= {t["name"] for t in MCP_TOOLS} |
| 282 | orient = next(p for p in PROMPT_CATALOGUE if p["name"] == "musehub/orientation") |
| 283 | assert any(a["name"] == "caller_type" for a in orient["arguments"]) and "<code>musehub/orientation</code>" in body and 'caller_type: "agent"' in body |
| 284 | |
| 285 | def test_the_order_equals_the_initialize_instructions(self, html: str, initialize: dict[str, Any]) -> None: |
| 286 | body = _section(html, "quickstart") |
| 287 | order = [body.index(f"<code>{n}</code>") for n in ("musehub_set_context", "musehub_read_context", "musehub_read_coord_swarm", "muse_push")] |
| 288 | assert order == sorted(order) |
| 289 | ins = initialize["instructions"] |
| 290 | assert ins.index("musehub_set_context") < ins.index("musehub_read_context") < ins.index("musehub_read_coord_swarm") |
| 291 | |
| 292 | def test_the_muse_mcp_page_no_longer_says_the_sequences_differ(self, rendered: dict[str, str]) -> None: |
| 293 | guide = rendered[rc.phase_path("mcp")] |
| 294 | assert "suggests a different first sequence" not in guide and "being consolidated" not in guide |
| 295 | assert 'href="/mcp/docs#quickstart"' in guide and 'id="known-issues"' in guide |
| 296 | |
| 297 | def test_the_documented_agent_registration_commands_parse(self, html: str) -> None: |
| 298 | parser = cc.capture_parser() |
| 299 | cmds = [c for c in cc.extract_commands(html)] |
| 300 | lines = {c.line for c in cmds} |
| 301 | assert {"muse auth keygen", "muse auth register --agent"} <= lines |
| 302 | _, problems = cc.check_page(parser, PAGE, html) |
| 303 | assert problems == [], "\n".join(problems) |
| 304 | |
| 305 | |
| 306 | # ── DOC_MCD_01/02/03 and the page's own claims ────────────────────────────────────────────────────────── |
| 307 | |
| 308 | |
| 309 | class TestPageClaims: |
| 310 | def test_documented_commands_parse(self, html: str) -> None: |
| 311 | _, problems = cc.check_page(cc.capture_parser(), PAGE, html) |
| 312 | assert problems == [] |
| 313 | |
| 314 | def test_in_page_and_docs_links_resolve(self, page: str, rendered: dict[str, str]) -> None: |
| 315 | from musehub.main import app |
| 316 | |
| 317 | parsed = {p: rc.parse_page(h) for p, h in rendered.items()} | {PAGE: rc.parse_page(page)} |
| 318 | other = {r.path for r in app.routes if hasattr(r, "path")} |
| 319 | problems = [p for p in rc.check_anchors(parsed, other_routes=other) if p.startswith(PAGE)] |
| 320 | assert problems == [] |
| 321 | |
| 322 | def test_the_msign_examples_carry_alg_and_the_servers_parser_accepts_them(self, html: str) -> None: |
| 323 | from musehub.auth.request_signing import _parse_msign_header |
| 324 | |
| 325 | raw = re.findall(r'Authorization: (MSign handle="<handle>".*?sig="<b64url>")', html) |
| 326 | assert len(raw) == 2 and all('alg="ed25519"' in e for e in raw), raw |
| 327 | for e in raw: |
| 328 | filled = html_lib.unescape(e).replace("<handle>", "alice").replace("<unix>", "1700000000").replace("<b64url>", "AAAA") |
| 329 | assert _parse_msign_header(filled) == ("alice", "ed25519", 1700000000, "AAAA") |
| 330 | assert _parse_msign_header(filled.replace(' alg="ed25519"', "")) is None # the old example, without alg, is refused |
| 331 | |
| 332 | def test_the_tool_filter_is_labelled_and_the_count_is_announced(self, html: str) -> None: |
| 333 | tag = re.search(r'<input id="tool-filter"[^>]*>', html) |
| 334 | assert tag and "aria-label=" in tag.group(0) |
| 335 | counter = re.search(r'<span id="tool-count"[^>]*>', html) |
| 336 | assert counter and 'role="status"' in counter.group(0) and 'aria-live="polite"' in counter.group(0) |
| 337 | |
| 338 | def test_external_links_open_with_noopener_and_there_is_one_main_and_one_h1(self, html: str) -> None: |
| 339 | for a in re.findall(r"<a [^>]*target=\"_blank\"[^>]*>", html): |
| 340 | assert "noopener" in a, a |
| 341 | assert html.count("<main ") == 1 and html.count("<h1") == 1 |
| 342 | |
| 343 | def test_required_marks_are_also_text_not_only_a_star(self, html: str) -> None: |
| 344 | assert html.count('<span class="mcpref__sr"> required</span>') > 100 and html.count('<span class="mcpref__sr"> optional</span>') > 100 |
| 345 | |
| 346 | def test_the_rate_limit_row_states_the_enforced_defaults(self, html: str) -> None: |
| 347 | from musehub.config import settings |
| 348 | from musehub.rate_limits import MCP_LIMIT |
| 349 | |
| 350 | assert (settings.mcp_rate_limit_anonymous, settings.mcp_rate_limit_human, settings.mcp_rate_limit_agent) == ( |
| 351 | "20/minute", "60/minute", "600/minute") |
| 352 | assert MCP_LIMIT == settings.mcp_rate_limit_agent # the per-IP ceiling on the route |
| 353 | assert ("anonymous 20 per client IP, human 60 per MSign handle, agent 600 per MSign handle; " |
| 354 | "at most 600 per client IP overall") in html |
| 355 | assert "the same for every caller" not in html and "musehub#325" not in html |
| 356 | |
| 357 | def test_the_route_no_longer_hides_render_errors_behind_a_redirect(self) -> None: |
| 358 | from unittest.mock import patch |
| 359 | |
| 360 | from musehub.api.routes.musehub import _templates |
| 361 | from musehub.main import app |
| 362 | |
| 363 | with patch.object(_templates.templates, "TemplateResponse", side_effect=RuntimeError("boom")): |
| 364 | with pytest.raises(RuntimeError, match="boom"): |
| 365 | TestClient(app).get(PAGE) |
| 366 | assert "except Exception" not in (_REPO / "musehub" / "api" / "routes" / "mcp.py").read_text(encoding="utf-8").split("async def mcp_docs(")[1].split("# ── Helpers")[0] |
| 367 | |
| 368 | def test_served_over_https_has_no_http_urls(self, trusted_proxies: str) -> None: # noqa: F811 |
| 369 | served = render_behind_proxy([PAGE], trusted_proxies, BRIDGE_GATEWAY_PEER) |
| 370 | assert sc.check_page(PAGE, served[PAGE]) == [] |
| 371 | |
| 372 | |
| 373 | # ── DOC_MCD_07: known defects, pinned: each flips when its ticket is fixed ───────────────────────────────── |
| 374 | |
| 375 | |
| 376 | @pytest.fixture(scope="module") |
| 377 | def anonymous_first_429(client: TestClient) -> int | None: |
| 378 | from musehub.rate_limits import limiter |
| 379 | |
| 380 | limiter.reset() |
| 381 | start = time.monotonic() |
| 382 | first = None |
| 383 | for i in range(1, 640): |
| 384 | if client.post("/mcp", json={"jsonrpc": "2.0", "id": i, "method": "ping"}).status_code == 429: |
| 385 | first = i |
| 386 | break |
| 387 | assert time.monotonic() - start < 120 |
| 388 | limiter.reset() |
| 389 | return first |
| 390 | |
| 391 | |
| 392 | class TestKnownDefects: |
| 393 | def test_every_known_issue_links_its_ticket_and_the_guide(self, html: str) -> None: |
| 394 | for n in _KNOWN: |
| 395 | assert f'href="{HUB_ISSUES}{n}"' in html, n |
| 396 | assert 'href="/muse/mcp#known-issues"' in html |
| 397 | |
| 398 | def test_an_anonymous_caller_is_held_to_the_anonymous_limit(self, anonymous_first_429: int | None) -> None: |
| 399 | from musehub.config import settings |
| 400 | |
| 401 | limit = int(settings.mcp_rate_limit_anonymous.split("/")[0]) |
| 402 | assert anonymous_first_429 == limit + 1 # not the 601 of the per-IP agent ceiling |
| 403 | |
| 404 | def test_every_mcp_rate_limit_setting_is_read_by_non_test_code(self) -> None: |
| 405 | src = "".join(p.read_text(encoding="utf-8") for p in (_REPO / "musehub").rglob("*.py") if p.name != "config.py") |
| 406 | assert "mcp_rate_limit_human" in src and "mcp_rate_limit_anonymous" in src |
| 407 | |
| 408 | def test_the_signed_read_only_tools_are_the_page_note(self, html: str, tools_list: list[dict[str, Any]]) -> None: |
| 409 | from musehub.mcp import scope_policy |
| 410 | from musehub.mcp.tools import MUSEHUB_WRITE_TOOL_NAMES |
| 411 | |
| 412 | listed = {t["name"]: t["annotations"] for t in tools_list} |
| 413 | signed_reads = sorted(n for n in MUSEHUB_WRITE_TOOL_NAMES if listed[n]["readOnlyHint"]) |
| 414 | assert signed_reads == sorted(scope_policy.READ_TOOLS - {"musehub_accept_collaborator_invite"}) and len(signed_reads) == 15 |
| 415 | assert f"{len(signed_reads)} read-only tools need a signature" in html and ", ".join(signed_reads) in html |
| 416 | assert "musehub#324" not in html and "Write tools require" not in html |
| 417 | |
| 418 | def test_read_class_tools_report_read_only(self, tools_list: list[dict[str, Any]]) -> None: |
| 419 | from musehub.mcp import scope_policy |
| 420 | |
| 421 | listed = {t["name"]: t for t in tools_list} |
| 422 | assert all(listed[n]["annotations"]["readOnlyHint"] for n in scope_policy.READ_TOOLS - {"musehub_accept_collaborator_invite"}) |
| 423 | |
| 424 | def test_the_gate_message_does_not_call_a_read_a_write(self, client: TestClient, sid: str) -> None: |
| 425 | r = _rpc(client, sid, "tools/call", {"name": "musehub_list_webhooks", "arguments": {}}) |
| 426 | assert "Write tools" not in r.json()["error"]["message"] |
| 427 | |
| 428 | def test_task_lists_sort_the_way_the_descriptions_say(self) -> None: |
| 429 | src = (_REPO / "musehub" / "services" / "musehub_coord_server.py").read_text(encoding="utf-8") |
| 430 | body = src.split("async def list_tasks(", 1)[1].split("async def ", 1)[0] |
| 431 | assert "priority.desc()" in body |
| 432 | |
| 433 | def test_the_page_states_the_task_order_the_descriptions_promise(self, html: str) -> None: |
| 434 | from musehub.mcp.tools import MCP_TOOLS |
| 435 | |
| 436 | d = {t["name"]: t["description"] for t in MCP_TOOLS} |
| 437 | assert "highest priority first" in d["musehub_list_coord_tasks"] |
| 438 | section = _section(html, "tools-coord-write") |
| 439 | assert "Tasks are listed highest <code>priority</code> first" in section and "lowest" not in section |
| 440 | |
| 441 | def test_no_docstring_states_a_stale_tool_count(self) -> None: |
| 442 | import musehub.mcp.tools as pkg |
| 443 | |
| 444 | assert "all 40" not in (pkg.__doc__ or "") |
File History
16 commits
sha256:0a2400b8017d871bff9916bfa6d3898b74b0dcce7f8e4d6e842365133f21090a
fix(coord): a task claim is one conditional UPDATE — exactl…
Opus 5.5
minor
⚠
1 day ago
sha256:2b93e88316d2f32df15a9f877b0b6e5fae363de59bc428ce5709f86e230581d8
docs(mcp): the cross-worker elicitation/push known issue mo…
Opus 5.5
patch
1 day ago
sha256:e6c07a0f17d2b30516cfe406c094c493c3aeaf8ea72db9ca098d24013bcc3bb9
Merge branch 'task/wave-hub-mcp-289' into dev
Opus 5.5
minor
⚠
1 day ago
sha256:08c30c873257205e342a68f5d55803ff3c6dd6abd4747b5444c68e1da4b8da39
fix(mcp): bind sessions to their principal; honest cross-wo…
Opus 5.5
minor
⚠
1 day ago
sha256:5e59815d34816a1aa12717d0ac82362d6a9919e8b6e096e66ed49c47a028d76f
fix(mcp): share Streamable HTTP sessions across worker proc…
Opus 5.5
minor
⚠
1 day ago
sha256:c2ee54efa85fcbdeea4ffc84a2dd1b8fcd4623463b22e35765df3013a26834aa
merge: #276 public URLs + muse#181 docs onto dev (#313 present)
Opus 5.5
minor
⚠
2 days ago
sha256:c777acd5605d4a83bbf9d2903bff0b0d419325b7bc49317700e4037b56594e8e
fix(web): absolute public URLs come from the canonical publ…
Opus 5.5
minor
⚠
2 days ago
sha256:d7af2b937831db3288db5589530c6c2f8e90f0c2c4efbbeb5dd0577076168b29
fix(mcp): SSE event ids + Last-Event-ID replay (#290); per-…
Opus 5.5
minor
⚠
2 days ago
sha256:c808b041005b5fb74b96123843a4033e94ecd49667c2fd84a9b45165e4433390
docs(mcp): progress events echo progressToken — drop the #2…
Opus 5.5
minor
⚠
2 days ago
sha256:f19d5e4a89766fc91b926cdf801255e12dcd968041c0ece8adf6627760788d22
merge: next build — MCP (#291 #292 #295 #324), profiles/sit…
Opus 5.5
minor
⚠
2 days ago
sha256:87f4c4d976afad92db715748495c09600f4aafed5f924e6b4b1664aab5a86fad
merge: rc26 — MCP wave (#291 #292 #295 #324)
Opus 5.5
minor
⚠
2 days ago
sha256:8f71621a510dbf00c5cef4b4a877ab154ea8c4af406d0fe7f0319a368b954f64
fix(mcp): notifications/elicitation/complete resolves the U…
Opus 5.5
minor
⚠
2 days ago
sha256:e0601efe55c167c25a25964556649adc67857bd02e415016a026c852e1a535b2
fix(mcp): gate and dispatcher errors carry error_code/error…
Opus 5.5
minor
⚠
2 days ago
sha256:ff23c9c281bee839f187bbaf3d30de9e88d331e3c404ed45e2845954f04cad82
fix(mcp): tools/list sets all four hints from one registry …
Opus 5.5
minor
⚠
2 days ago
sha256:3d450cb7100e86b4c435cbfeb8d185f2b659827e9beb43ab1dcd32e6e31e955c
docs(mcp): drop the stale #294 known issue
Sonnet 5.5
patch
6 days ago
sha256:0f032aa44c3e507f97d2fc10b144695c87c91110b2dd12888287d6446a81b668
docs(mcp): #261 MCP Reference QA contract v2 — render /mcp/…
Sonnet 5.5
minor
⚠
8 days ago