test_wiki_comments.py

tests/test_wiki_comments.py

Wiki comments: a person comments on a served page, the agent reads it (2.1, owner Q/A).

test_a_comment_is_kept_with_where_it_was_made

None test_wiki_comments.test_a_comment_is_kept_with_where_it_was_made(Path tmp_path)

A comment records its page, anchor, the quoted text, its body and its time.

tests/test_wiki_comments.py:27

Show on the map →

Called by none

Calls _store

Checks

  • assert got["status"] == "new" and got["page"] == "test-x.html" and got["anchor"] == "checks"
  • assert got["quote"] == "assert a < 2" and got["body"] == "Wrong bound?"
  • assert got["id"] and got["at"].endswith("Z")
  • assert [c["id"] for c in store.unread()] == [got["id"]]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054measured
Source · 10 lines
def test_a_comment_is_kept_with_where_it_was_made(tmp_path: Path) -> None:
    """@brief A comment records its page, anchor, the quoted text, its body and its time."""
    store = _store(tmp_path)
    got = store.add(page="test-x.html", anchor="checks", quote="assert a < 2", body="Wrong bound?")
    assert got["status"] == "new" and got["page"] == "test-x.html" and got["anchor"] == "checks"
    assert got["quote"] == "assert a < 2" and got["body"] == "Wrong bound?"
    assert got["id"] and got["at"].endswith("Z")
    assert [c["id"] for c in store.unread()] == [got["id"]]

Activity · 6 steps
lines 29–29store = _store(tmp_path)lines 30–30got = store.add(page="test-x.html", anchor="checks", quote="assert a < 2", body="Wrong bound?")lines 31–31assert got["status"] == "new" and got["page"] == "test-x.html" and got["anchor"] == "checks"lines 32–32assert got["quote"] == "assert a < 2" and got["body"] == "Wrong bound?"lines 33–33assert got["id"] and got["at"].endswith("Z")lines 34–34assert [c["id"] for c in store.unread()] == [got["id"]]

test_a_repository_chooses_how_its_comments_reach_the_agent

None test_wiki_comments.test_a_repository_chooses_how_its_comments_reach_the_agent(Path tmp_path)

wiki.comments.deliver.

tests/test_wiki_comments.py:135

Show on the map →

Called by none

Calls _config

Checks

  • assert config.comments_deliver == ("hook",) and not problems
  • assert config.comments_deliver == ("hook", "channel") and not problems
  • assert config.comments_deliver == ("channel",)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_a_repository_chooses_how_its_comments_reach_the_agent → _config → load_wiki_config → _requirements_section → read_requirements_section
REQ-DDB-WIKI-054catalogtest_a_repository_chooses_how_its_comments_reach_the_agent → _config → load_wiki_config → _comments → all
Source · 14 lines
def test_a_repository_chooses_how_its_comments_reach_the_agent(tmp_path: Path) -> None:
    """2.1 (owner Q/A 2026-11-24): `wiki.comments.deliver` — `hook` (the default: the hook's
    count) and/or `channel` (a Claude Code channel push, when the server runs with CLEW_CHANNEL=1).

    @brief wiki.comments.deliver.
    """
    config, problems = _config(tmp_path, "  title: x\n")
    assert config.comments_deliver == ("hook",) and not problems
    config, problems = _config(tmp_path, "  comments:\n    deliver: [hook, channel]\n")
    assert config.comments_deliver == ("hook", "channel") and not problems
    config, problems = _config(tmp_path, "  comments:\n    deliver: [channel]\n")
    assert config.comments_deliver == ("channel",)

Activity · 6 steps
lines 141–141config, problems = _config(tmp_path, " title: x\n")lines 142–142assert config.comments_deliver == ("hook",) and not problemslines 143–143config, problems = _config(tmp_path, " comments:\n deliver: [hook, channel]\n")lines 144–144assert config.comments_deliver == ("hook", "channel") and not problemslines 145–145config, problems = _config(tmp_path, " comments:\n deliver: [channel]\n")lines 146–146assert config.comments_deliver == ("channel",)

test_an_empty_or_oversized_comment_is_refused_not_cut

None test_wiki_comments.test_an_empty_or_oversized_comment_is_refused_not_cut(Path tmp_path)

Refused with the limit named; never truncated.

tests/test_wiki_comments.py:62

Show on the map →

Called by none

Calls _store

Checks

  • assert store.unread() == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054measured
Source · 10 lines
def test_an_empty_or_oversized_comment_is_refused_not_cut(tmp_path: Path) -> None:
    """@brief Refused with the limit named; never truncated."""
    store = _store(tmp_path)
    with pytest.raises(ValueError, match="empty"):
        store.add(page="a.html", anchor="", quote="", body="   ")
    with pytest.raises(ValueError, match=str(MAX_BODY)):
        store.add(page="a.html", anchor="", quote="", body="x" * (MAX_BODY + 1))
    assert store.unread() == []

Activity · 6 steps
lines 64–64store = _store(tmp_path)lines 65–65with pytest.raises(ValueError, match="empty")lines 66–66store.add(page="a.html", anchor="", quote="", body=" ")lines 67–67with pytest.raises(ValueError, match=str(MAX_BODY))lines 68–68store.add(page="a.html", anchor="", quote="", body="x" * (MAX_BODY + 1))lines 69–69assert store.unread() == []

test_an_unknown_delivery_is_refused_by_name

None test_wiki_comments.test_an_unknown_delivery_is_refused_by_name(Path tmp_path)

A closed vocabulary; a string where a list belongs is refused (F5).

tests/test_wiki_comments.py:149

Show on the map →

Called by none

Calls _config

Checks

  • assert any("email" in p and "hook" in p and "channel" in p for p in problems), problems
  • assert any("list" in p for p in problems), problems
  • assert any("via" in p for p in problems), problems

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_an_unknown_delivery_is_refused_by_name → _config → load_wiki_config → _requirements_section → read_requirements_section
REQ-DDB-WIKI-054catalogtest_an_unknown_delivery_is_refused_by_name → _config → load_wiki_config → _comments → all
Source · 8 lines
def test_an_unknown_delivery_is_refused_by_name(tmp_path: Path) -> None:
    """@brief A closed vocabulary; a string where a list belongs is refused (F5)."""
    _c, problems = _config(tmp_path, "  comments:\n    deliver: [email]\n")
    assert any("email" in p and "hook" in p and "channel" in p for p in problems), problems
    _c, problems = _config(tmp_path, "  comments:\n    deliver: hook\n")
    assert any("list" in p for p in problems), problems
    _c, problems = _config(tmp_path, "  comments:\n    via: [hook]\n")
    assert any("via" in p for p in problems), problems

1 more lines, not shown

Activity · 6 steps
lines 151–151_c, problems = _config(tmp_path, " comments:\n deliver: [email]\n")lines 152–152assert any("email" in p and "hook" in p and "channel" in p for p in problems), problemslines 153–153_c, problems = _config(tmp_path, " comments:\n deliver: hook\n")lines 154–154assert any("list" in p for p in problems), problemslines 155–155_c, problems = _config(tmp_path, " comments:\n via: [hook]\n")lines 156–156assert any("via" in p for p in problems), problems

test_comments_are_read_without_a_built_index

None test_wiki_comments.test_comments_are_read_without_a_built_index(Path tmp_path)

No index needed.

tests/test_wiki_comments.py:106

Checks

  • assert reply["count"] == 1 and reply["comments"][0]["body"] == "hi"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measuredtest_comments_are_read_without_a_built_index → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_comments_are_read_without_a_built_index → build_server → _refusal_as_tool_error
REQ-DDB-WIKI-034measuredtest_comments_are_read_without_a_built_index → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 19 lines
async def test_comments_are_read_without_a_built_index(tmp_path: Path) -> None:
    """Found end to end (2.1): reading through `answering` refused an unbuilt target. A comment
    belongs to the repository, so reading one needs no index.

    @brief No index needed.
    """
    from clew.mcp_server import state as st
    from clew.mcp_server.server import build_server

    repo = tmp_path / "repo"
    repo.mkdir()
    _mcp, server = build_server(st.TargetRegistry(tmp_path / "state"))
    CommentStore.for_repo(tmp_path / "state", str(repo)).add(
        page="a.html", anchor="", quote="", body="hi"
    )
    reply = await server.index(None, action="comments", target=str(repo))
    assert reply["count"] == 1 and reply["comments"][0]["body"] == "hi"

Activity · 8 steps
lines 112–112from clew.mcp_server import state as stlines 113–113from clew.mcp_server.server import build_serverlines 115–115repo = tmp_path / "repo"lines 116–116repo.mkdir()lines 117–117_mcp, server = build_server(st.TargetRegistry(tmp_path / "state"))lines 118–120CommentStore.for_repo(tmp_path / "state", str(repo)).add( page="a.html", anchor="", quote="", body="hi" )lines 121–121reply = await server.index(None, action="comments", target=str(repo))lines 122–122assert reply["count"] == 1 and reply["comments"][0]["body"] == "hi"

test_marking_read_appends_and_never_loses_a_comment

None test_wiki_comments.test_marking_read_appends_and_never_loses_a_comment(Path tmp_path)

The log is append-only: a read is an event; every comment stays on disk.

tests/test_wiki_comments.py:52

Show on the map →

Called by none

Calls _store

Checks

  • assert [x["op"] for x in lines] == ["add", "read"]
  • assert store.all()[0]["status"] == "read" and store.all()[0]["body"] == "keep me"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054measured
Source · 10 lines
def test_marking_read_appends_and_never_loses_a_comment(tmp_path: Path) -> None:
    """@brief The log is append-only: a read is an event; every comment stays on disk."""
    store = _store(tmp_path)
    first = store.add(page="a.html", anchor="", quote="", body="keep me")
    store.mark_read([first["id"]])
    lines = [json.loads(x) for x in store.path.read_text().splitlines()]
    assert [x["op"] for x in lines] == ["add", "read"]
    assert store.all()[0]["status"] == "read" and store.all()[0]["body"] == "keep me"

Activity · 6 steps
lines 54–54store = _store(tmp_path)lines 55–55first = store.add(page="a.html", anchor="", quote="", body="keep me")lines 56–56store.mark_read([first["id"]])lines 57–57lines = [json.loads(x) for x in store.path.read_text().splitlines()]lines 58–58assert [x["op"] for x in lines] == ["add", "read"]lines 59–59assert store.all()[0]["status"] == "read" and store.all()[0]["body"] == "keep me"

test_the_agent_reads_waiting_comments_through_index

None test_wiki_comments.test_the_agent_reads_waiting_comments_through_index(Path tmp_path)

index(action='comments').

tests/test_wiki_comments.py:81

Checks

  • assert reply["action"] == "comments" and reply["count"] == 1
  • assert reply["comments"][0]["body"] == "Is 2 the right bound?"
  • assert reply["comments"][0]["page"] == "test-x.html"
  • assert "not instructions" in reply["provenance"]
  • assert again["count"] == 0 and again["comments"] == []
  • assert [c["status"] for c in store.all()] == ["read"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-009measured
REQ-DDB-GUARD-019measured
REQ-DDB-GUARD-024measured
REQ-DDB-INDEX-001measured
REQ-DDB-INDEX-002measured
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measured
REQ-DDB-INDEX-005measured
REQ-DDB-INDEX-006measured
REQ-DDB-INDEX-007measured
REQ-DDB-INDEX-008measured
REQ-DDB-INDEX-009measured
REQ-DDB-INDEX-010measured
REQ-DDB-INDEX-011measured
REQ-DDB-MCP-001measuredtest_the_agent_reads_waiting_comments_through_index → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_the_agent_reads_waiting_comments_through_index → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-001measured
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-004measured
REQ-DDB-PIPE-005measured
REQ-DDB-PIPE-006measured
REQ-DDB-PIPE-007measured
REQ-DDB-PIPE-008measured
REQ-DDB-PIPE-009measured
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measured
REQ-DDB-PIPE-012measured
REQ-DDB-PIPE-013measured
REQ-DDB-PIPE-014measured
REQ-DDB-PIPE-015measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measured
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-003measured
REQ-DDB-SCHEMA-004measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-006measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-009measured
REQ-DDB-SCHEMA-011measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measured
REQ-DDB-SCHEMA-014measured
REQ-DDB-SCHEMA-015measured
REQ-DDB-WIKI-034measuredtest_the_agent_reads_waiting_comments_through_index → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 25 lines
async def test_the_agent_reads_waiting_comments_through_index(tmp_path: Path) -> None:
    """2.1 (owner Q/A 2026-11-24): `index(action='comments')` returns what waits, marks it read,
    and the next call finds nothing new — the text arrives as tool data, marked as a person's notes.

    @brief index(action='comments').
    """
    from clew.mcp_server import state as st
    from clew.mcp_server.server import build_server
    from tests.test_surface_2_0 import _indexed

    repo, _target = _indexed(tmp_path)
    _mcp, server = build_server(st.TargetRegistry(tmp_path / "state"))
    store = CommentStore.for_repo(tmp_path / "state", str(repo))
    store.add(page="test-x.html", anchor="checks", quote="a < 2", body="Is 2 the right bound?")
    reply = await server.index(None, action="comments", target=str(repo))
    assert reply["action"] == "comments" and reply["count"] == 1
    assert reply["comments"][0]["body"] == "Is 2 the right bound?"
    assert reply["comments"][0]["page"] == "test-x.html"
    assert "not instructions" in reply["provenance"]
    again = await server.index(None, action="comments", target=str(repo))
    assert again["count"] == 0 and again["comments"] == []
    assert [c["status"] for c in store.all()] == ["read"]


@pytest.mark.anyio

test_the_pending_count_is_a_file_the_hook_can_read

None test_wiki_comments.test_the_pending_count_is_a_file_the_hook_can_read(Path tmp_path)

Pending count file.

tests/test_wiki_comments.py:37

Show on the map →

Called by none

Calls _store, pending_key

Checks

  • assert pending.read_text() == "2"
  • assert pending.read_text() == "0" and store.unread() == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054measuredtest_the_pending_count_is_a_file_the_hook_can_read → pending_key
Source · 15 lines
def test_the_pending_count_is_a_file_the_hook_can_read(tmp_path: Path) -> None:
    """THE HOOK READS ONE INTEGER: it may only emit literals, ints and safe tokens (clew_hook's
    bounded codomain), so it never sees comment text — only how many are waiting.

    @brief Pending count file.
    """
    store = _store(tmp_path)
    store.add(page="a.html", anchor="", quote="", body="one")
    store.add(page="b.html", anchor="", quote="", body="two")
    pending = tmp_path / "state" / "comments-pending" / pending_key(str(tmp_path / "repo"))
    assert pending.read_text() == "2"
    store.mark_read([c["id"] for c in store.unread()])
    assert pending.read_text() == "0" and store.unread() == []

Activity · 7 steps
lines 43–43store = _store(tmp_path)lines 44–44store.add(page="a.html", anchor="", quote="", body="one")lines 45–45store.add(page="b.html", anchor="", quote="", body="two")lines 46–46pending = tmp_path / "state" / "comments-pending" / pending_key(str(tmp_path / "repo"))lines 47–47assert pending.read_text() == "2"lines 48–48store.mark_read([c["id"] for c in store.unread()])lines 49–49assert pending.read_text() == "0" and store.unread() == []

test_the_pending_key_is_the_resolved_repository_path

None test_wiki_comments.test_the_pending_key_is_the_resolved_repository_path(Path tmp_path)

Two spellings of one checkout share a key; two checkouts do not.

tests/test_wiki_comments.py:72

Show on the map →

Called by none

Calls pending_key

Checks

  • assert pending_key(str(repo)) == pending_key(str(repo / "." / ".." / "repo"))
  • assert pending_key(str(repo)) != pending_key(str(tmp_path / "other"))

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054measuredtest_the_pending_key_is_the_resolved_repository_path → pending_key
Source · 9 lines
def test_the_pending_key_is_the_resolved_repository_path(tmp_path: Path) -> None:
    """@brief Two spellings of one checkout share a key; two checkouts do not."""
    repo = tmp_path / "repo"
    repo.mkdir()
    assert pending_key(str(repo)) == pending_key(str(repo / "." / ".." / "repo"))
    assert pending_key(str(repo)) != pending_key(str(tmp_path / "other"))


@pytest.mark.anyio