test_mcp_progress_token.py
python
sha256:299f7e61ed29513b71569e957cfd8ce55e2132041d220b1387ce0b43b12a3d92
Merge branch 'task/313-on-dev' into dev
Opus 5.5
minor
⚠ breaking
1 day ago
| 1 | """#293 — progress notifications carry the request's _meta.progressToken.""" |
| 2 | import asyncio |
| 3 | |
| 4 | from musehub.mcp import session |
| 5 | from musehub.mcp.context import ToolCallContext |
| 6 | from musehub.mcp.dispatcher import _handle_tools_call |
| 7 | |
| 8 | |
| 9 | def _drain(q: "asyncio.Queue[str | None]") -> list[str]: |
| 10 | out: list[str] = [] |
| 11 | while not q.empty(): |
| 12 | out.append(q.get_nowait() or "") |
| 13 | return out |
| 14 | |
| 15 | |
| 16 | async def _call(meta: dict | None) -> list[str]: |
| 17 | sess = session.create_session("u", {}) |
| 18 | q: asyncio.Queue[str | None] = asyncio.Queue() |
| 19 | sess.sse_queues.append(q) |
| 20 | params: dict = { |
| 21 | "name": "musehub_create_release_interactive", |
| 22 | "arguments": {"repo_id": "", "tag": "v9.9.9"}, |
| 23 | } |
| 24 | if meta is not None: |
| 25 | params["_meta"] = meta |
| 26 | await _handle_tools_call(params, user_id="u", session=sess) |
| 27 | frames = [f for f in _drain(q) if "notifications/progress" in f] |
| 28 | session.delete_session(sess.session_id) |
| 29 | return frames |
| 30 | |
| 31 | |
| 32 | def test_progress_uses_request_token() -> None: |
| 33 | frames = asyncio.run(_call({"progressToken": "tok-xyz"})) |
| 34 | assert frames and all('"progressToken":"tok-xyz"' in f for f in frames) |
| 35 | |
| 36 | |
| 37 | def test_distinct_tokens_distinguish_streams() -> None: |
| 38 | a = asyncio.run(_call({"progressToken": "A"})) |
| 39 | b = asyncio.run(_call({"progressToken": "B"})) |
| 40 | assert all('"progressToken":"A"' in f for f in a) |
| 41 | assert all('"progressToken":"B"' in f for f in b) |
| 42 | |
| 43 | |
| 44 | def test_no_token_means_no_progress_events() -> None: |
| 45 | assert asyncio.run(_call(None)) == [] |
| 46 | |
| 47 | |
| 48 | def test_context_progress_silent_without_token() -> None: |
| 49 | sess = session.create_session("u", {}) |
| 50 | q: asyncio.Queue[str | None] = asyncio.Queue() |
| 51 | sess.sse_queues.append(q) |
| 52 | asyncio.run(ToolCallContext("u", sess).progress(1, 3)) |
| 53 | assert q.empty() |
| 54 | asyncio.run(ToolCallContext("u", sess, progress_token="p").progress(1, 3, "m")) |
| 55 | assert '"progressToken":"p"' in q.get_nowait() |
| 56 | session.delete_session(sess.session_id) |
| 57 | |
| 58 | |
| 59 | # ── #294 — one dimension vocabulary; #313 — the repository's domain chooses it ── |
| 60 | |
| 61 | |
| 62 | def test_review_vocabulary_is_single_set() -> None: |
| 63 | from musehub.mcp.elicitation import SCHEMAS |
| 64 | from musehub.mcp.tools.musehub import MUSEHUB_ELICITATION_TOOLS |
| 65 | from musehub.mcp.write_tools.elicitation_tools import execute_review_proposal_interactive |
| 66 | from musehub.services.musehub_divergence import CODE_DIMENSIONS, MUSIC_DIMENSIONS, REVIEW_DIMENSIONS |
| 67 | |
| 68 | guide = asyncio.run(execute_review_proposal_interactive("r", "p", ctx=ToolCallContext("u", None))).data |
| 69 | form = set(SCHEMAS["proposal_review_focus"]["properties"]["dimension_focus"]["enum"]) |
| 70 | tool = next(t for t in MUSEHUB_ELICITATION_TOOLS if t["name"] == "musehub_review_proposal_interactive") |
| 71 | schema = set(tool["inputSchema"]["properties"]["dimension"]["enum"]) |
| 72 | assert set(guide["dimension_options"]) == form == schema == set(REVIEW_DIMENSIONS) == {"all", *MUSIC_DIMENSIONS, *CODE_DIMENSIONS} |
| 73 | assert guide["dimension_options_by_domain"] == {"midi": ["all", *MUSIC_DIMENSIONS], "code": ["all", *CODE_DIMENSIONS]} |
| 74 | |
| 75 | |
| 76 | def test_review_form_offers_only_the_repository_domains_dimensions() -> None: |
| 77 | from musehub.mcp.elicitation import review_focus_schema |
| 78 | |
| 79 | def enum(domain: str | None) -> list[str]: |
| 80 | return review_focus_schema(domain)["properties"]["dimension_focus"]["enum"] |
| 81 | |
| 82 | assert enum("code") == enum(None) == ["all", "api", "logic", "structure", "tests", "docs", "deps"] |
| 83 | assert enum("midi") == ["all", "melodic", "harmonic", "rhythmic", "structural", "dynamic"] |
| 84 | |
| 85 | |
| 86 | def test_unknown_dimension_or_depth_is_invalid_args() -> None: |
| 87 | from musehub.mcp.write_tools.elicitation_tools import execute_review_proposal_interactive |
| 88 | |
| 89 | ctx = ToolCallContext("u", None) |
| 90 | for kw in ({"dimension": "tempo"}, {"dimension": "all", "depth": "deep"}): |
| 91 | r = asyncio.run(execute_review_proposal_interactive("r", "p", ctx=ctx, **kw)) |
| 92 | assert not r.ok and r.error_code == "invalid_args" |
| 93 | |
| 94 | |
| 95 | def test_a_dimension_from_another_domain_is_invalid_args() -> None: |
| 96 | from types import SimpleNamespace |
| 97 | from unittest.mock import AsyncMock, patch |
| 98 | |
| 99 | from musehub.mcp.write_tools import elicitation_tools |
| 100 | |
| 101 | target = (SimpleNamespace(from_branch="feat", to_branch="main"), "code") |
| 102 | with patch.object(elicitation_tools, "_load_review_target", AsyncMock(return_value=target)): |
| 103 | r = asyncio.run(elicitation_tools.execute_review_proposal_interactive( |
| 104 | "r", "p", dimension="harmonic", depth="quick", ctx=ToolCallContext("u", None))) |
| 105 | assert not r.ok and r.error_code == "invalid_args" |
| 106 | assert "api, logic, structure, tests, docs, deps" in (r.hint or "") |
File History
4 commits
sha256:299f7e61ed29513b71569e957cfd8ce55e2132041d220b1387ce0b43b12a3d92
Merge branch 'task/313-on-dev' into dev
Opus 5.5
minor
⚠
1 day ago
sha256:dc8a25669115527392507de6bb24bd7a06c109fdc1814cf7bed97ec10c835acb
fix(proposals): diff, compare, divergence and diff-summary …
Opus 5.5
minor
⚠
1 day ago
sha256:7509cea23a330ac39d3db91391c88932011b9ba6e7f5a8615cb7889e27e426c1
fix(mcp): one dimension vocabulary for interactive proposal…
Opus 5.5
patch
6 days ago
sha256:75ea6757bc3427a326603f3b7a5eee006173366f3f331a75ef4b01997f747e83
fix(mcp): progress notifications carry the request's _meta.…
Opus 5.5
minor
⚠
6 days ago