test_wiki_channel.py¶
tests/test_wiki_channel.py
The opt-in channel push of wiki comments (2.1, owner Q/A 2026-11-24).
test_a_2026_07_28_session_is_not_pushed_to
None test_wiki_channel.test_a_2026_07_28_session_is_not_pushed_to(pytest.MonkeyPatch monkeypatch, caplog)
Claude Code drops channel events there; clew says so instead of sending.
Checks
assert (anyio.run(lambda: hub.send("r", {"page": "a", "anchor": "", "quote": "", "body": "b", "id": "1"} ) ) is False )assert not sent and "2026-07-28" in caplog.text
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-054 | measured |
Source · 23 lines
def test_a_2026_07_28_session_is_not_pushed_to(monkeypatch: pytest.MonkeyPatch, caplog) -> None: # noqa: ANN001
"""@brief Claude Code drops channel events there; clew says so instead of sending."""
sent = []
async def notify(session, method, params): # noqa: ANN001, ANN202
sent.append(method)
monkeypatch.setattr(channel, "raw_notify", notify)
monkeypatch.setattr(channel, "protocol_version", lambda session: "2026-07-28")
hub = channel.Channel()
hub.session = object()
with caplog.at_level("INFO"):
assert (
anyio.run(
lambda: hub.send(
"r", {"page": "a", "anchor": "", "quote": "", "body": "b", "id": "1"}
)
)
is False
)
assert not sent and "2026-07-28" in caplog.text
Activity · 9 steps
test_a_comment_is_pushed_as_a_channel_notification
None test_wiki_channel.test_a_comment_is_pushed_as_a_channel_notification(pytest.MonkeyPatch monkeypatch)
On a handshake-era session the push is `notifications/claude/channel`.
Checks
assert anyio.run(lambda: hub.send("clew-123", comment)) is Trueassert method == "notifications/claude/channel"assert "Bound?" in params["content"] and "test-x.html" in params["content"]assert params["meta"] == {"repo": "clew-123", "page": "test-x.html", "comment_id": "ab"}assert all(k.replace("_", "").isalnum() for k in params["meta"])
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-054 | measured | test_a_comment_is_pushed_as_a_channel_notification → all |
Source · 26 lines
def test_a_comment_is_pushed_as_a_channel_notification(monkeypatch: pytest.MonkeyPatch) -> None:
"""@brief On a handshake-era session the push is `notifications/claude/channel`."""
sent = []
async def notify(session, method, params): # noqa: ANN001, ANN202
sent.append((method, params))
monkeypatch.setattr(channel, "raw_notify", notify)
monkeypatch.setattr(channel, "protocol_version", lambda session: "2025-06-18")
hub = channel.Channel()
hub.session = object()
comment = {
"page": "test-x.html",
"anchor": "checks",
"quote": "a < 2",
"body": "Bound?",
"id": "ab",
}
assert anyio.run(lambda: hub.send("clew-123", comment)) is True
method, params = sent[0]
assert method == "notifications/claude/channel"
assert "Bound?" in params["content"] and "test-x.html" in params["content"]
assert params["meta"] == {"repo": "clew-123", "page": "test-x.html", "comment_id": "ab"}
assert all(k.replace("_", "").isalnum() for k in params["meta"])
Activity · 13 steps
test_a_repository_that_chose_the_channel_has_its_comments_pushed
None test_wiki_channel.test_a_repository_that_chose_the_channel_has_its_comments_pushed(tmp_path)
`deliver: [channel]` → pushed, and no hook count (the hook route was not chosen).
tests/test_wiki_channel.py:173
Checks
assert _send(hub, target, "push me") == 201assert pushed == [(target.slug, "push me")]assert not (tmp_path / "state" / PENDING_DIR / pending_key(target.repo_path)).exists()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-012 | measured | |
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-WIKI-032 | measured | |
| REQ-DDB-WIKI-054 | measured | test_a_repository_that_chose_the_channel_has_its_comments_pushed → pending_key |
Source · 13 lines
def test_a_repository_that_chose_the_channel_has_its_comments_pushed(tmp_path) -> None: # noqa: ANN001
"""@brief `deliver: [channel]` → pushed, and no hook count (the hook route was not chosen)."""
from clew.mcp_server.comments import PENDING_DIR, pending_key
hub, target, pushed = _hub_with_repo(tmp_path, " comments:\n deliver: [channel]\n")
try:
assert _send(hub, target, "push me") == 201
finally:
hub.stop()
assert pushed == [(target.slug, "push me")]
assert not (tmp_path / "state" / PENDING_DIR / pending_key(target.repo_path)).exists()
Activity · 6 steps
test_by_default_a_comment_is_counted_for_the_hook_and_not_pushed
None test_wiki_channel.test_by_default_a_comment_is_counted_for_the_hook_and_not_pushed(tmp_path)
No `wiki.comments` → the hook's count, no push.
tests/test_wiki_channel.py:186
Checks
assert _send(hub, target, "count me") == 201assert pushed == []assert (tmp_path / "state" / PENDING_DIR / pending_key(target.repo_path)).read_text() == "1"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-WIKI-032 | measured | |
| REQ-DDB-WIKI-054 | measured | test_by_default_a_comment_is_counted_for_the_hook_and_not_pushed → pending_key |
Source · 11 lines
def test_by_default_a_comment_is_counted_for_the_hook_and_not_pushed(tmp_path) -> None: # noqa: ANN001
"""@brief No `wiki.comments` → the hook's count, no push."""
from clew.mcp_server.comments import PENDING_DIR, pending_key
hub, target, pushed = _hub_with_repo(tmp_path, None)
try:
assert _send(hub, target, "count me") == 201
finally:
hub.stop()
assert pushed == []
assert (tmp_path / "state" / PENDING_DIR / pending_key(target.repo_path)).read_text() == "1"1 more lines, not shown
Activity · 6 steps
test_no_session_yet_is_said_not_sent
None test_wiki_channel.test_no_session_yet_is_said_not_sent(caplog)
Before any tool call there is no session to push on.
Checks
assert (anyio.run(lambda: hub.send("r", {"page": "a", "anchor": "", "quote": "", "body": "b", "id": "1"} ) ) is False )assert "no session" in caplog.text
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-054 | measured |
Source · 15 lines
def test_no_session_yet_is_said_not_sent(caplog) -> None: # noqa: ANN001
"""@brief Before any tool call there is no session to push on."""
hub = channel.Channel()
with caplog.at_level("INFO"):
assert (
anyio.run(
lambda: hub.send(
"r", {"page": "a", "anchor": "", "quote": "", "body": "b", "id": "1"}
)
)
is False
)
assert "no session" in caplog.text
Activity · 4 steps
test_the_capability_is_declared_only_when_switched_on
None test_wiki_channel.test_the_capability_is_declared_only_when_switched_on(pytest.MonkeyPatch monkeypatch)
CLEW_CHANNEL=1 → `{'claude/channel': {}}`; otherwise none.
tests/test_wiki_channel.py:112
Checks
assert channel.experimental_capabilities() == {}assert channel.experimental_capabilities() == {"claude/channel": {}}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-054 | measured | test_the_capability_is_declared_only_when_switched_on → experimental_capabilities |
Source · 8 lines
def test_the_capability_is_declared_only_when_switched_on(monkeypatch: pytest.MonkeyPatch) -> None:
"""@brief CLEW_CHANNEL=1 → `{'claude/channel': {}}`; otherwise none."""
monkeypatch.delenv(channel.CHANNEL_ENV, raising=False)
assert channel.experimental_capabilities() == {}
monkeypatch.setenv(channel.CHANNEL_ENV, "1")
assert channel.experimental_capabilities() == {"claude/channel": {}}
Activity · 4 steps
test_the_query_tools_take_the_session_without_changing_their_schema
None test_wiki_channel.test_the_query_tools_take_the_session_without_changing_their_schema(tmp_path)
Session capture leaves schemas alone.
Checks
assert find_context_parameter(wrapped) == "ctx"assert anyio.run(lambda: wrapped(subject="x", ctx=seen)) == {"subject": "x"}assert channel.CHANNEL.session is seen.session
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-004 | measured | test_the_query_tools_take_the_session_without_changing_their_schema → _answering_with_refresh |
| REQ-DDB-WIKI-054 | measured | test_the_query_tools_take_the_session_without_changing_their_schema → _answering_with_refresh → _take_context |
Source · 24 lines
def test_the_query_tools_take_the_session_without_changing_their_schema(tmp_path) -> None: # noqa: ANN001
"""THE SCHEMA IS THE ONE SURFACE A CLIENT CANNOT TRUNCATE, so the session is taken through the
SDK's own context injection — a `ctx` the SDK fills and leaves out of the JSON Schema.
@brief Session capture leaves schemas alone.
"""
from mcp.server.mcpserver.utilities.context_injection import find_context_parameter
from clew.mcp_server.server import _answering_with_refresh
def dossier(subject: str, target: str | None = None) -> dict:
return {"subject": subject}
async def before(target, sub_index): # noqa: ANN001, ANN202
return None
wrapped = _answering_with_refresh(dossier, before)
assert find_context_parameter(wrapped) == "ctx"
seen = SimpleNamespace(session=object())
channel.CHANNEL.session = None
assert anyio.run(lambda: wrapped(subject="x", ctx=seen)) == {"subject": "x"}
assert channel.CHANNEL.session is seen.session
Activity · 10 steps
test_the_server_declares_the_channel_capability_only_when_switched_on
None test_wiki_channel.test_the_server_declares_the_channel_capability_only_when_switched_on(pytest.MonkeyPatch monkeypatch, tmp_path)
`initialize` carries `experimental: {claude/channel: {}}` with CLEW_CHANNEL=1.
tests/test_wiki_channel.py:120
Checks
assert not (_init_options(mcp).capabilities.experimental or {})assert _init_options(mcp).capabilities.experimental == {"claude/channel": {}}assert _init_options(mcp).capabilities.tools.list_changed is True
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-001 | measured | test_the_server_declares_the_channel_capability_only_when_switched_on → build_server |
| REQ-DDB-MCP-003 | measured | |
| REQ-DDB-MCP-004 | measured | test_the_server_declares_the_channel_capability_only_when_switched_on → build_server → _refusal_as_tool_error |
| REQ-DDB-WIKI-034 | measured | test_the_server_declares_the_channel_capability_only_when_switched_on → build_server → _register_prompts |
| REQ-DDB-WIKI-054 | measured | test_the_server_declares_the_channel_capability_only_when_switched_on → _init_options |
Source · 15 lines
def test_the_server_declares_the_channel_capability_only_when_switched_on(
monkeypatch: pytest.MonkeyPatch, tmp_path
) -> None: # noqa: ANN001
"""@brief `initialize` carries `experimental: {claude/channel: {}}` with CLEW_CHANNEL=1."""
from clew.mcp_server import state as st
from clew.mcp_server.server import _init_options, build_server
mcp, _state = build_server(st.TargetRegistry(tmp_path / "state"))
monkeypatch.delenv(channel.CHANNEL_ENV, raising=False)
assert not (_init_options(mcp).capabilities.experimental or {})
monkeypatch.setenv(channel.CHANNEL_ENV, "1")
assert _init_options(mcp).capabilities.experimental == {"claude/channel": {}}
assert _init_options(mcp).capabilities.tools.list_changed is True