test_wiki_hub.py

tests/test_wiki_hub.py

The wiki hub inside the MCP server (round 3, P4c-1).

test_a_comment_posted_on_a_served_page_is_stored_for_the_agent

None test_wiki_hub.test_a_comment_posted_on_a_served_page_is_stored_for_the_agent(hub)

Comment endpoint stores.

tests/test_wiki_hub.py:386

Show on the map →

Called by none

Calls _post

Checks

  • assert status == 201, reply
  • assert [c["body"] for c in stored] == ["Bound?"] and stored[0]["page"] == "test-x.html"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measured
REQ-DDB-WIKI-032catalog
REQ-DDB-WIKI-033catalog
REQ-DDB-WIKI-054measured
Source · 24 lines
def test_a_comment_posted_on_a_served_page_is_stored_for_the_agent(hub) -> None:  # noqa: ANN001
    """2.1 (owner Q/A 2026-11-24): the page's comment control POSTs here; the hub stores it in the
    repository's comment log, where the hook counts it and `index(action='comments')` reads it.

    @brief Comment endpoint stores.
    """
    import json

    from clew.mcp_server.comments import CommentStore

    server, builder, live, _gone = hub
    builder.release.set()
    cookie = f"clew_wiki={server.token}"
    body = json.dumps(
        {"page": "test-x.html", "anchor": "checks", "quote": "a < 2", "body": "Bound?"}
    )
    status, reply = _post(
        f"http://127.0.0.1:{server.port}/api/{live.slug}/comment", body.encode(), cookie
    )
    assert status == 201, reply
    stored = CommentStore.for_repo(server.home, live.repo_path).unread()
    assert [c["body"] for c in stored] == ["Bound?"] and stored[0]["page"] == "test-x.html"

Activity · 10 steps
lines 392–392import jsonlines 394–394from clew.mcp_server.comments import CommentStorelines 396–396server, builder, live, _gone = hublines 397–397builder.release.set()lines 398–398cookie = f"clew_wiki={server.token}"lines 399–401body = json.dumps( {"page": "test-x.html", "anchor": "checks", "quote": "a < 2", "body": "Bound?"} )lines 402–404status, reply = _post( f"http://127.0.0.1:{server.port}/api/{live.slug}/comment", body.encode(), cookie )lines 405–405assert status == 201, replylines 406–406stored = CommentStore.for_repo(server.home, live.repo_path).unread()lines 407–407assert [c["body"] for c in stored] == ["Bound?"] and stored[0]["page"] == "test-x.html"

test_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs

None test_wiki_hub.test_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs(Path tmp_path)

P4c-2a: wiki_url and focus.

tests/test_wiki_hub.py:277

Show on the map →

Called by none

Calls _build_argparser, _run_pipeline

Checks

  • assert "wiki_url" not in plain.dossier("alpha")
  • assert reply["wiki_url"] == f"http://127.0.0.1:4242/r/{target.slug}/sym-m-py.html#s-alpha"
  • assert "t=" not in reply["wiki_url"]
  • assert seen == [{"type": "focus", "slug": target.slug, "url": reply["wiki_url"]}]
  • assert "wiki_url" not in linked.dossier("no_such_function")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → report_stats
REQ-DDB-CLI-002inferredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → _doxygen_or_partial → _doxygen_stage → _run_doxygen_from_args → run_doxygen → doxygen_supports_sqlite3
REQ-DDB-CONFIG-001measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _apply_declared_document → stated_document_meta
REQ-DDB-CONFIG-003inferredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml → _is_flat_req_list
REQ-DDB-CONFIG-004measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → resolve_preprocessor
REQ-DDB-CONFIG-005measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → import_kconfig
REQ-DDB-CONFIG-006measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _recorded_entry_patterns → recorded_explicit
REQ-DDB-CONFIG-007measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → write_build_signature
REQ-DDB-CONFIG-009measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _apply_toolchain_exclusions → load_toolchain_config
REQ-DDB-GUARD-012inferredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → load_guard_config → read_guard_config → read_requirements_section
REQ-DDB-GUARD-019measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings → summarize → parse_doxygen_tags
REQ-DDB-GUARD-024measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings → summarize → apply_autobrief
REQ-DDB-INDEX-001measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _verify_extra_input_is_read → effective_file_patterns
REQ-DDB-INDEX-002measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → build_lock
REQ-DDB-INDEX-003measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → report_index_coverage
REQ-DDB-INDEX-004measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → recover_ast_symbols
REQ-DDB-INDEX-005measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → stamp_external_provenance
REQ-DDB-INDEX-006measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → record_code_text → code_text_rows
REQ-DDB-INDEX-007measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → record_owners
REQ-DDB-INDEX-008measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_licenses
REQ-DDB-INDEX-009measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_kerneldoc
REQ-DDB-INDEX-010measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → import_ast_includes
REQ-DDB-INDEX-011measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → import_property_keys
REQ-DDB-MCP-001measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _operator_excludes → meta_section
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measured
REQ-DDB-PIPE-001measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_database
REQ-DDB-PIPE-003measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → build_call_edges
REQ-DDB-PIPE-004measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → python_entry_seeds
REQ-DDB-PIPE-005measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → write_build_signature
REQ-DDB-PIPE-006measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → run_rustdoc → _require_nightly_rustdoc → clean_subprocess_env
REQ-DDB-PIPE-007measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → import_kconfig_gates
REQ-DDB-PIPE-008measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_docs
REQ-DDB-PIPE-009measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → prune_dominated_fuzzy_call_edges
REQ-DDB-PIPE-010measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → import_shared_key_edges_inferred → _build_inferred_edges
REQ-DDB-PIPE-011measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → import_ast_includes → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → build_harvest_plan → js_symbol_harvester
REQ-DDB-PIPE-013measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings
REQ-DDB-PIPE-014measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_kerneldoc → within_repo
REQ-DDB-PIPE-015measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → import_config_defaults
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-002measured
REQ-DDB-QUERY-003measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → mark_test_scope
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-009measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-011measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → extract_threads → _ensure_threads_tables
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-013measured
REQ-DDB-QUERY-014measured
REQ-DDB-SCHEMA-001measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → extract_threads
REQ-DDB-SCHEMA-002measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → import_shared_key_edges_inferred → _writer_dispatch_map
REQ-DDB-SCHEMA-003measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-004measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → load_dispatch_manifest
REQ-DDB-SCHEMA-005measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → resolve_key_alias_prefixes
REQ-DDB-SCHEMA-006measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml
REQ-DDB-SCHEMA-007measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-009measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → import_event_edges
REQ-DDB-SCHEMA-011measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → extract_context_conflicts
REQ-DDB-SCHEMA-012measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → load_dispatch_manifest → declaration_origin
REQ-DDB-SCHEMA-013measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → import_data_model_keys
REQ-DDB-SCHEMA-014measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_docs → ensure_file_docs_table
REQ-DDB-SCHEMA-015measuredtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml
REQ-DDB-WIKI-025measured
REQ-DDB-WIKI-032catalog
REQ-DDB-WIKI-033measured
REQ-DDB-WIKI-054catalogtest_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → recover_ast_symbols → _recover_into → all
Source · 33 lines
def test_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs(tmp_path: Path) -> None:
    """ADDITIVE, AND ONLY WHILE SERVING: a found function's reply names its symbol section on the
    hub (no token — the browser holds the session cookie), and the hub tells open pages the
    agent looked there. Without a linker no key is added.

    @brief P4c-2a: wiki_url and focus.
    """
    from clew.cli import _build_argparser, _run_pipeline
    from clew.mcp_server.tools_query import QueryTools
    from clew.mcp_server.wikihub import WikiHub

    repo = tmp_path / "repo"
    repo.mkdir()
    (repo / "m.py").write_text('def alpha():\n    """Alpha."""\n    return 1\n')
    home = tmp_path / "state"
    target = TargetRegistry(home).register(repo)
    db = Path(target.db_path)
    _run_pipeline(_build_argparser().parse_args(["--output", str(db), "--repo-root", str(repo)]))
    plain = QueryTools(lambda: db, lambda: repo)
    assert "wiki_url" not in plain.dossier("alpha")
    server = WikiHub(home, builder=_Builder())
    seen: list[dict] = []
    server.publish = seen.append  # type: ignore[method-assign]
    server.port = 4242
    linked = QueryTools(lambda: db, lambda: repo)
    linked.wiki_linker = server.link
    reply = linked.dossier("alpha")
    assert reply["wiki_url"] == f"http://127.0.0.1:4242/r/{target.slug}/sym-m-py.html#s-alpha"
    assert "t=" not in reply["wiki_url"]
    assert seen == [{"type": "focus", "slug": target.slug, "url": reply["wiki_url"]}]
    assert "wiki_url" not in linked.dossier("no_such_function")

Activity · 23 steps
lines 284–284from clew.cli import _build_argparser, _run_pipelinelines 285–285from clew.mcp_server.tools_query import QueryToolslines 286–286from clew.mcp_server.wikihub import WikiHublines 288–288repo = tmp_path / "repo"lines 289–289repo.mkdir()lines 290–290(repo / "m.py").write_text('def alpha():\n """Alpha."""\n return 1\n')lines 291–291home = tmp_path / "state"lines 292–292target = TargetRegistry(home).register(repo)lines 293–293db = Path(target.db_path)lines 294–294_run_pipeline(_build_argparser().parse_args(["--output", str(db), "--repo-root", str(repo)]))lines 295–295plain = QueryTools(lambda: db, lambda: repo)lines 296–296assert "wiki_url" not in plain.dossier("alpha")lines 297–297server = WikiHub(home, builder=_Builder())lines 298–298seen: list[dict] = []lines 299–299server.publish = seen.appendlines 300–300server.port = 4242lines 301–301linked = QueryTools(lambda: db, lambda: repo)lines 302–302linked.wiki_linker = server.linklines 303–303reply = linked.dossier("alpha")lines 304–304assert reply["wiki_url"] == f"http://127.0.0.1:4242/r/{target.slug}/sym-m-py.html#s-alpha"lines 305–305assert "t=" not in reply["wiki_url"]lines 306–306assert seen == [{"type": "focus", "slug": target.slug, "url": reply["wiki_url"]}]lines 307–307assert "wiki_url" not in linked.dossier("no_such_function")

test_a_refreshed_target_with_a_built_wiki_is_rebuilt_and_announced

None test_wiki_hub.test_a_refreshed_target_with_a_built_wiki_is_rebuilt_and_announced(hub)

P4c-2a: rebuild after refresh, `rebuilt` events.

tests/test_wiki_hub.py:199

Show on the map →

Called by none

Calls none

Checks

  • assert event == {"type": "rebuilt", "slug": live.slug}
  • assert builder.calls == [live.slug]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measured
REQ-DDB-WIKI-032measured
REQ-DDB-WIKI-033measured
REQ-DDB-WIKI-034measured
REQ-DDB-WIKI-054catalog
Source · 25 lines
def test_a_refreshed_target_with_a_built_wiki_is_rebuilt_and_announced(hub) -> None:  # noqa: ANN001
    """LIVE VIEW: after the refresh loop refreshes a target whose wiki is built, the hub rebuilds
    it and tells every open page; a target with no built wiki is left alone.

    @brief P4c-2a: rebuild after refresh, `rebuilt` events.
    """
    server, builder, live, gone = hub
    builder.release.set()
    site = server.site_dir(live)
    site.mkdir(parents=True)
    (site / "index.html").write_text("old")
    events: queue.Queue[dict] = queue.Queue()
    reader = threading.Thread(
        target=_stream,
        args=(f"http://127.0.0.1:{server.port}/events", f"clew_wiki={server.token}", events),
        daemon=True,
    )
    reader.start()
    threading.Event().wait(0.3)
    server.refreshed([live.slug, gone.slug])
    event = events.get(timeout=10)
    assert event == {"type": "rebuilt", "slug": live.slug}
    assert builder.calls == [live.slug]

Activity · 13 steps
lines 205–205server, builder, live, gone = hublines 206–206builder.release.set()lines 207–207site = server.site_dir(live)lines 208–208site.mkdir(parents=True)lines 209–209(site / "index.html").write_text("old")lines 210–210events: queue.Queue[dict] = queue.Queue()lines 211–215reader = threading.Thread( target=_stream, args=(f"http://127.0.0.1:{server.port}/events", f"clew_wiki={server.token}", events), daemon=True, )lines 216–216reader.start()lines 217–217threading.Event().wait(0.3)lines 218–218server.refreshed([live.slug, gone.slug])lines 219–219event = events.get(timeout=10)lines 220–220assert event == {"type": "rebuilt", "slug": live.slug}lines 221–221assert builder.calls == [live.slug]

test_a_wiki_is_built_on_demand_and_then_served

None test_wiki_hub.test_a_wiki_is_built_on_demand_and_then_served(hub)

First visit starts a build and says so; once built, the site is served.

tests/test_wiki_hub.py:104

Show on the map →

Called by none

Calls _get

Checks

  • assert status == 202 and "Building" in body and 'http-equiv="refresh"' in body
  • assert status == 200 and f"wiki of {live.slug}" in body
  • assert builder.calls == [live.slug]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measured
REQ-DDB-WIKI-032measured
REQ-DDB-WIKI-033measured
REQ-DDB-WIKI-034measured
REQ-DDB-WIKI-054catalog
Source · 16 lines
def test_a_wiki_is_built_on_demand_and_then_served(hub) -> None:  # noqa: ANN001
    """@brief First visit starts a build and says so; once built, the site is served."""
    server, builder, live, _gone = hub
    cookie = f"clew_wiki={server.token}"
    status, body, _h = _get(f"http://127.0.0.1:{server.port}/r/{live.slug}/", cookie)
    assert status == 202 and "Building" in body and 'http-equiv="refresh"' in body
    builder.release.set()
    for _ in range(100):
        status, body, _h = _get(f"http://127.0.0.1:{server.port}/r/{live.slug}/", cookie)
        if status == 200:
            break
        threading.Event().wait(0.05)
    assert status == 200 and f"wiki of {live.slug}" in body
    assert builder.calls == [live.slug]

Activity · 12 steps
lines 106–106server, builder, live, _gone = hublines 107–107cookie = f"clew_wiki={server.token}"lines 108–108status, body, _h = _get(f"http://127.0.0.1:{server.port}/r/{live.slug}/", cookie)lines 109–109assert status == 202 and "Building" in body and 'http-equiv="refresh"' in bodylines 110–110builder.release.set()lines 111–111◇ for _ in range(100)lines 112–112status, body, _h = _get(f"http://127.0.0.1:{server.port}/r/{live.slug}/", cookie)lines 113–113◇ if status == 200lines 114–114breaklines 115–115threading.Event().wait(0.05)lines 116–116assert status == 200 and f"wiki of {live.slug}" in bodylines 117–117assert builder.calls == [live.slug]

test_nothing_outside_the_site_is_served

None test_wiki_hub.test_nothing_outside_the_site_is_served(hub)

A path that climbs out of the built site is refused.

tests/test_wiki_hub.py:120

Show on the map →

Called by none

Calls _get

Checks

  • assert status in (403, 404), path

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measured
REQ-DDB-WIKI-032measured
REQ-DDB-WIKI-033measured
REQ-DDB-WIKI-034measured
REQ-DDB-WIKI-054catalog
Source · 15 lines
def test_nothing_outside_the_site_is_served(hub) -> None:  # noqa: ANN001
    """@brief A path that climbs out of the built site is refused."""
    server, builder, live, _gone = hub
    builder.release.set()
    cookie = f"clew_wiki={server.token}"
    _get(f"http://127.0.0.1:{server.port}/r/{live.slug}/", cookie)
    for path in (
        f"/r/{live.slug}/../../registry.json",
        f"/r/{live.slug}/%2e%2e/%2e%2e/registry.json",
        "/r/nope/",
    ):
        status, _body, _h = _get(f"http://127.0.0.1:{server.port}{path}", cookie)
        assert status in (403, 404), path

Activity · 7 steps
lines 122–122server, builder, live, _gone = hublines 123–123builder.release.set()lines 124–124cookie = f"clew_wiki={server.token}"lines 125–125_get(f"http://127.0.0.1:{server.port}/r/{live.slug}/", cookie)lines 126–126◇ for path in (lines 131–131status, _body, _h = _get(f"http://127.0.0.1:{server.port}{path}", cookie)lines 132–132assert status in (403, 404), path

test_pages_served_by_the_hub_carry_the_live_script

None test_wiki_hub.test_pages_served_by_the_hub_carry_the_live_script(hub)

P4c-2a: live script injection.

tests/test_wiki_hub.py:224

Show on the map →

Called by none

Calls _get

Checks

  • assert '<script src="/live.js"></script></body>' in page
  • assert status == 200 and "EventSource" in script and "javascript" in headers["Content-Type"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measured
REQ-DDB-WIKI-032catalog
REQ-DDB-WIKI-033catalog
REQ-DDB-WIKI-034measured
REQ-DDB-WIKI-054catalog
Source · 17 lines
def test_pages_served_by_the_hub_carry_the_live_script(hub) -> None:  # noqa: ANN001
    """THE STATIC SITE STAYS SERVER-FREE: the hub injects `/live.js` into the pages it serves.

    @brief P4c-2a: live script injection.
    """
    server, builder, live, _gone = hub
    builder.release.set()
    site = server.site_dir(live)
    site.mkdir(parents=True)
    (site / "index.html").write_text("<html><body><p>x</p></body></html>")
    cookie = f"clew_wiki={server.token}"
    _status, page, _h = _get(f"http://127.0.0.1:{server.port}/r/{live.slug}/", cookie)
    assert '<script src="/live.js"></script></body>' in page
    status, script, headers = _get(f"http://127.0.0.1:{server.port}/live.js", cookie)
    assert status == 200 and "EventSource" in script and "javascript" in headers["Content-Type"]

Activity · 10 steps
lines 229–229server, builder, live, _gone = hublines 230–230builder.release.set()lines 231–231site = server.site_dir(live)lines 232–232site.mkdir(parents=True)lines 233–233(site / "index.html").write_text("<html><body><p>x</p></body></html>")lines 234–234cookie = f"clew_wiki={server.token}"lines 235–235_status, page, _h = _get(f"http://127.0.0.1:{server.port}/r/{live.slug}/", cookie)lines 236–236assert '<script src="/live.js"></script></body>' in pagelines 237–237status, script, headers = _get(f"http://127.0.0.1:{server.port}/live.js", cookie)lines 238–238assert status == 200 and "EventSource" in script and "javascript" in headers["Content-Type"]

test_serve_attaches_the_hub_to_the_tools_and_the_refresh_loop

None test_wiki_hub.test_serve_attaches_the_hub_to_the_tools_and_the_refresh_loop(Path tmp_path, pytest.MonkeyPatch monkeypatch)

P4c-2a: with the hub on, replies gain links and refreshes reach the hub.

tests/test_wiki_hub.py:310

Show on the map →

Called by none

Calls none

Checks

  • assert seen["linker"] is not None and seen["hub"] is not None
  • assert state.tools.wiki_linker is None and state.wiki_hub is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measured
REQ-DDB-MCP-004measured
REQ-DDB-WIKI-032measured
REQ-DDB-WIKI-033measured
REQ-DDB-WIKI-054measured
Source · 31 lines
def test_serve_attaches_the_hub_to_the_tools_and_the_refresh_loop(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
    """@brief P4c-2a: with the hub on, replies gain links and refreshes reach the hub."""
    from clew.mcp_server import server as srv

    monkeypatch.setenv("CLEW_STATE_HOME", str(tmp_path / "state"))
    monkeypatch.setenv("CLEW_WIKI", "1")
    seen: dict[str, object] = {}

    class _Tools:
        wiki_linker = None

    class _State:
        tools = _Tools()
        wiki_hub = None

        async def keep_current(self, interval: float) -> None:  # noqa: ARG002
            await anyio.sleep_forever()

    state = _State()

    async def transport(_mcp: object) -> None:
        seen["linker"] = state.tools.wiki_linker
        seen["hub"] = state.wiki_hub

    anyio.run(srv.serve, None, state, 0, transport)
    assert seen["linker"] is not None and seen["hub"] is not None
    assert state.tools.wiki_linker is None and state.wiki_hub is None

Activity · 11 steps
lines 314–314from clew.mcp_server import server as srvlines 316–316monkeypatch.setenv("CLEW_STATE_HOME", str(tmp_path / "state"))lines 317–317monkeypatch.setenv("CLEW_WIKI", "1")lines 318–318seen: dict[str, object] = {}lines 320–321class _Tools: wiki_linker = Nonelines 323–328class _State: tools = _Tools() wiki_hub = None async def keep_current(self, interval: float) -> None: # noqa: ARG002 await anyio.sleep_forever()lines 330–330state = _State()lines 332–334async def transport(_mcp: object) -> None: seen["linker"] = state.tools.wiki_linker seen["hub"] = state.wiki_hublines 336–336anyio.run(srv.serve, None, state, 0, transport)lines 337–337assert seen["linker"] is not None and seen["hub"] is not Nonelines 338–338assert state.tools.wiki_linker is None and state.wiki_hub is None

test_serve_runs_the_hub_only_when_asked_and_records_its_url

None test_wiki_hub.test_serve_runs_the_hub_only_when_asked_and_records_its_url(Path tmp_path, pytest.MonkeyPatch monkeypatch)

serve() and the hub.

tests/test_wiki_hub.py:149

Show on the map →

Called by none

Calls none

Checks

  • assert seen["exists"] and "http://127.0.0.1:" in str(seen["text"])
  • assert not (tmp_path / "state" / "wiki.json").exists()
  • assert seen["exists"] is False

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measured
REQ-DDB-MCP-004measured
REQ-DDB-WIKI-032measured
REQ-DDB-WIKI-033measured
REQ-DDB-WIKI-054measured
Source · 33 lines
def test_serve_runs_the_hub_only_when_asked_and_records_its_url(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
    """OPT-IN: with `CLEW_WIKI=1` the hub runs beside the transport and its URL is written to the
    state root's `wiki.json`; when the transport ends the hub stops and the file goes.

    @brief serve() and the hub.
    """
    from clew.mcp_server import server as srv

    monkeypatch.setenv("CLEW_STATE_HOME", str(tmp_path / "state"))
    seen: dict[str, object] = {}

    async def transport(_mcp: object) -> None:
        record = tmp_path / "state" / "wiki.json"
        seen["exists"] = record.is_file()
        seen["text"] = record.read_text() if record.is_file() else ""

    class _State:
        async def keep_current(self, interval: float) -> None:  # noqa: ARG002
            await anyio.sleep_forever()

    monkeypatch.setenv("CLEW_WIKI", "1")
    anyio.run(srv.serve, None, _State(), 0, transport)
    assert seen["exists"] and "http://127.0.0.1:" in str(seen["text"])
    assert not (tmp_path / "state" / "wiki.json").exists()
    monkeypatch.delenv("CLEW_WIKI")
    anyio.run(srv.serve, None, _State(), 0, transport)
    assert seen["exists"] is False


# --- Round 3, P4c-2a: the live layer ------------------------------------------------------------
Activity · 12 steps
lines 157–157from clew.mcp_server import server as srvlines 159–159monkeypatch.setenv("CLEW_STATE_HOME", str(tmp_path / "state"))lines 160–160seen: dict[str, object] = {}lines 162–165async def transport(_mcp: object) -> None: record = tmp_path / "state" / "wiki.json" seen["exists"] = record.is_file() seen["text"] = record.read_text() if record.is_file() else ""lines 167–169class _State: async def keep_current(self, interval: float) -> None: # noqa: ARG002 await anyio.sleep_forever()lines 171–171monkeypatch.setenv("CLEW_WIKI", "1")lines 172–172anyio.run(srv.serve, None, _State(), 0, transport)lines 173–173assert seen["exists"] and "http://127.0.0.1:" in str(seen["text"])lines 174–174assert not (tmp_path / "state" / "wiki.json").exists()lines 175–175monkeypatch.delenv("CLEW_WIKI")lines 176–176anyio.run(srv.serve, None, _State(), 0, transport)lines 177–177assert seen["exists"] is False

test_served_pages_carry_the_comment_control

None test_wiki_hub.test_served_pages_carry_the_comment_control(hub)

The hub injects `/comment.js` with `/live.js`; the static site stays server-free.

tests/test_wiki_hub.py:437

Show on the map →

Called by none

Calls _get

Checks

  • assert '<script src="/comment.js"></script>' in page
  • assert status == 200 and "/comment" in script and "javascript" in headers["Content-Type"]
  • assert "textContent" in script and "innerHTML" not in script

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measured
REQ-DDB-WIKI-032catalog
REQ-DDB-WIKI-033catalog
REQ-DDB-WIKI-034measured
REQ-DDB-WIKI-054catalog
Source · 13 lines
def test_served_pages_carry_the_comment_control(hub) -> None:  # noqa: ANN001
    """@brief The hub injects `/comment.js` with `/live.js`; the static site stays server-free."""
    server, builder, live, _gone = hub
    builder.release.set()
    site = server.site_dir(live)
    site.mkdir(parents=True, exist_ok=True)
    (site / "index.html").write_text("<html><body><p>x</p></body></html>")
    cookie = f"clew_wiki={server.token}"
    _s, page, _h = _get(f"http://127.0.0.1:{server.port}/r/{live.slug}/", cookie)
    assert '<script src="/comment.js"></script>' in page
    status, script, headers = _get(f"http://127.0.0.1:{server.port}/comment.js", cookie)
    assert status == 200 and "/comment" in script and "javascript" in headers["Content-Type"]
    assert "textContent" in script and "innerHTML" not in script

1 more lines, not shown

Activity · 11 steps
lines 439–439server, builder, live, _gone = hublines 440–440builder.release.set()lines 441–441site = server.site_dir(live)lines 442–442site.mkdir(parents=True, exist_ok=True)lines 443–443(site / "index.html").write_text("<html><body><p>x</p></body></html>")lines 444–444cookie = f"clew_wiki={server.token}"lines 445–445_s, page, _h = _get(f"http://127.0.0.1:{server.port}/r/{live.slug}/", cookie)lines 446–446assert '<script src="/comment.js"></script>' in pagelines 447–447status, script, headers = _get(f"http://127.0.0.1:{server.port}/comment.js", cookie)lines 448–448assert status == 200 and "/comment" in script and "javascript" in headers["Content-Type"]lines 449–449assert "textContent" in script and "innerHTML" not in script

test_the_api_answers_with_the_query_engine

None test_wiki_hub.test_the_api_answers_with_the_query_engine(Path tmp_path)

P4c-2a: JSON API.

tests/test_wiki_hub.py:241

Show on the map →

Called by none

Calls _build_argparser, _get, _run_pipeline

Checks

  • assert status == 200 and "json" in headers["Content-Type"]
  • assert reply["name"] == "alpha" and [c["name"] for c in reply["callees"]] == ["beta"]
  • assert status == 200 and any(r["name"] == "beta" for r in json.loads(body)["results"])
  • assert status == 400

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → report_stats
REQ-DDB-CLI-002inferredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → _doxygen_or_partial → _doxygen_stage → _run_doxygen_from_args → run_doxygen → doxygen_supports_sqlite3
REQ-DDB-CONFIG-001measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _apply_declared_document → stated_document_meta
REQ-DDB-CONFIG-003inferredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml → _is_flat_req_list
REQ-DDB-CONFIG-004measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → resolve_preprocessor
REQ-DDB-CONFIG-005measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_kconfig
REQ-DDB-CONFIG-006measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _recorded_entry_patterns → recorded_explicit
REQ-DDB-CONFIG-007measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → write_build_signature
REQ-DDB-CONFIG-009measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _apply_toolchain_exclusions → load_toolchain_config
REQ-DDB-GUARD-012inferredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → load_guard_config → read_guard_config → read_requirements_section
REQ-DDB-GUARD-019measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings → summarize → parse_doxygen_tags
REQ-DDB-GUARD-024measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings → summarize → apply_autobrief
REQ-DDB-INDEX-001measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _verify_extra_input_is_read → effective_file_patterns
REQ-DDB-INDEX-002measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → build_lock
REQ-DDB-INDEX-003measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → report_index_coverage
REQ-DDB-INDEX-004measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → recover_ast_symbols
REQ-DDB-INDEX-005measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → stamp_external_provenance
REQ-DDB-INDEX-006measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → record_code_text → code_text_rows
REQ-DDB-INDEX-007measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → record_owners
REQ-DDB-INDEX-008measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_licenses
REQ-DDB-INDEX-009measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_kerneldoc
REQ-DDB-INDEX-010measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_ast_includes
REQ-DDB-INDEX-011measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_property_keys
REQ-DDB-MCP-001measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _operator_excludes → meta_section
REQ-DDB-MCP-004measured
REQ-DDB-PIPE-001measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_database
REQ-DDB-PIPE-003measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → build_call_edges
REQ-DDB-PIPE-004measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → python_entry_seeds
REQ-DDB-PIPE-005measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → write_build_signature
REQ-DDB-PIPE-006measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → run_rustdoc → _require_nightly_rustdoc → clean_subprocess_env
REQ-DDB-PIPE-007measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_kconfig_gates
REQ-DDB-PIPE-008measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_docs
REQ-DDB-PIPE-009measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → prune_dominated_fuzzy_call_edges
REQ-DDB-PIPE-010measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_shared_key_edges_inferred → _build_inferred_edges
REQ-DDB-PIPE-011measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_ast_includes → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → build_harvest_plan → js_symbol_harvester
REQ-DDB-PIPE-013measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings
REQ-DDB-PIPE-014measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_kerneldoc → within_repo
REQ-DDB-PIPE-015measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_config_defaults
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-002measured
REQ-DDB-QUERY-003measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → mark_test_scope
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-009measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-011measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → extract_threads → _ensure_threads_tables
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-014measured
REQ-DDB-SCHEMA-001measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → extract_threads
REQ-DDB-SCHEMA-002measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_shared_key_edges_inferred → _writer_dispatch_map
REQ-DDB-SCHEMA-003measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-004measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → load_dispatch_manifest
REQ-DDB-SCHEMA-005measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → resolve_key_alias_prefixes
REQ-DDB-SCHEMA-006measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml
REQ-DDB-SCHEMA-007measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-009measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_event_edges
REQ-DDB-SCHEMA-011measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → extract_context_conflicts
REQ-DDB-SCHEMA-012measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → load_dispatch_manifest → declaration_origin
REQ-DDB-SCHEMA-013measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_data_model_keys
REQ-DDB-SCHEMA-014measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_docs → ensure_file_docs_table
REQ-DDB-SCHEMA-015measuredtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml
REQ-DDB-WIKI-032measured
REQ-DDB-WIKI-033catalog
REQ-DDB-WIKI-054catalogtest_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → recover_ast_symbols → _recover_into → all
Source · 36 lines
def test_the_api_answers_with_the_query_engine(tmp_path: Path) -> None:
    """THE SAME ENGINE THE TOOLS USE: `/api/<slug>/dossier` and `/api/<slug>/search` answer
    through `clew.query.export`.

    @brief P4c-2a: JSON API.
    """
    from clew.cli import _build_argparser, _run_pipeline
    from clew.mcp_server.wikihub import WikiHub

    repo = tmp_path / "repo"
    repo.mkdir()
    (repo / "m.py").write_text(
        'def alpha():\n    """Alpha."""\n    return beta()\n\n\ndef beta():\n    """Beta."""\n    return 1\n'
    )
    home = tmp_path / "state"
    target = TargetRegistry(home).register(repo)
    _run_pipeline(
        _build_argparser().parse_args(["--output", target.db_path, "--repo-root", str(repo)])
    )
    server = WikiHub(home, builder=_Builder())
    server.start()
    try:
        cookie = f"clew_wiki={server.token}"
        base = f"http://127.0.0.1:{server.port}/api/{target.slug}"
        status, body, headers = _get(f"{base}/dossier?subject=alpha", cookie)
        reply = json.loads(body)
        assert status == 200 and "json" in headers["Content-Type"]
        assert reply["name"] == "alpha" and [c["name"] for c in reply["callees"]] == ["beta"]
        status, body, _h = _get(f"{base}/search?text=beta", cookie)
        assert status == 200 and any(r["name"] == "beta" for r in json.loads(body)["results"])
        status, _body, _h = _get(f"{base}/dossier", cookie)
        assert status == 400
    finally:
        server.stop()

Activity · 21 steps
lines 247–247from clew.cli import _build_argparser, _run_pipelinelines 248–248from clew.mcp_server.wikihub import WikiHublines 250–250repo = tmp_path / "repo"lines 251–251repo.mkdir()lines 252–254(repo / "m.py").write_text( 'def alpha():\n """Alpha."""\n return beta()\n\n\ndef beta():\n """Beta."""\n return 1\n' )lines 255–255home = tmp_path / "state"lines 256–256target = TargetRegistry(home).register(repo)lines 257–259_run_pipeline( _build_argparser().parse_args(["--output", target.db_path, "--repo-root", str(repo)]) )lines 260–260server = WikiHub(home, builder=_Builder())lines 261–261server.start()lines 262–262trylines 263–263cookie = f"clew_wiki={server.token}"lines 264–264base = f"http://127.0.0.1:{server.port}/api/{target.slug}"lines 265–265status, body, headers = _get(f"{base}/dossier?subject=alpha", cookie)lines 266–266reply = json.loads(body)lines 267–267assert status == 200 and "json" in headers["Content-Type"]lines 268–268assert reply["name"] == "alpha" and [c["name"] for c in reply["callees"]] == ["beta"]lines 269–269status, body, _h = _get(f"{base}/search?text=beta", cookie)lines 270–270assert status == 200 and any(r["name"] == "beta" for r in json.loads(body)["results"])lines 271–271status, _body, _h = _get(f"{base}/dossier", cookie)lines 272–272assert status == 400

test_the_comment_endpoint_refuses_what_it_must

None test_wiki_hub.test_the_comment_endpoint_refuses_what_it_must(hub)

Comment endpoint refusals.

tests/test_wiki_hub.py:410

Show on the map →

Called by none

Calls _post

Checks

  • assert _post(url, good)[0] == 403
  • assert _post(url, good, cookie, kind="text/plain")[0] == 415
  • assert _post(url, good, cookie, origin="http://evil.example")[0] == 403
  • assert _post(url, b"x" * 70_000, cookie)[0] == 413
  • assert status == 400 and "empty" in reply
  • assert _post(f"http://127.0.0.1:{server.port}/api/nosuch/comment", good, cookie)[0] == 404
  • assert CommentStore.for_repo(server.home, live.repo_path).unread() == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measured
REQ-DDB-WIKI-032catalog
REQ-DDB-WIKI-033catalog
REQ-DDB-WIKI-054measured
Source · 27 lines
def test_the_comment_endpoint_refuses_what_it_must(hub) -> None:  # noqa: ANN001
    """SAME DOOR AS EVERY PAGE: the session cookie, JSON only (a cross-site form cannot send it
    without a preflight), the hub's own origin when one is sent, a size cap, and the store's own
    refusals (empty, over the limit) passed back with their reason.

    @brief Comment endpoint refusals.
    """
    import json

    from clew.mcp_server.comments import CommentStore

    server, builder, live, _gone = hub
    builder.release.set()
    url = f"http://127.0.0.1:{server.port}/api/{live.slug}/comment"
    cookie = f"clew_wiki={server.token}"
    good = json.dumps({"page": "a.html", "anchor": "", "quote": "", "body": "hi"}).encode()
    assert _post(url, good)[0] == 403
    assert _post(url, good, cookie, kind="text/plain")[0] == 415
    assert _post(url, good, cookie, origin="http://evil.example")[0] == 403
    assert _post(url, b"x" * 70_000, cookie)[0] == 413
    empty = json.dumps({"page": "a.html", "anchor": "", "quote": "", "body": " "}).encode()
    status, reply = _post(url, empty, cookie)
    assert status == 400 and "empty" in reply
    assert _post(f"http://127.0.0.1:{server.port}/api/nosuch/comment", good, cookie)[0] == 404
    assert CommentStore.for_repo(server.home, live.repo_path).unread() == []

Activity · 16 steps
lines 417–417import jsonlines 419–419from clew.mcp_server.comments import CommentStorelines 421–421server, builder, live, _gone = hublines 422–422builder.release.set()lines 423–423url = f"http://127.0.0.1:{server.port}/api/{live.slug}/comment"lines 424–424cookie = f"clew_wiki={server.token}"lines 425–425good = json.dumps({"page": "a.html", "anchor": "", "quote": "", "body": "hi"}).encode()lines 426–426assert _post(url, good)[0] == 403lines 427–427assert _post(url, good, cookie, kind="text/plain")[0] == 415lines 428–428assert _post(url, good, cookie, origin="http://evil.example")[0] == 403lines 429–429assert _post(url, b"x" * 70_000, cookie)[0] == 413lines 430–430empty = json.dumps({"page": "a.html", "anchor": "", "quote": "", "body": " "}).encode()lines 431–431status, reply = _post(url, empty, cookie)lines 432–432assert status == 400 and "empty" in replylines 433–433assert _post(f"http://127.0.0.1:{server.port}/api/nosuch/comment", good, cookie)[0] == 404lines 434–434assert CommentStore.for_repo(server.home, live.repo_path).unread() == []

test_the_hub_binds_loopback_and_refuses_a_request_without_its_token

None test_wiki_hub.test_the_hub_binds_loopback_and_refuses_a_request_without_its_token(hub)

127.0.0.1 only; no token, no page.

tests/test_wiki_hub.py:81

Show on the map →

Called by none

Calls _get

Checks

  • assert server.host == "127.0.0.1" and server.port > 0
  • assert status == 403
  • assert status == 403

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-032catalog
REQ-DDB-WIKI-033catalog
REQ-DDB-WIKI-054catalog
Source · 10 lines
def test_the_hub_binds_loopback_and_refuses_a_request_without_its_token(hub) -> None:  # noqa: ANN001
    """@brief 127.0.0.1 only; no token, no page."""
    server, *_ = hub
    assert server.host == "127.0.0.1" and server.port > 0
    status, _body, _h = _get(f"http://127.0.0.1:{server.port}/")
    assert status == 403
    status, _body, _h = _get(f"http://127.0.0.1:{server.port}/?t=wrong")
    assert status == 403

Activity · 6 steps
lines 83–83server, *_ = hublines 84–84assert server.host == "127.0.0.1" and server.port > 0lines 85–85status, _body, _h = _get(f"http://127.0.0.1:{server.port}/")lines 86–86assert status == 403lines 87–87status, _body, _h = _get(f"http://127.0.0.1:{server.port}/?t=wrong")lines 88–88assert status == 403

test_the_hub_lists_every_target_and_says_which_are_unreachable

None test_wiki_hub.test_the_hub_lists_every_target_and_says_which_are_unreachable(hub)

The index of indexes; a vanished checkout stays listed.

tests/test_wiki_hub.py:91

Show on the map →

Called by none

Calls _get

Checks

  • assert status == 200
  • assert live.slug in body and f'href="/r/{live.slug}/"' in body
  • assert "unreachable" in row
  • assert ("HttpOnly" in headers.get("Set-Cookie", "") and "SameSite=Strict" in headers["Set-Cookie"] )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measured
REQ-DDB-WIKI-032catalog
REQ-DDB-WIKI-033catalog
REQ-DDB-WIKI-034measured
REQ-DDB-WIKI-054catalog
Source · 13 lines
def test_the_hub_lists_every_target_and_says_which_are_unreachable(hub) -> None:  # noqa: ANN001
    """@brief The index of indexes; a vanished checkout stays listed."""
    server, _builder, live, gone = hub
    status, body, headers = _get(server.url)
    assert status == 200
    assert live.slug in body and f'href="/r/{live.slug}/"' in body
    row = body[body.index(gone.slug) :].split("</tr>")[0]
    assert "unreachable" in row
    assert (
        "HttpOnly" in headers.get("Set-Cookie", "") and "SameSite=Strict" in headers["Set-Cookie"]
    )

Activity · 7 steps
lines 93–93server, _builder, live, gone = hublines 94–94status, body, headers = _get(server.url)lines 95–95assert status == 200lines 96–96assert live.slug in body and f'href="/r/{live.slug}/"' in bodylines 97–97row = body[body.index(gone.slug) :].split("</tr>")[0]lines 98–98assert "unreachable" in rowlines 99–101assert ( "HttpOnly" in headers.get("Set-Cookie", "") and "SameSite=Strict" in headers["Set-Cookie"] )

test_the_hub_writes_nothing_to_stdout

None test_wiki_hub.test_the_hub_writes_nothing_to_stdout(hub, pytest.CaptureFixture[str] capfd)

Clean stdout.

tests/test_wiki_hub.py:135

Show on the map →

Called by none

Calls _get

Checks

  • assert capfd.readouterr().out == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measured
REQ-DDB-WIKI-032measured
REQ-DDB-WIKI-033measured
REQ-DDB-WIKI-034measured
REQ-DDB-WIKI-054catalog
Source · 14 lines
def test_the_hub_writes_nothing_to_stdout(hub, capfd: pytest.CaptureFixture[str]) -> None:  # noqa: ANN001
    """THE STDOUT IS THE JSON-RPC WIRE: request logging goes to the logger, never print.

    @brief Clean stdout.
    """
    server, builder, live, _gone = hub
    builder.release.set()
    capfd.readouterr()
    _get(server.url)
    _get(f"http://127.0.0.1:{server.port}/r/{live.slug}/?t={server.token}")
    _get(f"http://127.0.0.1:{server.port}/")
    assert capfd.readouterr().out == ""

Activity · 7 steps
lines 140–140server, builder, live, _gone = hublines 141–141builder.release.set()lines 142–142capfd.readouterr()lines 143–143_get(server.url)lines 144–144_get(f"http://127.0.0.1:{server.port}/r/{live.slug}/?t={server.token}")lines 145–145_get(f"http://127.0.0.1:{server.port}/")lines 146–146assert capfd.readouterr().out == ""

test_the_refresh_loop_tells_the_hub_what_it_refreshed

None test_wiki_hub.test_the_refresh_loop_tells_the_hub_what_it_refreshed(pytest.MonkeyPatch monkeypatch)

P4c-2a: keep_current hands the refreshed slugs to the hub.

tests/test_wiki_hub.py:341

Show on the map →

Called by none

Calls none

Checks

  • assert told and told[0] == ["a-123456"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-004measured
REQ-DDB-WIKI-032catalog
REQ-DDB-WIKI-033catalog
REQ-DDB-WIKI-054catalog
Source · 28 lines
def test_the_refresh_loop_tells_the_hub_what_it_refreshed(monkeypatch: pytest.MonkeyPatch) -> None:
    """@brief P4c-2a: keep_current hands the refreshed slugs to the hub."""
    from clew.mcp_server.server import DocsDbServer

    told: list[list[str]] = []

    class _Hub:
        def refreshed(self, slugs: list[str]) -> None:
            told.append(slugs)

    server = DocsDbServer.__new__(DocsDbServer)
    server.wiki_hub = _Hub()

    async def refresh() -> list[str]:
        return ["a-123456"]

    monkeypatch.setattr(server, "refresh_touched", refresh, raising=False)
    server._watcher = type("W", (), {"sync": lambda self, paths: None, "stop": lambda self: None})()
    server._touched = {}

    async def run() -> None:
        with anyio.move_on_after(0.5):
            await server.keep_current(0.05)

    anyio.run(run)
    assert told and told[0] == ["a-123456"]

Activity · 12 steps
lines 343–343from clew.mcp_server.server import DocsDbServerlines 345–345told: list[list[str]] = []lines 347–349class _Hub: def refreshed(self, slugs: list[str]) -> None: told.append(slugs)lines 351–351server = DocsDbServer.__new__(DocsDbServer)lines 352–352server.wiki_hub = _Hub()lines 354–355async def refresh() -> list[str]: return ["a-123456"]lines 357–357monkeypatch.setattr(server, "refresh_touched", refresh, raising=False)lines 358–358server._watcher = type("W", (), {"sync": lambda self, paths: None, "stop": lambda self: None})()lines 359–359server._touched = {}lines 361–363async def run() -> None: with anyio.move_on_after(0.5): await server.keep_current(0.05)lines 365–365anyio.run(run)lines 366–366assert told and told[0] == ["a-123456"]