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.
Checks
assert status == 201, replyassert [c["body"] for c in stored] == ["Bound?"] and stored[0]["page"] == "test-x.html"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-WIKI-032 | catalog | |
| REQ-DDB-WIKI-033 | catalog | |
| REQ-DDB-WIKI-054 | measured |
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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → report_stats |
| REQ-DDB-CLI-002 | inferred | test_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-001 | measured | test_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-003 | inferred | test_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-004 | measured | test_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → resolve_preprocessor |
| REQ-DDB-CONFIG-005 | measured | test_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → import_kconfig |
| REQ-DDB-CONFIG-006 | measured | test_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-007 | measured | test_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-009 | measured | test_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-012 | inferred | test_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-019 | measured | test_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-024 | measured | test_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-001 | measured | test_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-002 | measured | test_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → build_lock |
| REQ-DDB-INDEX-003 | measured | test_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-004 | measured | test_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-005 | measured | test_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-006 | measured | test_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-007 | measured | test_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → record_owners |
| REQ-DDB-INDEX-008 | measured | test_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-009 | measured | test_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_kerneldoc |
| REQ-DDB-INDEX-010 | measured | test_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-011 | measured | test_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-001 | measured | test_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _operator_excludes → meta_section |
| REQ-DDB-MCP-003 | measured | |
| REQ-DDB-MCP-004 | measured | |
| REQ-DDB-PIPE-001 | measured | test_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_database |
| REQ-DDB-PIPE-003 | measured | test_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-004 | measured | test_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-005 | measured | test_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-006 | measured | test_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-007 | measured | test_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-008 | measured | test_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-009 | measured | test_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-010 | measured | test_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-011 | measured | test_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-012 | measured | test_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-013 | measured | test_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-014 | measured | test_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-015 | measured | test_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-001 | measured | |
| REQ-DDB-QUERY-002 | measured | |
| REQ-DDB-QUERY-003 | measured | test_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-004 | measured | |
| REQ-DDB-QUERY-006 | measured | |
| REQ-DDB-QUERY-009 | measured | |
| REQ-DDB-QUERY-010 | measured | |
| REQ-DDB-QUERY-011 | measured | test_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-012 | measured | |
| REQ-DDB-QUERY-013 | measured | |
| REQ-DDB-QUERY-014 | measured | |
| REQ-DDB-SCHEMA-001 | measured | test_a_dossier_reply_carries_a_wiki_url_only_while_the_hub_runs → _run_pipeline → _run_pipeline_inner → _build_stages → extract_threads |
| REQ-DDB-SCHEMA-002 | measured | test_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-003 | measured | test_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-004 | measured | test_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-005 | measured | test_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-006 | measured | test_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-007 | measured | test_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-009 | measured | test_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-011 | measured | test_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-012 | measured | test_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-013 | measured | test_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-014 | measured | test_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-015 | measured | test_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-025 | measured | |
| REQ-DDB-WIKI-032 | catalog | |
| REQ-DDB-WIKI-033 | measured | |
| REQ-DDB-WIKI-054 | catalog | test_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
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.
Checks
assert event == {"type": "rebuilt", "slug": live.slug}assert builder.calls == [live.slug]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-WIKI-032 | measured | |
| REQ-DDB-WIKI-033 | measured | |
| REQ-DDB-WIKI-034 | measured | |
| REQ-DDB-WIKI-054 | catalog |
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
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.
Checks
assert status == 202 and "Building" in body and 'http-equiv="refresh"' in bodyassert status == 200 and f"wiki of {live.slug}" in bodyassert builder.calls == [live.slug]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-WIKI-032 | measured | |
| REQ-DDB-WIKI-033 | measured | |
| REQ-DDB-WIKI-034 | measured | |
| REQ-DDB-WIKI-054 | catalog |
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
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.
Checks
assert status in (403, 404), path
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-WIKI-032 | measured | |
| REQ-DDB-WIKI-033 | measured | |
| REQ-DDB-WIKI-034 | measured | |
| REQ-DDB-WIKI-054 | catalog |
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
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.
Checks
assert '<script src="/live.js"></script></body>' in pageassert status == 200 and "EventSource" in script and "javascript" in headers["Content-Type"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-WIKI-032 | catalog | |
| REQ-DDB-WIKI-033 | catalog | |
| REQ-DDB-WIKI-034 | measured | |
| REQ-DDB-WIKI-054 | catalog |
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
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.
Checks
assert seen["linker"] is not None and seen["hub"] is not Noneassert state.tools.wiki_linker is None and state.wiki_hub is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-MCP-004 | measured | |
| REQ-DDB-WIKI-032 | measured | |
| REQ-DDB-WIKI-033 | measured | |
| REQ-DDB-WIKI-054 | measured |
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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-MCP-004 | measured | |
| REQ-DDB-WIKI-032 | measured | |
| REQ-DDB-WIKI-033 | measured | |
| REQ-DDB-WIKI-054 | measured |
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
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.
Checks
assert '<script src="/comment.js"></script>' in pageassert status == 200 and "/comment" in script and "javascript" in headers["Content-Type"]assert "textContent" in script and "innerHTML" not in script
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-WIKI-032 | catalog | |
| REQ-DDB-WIKI-033 | catalog | |
| REQ-DDB-WIKI-034 | measured | |
| REQ-DDB-WIKI-054 | catalog |
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 script1 more lines, not shown
Activity · 11 steps
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → report_stats |
| REQ-DDB-CLI-002 | inferred | test_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-001 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _apply_declared_document → stated_document_meta |
| REQ-DDB-CONFIG-003 | inferred | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml → _is_flat_req_list |
| REQ-DDB-CONFIG-004 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → resolve_preprocessor |
| REQ-DDB-CONFIG-005 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_kconfig |
| REQ-DDB-CONFIG-006 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _recorded_entry_patterns → recorded_explicit |
| REQ-DDB-CONFIG-007 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → write_build_signature |
| REQ-DDB-CONFIG-009 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _apply_toolchain_exclusions → load_toolchain_config |
| REQ-DDB-GUARD-012 | inferred | test_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-019 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings → summarize → parse_doxygen_tags |
| REQ-DDB-GUARD-024 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings → summarize → apply_autobrief |
| REQ-DDB-INDEX-001 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _verify_extra_input_is_read → effective_file_patterns |
| REQ-DDB-INDEX-002 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → build_lock |
| REQ-DDB-INDEX-003 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → report_index_coverage |
| REQ-DDB-INDEX-004 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → recover_ast_symbols |
| REQ-DDB-INDEX-005 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → stamp_external_provenance |
| REQ-DDB-INDEX-006 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → record_code_text → code_text_rows |
| REQ-DDB-INDEX-007 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → record_owners |
| REQ-DDB-INDEX-008 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_licenses |
| REQ-DDB-INDEX-009 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_kerneldoc |
| REQ-DDB-INDEX-010 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_ast_includes |
| REQ-DDB-INDEX-011 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_property_keys |
| REQ-DDB-MCP-001 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _operator_excludes → meta_section |
| REQ-DDB-MCP-004 | measured | |
| REQ-DDB-PIPE-001 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_database |
| REQ-DDB-PIPE-003 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → build_call_edges |
| REQ-DDB-PIPE-004 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → python_entry_seeds |
| REQ-DDB-PIPE-005 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → write_build_signature |
| REQ-DDB-PIPE-006 | measured | test_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-007 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_kconfig_gates |
| REQ-DDB-PIPE-008 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_docs |
| REQ-DDB-PIPE-009 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → prune_dominated_fuzzy_call_edges |
| REQ-DDB-PIPE-010 | measured | test_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-011 | measured | test_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-012 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → build_harvest_plan → js_symbol_harvester |
| REQ-DDB-PIPE-013 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings |
| REQ-DDB-PIPE-014 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_kerneldoc → within_repo |
| REQ-DDB-PIPE-015 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_config_defaults |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-002 | measured | |
| REQ-DDB-QUERY-003 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → mark_test_scope |
| REQ-DDB-QUERY-004 | measured | |
| REQ-DDB-QUERY-006 | measured | |
| REQ-DDB-QUERY-007 | measured | |
| REQ-DDB-QUERY-009 | measured | |
| REQ-DDB-QUERY-010 | measured | |
| REQ-DDB-QUERY-011 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → extract_threads → _ensure_threads_tables |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-QUERY-014 | measured | |
| REQ-DDB-SCHEMA-001 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → extract_threads |
| REQ-DDB-SCHEMA-002 | measured | test_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-003 | measured | test_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-004 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → load_dispatch_manifest |
| REQ-DDB-SCHEMA-005 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → resolve_key_alias_prefixes |
| REQ-DDB-SCHEMA-006 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml |
| REQ-DDB-SCHEMA-007 | measured | test_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-009 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_event_edges |
| REQ-DDB-SCHEMA-011 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → extract_context_conflicts |
| REQ-DDB-SCHEMA-012 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → load_dispatch_manifest → declaration_origin |
| REQ-DDB-SCHEMA-013 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → import_data_model_keys |
| REQ-DDB-SCHEMA-014 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_docs → ensure_file_docs_table |
| REQ-DDB-SCHEMA-015 | measured | test_the_api_answers_with_the_query_engine → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml |
| REQ-DDB-WIKI-032 | measured | |
| REQ-DDB-WIKI-033 | catalog | |
| REQ-DDB-WIKI-054 | catalog | test_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
test_the_comment_endpoint_refuses_what_it_must
None test_wiki_hub.test_the_comment_endpoint_refuses_what_it_must(hub)
Comment endpoint refusals.
Checks
assert _post(url, good)[0] == 403assert _post(url, good, cookie, kind="text/plain")[0] == 415assert _post(url, good, cookie, origin="http://evil.example")[0] == 403assert _post(url, b"x" * 70_000, cookie)[0] == 413assert status == 400 and "empty" in replyassert _post(f"http://127.0.0.1:{server.port}/api/nosuch/comment", good, cookie)[0] == 404assert CommentStore.for_repo(server.home, live.repo_path).unread() == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-WIKI-032 | catalog | |
| REQ-DDB-WIKI-033 | catalog | |
| REQ-DDB-WIKI-054 | measured |
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
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.
Checks
assert server.host == "127.0.0.1" and server.port > 0assert status == 403assert status == 403
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-032 | catalog | |
| REQ-DDB-WIKI-033 | catalog | |
| REQ-DDB-WIKI-054 | catalog |
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
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.
Checks
assert status == 200assert live.slug in body and f'href="/r/{live.slug}/"' in bodyassert "unreachable" in rowassert ("HttpOnly" in headers.get("Set-Cookie", "") and "SameSite=Strict" in headers["Set-Cookie"] )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-WIKI-032 | catalog | |
| REQ-DDB-WIKI-033 | catalog | |
| REQ-DDB-WIKI-034 | measured | |
| REQ-DDB-WIKI-054 | catalog |
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
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.
Checks
assert capfd.readouterr().out == ""
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-001 | measured | |
| REQ-DDB-WIKI-032 | measured | |
| REQ-DDB-WIKI-033 | measured | |
| REQ-DDB-WIKI-034 | measured | |
| REQ-DDB-WIKI-054 | catalog |
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
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.
Checks
assert told and told[0] == ["a-123456"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-004 | measured | |
| REQ-DDB-WIKI-032 | catalog | |
| REQ-DDB-WIKI-033 | catalog | |
| REQ-DDB-WIKI-054 | catalog |
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"]