test_invoking_a_registered_tool_runs_the_refresh_hook¶
Tests › tests/test_mcp_server.py
What this test is for
Why it exists
CLOSES A FAIL-OPEN THAT MUTATION FOUND. `server.py`'s `await before(kwargs.get("target"), kwargs.get("sub_index"))` is the ONE line that makes a query refresh, and `register_query_tools(..., before=None)` falls back to a plain binding — so an omitted argument silently disables the feature. Deleting that `await`, or passing `before=None` at either production registration, left the entire suite green.
Verifies REQ-DDB-MCP-001 REQ-DDB-QUERY-006 REQ-DDB-QUERY-008 REQ-DDB-QUERY-009
Given
seen: list[tuple[str | None, str | None]] = []async def hook(target: str | None, sub_index: str | None = None) -> None: seen.append((target, sub_index))
2 more
mcp = MCPServer("hook-probe")tools = QueryTools(lambda: "/nonexistent.db", lambda: "/tmp", lambda: [], None)
When
register_query_tools(mcp, tools, hook)with contextlib.suppress(Exception): await mcp._tool_manager.call_tool( "search", {"text": "anything", "target": "/some/repo"}, None )
Then
- ✓ inspect.iscoroutinefunction(mcp._tool_manager.get_tool("search").fn) holds
- ✓ seen equals [("/some/repo", None)]
What it exercises
The parts of the system's flows this test ran, measured by per-test coverage: lit steps ran in this test, dimmed ones did not, and ▶ marks where the test called in. Each title opens the whole flow with these steps lit.
Build, refresh and check the index · 9 of 153 steps
… 22 earlier steps
… 118 later steps
2 more
- clew-mcp — `main` (clew/mcp_server/server.py) · 3 of 17 steps
- Look up one name: everything the index holds about it · 1 of 226 steps
tests/test_mcp_server.py:3694 · its file's page
What it checks (2)
assert inspect.iscoroutinefunction(mcp._tool_manager.get_tool("search").fn), ( "the registered callable is not the async refresh wrapper, so no hook can run" )not attributedassert seen == [("/some/repo", None)], ( f"invoking the registered `search` tool did not run the refresh hook with the " f"caller's target and sub_index (hook calls: {seen}). The wrapper is what makes a " f"stale query refresh, and without this assertion deleting it leaves the suite green" )not attributed
Where the product reaches it
index→_index_action→build_or_refresh→_activate_tier1→register_query_tools(flow)
Call flow
What it reaches
Each row runs from this test, through the calls it makes, to the code a requirement names. If that code breaks, the test's checks are what should catch it. Reaching is not proving: a check only proves what it observes. No mutation records were given, so these rows say what the test REACHES.
Requirements it verifies (4)
| requirement | linked by | implementers exercised |
|---|---|---|
| REQ-DDB-MCP-001 | catalog | unknown |
| REQ-DDB-QUERY-006 | catalog | unknown |
| REQ-DDB-QUERY-008 | catalog | unknown |
| REQ-DDB-QUERY-009 | catalog | unknown |
Also reaches 3 requirements
Its run touches their code; that is reach, not proof.
- REQ-DDB-MCP-003 measured
- REQ-DDB-MCP-004 measured
- REQ-DDB-WIKI-054 measured