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.

tests/test_wiki_channel.py:74

Show on the map →

Called by none

Calls none

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

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054measured
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
lines 76–76sent = []lines 78–79async def notify(session, method, params): # noqa: ANN001, ANN202 sent.append(method)lines 81–81monkeypatch.setattr(channel, "raw_notify", notify)lines 82–82monkeypatch.setattr(channel, "protocol_version", lambda session: "2026-07-28")lines 83–83hub = channel.Channel()lines 84–84hub.session = object()lines 85–85with caplog.at_level("INFO")lines 86–93assert ( anyio.run( lambda: hub.send( "r", {"page": "a", "anchor": "", "quote": "", "body": "b", "id": "1"} ) ) is False )lines 94–94assert not sent and "2026-07-28" in caplog.text

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`.

tests/test_wiki_channel.py:48

Show on the map →

Called by none

Calls all

Checks

  • assert anyio.run(lambda: hub.send("clew-123", comment)) is True
  • 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"])

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054measuredtest_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
lines 50–50sent = []lines 52–53async def notify(session, method, params): # noqa: ANN001, ANN202 sent.append((method, params))lines 55–55monkeypatch.setattr(channel, "raw_notify", notify)lines 56–56monkeypatch.setattr(channel, "protocol_version", lambda session: "2025-06-18")lines 57–57hub = channel.Channel()lines 58–58hub.session = object()lines 59–65comment = { "page": "test-x.html", "anchor": "checks", "quote": "a < 2", "body": "Bound?", "id": "ab", }lines 66–66assert anyio.run(lambda: hub.send("clew-123", comment)) is Truelines 67–67method, params = sent[0]lines 68–68assert method == "notifications/claude/channel"lines 69–69assert "Bound?" in params["content"] and "test-x.html" in params["content"]lines 70–70assert params["meta"] == {"repo": "clew-123", "page": "test-x.html", "comment_id": "ab"}lines 71–71assert all(k.replace("_", "").isalnum() for k in params["meta"])

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

Show on the map →

Called by none

Calls _hub_with_repo, _send, pending_key

Checks

  • assert _send(hub, target, "push me") == 201
  • assert pushed == [(target.slug, "push me")]
  • assert not (tmp_path / "state" / PENDING_DIR / pending_key(target.repo_path)).exists()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measured
REQ-DDB-MCP-001measured
REQ-DDB-WIKI-032measured
REQ-DDB-WIKI-054measuredtest_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
lines 175–175from clew.mcp_server.comments import PENDING_DIR, pending_keylines 177–177hub, target, pushed = _hub_with_repo(tmp_path, " comments:\n deliver: [channel]\n")lines 178–178trylines 179–179assert _send(hub, target, "push me") == 201lines 182–182assert pushed == [(target.slug, "push me")]lines 183–183assert not (tmp_path / "state" / PENDING_DIR / pending_key(target.repo_path)).exists()

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

Show on the map →

Called by none

Calls _hub_with_repo, _send, pending_key

Checks

  • assert _send(hub, target, "count me") == 201
  • assert pushed == []
  • assert (tmp_path / "state" / PENDING_DIR / pending_key(target.repo_path)).read_text() == "1"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measured
REQ-DDB-WIKI-032measured
REQ-DDB-WIKI-054measuredtest_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
lines 188–188from clew.mcp_server.comments import PENDING_DIR, pending_keylines 190–190hub, target, pushed = _hub_with_repo(tmp_path, None)lines 191–191trylines 192–192assert _send(hub, target, "count me") == 201lines 195–195assert pushed == []lines 196–196assert (tmp_path / "state" / PENDING_DIR / pending_key(target.repo_path)).read_text() == "1"

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.

tests/test_wiki_channel.py:97

Show on the map →

Called by none

Calls none

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

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054measured
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
lines 99–99hub = channel.Channel()lines 100–100with caplog.at_level("INFO")lines 101–108assert ( anyio.run( lambda: hub.send( "r", {"page": "a", "anchor": "", "quote": "", "body": "b", "id": "1"} ) ) is False )lines 109–109assert "no session" in caplog.text

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

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054measuredtest_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
lines 114–114monkeypatch.delenv(channel.CHANNEL_ENV, raising=False)lines 115–115assert channel.experimental_capabilities() == {}lines 116–116monkeypatch.setenv(channel.CHANNEL_ENV, "1")lines 117–117assert channel.experimental_capabilities() == {"claude/channel": {}}

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.

tests/test_wiki_channel.py:24

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

requirementlinkedpath to the implementer
REQ-DDB-MCP-004measuredtest_the_query_tools_take_the_session_without_changing_their_schema → _answering_with_refresh
REQ-DDB-WIKI-054measuredtest_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
lines 30–30from mcp.server.mcpserver.utilities.context_injection import find_context_parameterlines 32–32from clew.mcp_server.server import _answering_with_refreshlines 34–35def dossier(subject: str, target: str | None = None) -> dict: return {"subject": subject}lines 37–38async def before(target, sub_index): # noqa: ANN001, ANN202 return Nonelines 40–40wrapped = _answering_with_refresh(dossier, before)lines 41–41assert find_context_parameter(wrapped) == "ctx"lines 42–42seen = SimpleNamespace(session=object())lines 43–43channel.CHANNEL.session = Nonelines 44–44assert anyio.run(lambda: wrapped(subject="x", ctx=seen)) == {"subject": "x"}lines 45–45assert channel.CHANNEL.session is seen.session

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

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_the_server_declares_the_channel_capability_only_when_switched_on → build_server
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_the_server_declares_the_channel_capability_only_when_switched_on → build_server → _refusal_as_tool_error
REQ-DDB-WIKI-034measuredtest_the_server_declares_the_channel_capability_only_when_switched_on → build_server → _register_prompts
REQ-DDB-WIKI-054measuredtest_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

Activity · 8 steps
lines 124–124from clew.mcp_server import state as stlines 125–125from clew.mcp_server.server import _init_options, build_serverlines 127–127mcp, _state = build_server(st.TargetRegistry(tmp_path / "state"))lines 128–128monkeypatch.delenv(channel.CHANNEL_ENV, raising=False)lines 129–129assert not (_init_options(mcp).capabilities.experimental or {})lines 130–130monkeypatch.setenv(channel.CHANNEL_ENV, "1")lines 131–131assert _init_options(mcp).capabilities.experimental == {"claude/channel": {}}lines 132–132assert _init_options(mcp).capabilities.tools.list_changed is True