test_query.py¶
tests/test_query.py
R2 query-library tests.
test_a_prose_miss_is_graded_by_what_the_index_holds_elsewhere
None test_query.test_a_prose_miss_is_graded_by_what_the_index_holds_elsewhere(Path tmp_path)
An empty prose reply claims only what it has earned.
Checks
assert "NOT DEFINITIVE" in elsewhere, f"the index holds this name: {elsewhere}"assert "token_hits" in extra, "and the claim must be checkable, not merely worded"assert "definitive empty result" in nowhere, (f"a token in NO corpus is a definitive negative — refusing to say so would be the " f"dilution the anti-dilution test guards: {nowhere}" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_a_prose_miss_is_graded_by_what_the_index_holds_elsewhere → prose_emptiness → has_prose_corpus → connect |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_a_prose_miss_is_graded_by_what_the_index_holds_elsewhere → prose_emptiness → has_prose_corpus → table_exists |
| REQ-DDB-QUERY-007 | measured | test_a_prose_miss_is_graded_by_what_the_index_holds_elsewhere → prose_emptiness |
Source · 28 lines
def test_a_prose_miss_is_graded_by_what_the_index_holds_elsewhere(tmp_path: Path) -> None:
"""THE NOTE, AND BOTH DIRECTIONS OF IT. `_many`'s default wording — "a definitive empty
result… Do not retry this query or fall back to guessing" — is correct for a tool whose
emptiness can only mean absence, and was flatly wrong for prose. It is the specific sentence
that sent a graded agent to grep.
TWO-SIDED ON PURPOSE. A token the index holds elsewhere must be graded DOWN; a token that is
genuinely nowhere must KEEP the strong wording, because that is the case which earns it. A
one-sided version of this test passes against an implementation that never claims certainty
at all, which would be the dilution the anti-dilution test guards.
@brief An empty prose reply claims only what it has earned.
@version 1
"""
from clew.mcp_server.emptiness import prose_emptiness
db = _member_doc_db(tmp_path)
## The name IS in this index (as a macro-definition row), just not in prose the corpus reads.
elsewhere, extra = prose_emptiness(db, "PROJ_ALLOW_PRIVATE_ACCESS")
assert "NOT DEFINITIVE" in elsewhere, f"the index holds this name: {elsewhere}"
assert "token_hits" in extra, "and the claim must be checkable, not merely worded"
## A token nowhere in the index keeps the strong wording it has now earned.
nowhere, _extra = prose_emptiness(db, "zzz_absent_token_qqq")
assert "definitive empty result" in nowhere, (
f"a token in NO corpus is a definitive negative — refusing to say so would be the "
f"dilution the anti-dilution test guards: {nowhere}"
)1 more lines, not shown
Activity · 7 steps
test_all_req_edges_agrees_with_req_trace
None test_query.test_all_req_edges_agrees_with_req_trace(Path rich_db)
all_req_edges lists the implementer edges, agreeing with req_trace.
Checks
assert {i.name for i in rt.implementers} <= bulk_impl
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_all_req_edges_agrees_with_req_trace → req_trace |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_all_req_edges_agrees_with_req_trace → all_req_edges → table_exists |
| REQ-DDB-QUERY-004 | measured | test_all_req_edges_agrees_with_req_trace → all_req_edges |
| REQ-DDB-QUERY-010 | measured | test_all_req_edges_agrees_with_req_trace → req_trace → _req_implementers → resolve_rowid |
| REQ-DDB-SCHEMA-006 | measured | test_all_req_edges_agrees_with_req_trace → req_trace → _req_failure_modes |
| REQ-DDB-SCHEMA-015 | measured | test_all_req_edges_agrees_with_req_trace → req_trace → _req_links |
Source · 7 lines
def test_all_req_edges_agrees_with_req_trace(rich_db: Path) -> None:
"""all_req_edges lists the implementer edges, agreeing with req_trace."""
rt = q.req_trace(rich_db, "REQ-0621")
bulk_impl = {e.fn for e in q.all_req_edges(rich_db) if e.req_id == "REQ-0621"}
assert {i.name for i in rt.implementers} <= bulk_impl
Activity · 3 steps
test_callees_merge_dataflow_tagged_as_key_not_call
None test_query.test_callees_merge_dataflow_tagged_as_key_not_call(Path rich_db)
Checks
assert seam, "the dataflow neighbour must be present"assert all(c.edge_class == "key" for c in seam)assert {c.key_name for c in seam} == {"DEMOBOT_POWER_BATTERY_MV"}assert all(c.rowid > 0 for c in seam), "a dataflow neighbour is still name-resolved"assert len({c.source for c in seam}) == len(seam)assert call.edge_class == "call"assert call.key_name is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_callees_merge_dataflow_tagged_as_key_not_call → callees |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_callees_merge_dataflow_tagged_as_key_not_call → callees → _call_edges → _dataflow_edges → resolve_rowid |
| REQ-DDB-QUERY-009 | measured | test_callees_merge_dataflow_tagged_as_key_not_call → callees → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_callees_merge_dataflow_tagged_as_key_not_call → callees |
| REQ-DDB-WIKI-054 | inferred | test_callees_merge_dataflow_tagged_as_key_not_call → all |
Source · 26 lines
def test_callees_merge_dataflow_tagged_as_key_not_call(rich_db: Path) -> None:
"""#46: callees() returns causal successors, not just call successors. The
sensor_poll → telemetry_report seam is pure dataflow — no call path connects
them — so before the merge the cheap tool answered "sensor_poll reaches
nothing but hardware", which is wrong about the system, not merely thin.
It must arrive TAGGED. An untagged merge trades a false negative for a false
positive ("sensor_poll calls telemetry_report"), which is worse: a missing
row invites another query, a wrong row does not."""
merged = q.callees(rich_db, "sensor_poll")
seam = [c for c in merged if c.name == "telemetry_report"]
assert seam, "the dataflow neighbour must be present"
assert all(c.edge_class == "key" for c in seam)
assert {c.key_name for c in seam} == {"DEMOBOT_POWER_BATTERY_MV"}
assert all(c.rowid > 0 for c in seam), "a dataflow neighbour is still name-resolved"
# The seam appears once per PROVENANCE layer (declared + inferred both find
# it here), which is the pre-existing #38 duplication the merge inherits
# unchanged — NOT a duplicate introduced by merging. Pinned so #38's collapse
# has a baseline: the rows differ only in `source`.
assert len({c.source for c in seam}) == len(seam)
# The call half is untouched by the merge.
call = next(c for c in merged if c.name == "hw_read_battery_adc")
assert call.edge_class == "call"
assert call.key_name is None
Activity · 10 steps
test_callees_of_writer
None test_query.test_callees_of_writer(Path rich_db)
Checks
assert "hw_read_battery_adc" in namesassert "DataModel_Set_DEMOBOT_POWER_BATTERY_MV" in names
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_callees_of_writer → callees |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_callees_of_writer → callees → _call_edges → _dataflow_edges → resolve_rowid |
| REQ-DDB-QUERY-009 | measured | test_callees_of_writer → callees → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_callees_of_writer → callees |
Source · 9 lines
def test_callees_of_writer(rich_db: Path) -> None:
names = {c.name for c in q.callees(rich_db, "sensor_poll")}
assert "hw_read_battery_adc" in names
assert "DataModel_Set_DEMOBOT_POWER_BATTERY_MV" in names
# ─── integration: the #46 dataflow merge ─────────────────────────────────────
Activity · 3 steps
test_callers_includes_fnptr_dispatch
None test_query.test_callers_includes_fnptr_dispatch(Path rich_db)
handle_cloud_command is dispatched via a resolved fnptr edge from event_bus_dispatch — callers() must surface it.
Checks
assert "event_bus_dispatch" in names
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_callers_includes_fnptr_dispatch → callers |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_callers_includes_fnptr_dispatch → callers → _call_edges → _dataflow_edges → resolve_rowid |
| REQ-DDB-QUERY-009 | measured | test_callers_includes_fnptr_dispatch → callers → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_callers_includes_fnptr_dispatch → callers |
Source · 7 lines
def test_callers_includes_fnptr_dispatch(rich_db: Path) -> None:
"""handle_cloud_command is dispatched via a resolved fnptr edge from
event_bus_dispatch — callers() must surface it."""
names = {c.name for c in q.callers(rich_db, "handle_cloud_command")}
assert "event_bus_dispatch" in names
Activity · 2 steps
test_cap_at_depth_taper
None test_query.test_cap_at_depth_taper()
@req REQ-DDB-QUERY-002
Checks
assert _cap_at_depth(8, 1) == 8assert _cap_at_depth(8, 2) == 4assert _cap_at_depth(8, 4) == 1assert _cap_at_depth(8, 12) == 1assert _cap_at_depth(1, 3) == 1
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | catalog | |
| REQ-DDB-QUERY-002 | tag | test_cap_at_depth_taper → _cap_at_depth |
Source · 8 lines
def test_cap_at_depth_taper() -> None:
assert _cap_at_depth(8, 1) == 8
assert _cap_at_depth(8, 2) == 4
assert _cap_at_depth(8, 4) == 1
assert _cap_at_depth(8, 12) == 1
assert _cap_at_depth(1, 3) == 1
Activity · 5 steps
test_chain_trace_backward_reaches_writer
None test_query.test_chain_trace_backward_reaches_writer(Path rich_db)
Backward from the reader recovers the writer across the key seam.
Checks
assert "sensor_poll" in {n.name for n in chain.nodes}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_chain_trace_backward_reaches_writer → chain_trace → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_chain_trace_backward_reaches_writer → chain_trace → connect |
| REQ-DDB-QUERY-002 | measured | test_chain_trace_backward_reaches_writer → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_chain_trace_backward_reaches_writer → chain_trace → function_candidates |
| REQ-DDB-QUERY-005 | measured | test_chain_trace_backward_reaches_writer → chain_trace → _make_node |
| REQ-DDB-QUERY-010 | measured | test_chain_trace_backward_reaches_writer → chain_trace → function_candidates |
Source · 6 lines
def test_chain_trace_backward_reaches_writer(rich_db: Path) -> None:
"""Backward from the reader recovers the writer across the key seam."""
chain = q.chain_trace(rich_db, "telemetry_report", direction="backward", max_depth=3)
assert "sensor_poll" in {n.name for n in chain.nodes}
Activity · 2 steps
test_chain_trace_crosses_thread_key_hop
None test_query.test_chain_trace_crosses_thread_key_hop(Path tmp_path)
A shared-key hop annotated crosses_thread=1 / to_thread_id surfaces on the Hop with the reader thread's NAME and its dispatch_mode.
Checks
assert len(key_hops) == 1assert (hop.from_name, hop.to_name) == ("producer", "consumer")assert hop.crosses_thread is Trueassert hop.dispatch_mode == "queued"assert hop.to_thread == "consumer_thread"assert d_writer is not Noneassert write.crosses_thread is Trueassert write.to_thread == "consumer_thread"assert [t.name for t in roster.threads] == ["consumer_thread"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_chain_trace_crosses_thread_key_hop → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_chain_trace_crosses_thread_key_hop → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | inferred | test_chain_trace_crosses_thread_key_hop → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_chain_trace_crosses_thread_key_hop → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_chain_trace_crosses_thread_key_hop → thread_roster |
| REQ-DDB-QUERY-002 | measured | test_chain_trace_crosses_thread_key_hop → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_chain_trace_crosses_thread_key_hop → thread_roster → table_exists |
| REQ-DDB-QUERY-004 | measured | test_chain_trace_crosses_thread_key_hop → function_dossier |
| REQ-DDB-QUERY-005 | measured | test_chain_trace_crosses_thread_key_hop → chain_trace → _make_node |
| REQ-DDB-QUERY-006 | measured | test_chain_trace_crosses_thread_key_hop → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_chain_trace_crosses_thread_key_hop → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_chain_trace_crosses_thread_key_hop → function_dossier |
| REQ-DDB-QUERY-011 | measured | test_chain_trace_crosses_thread_key_hop → thread_roster |
| REQ-DDB-QUERY-012 | measured | test_chain_trace_crosses_thread_key_hop → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_chain_trace_crosses_thread_key_hop → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_chain_trace_crosses_thread_key_hop → function_dossier → _dossier_conn → locks_held_for_rowids |
Source · 61 lines
def test_chain_trace_crosses_thread_key_hop(tmp_path: Path) -> None:
"""A shared-key hop annotated crosses_thread=1 / to_thread_id surfaces on
the Hop with the reader thread's NAME and its dispatch_mode."""
db = _hand_db(tmp_path, [(1, "producer"), (2, "consumer")])
conn = sqlite3.connect(str(db))
conn.execute(
"""
CREATE TABLE threads (
id INTEGER PRIMARY KEY, name TEXT, entry_memberdef_rowid INTEGER,
kind TEXT, source TEXT, confidence TEXT
)
""",
)
conn.execute(
"INSERT INTO threads (id, name, entry_memberdef_rowid, kind, source, "
"confidence) VALUES (7, 'consumer_thread', 2, 'task', 'ast_spawn', 'medium')",
)
conn.execute(
"""
CREATE TABLE shared_key_edges (
writer_rowid INTEGER, reader_rowid INTEGER, key_name TEXT,
edge_kind TEXT, declared INTEGER, source TEXT, confidence TEXT,
dispatch_mode TEXT, edge_triggered INTEGER, crosses_thread INTEGER,
to_thread_id INTEGER
)
""",
)
conn.execute(
"INSERT INTO shared_key_edges (writer_rowid, reader_rowid, key_name, "
"edge_kind, declared, source, confidence, dispatch_mode, edge_triggered, "
"crosses_thread, to_thread_id) VALUES "
"(1, 2, 'msg_queue', 'event', 0, 'shared_key_inferred', 'medium', "
"'queued', NULL, 1, 7)",
)
conn.commit()
conn.close()
chain = q.chain_trace(db, "producer", max_depth=3)
key_hops = [h for h in chain.hops if h.edge_class == "key"]
assert len(key_hops) == 1
hop = key_hops[0]
assert (hop.from_name, hop.to_name) == ("producer", "consumer")
assert hop.crosses_thread is True
assert hop.dispatch_mode == "queued"
assert hop.to_thread == "consumer_thread"
# And the dossier surfaces the same hop's thread membership on the reader.
d_writer = q.function_dossier(db, "producer")
assert d_writer is not None
write = d_writer.writes[0]
assert write.crosses_thread is True
assert write.to_thread == "consumer_thread"
# thread APIs see the declared thread + its (spawn-entry) membership is empty
# here (no thread_membership table), so thread_of is empty but roster lists it.
roster = q.thread_roster(db)
assert [t.name for t in roster.threads] == ["consumer_thread"]
# ─── unit: lookup_class (the fixture is C — a compound DB is hand-built) ─────
Activity · 23 steps
test_chain_trace_cycle_bounded_by_path
None test_query.test_chain_trace_cycle_bounded_by_path(Path tmp_path)
A mutually-recursive pair (a→b→a) terminates: both nodes appear once, both hops are recorded, and the back-edge does not recurse forever.
Checks
assert {n.name for n in chain.nodes} == {"a", "b"}assert {(h.from_name, h.to_name) for h in chain.hops} == {("a", "b"), ("b", "a")}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_chain_trace_cycle_bounded_by_path → chain_trace → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_chain_trace_cycle_bounded_by_path → chain_trace → connect |
| REQ-DDB-QUERY-002 | measured | test_chain_trace_cycle_bounded_by_path → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_chain_trace_cycle_bounded_by_path → chain_trace → function_candidates |
| REQ-DDB-QUERY-005 | measured | test_chain_trace_cycle_bounded_by_path → chain_trace → _make_node |
| REQ-DDB-QUERY-010 | measured | test_chain_trace_cycle_bounded_by_path → chain_trace → function_candidates |
Source · 13 lines
def test_chain_trace_cycle_bounded_by_path(tmp_path: Path) -> None:
"""A mutually-recursive pair (a→b→a) terminates: both nodes appear once,
both hops are recorded, and the back-edge does not recurse forever."""
db = _hand_db(
tmp_path,
[(1, "a"), (2, "b")],
call_edges=[(1, 2), (2, 1)],
)
chain = q.chain_trace(db, "a", max_depth=10)
assert {n.name for n in chain.nodes} == {"a", "b"}
assert {(h.from_name, h.to_name) for h in chain.hops} == {("a", "b"), ("b", "a")}
Activity · 4 steps
test_chain_trace_depth_cap
None test_query.test_chain_trace_depth_cap(Path tmp_path)
A linear chain a→b→c→d→e stops at max_depth=2 (nodes at depth 0,1,2).
Checks
assert set(by_name) == {"a", "b", "c"}assert by_name == {"a": 0, "b": 1, "c": 2}assert "d" not in by_name
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_chain_trace_depth_cap → chain_trace → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_chain_trace_depth_cap → chain_trace → connect |
| REQ-DDB-QUERY-002 | measured | test_chain_trace_depth_cap → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_chain_trace_depth_cap → chain_trace → function_candidates |
| REQ-DDB-QUERY-005 | measured | test_chain_trace_depth_cap → chain_trace → _make_node |
| REQ-DDB-QUERY-010 | measured | test_chain_trace_depth_cap → chain_trace → function_candidates |
Source · 14 lines
def test_chain_trace_depth_cap(tmp_path: Path) -> None:
"""A linear chain a→b→c→d→e stops at max_depth=2 (nodes at depth 0,1,2)."""
db = _hand_db(
tmp_path,
[(1, "a"), (2, "b"), (3, "c"), (4, "d"), (5, "e")],
call_edges=[(1, 2), (2, 3), (3, 4), (4, 5)],
)
chain = q.chain_trace(db, "a", max_depth=2)
by_name = {n.name: n.depth for n in chain.nodes}
assert set(by_name) == {"a", "b", "c"}
assert by_name == {"a": 0, "b": 1, "c": 2}
assert "d" not in by_name
Activity · 6 steps
test_chain_trace_direction_aliases_and_rejects_unknown
None test_query.test_chain_trace_direction_aliases_and_rejects_unknown(Path rich_db)
Checks
assert "sensor_poll" in {n.name for n in backward.nodes}assert chain.direction == "backward", f"{alias!r} must normalize, not echo"assert {n.name for n in chain.nodes} == {n.name for n in backward.nodes}assert chain.direction == "forward"assert {n.name for n in chain.nodes} == {n.name for n in forward.nodes}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_chain_trace_direction_aliases_and_rejects_unknown → chain_trace → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_chain_trace_direction_aliases_and_rejects_unknown → chain_trace → connect |
| REQ-DDB-QUERY-002 | measured | test_chain_trace_direction_aliases_and_rejects_unknown → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_chain_trace_direction_aliases_and_rejects_unknown → chain_trace → function_candidates |
| REQ-DDB-QUERY-005 | measured | test_chain_trace_direction_aliases_and_rejects_unknown → chain_trace → _make_node |
| REQ-DDB-QUERY-010 | measured | test_chain_trace_direction_aliases_and_rejects_unknown → chain_trace → function_candidates |
Source · 31 lines
def test_chain_trace_direction_aliases_and_rejects_unknown(rich_db: Path) -> None:
"""#44: `forward = direction != "backward"` failed OPEN — only the exact
lowercase "backward" traced backward, so 'upstream', 'backwards', 'BACKWARD'
and every typo silently produced a FORWARD trace while the Chain echoed the
caller's own word back, labelling the result with the direction that was
asked for and carrying the opposite data. On a causal tool that is the one
wrong answer a consumer cannot detect.
Aliases now resolve, and an unknown word is a correctable ERROR, never a
silent inversion. The echoed direction is the NORMALIZED one."""
backward = q.chain_trace(rich_db, "telemetry_report", direction="backward", max_depth=3)
assert "sensor_poll" in {n.name for n in backward.nodes}
# every backward alias/casing gives the SAME trace, labelled canonically
for alias in ("backwards", "upstream", "BACKWARD", " Backward "):
chain = q.chain_trace(rich_db, "telemetry_report", direction=alias, max_depth=3)
assert chain.direction == "backward", f"{alias!r} must normalize, not echo"
assert {n.name for n in chain.nodes} == {n.name for n in backward.nodes}
forward = q.chain_trace(rich_db, "sensor_poll", direction="forward", max_depth=3)
for alias in ("forwards", "downstream", "FORWARD"):
chain = q.chain_trace(rich_db, "sensor_poll", direction=alias, max_depth=3)
assert chain.direction == "forward"
assert {n.name for n in chain.nodes} == {n.name for n in forward.nodes}
# the old bug: an unknown word used to return a forward trace mislabelled
for bogus in ("sideways", "up", ""):
with pytest.raises(ValueError, match="unknown direction"):
q.chain_trace(rich_db, "sensor_poll", direction=bogus)
Activity · 14 steps
test_chain_trace_overloaded_seed_surfaces_candidates
None test_query.test_chain_trace_overloaded_seed_surfaces_candidates(Path tmp_path)
An overloaded seed traces from the definition-preferring pick but lists the alternatives, so a bare ambiguous seed never silently traces the wrong function. (No edge tables here: the trace is empty, but the seed-ambiguity signal must still fire.)
Checks
assert chain.seed == "publish"assert {c.signature for c in chain.candidates} == {"bool A::publish", "bool B::publish"}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_chain_trace_overloaded_seed_surfaces_candidates → chain_trace → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_chain_trace_overloaded_seed_surfaces_candidates → chain_trace → connect |
| REQ-DDB-QUERY-002 | measured | test_chain_trace_overloaded_seed_surfaces_candidates → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_chain_trace_overloaded_seed_surfaces_candidates → chain_trace → function_candidates |
| REQ-DDB-QUERY-005 | measured | test_chain_trace_overloaded_seed_surfaces_candidates → chain_trace → _make_node |
| REQ-DDB-QUERY-010 | measured | test_chain_trace_overloaded_seed_surfaces_candidates → chain_trace → function_candidates |
Source · 17 lines
def test_chain_trace_overloaded_seed_surfaces_candidates(tmp_path: Path) -> None:
"""An overloaded seed traces from the definition-preferring pick but lists
the alternatives, so a bare ambiguous seed never silently traces the wrong
function. (No edge tables here: the trace is empty, but the seed-ambiguity
signal must still fire.)"""
db = _overload_db(
tmp_path,
[
(30, "publish", "bool A::publish", "src/a.cpp", True),
(31, "publish", "bool B::publish", "src/b.cpp", True),
],
)
chain = q.chain_trace(db, "publish")
assert chain.seed == "publish"
assert {c.signature for c in chain.candidates} == {"bool A::publish", "bool B::publish"}
Activity · 4 steps
test_chain_trace_records_what_the_fanout_taper_dropped
None test_query.test_chain_trace_records_what_the_fanout_taper_dropped(Path tmp_path)
@req REQ-DDB-QUERY-002
Checks
assert root.omitted == callees - capassert len([h for h in chain.hops if h.from_name == "root"]) == capassert root.omitted + cap == calleesassert leaves, "the fixture must reach the callees"assert all(n.omitted == 0 for n in leaves)assert next(n for n in roomy.nodes if n.name == "root").omitted == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_chain_trace_records_what_the_fanout_taper_dropped → chain_trace → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_chain_trace_records_what_the_fanout_taper_dropped → chain_trace → connect |
| REQ-DDB-QUERY-002 | tag | test_chain_trace_records_what_the_fanout_taper_dropped → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_chain_trace_records_what_the_fanout_taper_dropped → chain_trace → function_candidates |
| REQ-DDB-QUERY-005 | measured | test_chain_trace_records_what_the_fanout_taper_dropped → chain_trace → _make_node |
| REQ-DDB-QUERY-010 | measured | test_chain_trace_records_what_the_fanout_taper_dropped → chain_trace → function_candidates |
| REQ-DDB-WIKI-054 | inferred | test_chain_trace_records_what_the_fanout_taper_dropped → all |
Source · 55 lines
def test_chain_trace_records_what_the_fanout_taper_dropped(tmp_path: Path) -> None:
"""#134. The taper halves the neighbour budget per level and floors it at 1 — which is
what stops a deep trace exploding — but it applied that with a bare slice and recorded
NOTHING. A node with 131 callers and a cap of 8 reported 8 and looked exhausted, and
the gap was not derivable from the payload: the dropped neighbours leave no trace in
`nodes` or `hops`, so "is this all of them?" had no answer.
Measured on the public entropic index after the fix: `chain_trace('dispatch',
forward)` drops 21 neighbours across 9 nodes, every one of them previously invisible.
A hand-built fixture rather than `rich_db`, because the shape needed is one node with
more neighbours than the cap — and the assertion is about the ARITHMETIC (shown +
omitted == available), which needs a known total."""
db = tmp_path / "taper.db"
conn = sqlite3.connect(str(db))
callees = 12
cap = 4
rows = ", ".join(
f"({10 + i}, 'function', 'callee_{i:02d}', 'void callee_{i:02d}()')" for i in range(callees)
)
edges = ", ".join(f"(1, {10 + i}, 'ast', 'resolved')" for i in range(callees))
conn.executescript(
"CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, "
"definition TEXT, file_id INTEGER, bodyfile_id INTEGER, bodystart INTEGER, "
"bodyend INTEGER);"
"CREATE TABLE path (rowid INTEGER PRIMARY KEY, type INTEGER, name TEXT);"
"CREATE TABLE call_edges (caller_rowid INTEGER, callee_rowid INTEGER, source TEXT, "
"confidence TEXT);"
"INSERT INTO memberdef (rowid, kind, name, definition) VALUES "
f"(1, 'function', 'root', 'void root()'), {rows};"
f"INSERT INTO call_edges VALUES {edges};"
)
conn.commit()
conn.close()
chain = q.chain_trace(db, "root", direction="forward", max_depth=2, max_neighbors=cap)
root = next(n for n in chain.nodes if n.name == "root")
## The arithmetic is the assertion: what was shown plus what was omitted must equal
## what existed. A test that only checked `omitted > 0` would pass on any wrong number.
assert root.omitted == callees - cap
assert len([h for h in chain.hops if h.from_name == "root"]) == cap
assert root.omitted + cap == callees
## An exhausted node reports 0, and that 0 is a MEASUREMENT — it is what lets a
## consumer conclude a branch really is complete.
leaves = [n for n in chain.nodes if n.name != "root"]
assert leaves, "the fixture must reach the callees"
assert all(n.omitted == 0 for n in leaves)
## And a cap that is not exceeded must not invent a count.
roomy = q.chain_trace(db, "root", direction="forward", max_depth=2, max_neighbors=99)
assert next(n for n in roomy.nodes if n.name == "root").omitted == 0
Activity · 19 steps
test_chain_trace_terminates_at_external_boundary
None test_query.test_chain_trace_terminates_at_external_boundary(Path tmp_path)
A branch stops at an external_boundaries terminus: the terminus node is flagged and its downstream callee is NOT expanded into.
Checks
assert "invoke_cb" in namesassert "beyond" not in names # branch terminated at the boundaryassert term.is_terminus is Trueassert term.termini[0].global_name == "svc_notify_cb"assert term.termini[0].registered_by == "register_cb"assert term.termini[0].kind == "unresolved_callback"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_chain_trace_terminates_at_external_boundary → chain_trace → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_chain_trace_terminates_at_external_boundary → chain_trace → connect |
| REQ-DDB-QUERY-002 | measured | test_chain_trace_terminates_at_external_boundary → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_chain_trace_terminates_at_external_boundary → chain_trace → function_candidates |
| REQ-DDB-QUERY-005 | measured | test_chain_trace_terminates_at_external_boundary → chain_trace → _make_node |
| REQ-DDB-QUERY-010 | measured | test_chain_trace_terminates_at_external_boundary → chain_trace → function_candidates |
Source · 38 lines
def test_chain_trace_terminates_at_external_boundary(tmp_path: Path) -> None:
"""A branch stops at an external_boundaries terminus: the terminus node is
flagged and its downstream callee is NOT expanded into."""
db = _hand_db(
tmp_path,
[(1, "entry"), (2, "invoke_cb"), (3, "beyond"), (4, "register_cb")],
# entry -> invoke_cb (call); invoke_cb -> beyond (would continue).
call_edges=[(1, 2), (2, 3)],
)
conn = sqlite3.connect(str(db))
conn.execute(
"""
CREATE TABLE external_boundaries (
memberdef_rowid INTEGER, global_name TEXT, kind TEXT,
registered_by_rowid INTEGER, registered_param_index INTEGER,
note TEXT, source TEXT, confidence TEXT
)
""",
)
conn.execute(
"INSERT INTO external_boundaries (memberdef_rowid, global_name, kind, "
"registered_by_rowid, confidence) VALUES "
"(2, 'svc_notify_cb', 'unresolved_callback', 4, 'high')",
)
conn.commit()
conn.close()
chain = q.chain_trace(db, "entry", max_depth=6)
names = {n.name for n in chain.nodes}
assert "invoke_cb" in names
assert "beyond" not in names # branch terminated at the boundary
term = next(n for n in chain.nodes if n.name == "invoke_cb")
assert term.is_terminus is True
assert term.termini[0].global_name == "svc_notify_cb"
assert term.termini[0].registered_by == "register_cb"
assert term.termini[0].kind == "unresolved_callback"
Activity · 15 steps
test_chain_trace_unambiguous_seed_has_no_candidates
None test_query.test_chain_trace_unambiguous_seed_has_no_candidates(Path rich_db)
The seed-overload signal must not fire for a uniquely-named seed.
Checks
assert chain.candidates == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_chain_trace_unambiguous_seed_has_no_candidates → chain_trace → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_chain_trace_unambiguous_seed_has_no_candidates → chain_trace → connect |
| REQ-DDB-QUERY-002 | measured | test_chain_trace_unambiguous_seed_has_no_candidates → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_chain_trace_unambiguous_seed_has_no_candidates → chain_trace → function_candidates |
| REQ-DDB-QUERY-005 | measured | test_chain_trace_unambiguous_seed_has_no_candidates → chain_trace → _make_node |
| REQ-DDB-QUERY-010 | measured | test_chain_trace_unambiguous_seed_has_no_candidates → chain_trace → function_candidates |
Source · 9 lines
def test_chain_trace_unambiguous_seed_has_no_candidates(rich_db: Path) -> None:
"""The seed-overload signal must not fire for a uniquely-named seed."""
chain = q.chain_trace(rich_db, "sensor_poll", max_depth=1)
assert chain.candidates == []
# ─── integration: req_trace / threads / search ───────────────────────────────
Activity · 2 steps
test_chain_trace_unknown_seed_is_empty
None test_query.test_chain_trace_unknown_seed_is_empty(Path rich_db)
Checks
assert chain.nodes == []assert chain.hops == []assert chain.candidates == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_chain_trace_unknown_seed_is_empty → chain_trace → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_chain_trace_unknown_seed_is_empty → chain_trace → connect |
| REQ-DDB-QUERY-002 | measured | test_chain_trace_unknown_seed_is_empty → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_chain_trace_unknown_seed_is_empty → chain_trace → function_candidates |
| REQ-DDB-QUERY-005 | inferred | test_chain_trace_unknown_seed_is_empty → chain_trace → _make_node |
| REQ-DDB-QUERY-010 | measured | test_chain_trace_unknown_seed_is_empty → chain_trace → function_candidates |
Source · 7 lines
def test_chain_trace_unknown_seed_is_empty(rich_db: Path) -> None:
chain = q.chain_trace(rich_db, "no_such_function_xyz")
assert chain.nodes == []
assert chain.hops == []
assert chain.candidates == []
Activity · 4 steps
test_collision_free_names_are_unaffected
None test_query.test_collision_free_names_are_unaffected(Path tmp_path)
The direction-of-harm control. An identity rule that over-splits would fragment ordinary nodes, so pin that a name with no collision behaves exactly as before: `_guard_scope` keeps BOTH its callees, one of which is the collided name.
Checks
assert sorted(callees) == ["_classify", "plain"], "an unambiguous caller keeps its fan-out"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_collision_free_names_are_unaffected → callees |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_collision_free_names_are_unaffected → callees → _call_edges → _dataflow_edges → resolve_rowid |
| REQ-DDB-QUERY-009 | measured | test_collision_free_names_are_unaffected → callees → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_collision_free_names_are_unaffected → callees |
Source · 12 lines
def test_collision_free_names_are_unaffected(tmp_path: Path) -> None:
"""The direction-of-harm control. An identity rule that over-splits would
fragment ordinary nodes, so pin that a name with no collision behaves exactly
as before: `_guard_scope` keeps BOTH its callees, one of which is the
collided name."""
db = tmp_path / "collide.db"
_name_collision_db(db)
callees = [c.name for c in q.callees(db, "_guard_scope") if c.edge_class == "call"]
assert sorted(callees) == ["_classify", "plain"], "an unambiguous caller keeps its fan-out"
Activity · 4 steps
test_confidence_and_strength_are_never_mixed_in_one_field
None test_query.test_confidence_and_strength_are_never_mixed_in_one_field(Path rich_db)
A merged row must not put a `key_strength` ('low'/'medium'/'high') in the same field a call row fills with a `call_match` ('exact'/'resolved'/'fuzzy'). Every shared-key row on a C++ codebase and a C/POSIX library carries confidence='medium', so without the split EVERY dataflow neighbour would sit in one JSON list labelled 'medium' beside calls labelled 'exact' — and a consumer filtering `confidence != 'fuzzy'` would admit all of them unconditionally, believing it had filtered.
Checks
assert edge.confidence in CALL_MATCH, edgeassert edge.strength is None, edgeassert edge.strength in KEY_STRENGTH, edgeassert edge.confidence is None, edgeassert seen == {"call", "key"}, "the sweep must actually observe both classes"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_confidence_and_strength_are_never_mixed_in_one_field → callers |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_confidence_and_strength_are_never_mixed_in_one_field → callers → _call_edges → _dataflow_edges → resolve_rowid |
| REQ-DDB-QUERY-009 | measured | test_confidence_and_strength_are_never_mixed_in_one_field → callers → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_confidence_and_strength_are_never_mixed_in_one_field → callers |
Source · 25 lines
def test_confidence_and_strength_are_never_mixed_in_one_field(rich_db: Path) -> None:
"""A merged row must not put a `key_strength` ('low'/'medium'/'high') in the
same field a call row fills with a `call_match` ('exact'/'resolved'/'fuzzy').
Every shared-key row on a C++ codebase and a C/POSIX library carries confidence='medium', so
without the split EVERY dataflow neighbour would sit in one JSON list
labelled 'medium' beside calls labelled 'exact' — and a consumer filtering
`confidence != 'fuzzy'` would admit all of them unconditionally, believing it
had filtered.
Swept over every function in the fixture, not a hand-picked one."""
from clew.vocabulary import CALL_MATCH, KEY_STRENGTH
seen = set()
for name in _all_function_names(rich_db):
for edge in q.callers(rich_db, name) + q.callees(rich_db, name):
seen.add(edge.edge_class)
if edge.edge_class == "call":
assert edge.confidence in CALL_MATCH, edge
assert edge.strength is None, edge
else:
assert edge.strength in KEY_STRENGTH, edge
assert edge.confidence is None, edge
assert seen == {"call", "key"}, "the sweep must actually observe both classes"
Activity · 12 steps
test_dataflow_polarity_is_the_writer_side_of_callers
None test_query.test_dataflow_polarity_is_the_writer_side_of_callers(Path rich_db)
@req REQ-DDB-QUERY-004
Checks
assert upstream == {k.other for k in key_edges(conn, "telemetry_report", as_writer=False)}assert "sensor_poll" in upstreamassert downstream == {k.other for k in key_edges(conn, "sensor_poll", as_writer=True)}assert "telemetry_report" in downstream
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_dataflow_polarity_is_the_writer_side_of_callers → callers |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_dataflow_polarity_is_the_writer_side_of_callers → key_edges → resolve_rowid |
| REQ-DDB-QUERY-004 | tag | test_dataflow_polarity_is_the_writer_side_of_callers → key_edges |
| REQ-DDB-QUERY-009 | measured | test_dataflow_polarity_is_the_writer_side_of_callers → callers → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_dataflow_polarity_is_the_writer_side_of_callers → callers |
Source · 24 lines
def test_dataflow_polarity_is_the_writer_side_of_callers(rich_db: Path) -> None:
"""The direction axis is spelled three ways for the same thing —
`want_callers` / `as_writer` / `forward` — with want_callers=True ⟺
as_writer=False. Inverting it silently answers the OPPOSITE causal question
with no error, so pin both directions against the KeyEdge view they must
mirror."""
import sqlite3 as _sqlite3
from clew.query.symbols import key_edges
conn = _sqlite3.connect(str(rich_db))
try:
# callers(reader) must be the WRITERS whose values it reads.
upstream = {c.name for c in q.callers(rich_db, "telemetry_report") if c.edge_class == "key"}
assert upstream == {k.other for k in key_edges(conn, "telemetry_report", as_writer=False)}
assert "sensor_poll" in upstream
# callees(writer) must be the READERS of what it writes.
downstream = {c.name for c in q.callees(rich_db, "sensor_poll") if c.edge_class == "key"}
assert downstream == {k.other for k in key_edges(conn, "sensor_poll", as_writer=True)}
assert "telemetry_report" in downstream
finally:
conn.close()
Activity · 10 steps
test_decl_def_duality_keeps_its_edges
None test_query.test_decl_def_duality_keeps_its_edges(Path rich_db)
The direction-of-harm pin for gh#26, on the whole-graph fixture. C/C++ decl/def duality is real: doxygen emits a memberdef for a definition AND one per documented header declaration, and a call edge attaches to whichever row the extraction layer saw. An identity rule that split those two rows apart would silently drop half the graph's edges.
Checks
assert len(rowids) == 2, "the decl and the def are ONE function, not two"assert "hw_read_battery_adc" in calleesassert "app_run" in callers
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_decl_def_duality_keeps_its_edges → connect |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_decl_def_duality_keeps_its_edges → identity_rowids |
| REQ-DDB-QUERY-009 | measured | test_decl_def_duality_keeps_its_edges → callers → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_decl_def_duality_keeps_its_edges → identity_rowids |
Source · 27 lines
def test_decl_def_duality_keeps_its_edges(rich_db: Path) -> None:
"""The direction-of-harm pin for gh#26, on the whole-graph fixture. C/C++
decl/def duality is real: doxygen emits a memberdef for a definition AND one
per documented header declaration, and a call edge attaches to whichever row
the extraction layer saw. An identity rule that split those two rows apart
would silently drop half the graph's edges.
`sensor_poll` carries exactly that duality (a definition row in sensor.c and
a declaration row in sensor.h), so both of its rowids must land in ONE
identity and its fan-out must survive intact.
Measured, and the reason the identity key is the QUALIFIED NAME rather than
the whole `definition` signature: comparing whole signatures over-splits 122
names on entropic and 13 on mbedtls, because a declaration and its definition
can differ by a macro attribute or an inline/static qualifier."""
from clew.query._common import connect, identity_rowids
with connect(rich_db) as conn:
rowids = identity_rowids(conn, "sensor_poll")
assert len(rowids) == 2, "the decl and the def are ONE function, not two"
callees = {c.name for c in q.callees(rich_db, "sensor_poll") if c.edge_class == "call"}
assert "hw_read_battery_adc" in callees
callers = {c.name for c in q.callers(rich_db, "sensor_poll") if c.edge_class == "call"}
assert "app_run" in callers
Activity · 8 steps
test_dossier_does_not_double_report_dataflow
None test_query.test_dossier_does_not_double_report_dataflow(Path rich_db)
dossier keeps `include_dataflow=False` on purpose: it ALREADY composes writes/reads separately, so merging there would report every dataflow edge twice in one payload in two different shapes (CallEdge.name vs KeyEdge.other). Pins that the split shape stayed split.
Checks
assert d is not Noneassert all(c.edge_class == "call" for c in d.callers + d.callees)assert "telemetry_report" not in {c.name for c in d.callees}assert hits, "the seam must still be reported, under writes"assert len({w.source for w in hits}) == len(hits)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | inferred | test_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_dossier_does_not_double_report_dataflow → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_dossier_does_not_double_report_dataflow → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_dossier_does_not_double_report_dataflow → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_dossier_does_not_double_report_dataflow → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → locks_held_for_rowids |
| REQ-DDB-WIKI-054 | inferred | test_dossier_does_not_double_report_dataflow → all |
Source · 16 lines
def test_dossier_does_not_double_report_dataflow(rich_db: Path) -> None:
"""dossier keeps `include_dataflow=False` on purpose: it ALREADY composes
writes/reads separately, so merging there would report every dataflow edge
twice in one payload in two different shapes (CallEdge.name vs
KeyEdge.other). Pins that the split shape stayed split."""
d = q.function_dossier(rich_db, "sensor_poll")
assert d is not None
assert all(c.edge_class == "call" for c in d.callers + d.callees)
assert "telemetry_report" not in {c.name for c in d.callees}
hits = [w for w in d.writes if w.other == "telemetry_report"]
assert hits, "the seam must still be reported, under writes"
# One row per provenance layer (#38), and NOT once more from a merged
# callees — the payload must not carry the same edge in two shapes.
assert len({w.source for w in hits}) == len(hits)
Activity · 7 steps
test_dossier_reader_and_requirements
None test_query.test_dossier_reader_and_requirements(Path rich_db)
telemetry_report reads the battery key (other = the writer) and links its own requirement.
Checks
assert d is not Noneassert "sensor_poll" in readsassert any(r.req_id == "REQ-0400" for r in d.requirements)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_dossier_reader_and_requirements → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_dossier_reader_and_requirements → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | inferred | test_dossier_reader_and_requirements → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_dossier_reader_and_requirements → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_dossier_reader_and_requirements → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_dossier_reader_and_requirements → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_dossier_reader_and_requirements → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_dossier_reader_and_requirements → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_dossier_reader_and_requirements → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_dossier_reader_and_requirements → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_dossier_reader_and_requirements → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_dossier_reader_and_requirements → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_dossier_reader_and_requirements → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_dossier_reader_and_requirements → function_dossier → _dossier_conn → locks_held_for_rowids |
Source · 10 lines
def test_dossier_reader_and_requirements(rich_db: Path) -> None:
"""telemetry_report reads the battery key (other = the writer) and links
its own requirement."""
d = q.function_dossier(rich_db, "telemetry_report")
assert d is not None
reads = {r.other for r in d.reads if r.key_name == "DEMOBOT_POWER_BATTERY_MV"}
assert "sensor_poll" in reads
assert any(r.req_id == "REQ-0400" for r in d.requirements)
Activity · 5 steps
test_dossier_unambiguous_has_no_candidates
None test_query.test_dossier_unambiguous_has_no_candidates(Path rich_db)
A uniquely-named function's dossier carries an empty `candidates` — the overload signal must not fire on the common case.
Checks
assert d is not Noneassert d.candidates == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | inferred | test_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_dossier_unambiguous_has_no_candidates → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_dossier_unambiguous_has_no_candidates → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_dossier_unambiguous_has_no_candidates → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_dossier_unambiguous_has_no_candidates → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → locks_held_for_rowids |
Source · 11 lines
def test_dossier_unambiguous_has_no_candidates(rich_db: Path) -> None:
"""A uniquely-named function's dossier carries an empty `candidates` — the
overload signal must not fire on the common case."""
d = q.function_dossier(rich_db, "sensor_poll")
assert d is not None
assert d.candidates == []
# ─── integration: callers / callees ──────────────────────────────────────────
Activity · 3 steps
test_dossier_unknown_function_is_none
None test_query.test_dossier_unknown_function_is_none(Path rich_db)
Checks
assert q.function_dossier(rich_db, "no_such_function_xyz") is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_dossier_unknown_function_is_none → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_dossier_unknown_function_is_none → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | inferred | test_dossier_unknown_function_is_none → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_dossier_unknown_function_is_none → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_dossier_unknown_function_is_none → function_dossier → connect |
| REQ-DDB-QUERY-002 | catalog | test_dossier_unknown_function_is_none → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_dossier_unknown_function_is_none → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_dossier_unknown_function_is_none → function_dossier |
| REQ-DDB-QUERY-006 | inferred | test_dossier_unknown_function_is_none → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_dossier_unknown_function_is_none → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_dossier_unknown_function_is_none → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_dossier_unknown_function_is_none → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_dossier_unknown_function_is_none → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | inferred | test_dossier_unknown_function_is_none → function_dossier → _dossier_conn → locks_held_for_rowids |
Source · 4 lines
def test_dossier_unknown_function_is_none(rich_db: Path) -> None:
assert q.function_dossier(rich_db, "no_such_function_xyz") is None
Activity · 1 steps
test_dossier_writer_identity_and_liveness
None test_query.test_dossier_writer_identity_and_liveness(Path rich_db)
The dossier's identity + liveness/thread/terminus structure for a plain writer. Split from the R1-field assertions below so each test names one thing (and so neither exceeds the complexity standard).
Checks
assert d is not Noneassert d.name == "sensor_poll"assert d.signature == "void sensor_poll(void)"assert d.liveness == "live"assert d.is_terminus is Falseassert d.threads == []assert d.termini == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | inferred | test_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_dossier_writer_identity_and_liveness → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_dossier_writer_identity_and_liveness → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_dossier_writer_identity_and_liveness → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_dossier_writer_identity_and_liveness → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → locks_held_for_rowids |
Source · 14 lines
def test_dossier_writer_identity_and_liveness(rich_db: Path) -> None:
"""The dossier's identity + liveness/thread/terminus structure for a plain
writer. Split from the R1-field assertions below so each test names one
thing (and so neither exceeds the complexity standard)."""
d = q.function_dossier(rich_db, "sensor_poll")
assert d is not None
assert d.name == "sensor_poll"
assert d.signature == "void sensor_poll(void)"
assert d.liveness == "live"
assert d.is_terminus is False
assert d.threads == []
assert d.termini == []
Activity · 8 steps
test_edge_class_is_exactly_the_registered_vocabulary
None test_query.test_edge_class_is_exactly_the_registered_vocabulary(Path rich_db)
Events are NOT a third edge_class — an event edge stays edge_class='key' and is distinguished by edge_kind. A third value would silently break every consumer branching on the two.
Checks
assert observed <= set(EDGE_CLASS.values)assert observed == {"call", "key"}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_edge_class_is_exactly_the_registered_vocabulary → chain_trace → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_edge_class_is_exactly_the_registered_vocabulary → callees |
| REQ-DDB-QUERY-002 | measured | test_edge_class_is_exactly_the_registered_vocabulary → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_edge_class_is_exactly_the_registered_vocabulary → chain_trace → function_candidates |
| REQ-DDB-QUERY-005 | measured | test_edge_class_is_exactly_the_registered_vocabulary → chain_trace → _make_node |
| REQ-DDB-QUERY-009 | measured | test_edge_class_is_exactly_the_registered_vocabulary → callees → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_edge_class_is_exactly_the_registered_vocabulary → callees |
Source · 12 lines
def test_edge_class_is_exactly_the_registered_vocabulary(rich_db: Path) -> None:
"""Events are NOT a third edge_class — an event edge stays edge_class='key'
and is distinguished by edge_kind. A third value would silently break every
consumer branching on the two."""
from clew.vocabulary import EDGE_CLASS
observed = {c.edge_class for n in _all_function_names(rich_db) for c in q.callees(rich_db, n)}
observed |= {h.edge_class for h in q.chain_trace(rich_db, "sensor_poll", max_depth=4).hops}
assert observed <= set(EDGE_CLASS.values)
assert observed == {"call", "key"}
Activity · 5 steps
test_every_direction_word_the_served_text_offers_is_accepted
None test_query.test_every_direction_word_the_served_text_offers_is_accepted(Path rich_db)
1.4.0 GRID: the dossier `direction` description said "'back' for upstream" while the walker refused `back` — 6 of the 14 direction-setting calls in the grid's index arms paid a REFUSED reply and a retry (one mattermost cell then tried `downstream`, the WRONG way, before `upstream`). A word the tool's own text offers must be one the tool accepts.
Checks
assert match, "the dossier `direction` parameter description was not found"assert offered, match.group(1)assert chain.direction in ("forward", "backward"), wordassert back.direction == "backward"assert "sensor_poll" in {n.name for n in back.nodes}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_every_direction_word_the_served_text_offers_is_accepted → chain_trace → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_every_direction_word_the_served_text_offers_is_accepted → chain_trace → connect |
| REQ-DDB-QUERY-002 | measured | test_every_direction_word_the_served_text_offers_is_accepted → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_every_direction_word_the_served_text_offers_is_accepted → chain_trace → function_candidates |
| REQ-DDB-QUERY-005 | measured | test_every_direction_word_the_served_text_offers_is_accepted → chain_trace → _make_node |
| REQ-DDB-QUERY-010 | measured | test_every_direction_word_the_served_text_offers_is_accepted → chain_trace → function_candidates |
Source · 22 lines
def test_every_direction_word_the_served_text_offers_is_accepted(rich_db: Path) -> None:
"""1.4.0 GRID: the dossier `direction` description said "'back' for upstream" while the
walker refused `back` — 6 of the 14 direction-setting calls in the grid's index arms paid a
REFUSED reply and a retry (one mattermost cell then tried `downstream`, the WRONG way, before
`upstream`). A word the tool's own text offers must be one the tool accepts."""
import re
from clew.mcp_server import tools_query
source = Path(tools_query.__file__).read_text(encoding="utf-8")
match = re.search(r"Field\(description=\"([^\"]*for downstream[^\"]*)\"\)", source)
assert match, "the dossier `direction` parameter description was not found"
offered = re.findall(r"'([a-z]+)'", match.group(1))
assert offered, match.group(1)
for word in offered:
chain = q.chain_trace(rich_db, "telemetry_report", direction=word, max_depth=2)
assert chain.direction in ("forward", "backward"), word
back = q.chain_trace(rich_db, "telemetry_report", direction="back", max_depth=3)
assert back.direction == "backward"
assert "sensor_poll" in {n.name for n in back.nodes}
Activity · 13 steps
test_genuine_recursion_survives_the_identity_split
None test_query.test_genuine_recursion_survives_the_identity_split(Path tmp_path)
The control for the test above, and the reason it cannot simply drop every self-edge on an ambiguous name: `scope._classify` really does recurse. A fix that suppressed self-edges whenever `candidates` was non-empty would pass the gh#26 test and DELETE a true fact, so the split must be by identity rather than by ambiguity.
Checks
assert "_guard_scope" not in {c.name for c in scope_callers}assert identity_rowids(conn, "_classify") == [1], "bare name resolves to ONE identity"assert rows == [(3, 3)], "scope._classify's recursion is untouched in the db"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_genuine_recursion_survives_the_identity_split → connect |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_genuine_recursion_survives_the_identity_split → identity_rowids |
| REQ-DDB-QUERY-009 | measured | test_genuine_recursion_survives_the_identity_split → callers → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_genuine_recursion_survives_the_identity_split → identity_rowids |
Source · 25 lines
def test_genuine_recursion_survives_the_identity_split(tmp_path: Path) -> None:
"""The control for the test above, and the reason it cannot simply drop every
self-edge on an ambiguous name: `scope._classify` really does recurse. A fix
that suppressed self-edges whenever `candidates` was non-empty would pass the
gh#26 test and DELETE a true fact, so the split must be by identity rather
than by ambiguity."""
db = tmp_path / "collide.db"
_name_collision_db(db)
# Resolution by bare name still picks guidance; ask about scope's by rowid.
scope_callers = q.callers(db, "_classify")
assert "_guard_scope" not in {c.name for c in scope_callers}
# The genuine self-edge is still IN the database and still attributed to the
# function that owns it -- verified through the identity resolver directly.
from clew.query._common import connect, identity_rowids
with connect(db) as conn:
assert identity_rowids(conn, "_classify") == [1], "bare name resolves to ONE identity"
rows = conn.execute(
"SELECT caller_rowid, callee_rowid FROM call_edges WHERE caller_rowid = callee_rowid"
).fetchall()
assert rows == [(3, 3)], "scope._classify's recursion is untouched in the db"
Activity · 9 steps
test_hop_confidence_and_strength_are_split_too
None test_query.test_hop_confidence_and_strength_are_split_too(Path rich_db)
The same collision existed on Hop and was LIVE: a key hop wrote a key_strength into the field a call hop fills with a call_match.
Checks
assert hop.confidence in CALL_MATCH and hop.strength is None, hopassert hop.strength in KEY_STRENGTH and hop.confidence is None, hopassert classes == {"call", "key"}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_hop_confidence_and_strength_are_split_too → chain_trace → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_hop_confidence_and_strength_are_split_too → chain_trace → connect |
| REQ-DDB-QUERY-002 | measured | test_hop_confidence_and_strength_are_split_too → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_hop_confidence_and_strength_are_split_too → chain_trace → function_candidates |
| REQ-DDB-QUERY-005 | measured | test_hop_confidence_and_strength_are_split_too → chain_trace → _make_node |
| REQ-DDB-QUERY-010 | measured | test_hop_confidence_and_strength_are_split_too → chain_trace → function_candidates |
Source · 16 lines
def test_hop_confidence_and_strength_are_split_too(rich_db: Path) -> None:
"""The same collision existed on Hop and was LIVE: a key hop wrote a
key_strength into the field a call hop fills with a call_match."""
from clew.vocabulary import CALL_MATCH, KEY_STRENGTH
chain = q.chain_trace(rich_db, "sensor_poll", max_depth=3)
classes = set()
for hop in chain.hops:
classes.add(hop.edge_class)
if hop.edge_class == "call":
assert hop.confidence in CALL_MATCH and hop.strength is None, hop
else:
assert hop.strength in KEY_STRENGTH and hop.confidence is None, hop
assert classes == {"call", "key"}
Activity · 10 steps
test_list_files_inventory
None test_query.test_list_files_inventory(Path rich_db)
Every real source file is listed with a symbol count; doxygen's synthetic bracket rows ('[STL]', '[generated]') are not files and must not appear.
Checks
assert paths == sorted(paths)assert not [p for p in paths if p.startswith("[")], "synthetic path rows must be excluded"assert any(p.endswith("sensor_driver.c") for p in paths)assert any(f.symbol_count > 0 for f in files)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_list_files_inventory → list_files |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_list_files_inventory → list_files → table_exists |
Source · 12 lines
def test_list_files_inventory(rich_db: Path) -> None:
"""Every real source file is listed with a symbol count; doxygen's
synthetic bracket rows ('[STL]', '[generated]') are not files and must not
appear."""
files = q.list_files(rich_db)
paths = [f.path for f in files]
assert paths == sorted(paths)
assert not [p for p in paths if p.startswith("[")], "synthetic path rows must be excluded"
assert any(p.endswith("sensor_driver.c") for p in paths)
assert any(f.symbol_count > 0 for f in files)
Activity · 6 steps
test_list_files_pattern_is_a_glob_over_path_or_filename
None test_query.test_list_files_pattern_is_a_glob_over_path_or_filename(Path rich_db)
`pattern` is a * glob matched against the repo-relative path OR the bare filename, so a nested file is reachable without naming its directory.
Checks
assert only_c, "the fixture tree is C — '*.c' cannot be empty"assert all(f.path.endswith(".c") for f in only_c)assert len(only_c) < len(files)assert [f.path for f in q.list_files(rich_db, "sensor_driver.*")]assert q.list_files(rich_db, "*.no_such_extension") == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_list_files_pattern_is_a_glob_over_path_or_filename → list_files |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_list_files_pattern_is_a_glob_over_path_or_filename → list_files → table_exists |
| REQ-DDB-WIKI-054 | inferred | test_list_files_pattern_is_a_glob_over_path_or_filename → all |
Source · 14 lines
def test_list_files_pattern_is_a_glob_over_path_or_filename(rich_db: Path) -> None:
"""`pattern` is a * glob matched against the repo-relative path OR the bare
filename, so a nested file is reachable without naming its directory."""
files = q.list_files(rich_db)
only_c = q.list_files(rich_db, "*.c")
assert only_c, "the fixture tree is C — '*.c' cannot be empty"
assert all(f.path.endswith(".c") for f in only_c)
assert len(only_c) < len(files)
# Bare-filename globs work even though the paths are nested.
assert [f.path for f in q.list_files(rich_db, "sensor_driver.*")]
assert q.list_files(rich_db, "*.no_such_extension") == []
Activity · 7 steps
test_lookup_class_lists_candidates_when_the_name_is_ambiguous
None test_query.test_lookup_class_lists_candidates_when_the_name_is_ambiguous(Path tmp_path)
gh#315. `lookup_class` fetches every substring match and returns the single best-ranked one, silently discarding the rest — so a caller asking for `PolygonWidget` in a repo that also has `RoundedPolygonWidget` is told about one class and never learns the other exists. Every other disambiguating surface (`resolve_symbol` / `dossier` / `chain_trace` / `source`) reports its rejects; this one did not.
Checks
assert entry is not Noneassert entry.name == "demo::shape::PolygonWidget"assert "demo::shape::PolygonWidget" in namesassert "demo::shape::RoundedPolygonWidget" in namesassert "std::PolygonWidget_traits" in namesassert [c.kind for c in entry.candidates] == ["class"] * len(names)assert selected is not Noneassert selected.name == candidate.qualified
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_lookup_class_lists_candidates_when_the_name_is_ambiguous → lookup_class |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_lookup_class_lists_candidates_when_the_name_is_ambiguous → lookup_class → table_exists |
| REQ-DDB-QUERY-010 | measured | test_lookup_class_lists_candidates_when_the_name_is_ambiguous → lookup_class |
Source · 25 lines
def test_lookup_class_lists_candidates_when_the_name_is_ambiguous(tmp_path: Path) -> None:
"""gh#315. `lookup_class` fetches every substring match and returns the single
best-ranked one, silently discarding the rest — so a caller asking for
`PolygonWidget` in a repo that also has `RoundedPolygonWidget` is told about one
class and never learns the other exists. Every other disambiguating surface
(`resolve_symbol` / `dossier` / `chain_trace` / `source`) reports its rejects;
this one did not."""
db = _class_db(tmp_path)
entry = q.lookup_class(db, "PolygonWidget")
assert entry is not None
assert entry.name == "demo::shape::PolygonWidget"
names = [c.qualified for c in entry.candidates]
assert "demo::shape::PolygonWidget" in names
assert "demo::shape::RoundedPolygonWidget" in names
assert "std::PolygonWidget_traits" in names
assert [c.kind for c in entry.candidates] == ["class"] * len(names)
# REQ-DDB-QUERY-010: the selector must be USABLE, not merely reported — every
# published string has to round-trip back through this same accessor and land on
# that exact compound. A candidate list nobody can act on is gh#37's defect.
for candidate in entry.candidates:
selected = q.lookup_class(db, candidate.qualified)
assert selected is not None
assert selected.name == candidate.qualified
Activity · 13 steps
test_lookup_class_members_and_hierarchy
None test_query.test_lookup_class_members_and_hierarchy(Path tmp_path)
Members carry a reassembled signature + declaration line; the immediate base and derived compounds come from compoundref.
Checks
assert entry is not Noneassert members["redraw"].signature == "void redraw() noexcept"assert members["redraw"].kind == "function"assert members["redraw"].line == 46assert members["canvas_"].signature == "render::Canvas & canvas_"assert entry.bases == ["demo::shape::IShapeWidget"]assert entry.derived == ["demo::shape::RoundedPolygonWidget"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_lookup_class_members_and_hierarchy → lookup_class |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_lookup_class_members_and_hierarchy → lookup_class → table_exists |
| REQ-DDB-QUERY-010 | measured | test_lookup_class_members_and_hierarchy → lookup_class |
Source · 14 lines
def test_lookup_class_members_and_hierarchy(tmp_path: Path) -> None:
"""Members carry a reassembled signature + declaration line; the immediate
base and derived compounds come from compoundref."""
entry = q.lookup_class(_class_db(tmp_path), "demo::shape::PolygonWidget")
assert entry is not None
members = {m.name: m for m in entry.members}
assert members["redraw"].signature == "void redraw() noexcept"
assert members["redraw"].kind == "function"
assert members["redraw"].line == 46
assert members["canvas_"].signature == "render::Canvas & canvas_"
assert entry.bases == ["demo::shape::IShapeWidget"]
assert entry.derived == ["demo::shape::RoundedPolygonWidget"]
Activity · 9 steps
test_lookup_class_members_carry_their_documentation
None test_query.test_lookup_class_members_carry_their_documentation(Path tmp_path)
gh#16. `_members` selected name/kind/type/argsstring/line and NOTHING ELSE, so a struct's members came back as an index of field names with their documentation dropped — and the `///<` comments on a C or C++ config header are the whole reason that struct is being read. The class view was the only subject kind that discarded documentation: the FUNCTION view has always returned brief, detail and body.
Checks
assert entry is not Noneassert members["redraw"].brief == "Redraws the widget outline."assert members["redraw"].detail == "Recomputation is deferred until the next paint."assert members["canvas_"].brief == ""assert members["canvas_"].detail == ""
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_lookup_class_members_carry_their_documentation → lookup_class |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_lookup_class_members_carry_their_documentation → lookup_class → table_exists |
| REQ-DDB-QUERY-010 | measured | test_lookup_class_members_carry_their_documentation → lookup_class |
Source · 28 lines
def test_lookup_class_members_carry_their_documentation(tmp_path: Path) -> None:
"""gh#16. `_members` selected name/kind/type/argsstring/line and NOTHING ELSE, so a
struct's members came back as an index of field names with their documentation
dropped — and the `///<` comments on a C or C++ config header are the whole reason
that struct is being read. The class view was the only subject kind that discarded
documentation: the FUNCTION view has always returned brief, detail and body.
Sharper than an omission: `search` RANKS members on `briefdescription`
(`member_doc_rows`, same table, same column), so a field was findable by a comment
`dossier` would then refuse to show. Reported by a documentation-review agent that
read the member index, found no documentation to assess, and emitted a false
positive saying the symbol was not in the index.
BOTH columns, not just the brief. doxygen splits a multi-line `///` block at the
first sentence — brief takes the sentence, detail takes the remainder — and in the
reported case the STALE half of the comment was in the remainder. A brief-only fix
would not have caught the defect the issue was filed over."""
entry = q.lookup_class(_class_db(tmp_path), "demo::shape::PolygonWidget")
assert entry is not None
members = {m.name: m for m in entry.members}
assert members["redraw"].brief == "Redraws the widget outline."
assert members["redraw"].detail == "Recomputation is deferred until the next paint."
# An undocumented member reports empty strings, not None: the field is always
# present so a consumer can tell "no comment" from "this index cannot say".
assert members["canvas_"].brief == ""
assert members["canvas_"].detail == ""
Activity · 7 steps
test_lookup_class_members_degrade_when_the_description_columns_are_absent
None test_query.test_lookup_class_members_degrade_when_the_description_columns_are_absent(Path tmp_path)
The graceful-degradation contract `_members` already honours for a missing `member` table has to extend to the new columns. This repo's own minimal test indexes omit the description columns — they are part of doxygen's schema, not of every database — so selecting them unguarded would turn a thin index from answering thinly into raising OperationalError.
Checks
assert entry is not Noneassert [m.name for m in entry.members] == ["extent"]assert entry.members[0].signature == "int extent"assert entry.members[0].brief == ""assert entry.members[0].detail == ""
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_lookup_class_members_degrade_when_the_description_columns_are_absent → lookup_class |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_lookup_class_members_degrade_when_the_description_columns_are_absent → lookup_class → table_exists |
| REQ-DDB-QUERY-010 | measured | test_lookup_class_members_degrade_when_the_description_columns_are_absent → lookup_class |
Source · 43 lines
def test_lookup_class_members_degrade_when_the_description_columns_are_absent(
tmp_path: Path,
) -> None:
"""The graceful-degradation contract `_members` already honours for a missing
`member` table has to extend to the new columns. This repo's own minimal test
indexes omit the description columns — they are part of doxygen's schema, not of
every database — so selecting them unguarded would turn a thin index from
answering thinly into raising OperationalError.
A thin index still returns its members; their documentation is empty."""
db = tmp_path / "thin.db"
conn = sqlite3.connect(str(db))
conn.executescript(
"""
CREATE TABLE path (rowid INTEGER PRIMARY KEY, type INTEGER, name TEXT);
CREATE TABLE compounddef (
rowid INTEGER PRIMARY KEY, name TEXT, kind TEXT, file_id INTEGER,
line INTEGER, briefdescription TEXT, detaileddescription TEXT
);
CREATE TABLE memberdef (
rowid INTEGER PRIMARY KEY, name TEXT, kind TEXT, type TEXT,
argsstring TEXT, line INTEGER
);
CREATE TABLE member (scope_rowid INTEGER, memberdef_rowid INTEGER);
INSERT INTO path (rowid, type, name) VALUES (2, 1, 'src/demo/shape/Thin.hpp');
INSERT INTO compounddef (rowid, name, kind, file_id, line, briefdescription)
VALUES (11, 'demo::shape::ThinWidget', 'struct', 2, 4, 'no doc columns here');
INSERT INTO memberdef (rowid, name, kind, type, argsstring, line) VALUES
(20, 'extent', 'variable', 'int', '', 6);
INSERT INTO member (scope_rowid, memberdef_rowid) VALUES (11, 20);
""",
)
conn.commit()
conn.close()
entry = q.lookup_class(db, "ThinWidget")
assert entry is not None
assert [m.name for m in entry.members] == ["extent"]
assert entry.members[0].signature == "int extent"
assert entry.members[0].brief == ""
assert entry.members[0].detail == ""
Activity · 11 steps
test_lookup_class_prefers_project_over_std
None test_query.test_lookup_class_prefers_project_over_std(Path tmp_path)
compounddef is POLLUTED with std:: compounds harvested from system headers (registered against the synthetic '[STL]' path). A project class must always outrank them, and a qualified-tail exact match must outrank an incidental substring.
Checks
assert entry is not Noneassert entry.name == "demo::shape::PolygonWidget"assert entry.kind == "class"assert entry.file == "src/demo/shape/PolygonWidget.hpp"assert entry.line == 38assert entry.brief == "Recomputes the cached outline."
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_lookup_class_prefers_project_over_std → lookup_class |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_lookup_class_prefers_project_over_std → lookup_class → table_exists |
| REQ-DDB-QUERY-010 | measured | test_lookup_class_prefers_project_over_std → lookup_class |
Source · 15 lines
def test_lookup_class_prefers_project_over_std(tmp_path: Path) -> None:
"""compounddef is POLLUTED with std:: compounds harvested from system
headers (registered against the synthetic '[STL]' path). A project class
must always outrank them, and a qualified-tail exact match must outrank an
incidental substring."""
db = _class_db(tmp_path)
entry = q.lookup_class(db, "PolygonWidget")
assert entry is not None
assert entry.name == "demo::shape::PolygonWidget"
assert entry.kind == "class"
assert entry.file == "src/demo/shape/PolygonWidget.hpp"
assert entry.line == 38
assert entry.brief == "Recomputes the cached outline."
Activity · 8 steps
test_lookup_class_std_is_still_reachable
None test_query.test_lookup_class_std_is_still_reachable(Path tmp_path)
Demotion is not exclusion — asking for the std:: name still finds it.
Checks
assert entry is not Noneassert entry.name == "std::PolygonWidget_traits"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_lookup_class_std_is_still_reachable → lookup_class |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_lookup_class_std_is_still_reachable → lookup_class → table_exists |
| REQ-DDB-QUERY-010 | measured | test_lookup_class_std_is_still_reachable → lookup_class |
Source · 7 lines
def test_lookup_class_std_is_still_reachable(tmp_path: Path) -> None:
"""Demotion is not exclusion — asking for the std:: name still finds it."""
entry = q.lookup_class(_class_db(tmp_path), "std::PolygonWidget_traits")
assert entry is not None
assert entry.name == "std::PolygonWidget_traits"
Activity · 3 steps
test_lookup_class_unambiguous_name_has_no_candidates
None test_query.test_lookup_class_unambiguous_name_has_no_candidates(Path tmp_path)
The CONTROL for the test above: `candidates` must stay empty on the common path, exactly as it does for functions. A list that is always populated disambiguates nothing and is pure payload.
Checks
assert entry is not Noneassert entry.candidates == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_lookup_class_unambiguous_name_has_no_candidates → lookup_class |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_lookup_class_unambiguous_name_has_no_candidates → lookup_class → table_exists |
| REQ-DDB-QUERY-010 | measured | test_lookup_class_unambiguous_name_has_no_candidates → lookup_class |
Source · 9 lines
def test_lookup_class_unambiguous_name_has_no_candidates(tmp_path: Path) -> None:
"""The CONTROL for the test above: `candidates` must stay empty on the common
path, exactly as it does for functions. A list that is always populated
disambiguates nothing and is pure payload."""
entry = q.lookup_class(_class_db(tmp_path), "IShapeWidget")
assert entry is not None
assert entry.candidates == []
Activity · 3 steps
test_lookup_class_unknown_is_none
None test_query.test_lookup_class_unknown_is_none(Path tmp_path)
Checks
assert q.lookup_class(_class_db(tmp_path), "NoSuchClass") is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_lookup_class_unknown_is_none → lookup_class |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_lookup_class_unknown_is_none → lookup_class → table_exists |
| REQ-DDB-QUERY-010 | measured | test_lookup_class_unknown_is_none → lookup_class |
Source · 4 lines
def test_lookup_class_unknown_is_none(tmp_path: Path) -> None:
assert q.lookup_class(_class_db(tmp_path), "NoSuchClass") is None
Activity · 1 steps
test_merged_neighbours_are_a_superset_of_chain_trace_depth_one
None test_query.test_merged_neighbours_are_a_superset_of_chain_trace_depth_one(Path rich_db)
chain_trace filters `confidence='fuzzy'` because it EXPANDS each hop and one wrong name multiplies into a wrong subtree; the flat neighbour list keeps fuzzy rows so a caller can weigh them (26.1% of a C++ codebase's call edges are fuzzy, and the tool description tells the model to read that field). The divergence is contract, so pin its direction: the flat list can only ever be a SUPERSET, and the difference is fuzzy-only.
Checks
assert depth1 <= merged, (name, want_callers, depth1 - merged)assert checked > len(nodes), f"only {checked} non-empty pairs over {len(nodes)} nodes"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | catalog | |
| REQ-DDB-QUERY-002 | measured | test_merged_neighbours_are_a_superset_of_chain_trace_depth_one → _neighbors |
| REQ-DDB-QUERY-003 | measured | test_merged_neighbours_are_a_superset_of_chain_trace_depth_one → _call_edges → _dataflow_edges → resolve_rowid |
| REQ-DDB-QUERY-009 | measured | test_merged_neighbours_are_a_superset_of_chain_trace_depth_one → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_merged_neighbours_are_a_superset_of_chain_trace_depth_one → _call_edges → _dataflow_edges → resolve_rowid |
Source · 34 lines
def test_merged_neighbours_are_a_superset_of_chain_trace_depth_one(rich_db: Path) -> None:
"""chain_trace filters `confidence='fuzzy'` because it EXPANDS each hop and
one wrong name multiplies into a wrong subtree; the flat neighbour list keeps
fuzzy rows so a caller can weigh them (26.1% of a C++ codebase's call edges are fuzzy,
and the tool description tells the model to read that field). The divergence
is contract, so pin its direction: the flat list can only ever be a
SUPERSET, and the difference is fuzzy-only."""
import sqlite3 as _sqlite3
from clew.query.symbols import _call_edges
from clew.query.traversal import _neighbors
conn = _sqlite3.connect(str(rich_db))
try:
nodes = _all_function_names(rich_db)
checked = 0
for name in nodes:
for want_callers in (True, False):
merged = {
(e.name, e.edge_class)
for e in _call_edges(conn, name, want_callers, include_dataflow=True)
}
depth1 = {
(n, h.edge_class) for n, h in _neighbors(conn, name, forward=not want_callers)
}
assert depth1 <= merged, (name, want_callers, depth1 - merged)
checked += 1 if depth1 else 0
# Anti-vacuity: a sweep in which every depth1 set was empty would pass
# `<=` trivially. Demand that most of the graph actually had neighbours.
assert checked > len(nodes), f"only {checked} non-empty pairs over {len(nodes)} nodes"
finally:
conn.close()
Activity · 14 steps
test_merged_order_is_identical_to_the_traversal_neighbour_order
None test_query.test_merged_order_is_identical_to_the_traversal_neighbour_order(Path rich_db)
The merged list and chain_trace's neighbour list sort by the SAME key tuple, so the two surfaces are provably consistent rather than merely overlapping. A shared constant would not prove it — compare the emitted order for a name that has both a call and a key neighbour.
Checks
assert {e.edge_class for e in merged} == {"call", "key"}, "fixture must exercise both"assert merged_keys == sorted(merged_keys)assert neigh_keys == sorted(neigh_keys)assert [k for k in dict.fromkeys(merged_keys) if k in shared] == sorted(shared)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | catalog | |
| REQ-DDB-QUERY-002 | measured | test_merged_order_is_identical_to_the_traversal_neighbour_order → _neighbors |
| REQ-DDB-QUERY-003 | measured | test_merged_order_is_identical_to_the_traversal_neighbour_order → _call_edges → _dataflow_edges → resolve_rowid |
| REQ-DDB-QUERY-009 | measured | test_merged_order_is_identical_to_the_traversal_neighbour_order → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_merged_order_is_identical_to_the_traversal_neighbour_order → _call_edges → _dataflow_edges → resolve_rowid |
Source · 28 lines
def test_merged_order_is_identical_to_the_traversal_neighbour_order(rich_db: Path) -> None:
"""The merged list and chain_trace's neighbour list sort by the SAME key
tuple, so the two surfaces are provably consistent rather than merely
overlapping. A shared constant would not prove it — compare the emitted
order for a name that has both a call and a key neighbour."""
import sqlite3 as _sqlite3
from clew.query.symbols import _call_edges
from clew.query.traversal import _neighbors
conn = _sqlite3.connect(str(rich_db))
try:
merged = _call_edges(conn, "sensor_poll", want_callers=False, include_dataflow=True)
assert {e.edge_class for e in merged} == {"call", "key"}, "fixture must exercise both"
neighbours = _neighbors(conn, "sensor_poll", forward=True)
merged_keys = [(e.name, e.edge_class, e.key_name or "") for e in merged]
neigh_keys = [(n, h.edge_class, h.key_name or "") for n, h in neighbours]
# Both surfaces emit in the SAME key order, so a consumer reading one
# after the other never sees the neighbours reshuffled.
assert merged_keys == sorted(merged_keys)
assert neigh_keys == sorted(neigh_keys)
# ...and the shared neighbours appear in the same relative sequence.
shared = set(neigh_keys)
assert [k for k in dict.fromkeys(merged_keys) if k in shared] == sorted(shared)
finally:
conn.close()
Activity · 14 steps
test_multi_source_edge_collapses_to_one_row_per_endpoint
None test_query.test_multi_source_edge_collapses_to_one_row_per_endpoint(Path tmp_path)
Checks
assert [c.name for c in calls] == ["pump", "solo"], "one row per endpoint, name-ordered"assert (pump.source, pump.confidence) == ("doxygen_sqlite", "exact")assert (solo.source, solo.confidence) == ("ast", "resolved")assert [c.name for c in inbound] == ["driver"]assert (inbound[0].source, inbound[0].confidence) == ("doxygen_sqlite", "exact")
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_multi_source_edge_collapses_to_one_row_per_endpoint → callers |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_multi_source_edge_collapses_to_one_row_per_endpoint → callers → _call_edges → _dataflow_edges → resolve_rowid |
| REQ-DDB-QUERY-009 | measured | test_multi_source_edge_collapses_to_one_row_per_endpoint → callers → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_multi_source_edge_collapses_to_one_row_per_endpoint → callers |
Source · 29 lines
def test_multi_source_edge_collapses_to_one_row_per_endpoint(tmp_path: Path) -> None:
"""#38. One logical edge found by two layers must surface ONCE.
This is the test whose absence let the defect ship: the whole existing suite
passed both before and after the fix, because nothing pinned the row COUNT.
Measured impact on clew's own index — callees("_run_pipeline") reported 8
results for four real callees, so every neighbour count was doubled and every
depth/neighbour cap admitted half as many real edges as intended."""
db = tmp_path / "multi.db"
_multi_source_db(db)
calls = [c for c in q.callees(db, "driver") if c.edge_class == "call"]
assert [c.name for c in calls] == ["pump", "solo"], "one row per endpoint, name-ordered"
pump = next(c for c in calls if c.name == "pump")
# STRONGEST evidence wins: doxygen_sqlite/exact beats ast/resolved. `source`
# stays a single vocabulary-registered value rather than becoming a joined
# string.
assert (pump.source, pump.confidence) == ("doxygen_sqlite", "exact")
solo = next(c for c in calls if c.name == "solo")
assert (solo.source, solo.confidence) == ("ast", "resolved")
# The inbound direction collapses identically; the bug was symmetric.
inbound = [c for c in q.callers(db, "pump") if c.edge_class == "call"]
assert [c.name for c in inbound] == ["driver"]
assert (inbound[0].source, inbound[0].confidence) == ("doxygen_sqlite", "exact")
Activity · 11 steps
test_name_accessors_degrade_gracefully_on_table_less_db
None test_query.test_name_accessors_degrade_gracefully_on_table_less_db(Path tmp_path)
Called by none
Calls callees, callers, chain_trace, function_dossier, resolve_symbol, search, source, thread_of
Checks
assert q.callers(p, "x") == []assert q.callees(p, "x") == []assert q.search(p, "x") == []assert q.thread_of(p, "x") == []assert q.function_dossier(p, "x") is Noneassert q.source(p, "x", tmp_path) is Noneassert q.resolve_symbol(p, "x") is Noneassert q.chain_trace(p, "x") is not None # returns an (empty) Chain, does not raise
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_name_accessors_degrade_gracefully_on_table_less_db → source → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_name_accessors_degrade_gracefully_on_table_less_db → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | inferred | test_name_accessors_degrade_gracefully_on_table_less_db → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_name_accessors_degrade_gracefully_on_table_less_db → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_name_accessors_degrade_gracefully_on_table_less_db → source |
| REQ-DDB-QUERY-002 | measured | test_name_accessors_degrade_gracefully_on_table_less_db → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_name_accessors_degrade_gracefully_on_table_less_db → resolve_symbol |
| REQ-DDB-QUERY-004 | measured | test_name_accessors_degrade_gracefully_on_table_less_db → function_dossier |
| REQ-DDB-QUERY-005 | inferred | test_name_accessors_degrade_gracefully_on_table_less_db → chain_trace → _make_node |
| REQ-DDB-QUERY-006 | inferred | test_name_accessors_degrade_gracefully_on_table_less_db → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-007 | measured | test_name_accessors_degrade_gracefully_on_table_less_db → search → search_counted → _class_candidates → class_rows |
| REQ-DDB-QUERY-009 | measured | test_name_accessors_degrade_gracefully_on_table_less_db → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_name_accessors_degrade_gracefully_on_table_less_db → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_name_accessors_degrade_gracefully_on_table_less_db → search |
| REQ-DDB-QUERY-013 | inferred | test_name_accessors_degrade_gracefully_on_table_less_db → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | inferred | test_name_accessors_degrade_gracefully_on_table_less_db → function_dossier → _dossier_conn → locks_held_for_rowids |
Source · 24 lines
def test_name_accessors_degrade_gracefully_on_table_less_db(tmp_path: Path) -> None:
"""#41: a corrupt/unbuilt db (valid sqlite, no pipeline tables) must make
EVERY name-based accessor degrade to "not found" (empty/None), never raise a
raw sqlite OperationalError — matching the table_exists convention already
pervasive across the query layer. Before the fix callers/callees guarded
their table, but dossier/source/search/thread_of/chain_trace/resolve_symbol
queried memberdef cold and raised, so the same corrupt db gave inconsistent
behaviour across the tier-1 surface."""
p = tmp_path / "corrupt.db"
conn = sqlite3.connect(p)
conn.execute("CREATE TABLE junk(x)") # valid sqlite, zero pipeline tables
conn.commit()
conn.close()
assert q.callers(p, "x") == []
assert q.callees(p, "x") == []
assert q.search(p, "x") == []
assert q.thread_of(p, "x") == []
assert q.function_dossier(p, "x") is None
assert q.source(p, "x", tmp_path) is None
assert q.resolve_symbol(p, "x") is None
assert q.chain_trace(p, "x") is not None # returns an (empty) Chain, does not raise
Activity · 13 steps
test_namesake_fanout_is_no_longer_laundered_into_exact
None test_query.test_namesake_fanout_is_no_longer_laundered_into_exact(Path tmp_path)
gh#26, the half a query-layer fix CAN reach, pinned on the real data shape.
Checks
assert d is not None and d.file == "pkg/guidance.py"assert by_name["plan_guidance"].confidence == "exact"assert by_name["plan_guidance"].source == "doxygen_sqlite"assert by_name[fabricated].confidence == "fuzzy", (f"{fabricated} reaches a DIFFERENT module's _classify; " "reporting it as 'exact' is the gh#26 defect" )assert by_name[fabricated].source == "ast"assert [c.name for c in d.callees if c.edge_class == "call"] == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | inferred | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → locks_held_for_rowids |
Source · 50 lines
def test_namesake_fanout_is_no_longer_laundered_into_exact(tmp_path: Path) -> None:
"""gh#26, the half a query-layer fix CAN reach, pinned on the real data shape.
The fabricated inbound rows are written by the pipeline's `ast` layer, which
resolves an ambiguous bare name by fanning out to every namesake. Those rows
EXIST, so this surface cannot invent their absence. What it must not do is
what it used to: bucket every namesake under one endpoint NAME and then report
`_collapse_variants`' strongest evidence across the merged bucket, which
dressed a fuzzy guess as `exact` -- the precise complaint in gh#26, that
fabricated relationships arrive at the HIGHEST confidence level.
Now each identity is its own bucket and is graded on its OWN evidence, so a
fan-out row reads `fuzzy` -- which is exactly what the tool description says
fuzzy means: only that a function of that name exists, the target never
confirmed. A model instructed to weigh `confidence` can now act on it.
NOT yet fixed, deliberately and with the evidence recorded: suppressing a
fuzzy edge to one namesake when the SAME caller has a non-fuzzy edge to
another would remove these rows entirely, because the doxygen layers resolve
this case correctly. It is not done here because a caller may genuinely call
two different same-named functions, and on a C++ target member-call edges are
mostly fuzzy by construction -- so the rule needs a false-deletion
measurement on the public C/C++ targets before it can ship."""
db = tmp_path / "fanout.db"
_fanout_collision_db(db)
d = q.function_dossier(db, "_classify")
assert d is not None and d.file == "pkg/guidance.py"
by_name = {c.name: c for c in d.callers if c.edge_class == "call"}
# The one REAL caller keeps its strong grading, from the layer that resolved
# the endpoint outright.
assert by_name["plan_guidance"].confidence == "exact"
assert by_name["plan_guidance"].source == "doxygen_sqlite"
# The fan-out rows are still listed -- but as fuzzy, single-layer guesses.
for fabricated in ("_guard_scope", "plan_merge", "_classify"):
assert by_name[fabricated].confidence == "fuzzy", (
f"{fabricated} reaches a DIFFERENT module's _classify; "
"reporting it as 'exact' is the gh#26 defect"
)
assert by_name[fabricated].source == "ast"
# Outbound stays clean: guidance._classify's own fan-out rows point AWAY from
# it, so nothing fabricates a callee for a function that calls nothing.
assert [c.name for c in d.callees if c.edge_class == "call"] == []
# ─── prose: member documentation is prose too (gh#404) ───────────────────────
Activity · 11 steps
test_prose_search_reaches_documentation_attached_to_a_member
None test_query.test_prose_search_reaches_documentation_attached_to_a_member(Path tmp_path)
A member's documentation is reachable as prose.
Checks
assert found.hits, "the member's documentation is the only prose here and must be found"assert hit.file_path == "library/common.h"assert "member documentation" in hit.heading, "the heading must say where the prose came from"assert "<para>" not in hit.snippet, f"doxygen's XML must be stripped: {hit.snippet!r}"assert "their members are private" in hit.snippet
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_prose_search_reaches_documentation_attached_to_a_member → search_prose_graded |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_prose_search_reaches_documentation_attached_to_a_member → search_prose_graded → table_exists |
| REQ-DDB-QUERY-007 | measured | test_prose_search_reaches_documentation_attached_to_a_member → search_prose_graded → member_doc_rows |
Source · 23 lines
def test_prose_search_reaches_documentation_attached_to_a_member(tmp_path: Path) -> None:
"""gh#404 — THE TEXT WAS ALWAYS STORED AND NEVER SEARCHED. The prose corpus read markdown and
file-level doc comments; a doc comment on a MEMBER went nowhere. Measured on mbedtls:
`search_prose("MBEDTLS_ALLOW_PRIVATE_ACCESS")` returned zero while
`memberdef.detaileddescription` held the paragraph that answers the question — and the graded
cell was told the miss was definitive and ran three greps to find what the index was holding.
ASSERTED ON THE STRIPPED TEXT, because doxygen stores these columns as XML: the first live
check came back wearing `<para>` tags, which a reader pays for and cannot use.
@brief A member's documentation is reachable as prose.
@version 1
"""
db = _member_doc_db(tmp_path)
found = q.search_prose_graded(db, "private members", limit=5)
assert found.hits, "the member's documentation is the only prose here and must be found"
hit = found.hits[0]
assert hit.file_path == "library/common.h"
assert "member documentation" in hit.heading, "the heading must say where the prose came from"
assert "<para>" not in hit.snippet, f"doxygen's XML must be stripped: {hit.snippet!r}"
assert "their members are private" in hit.snippet
Activity · 8 steps
test_read_body_refuses_paths_escaping_repo_root
None test_query.test_read_body_refuses_paths_escaping_repo_root(Path tmp_path)
Checks
assert ok is not None and ok[0] == ["line1", "line2"]assert _read_body(root, str(outside), 1, 1, 10) is None # absolute escape → refusedassert _read_body(root, "../secret.txt", 1, 1, 10) is None # ../ escape → refused
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | catalog | |
| REQ-DDB-QUERY-002 | catalog |
Source · 21 lines
def test_read_body_refuses_paths_escaping_repo_root(tmp_path: Path) -> None:
"""#39 defense-in-depth: R3 serves whatever db a caller points it at, so a
tampered/foreign db could record an absolute (`/etc/passwd`) or `../`-escaping
body path — which `root / file` would happily follow OUTSIDE the working tree,
turning `source` into an arbitrary-file read. The escape target here EXISTS and
is readable, so a None result proves the containment check (not an OSError
fallback) is what refuses it; the contained control reads normally."""
from clew.query.source import _read_body
root = tmp_path / "repo"
root.mkdir()
(root / "src.c").write_text("line1\nline2\n", encoding="utf-8")
outside = tmp_path / "secret.txt"
outside.write_text("TOP SECRET\n", encoding="utf-8")
ok = _read_body(root, "src.c", 1, 2, 10) # contained → reads
assert ok is not None and ok[0] == ["line1", "line2"]
assert _read_body(root, str(outside), 1, 1, 10) is None # absolute escape → refused
assert _read_body(root, "../secret.txt", 1, 1, 10) is None # ../ escape → refused
Activity · 10 steps
test_req_trace_findme
None test_query.test_req_trace_findme(Path rich_db)
Checks
assert rt.title == "Find-my-robot audible ping"assert rt.priority == "P1"assert "sound_play_findme" in implsassert impls["sound_play_findme"].liveness == "live"assert "test_findme_chime_plays" in rt.testsassert "test_findme_chime_plays" not in impls
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_req_trace_findme → req_trace |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_req_trace_findme → req_trace → table_exists |
| REQ-DDB-QUERY-010 | measured | test_req_trace_findme → req_trace → _req_implementers → resolve_rowid |
| REQ-DDB-SCHEMA-006 | measured | test_req_trace_findme → req_trace → _req_failure_modes |
| REQ-DDB-SCHEMA-015 | measured | test_req_trace_findme → req_trace → _req_links |
Source · 12 lines
def test_req_trace_findme(rich_db: Path) -> None:
rt = q.req_trace(rich_db, "REQ-0621")
assert rt.title == "Find-my-robot audible ping"
assert rt.priority == "P1"
impls = {i.name: i for i in rt.implementers}
assert "sound_play_findme" in impls
assert impls["sound_play_findme"].liveness == "live"
assert "test_findme_chime_plays" in rt.tests
# The test function is not itself listed as an implementer.
assert "test_findme_chime_plays" not in impls
Activity · 8 steps
test_resolve_symbol_decl_def_duality_is_not_an_overload
None test_query.test_resolve_symbol_decl_def_duality_is_not_an_overload(Path tmp_path)
Decl + def of ONE function share a signature and must NOT read as an overload — otherwise every documented header declaration would falsely trip the ambiguity signal.
Checks
assert ref is not Noneassert ref.rowid == 20 # definition-preferringassert ref.candidates == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_resolve_symbol_decl_def_duality_is_not_an_overload → resolve_symbol → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_resolve_symbol_decl_def_duality_is_not_an_overload → resolve_symbol → connect |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_resolve_symbol_decl_def_duality_is_not_an_overload → resolve_symbol |
| REQ-DDB-QUERY-010 | measured | test_resolve_symbol_decl_def_duality_is_not_an_overload → resolve_symbol |
Source · 20 lines
def test_resolve_symbol_decl_def_duality_is_not_an_overload(tmp_path: Path) -> None:
"""Decl + def of ONE function share a signature and must NOT read as an
overload — otherwise every documented header declaration would falsely
trip the ambiguity signal."""
db = _overload_db(
tmp_path,
[
(20, "solo", "void solo", "src/s.cpp", True), # definition
(21, "solo", "void solo", "include/s.hpp", False), # declaration
],
)
ref = q.resolve_symbol(db, "solo")
assert ref is not None
assert ref.rowid == 20 # definition-preferring
assert ref.candidates == []
# ─── integration: source / list_files / search_prose ─────────────────────────
Activity · 5 steps
test_resolve_symbol_definition_preferring
None test_query.test_resolve_symbol_definition_preferring(Path rich_db)
Checks
assert ref is not Noneassert ref.kind == "function"assert ref.file.endswith("sensor_driver.c")assert ref.candidates == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_resolve_symbol_definition_preferring → resolve_symbol → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_resolve_symbol_definition_preferring → resolve_symbol → connect |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_resolve_symbol_definition_preferring → resolve_symbol |
| REQ-DDB-QUERY-010 | measured | test_resolve_symbol_definition_preferring → resolve_symbol |
Source · 10 lines
def test_resolve_symbol_definition_preferring(rich_db: Path) -> None:
ref = q.resolve_symbol(rich_db, "sensor_poll")
assert ref is not None
assert ref.kind == "function"
assert ref.file.endswith("sensor_driver.c")
# An unambiguous name must NOT be flagged an overload — no regression on the
# single-result path every consumer already depends on.
assert ref.candidates == []
Activity · 5 steps
test_resolve_symbol_flags_genuine_overload
None test_query.test_resolve_symbol_flags_genuine_overload(Path tmp_path)
A name mapping to distinct signatures (different classes) is a genuine overload: resolve_symbol still returns a definition-preferring primary but exposes every alternative so a consumer can pick the right one by file, rather than silently tracing an arbitrary overload.
Checks
assert ref is not Noneassert ref.rowid == 10assert sigs == {"void A::react", "void B::react", "void C::react"}assert files == {"src/a.cpp", "src/b.cpp", "include/c.hpp"}assert any(c.file.endswith("c.hpp") and c.has_body is False for c in ref.candidates)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_resolve_symbol_flags_genuine_overload → resolve_symbol → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_resolve_symbol_flags_genuine_overload → resolve_symbol → connect |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_resolve_symbol_flags_genuine_overload → resolve_symbol |
| REQ-DDB-QUERY-010 | measured | test_resolve_symbol_flags_genuine_overload → resolve_symbol |
Source · 25 lines
def test_resolve_symbol_flags_genuine_overload(tmp_path: Path) -> None:
"""A name mapping to distinct signatures (different classes) is a genuine
overload: resolve_symbol still returns a definition-preferring primary but
exposes every alternative so a consumer can pick the right one by file,
rather than silently tracing an arbitrary overload."""
db = _overload_db(
tmp_path,
[
(10, "react", "void A::react", "src/a.cpp", True),
(11, "react", "void B::react", "src/b.cpp", True),
(12, "react", "void C::react", "include/c.hpp", False),
],
)
ref = q.resolve_symbol(db, "react")
assert ref is not None
# Primary is definition-preferring (a body row, lowest rowid among them).
assert ref.rowid == 10
sigs = {c.signature for c in ref.candidates}
assert sigs == {"void A::react", "void B::react", "void C::react"}
files = {c.file for c in ref.candidates}
assert files == {"src/a.cpp", "src/b.cpp", "include/c.hpp"}
# The header-only candidate is flagged as such.
assert any(c.file.endswith("c.hpp") and c.has_body is False for c in ref.candidates)
Activity · 9 steps
test_same_named_c_statics_in_different_files_still_merge
None test_query.test_same_named_c_statics_in_different_files_still_merge(Path rich_db)
KNOWN LIMITATION, pinned deliberately so a future change notices it.
Checks
assert "app_run" in callees, "src/main.c's main"assert "test_findme_chime_plays" in callees, "the test file's main -- STILL merged"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_same_named_c_statics_in_different_files_still_merge → callees |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_same_named_c_statics_in_different_files_still_merge → callees → _call_edges → _dataflow_edges → resolve_rowid |
| REQ-DDB-QUERY-009 | measured | test_same_named_c_statics_in_different_files_still_merge → callees → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_same_named_c_statics_in_different_files_still_merge → callees |
Source · 23 lines
def test_same_named_c_statics_in_different_files_still_merge(rich_db: Path) -> None:
"""KNOWN LIMITATION, pinned deliberately so a future change notices it.
The gh#26 fix keys identity on the QUALIFIED name, which doxygen derives from
the module for Python (`pkg.scope._classify`) and from the class/namespace for
C++ (`LinkOwner::rx_loop`). A C free or file-static function has NO
qualification, so two functions of the same name in different translation
units share one identity and their edges still merge.
The fixture has exactly that shape: `main` in src/main.c (which calls the
subsystem inits) and `main` in the test file (which calls
`test_findme_chime_plays`). Both remain one node.
NOT fixed here because the obvious repair measured worse than the defect.
Adding the definition's `bodyfile_id` to the key separates the statics, but it
tore 957 declaration rows away from their definitions on entropic while
fixing only 10 collisions there and 41 on mbedtls -- trading a rare
fabrication for a common one. Recorded in gh#26 rather than patched blind."""
callees = {c.name for c in q.callees(rich_db, "main") if c.edge_class == "call"}
assert "app_run" in callees, "src/main.c's main"
assert "test_findme_chime_plays" in callees, "the test file's main -- STILL merged"
Activity · 3 steps
test_search_empty_and_unmatched_queries_stay_empty
None test_query.test_search_empty_and_unmatched_queries_stay_empty(Path rich_db)
Correct negatives must survive the rewrite: a whitespace-only query has no tokens to match, and a genuinely absent term still returns nothing.
Checks
assert q.search(rich_db, " ") == []assert q.search(rich_db, "zzz_definitely_absent_xyz") == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_search_empty_and_unmatched_queries_stay_empty → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_search_empty_and_unmatched_queries_stay_empty → search |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_empty_and_unmatched_queries_stay_empty → search → search_counted → _class_candidates → class_rows → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_empty_and_unmatched_queries_stay_empty → search → search_counted → _class_candidates → class_rows |
| REQ-DDB-QUERY-012 | measured | test_search_empty_and_unmatched_queries_stay_empty → search |
Source · 7 lines
def test_search_empty_and_unmatched_queries_stay_empty(rich_db: Path) -> None:
"""Correct negatives must survive the rewrite: a whitespace-only query has
no tokens to match, and a genuinely absent term still returns nothing."""
assert q.search(rich_db, " ") == []
assert q.search(rich_db, "zzz_definitely_absent_xyz") == []
Activity · 2 steps
test_search_excludes_stl_compounds_but_lookup_class_still_reaches_them
None test_query.test_search_excludes_stl_compounds_but_lookup_class_still_reaches_them(Path tmp_path)
doxygen registers hundreds of `std::` compounds against its synthetic `[STL]` path row. Ranking them into a DISCOVERY surface would let system headers crowd out the repository the caller is asking about, so `search` excludes them exactly as `list_files` does. Demotion-not-exclusion stays true where it is reachable: `lookup_class` still answers for the std:: name.
Checks
assert "std::PolygonWidget_traits" not in [h.name for h in q.search(db, "PolygonWidget")]assert q.search(db, "PolygonWidget_traits") == []assert entry is not None and entry.name == "std::PolygonWidget_traits"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_search_excludes_stl_compounds_but_lookup_class_still_reaches_them → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_search_excludes_stl_compounds_but_lookup_class_still_reaches_them → lookup_class |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_excludes_stl_compounds_but_lookup_class_still_reaches_them → lookup_class → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_excludes_stl_compounds_but_lookup_class_still_reaches_them → search → search_counted → _class_candidates → class_rows |
| REQ-DDB-QUERY-010 | measured | test_search_excludes_stl_compounds_but_lookup_class_still_reaches_them → lookup_class |
| REQ-DDB-QUERY-012 | measured | test_search_excludes_stl_compounds_but_lookup_class_still_reaches_them → search |
Source · 15 lines
def test_search_excludes_stl_compounds_but_lookup_class_still_reaches_them(
tmp_path: Path,
) -> None:
"""doxygen registers hundreds of `std::` compounds against its synthetic `[STL]`
path row. Ranking them into a DISCOVERY surface would let system headers crowd
out the repository the caller is asking about, so `search` excludes them exactly
as `list_files` does. Demotion-not-exclusion stays true where it is reachable:
`lookup_class` still answers for the std:: name."""
db = _class_db(tmp_path)
assert "std::PolygonWidget_traits" not in [h.name for h in q.search(db, "PolygonWidget")]
assert q.search(db, "PolygonWidget_traits") == []
entry = q.lookup_class(db, "std::PolygonWidget_traits")
assert entry is not None and entry.name == "std::PolygonWidget_traits"
Activity · 5 steps
test_search_finds_a_class_by_its_brief
None test_query.test_search_finds_a_class_by_its_brief(Path tmp_path)
The class corpus is matched the same way the other two are — over name AND brief — so a conceptual token in a class's documentation reaches it.
Checks
assert [h.name for h in hits] == ["demo::shape::IShapeWidget"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_search_finds_a_class_by_its_brief → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_search_finds_a_class_by_its_brief → search |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_finds_a_class_by_its_brief → search → search_counted → _class_candidates → class_rows → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_finds_a_class_by_its_brief → search → search_counted → _class_candidates → class_rows |
| REQ-DDB-QUERY-012 | measured | test_search_finds_a_class_by_its_brief → search |
Source · 7 lines
def test_search_finds_a_class_by_its_brief(tmp_path: Path) -> None:
"""The class corpus is matched the same way the other two are — over name AND
brief — so a conceptual token in a class's documentation reaches it."""
hits = q.search(_class_db(tmp_path), "base interface")
assert [h.name for h in hits] == ["demo::shape::IShapeWidget"]
Activity · 2 steps
test_search_finds_a_class_by_name
None test_query.test_search_finds_a_class_by_name(Path tmp_path)
gh#315, the headline defect. `search` read `memberdef WHERE kind='function'` and the file-doc corpus, and NOTHING ELSE — classes live in `compounddef`, a table it never touched. So a class name returned a confident empty result, which is indistinguishable from a measured negative and is the worst failure mode this project has. Reproduced live on this repo's own index: `search("WritePlan")` returned only the mcp_config.py FILE DOC while the class sits at line 132.
Checks
assert "demo::shape::PolygonWidget" in by_nameassert by_name["demo::shape::PolygonWidget"].kind == "class"assert by_name["demo::shape::PolygonWidget"].file == "src/demo/shape/PolygonWidget.hpp"assert by_name["demo::shape::PolygonWidget"].brief == "Recomputes the cached outline."
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_search_finds_a_class_by_name → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_search_finds_a_class_by_name → search |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_finds_a_class_by_name → search → search_counted → _class_candidates → class_rows → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_finds_a_class_by_name → search → search_counted → _class_candidates → class_rows |
| REQ-DDB-QUERY-012 | measured | test_search_finds_a_class_by_name → search |
Source · 15 lines
def test_search_finds_a_class_by_name(tmp_path: Path) -> None:
"""gh#315, the headline defect. `search` read `memberdef WHERE kind='function'`
and the file-doc corpus, and NOTHING ELSE — classes live in `compounddef`, a
table it never touched. So a class name returned a confident empty result, which
is indistinguishable from a measured negative and is the worst failure mode this
project has. Reproduced live on this repo's own index: `search("WritePlan")`
returned only the mcp_config.py FILE DOC while the class sits at line 132."""
hits = q.search(_class_db(tmp_path), "PolygonWidget")
by_name = {h.name: h for h in hits}
assert "demo::shape::PolygonWidget" in by_name
assert by_name["demo::shape::PolygonWidget"].kind == "class"
assert by_name["demo::shape::PolygonWidget"].file == "src/demo/shape/PolygonWidget.hpp"
assert by_name["demo::shape::PolygonWidget"].brief == "Recomputes the cached outline."
Activity · 6 steps
test_search_finds_known_symbol
None test_query.test_search_finds_known_symbol(Path rich_db)
Checks
assert "sensor_poll" in hitsassert any(h.name == "telemetry_report" for h in tele)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_search_finds_known_symbol → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_search_finds_known_symbol → search |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_finds_known_symbol → search → search_counted → _class_candidates → class_rows → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_finds_known_symbol → search → search_counted → _class_candidates → class_rows |
| REQ-DDB-QUERY-012 | measured | test_search_finds_known_symbol → search |
Source · 8 lines
def test_search_finds_known_symbol(rich_db: Path) -> None:
hits = {h.name for h in q.search(rich_db, "sensor_poll")}
assert "sensor_poll" in hits
# Brief-text search also matches.
tele = q.search(rich_db, "telemetry")
assert any(h.name == "telemetry_report" for h in tele)
Activity · 4 steps
test_search_for_an_absent_class_name_is_still_empty
None test_query.test_search_for_an_absent_class_name_is_still_empty(Path tmp_path)
THE NEGATIVE CONTROL. Widening the searched set must not make a genuinely absent name start matching something; a correct negative has to survive.
Checks
assert q.search(_class_db(tmp_path), "NoSuchWidgetAnywhere") == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_search_for_an_absent_class_name_is_still_empty → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_search_for_an_absent_class_name_is_still_empty → search |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_for_an_absent_class_name_is_still_empty → search → search_counted → _class_candidates → class_rows → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_for_an_absent_class_name_is_still_empty → search → search_counted → _class_candidates → class_rows |
| REQ-DDB-QUERY-012 | measured | test_search_for_an_absent_class_name_is_still_empty → search |
Source · 6 lines
def test_search_for_an_absent_class_name_is_still_empty(tmp_path: Path) -> None:
"""THE NEGATIVE CONTROL. Widening the searched set must not make a genuinely
absent name start matching something; a correct negative has to survive."""
assert q.search(_class_db(tmp_path), "NoSuchWidgetAnywhere") == []
Activity · 1 steps
test_search_is_capped_and_the_cap_is_caller_controlled
None test_query.test_search_is_capped_and_the_cap_is_caller_controlled(Path rich_db)
The old implementation had NO limit: a common token returned every match in alphabetical order, so the useful hit could be anywhere.
Checks
assert len(q.search(rich_db, "e", limit=3)) <= 3assert len(q.search(rich_db, "e", limit=1)) == 1
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_search_is_capped_and_the_cap_is_caller_controlled → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_search_is_capped_and_the_cap_is_caller_controlled → search |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_is_capped_and_the_cap_is_caller_controlled → search → search_counted → _class_candidates → class_rows → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_is_capped_and_the_cap_is_caller_controlled → search → search_counted → _class_candidates → class_rows |
| REQ-DDB-QUERY-012 | measured | test_search_is_capped_and_the_cap_is_caller_controlled → search |
Source · 7 lines
def test_search_is_capped_and_the_cap_is_caller_controlled(rich_db: Path) -> None:
"""The old implementation had NO limit: a common token returned every match
in alphabetical order, so the useful hit could be anywhere."""
assert len(q.search(rich_db, "e", limit=3)) <= 3
assert len(q.search(rich_db, "e", limit=1)) == 1
Activity · 2 steps
test_search_matches_every_token_not_the_literal_phrase
None test_query.test_search_matches_every_token_not_the_literal_phrase(Path rich_db)
Checks
assert single, "single-token search must still work"assert any(h.name == "sensor_poll" for h in both)assert {h.name for h in q.search(rich_db, "poll sensor")} == {h.name for h in both}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_search_matches_every_token_not_the_literal_phrase → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_search_matches_every_token_not_the_literal_phrase → search |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_matches_every_token_not_the_literal_phrase → search → search_counted → _class_candidates → class_rows → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_matches_every_token_not_the_literal_phrase → search → search_counted → _class_candidates → class_rows |
| REQ-DDB-QUERY-012 | measured | test_search_matches_every_token_not_the_literal_phrase → search |
Source · 19 lines
def test_search_matches_every_token_not_the_literal_phrase(rich_db: Path) -> None:
"""#45: search was a single literal LIKE '%<whole query>%', so any
multi-word query returned NOTHING — '%lock acquisition%' is a substring no
identifier contains. Verified on clew's own index before the fix:
search('lock') gave 9 hits, search('lock acquisition') gave ZERO, and the
empty envelope then asserted "This is a definitive empty result ... Do not
retry". Search is the discovery entry point; if a natural phrase answers
nothing, a consumer never reaches dossier or chain_trace at all."""
single = q.search(rich_db, "sensor")
assert single, "single-token search must still work"
# Tokens drawn from the name and the brief respectively must AND together.
both = q.search(rich_db, "sensor poll")
assert any(h.name == "sensor_poll" for h in both)
# Word order is irrelevant — these are tokens, not a phrase.
assert {h.name for h in q.search(rich_db, "poll sensor")} == {h.name for h in both}
Activity · 5 steps
test_search_prose_absent_table_is_empty
None test_query.test_search_prose_absent_table_is_empty(Path tmp_path)
Databases built before the prose layer simply have no hits.
Checks
assert q.search_prose(db, "anything") == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_search_prose_absent_table_is_empty → search_prose |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_prose_absent_table_is_empty → search_prose → search_prose_graded → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_prose_absent_table_is_empty → search_prose → search_prose_graded → member_doc_rows |
Source · 13 lines
def test_search_prose_absent_table_is_empty(tmp_path: Path) -> None:
"""Databases built before the prose layer simply have no hits."""
db = tmp_path / "noprose.db"
conn = sqlite3.connect(str(db))
conn.execute("CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, name TEXT)")
conn.commit()
conn.close()
assert q.search_prose(db, "anything") == []
# ─── unit: hand-built DBs for the traversal invariants ───────────────────────
Activity · 6 steps
test_search_prose_does_not_widen_a_query_that_already_matched
None test_query.test_search_prose_does_not_widen_a_query_that_already_matched(Path rich_db)
WIDENING IS A LAST RESORT, NOT A DEFAULT. If an OR ran whenever it could, a query with exact hits would return them buried under loosely-related ones — the opposite failure to the one above, and harder to notice because the reply is not empty.
Checks
assert result.hitsassert result.widened is False
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_search_prose_does_not_widen_a_query_that_already_matched → search_prose_graded |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_prose_does_not_widen_a_query_that_already_matched → search_prose_graded → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_prose_does_not_widen_a_query_that_already_matched → search_prose_graded → member_doc_rows |
Source · 10 lines
def test_search_prose_does_not_widen_a_query_that_already_matched(rich_db: Path) -> None:
"""WIDENING IS A LAST RESORT, NOT A DEFAULT. If an OR ran whenever it could, a query
with exact hits would return them buried under loosely-related ones — the opposite
failure to the one above, and harder to notice because the reply is not empty.
"""
result = q.search_prose_graded(rich_db, "chime")
assert result.hits
assert result.widened is False
Activity · 3 steps
test_search_prose_limit_and_bad_expression
None test_query.test_search_prose_limit_and_bad_expression(Path rich_db)
The limit is honoured, and an FTS5-invalid expression is retried as a literal phrase instead of surfacing a syntax error to the caller.
Checks
assert len(q.search_prose(rich_db, "the OR robot OR key", limit=2)) <= 2
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_search_prose_limit_and_bad_expression → search_prose |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_prose_limit_and_bad_expression → search_prose → search_prose_graded → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_prose_limit_and_bad_expression → search_prose → search_prose_graded → member_doc_rows |
Source · 7 lines
def test_search_prose_limit_and_bad_expression(rich_db: Path) -> None:
"""The limit is honoured, and an FTS5-invalid expression is retried as a
literal phrase instead of surfacing a syntax error to the caller."""
assert len(q.search_prose(rich_db, "the OR robot OR key", limit=2)) <= 2
q.search_prose(rich_db, 'unbalanced " quote') # must not raise
Activity · 2 steps
test_search_prose_punctuation_only_tokens_never_reach_fts5
None test_query.test_search_prose_punctuation_only_tokens_never_reach_fts5(Path rich_db)
A token of pure punctuation tokenizes to an EMPTY phrase, and an empty phrase is an FTS5 syntax error rather than a harmless no-op — so it must be dropped before the OR is composed, not after.
Checks
assert result.tokens == ("chime",)assert result.hits
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_search_prose_punctuation_only_tokens_never_reach_fts5 → search_prose_graded |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_prose_punctuation_only_tokens_never_reach_fts5 → search_prose_graded → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_prose_punctuation_only_tokens_never_reach_fts5 → search_prose_graded → member_doc_rows |
Source · 10 lines
def test_search_prose_punctuation_only_tokens_never_reach_fts5(rich_db: Path) -> None:
"""A token of pure punctuation tokenizes to an EMPTY phrase, and an empty phrase is an
FTS5 syntax error rather than a harmless no-op — so it must be dropped before the OR
is composed, not after.
"""
result = q.search_prose_graded(rich_db, "chime _ ' -")
assert result.tokens == ("chime",)
assert result.hits
Activity · 3 steps
test_search_prose_returns_a_snippet
None test_query.test_search_prose_returns_a_snippet(Path rich_db)
The sample's markdown is ingested into FTS5; a term known to be in it comes back with a heading and a snippet showing the match in context.
Checks
assert hits, "'chime' is in the fixture tree's docs/architecture.md"assert any(h.file_path.endswith(".md") for h in hits)assert all(h.snippet for h in hits)assert any(">>" in h.snippet for h in hits), "snippet() must mark the match"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_search_prose_returns_a_snippet → search_prose |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_prose_returns_a_snippet → search_prose → search_prose_graded → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_prose_returns_a_snippet → search_prose → search_prose_graded → member_doc_rows |
| REQ-DDB-WIKI-054 | inferred | test_search_prose_returns_a_snippet → all |
Source · 10 lines
def test_search_prose_returns_a_snippet(rich_db: Path) -> None:
"""The sample's markdown is ingested into FTS5; a term known to be in it
comes back with a heading and a snippet showing the match in context."""
hits = q.search_prose(rich_db, "chime")
assert hits, "'chime' is in the fixture tree's docs/architecture.md"
assert any(h.file_path.endswith(".md") for h in hits)
assert all(h.snippet for h in hits)
assert any(">>" in h.snippet for h in hits), "snippet() must mark the match"
Activity · 5 steps
test_search_prose_single_token_miss_reports_no_widening
None test_query.test_search_prose_single_token_miss_reports_no_widening(Path rich_db)
A one-word query has no conjunction to relax, so a miss is a genuine absence and must NOT be dressed up as a widened search. This is the case where "definitive" is the honest word — the distinction the emptiness note depends on.
Checks
assert result.hits == []assert result.widened is Falseassert result.tokens == ("zzqqxwv",)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_search_prose_single_token_miss_reports_no_widening → search_prose_graded |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_prose_single_token_miss_reports_no_widening → search_prose_graded → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_prose_single_token_miss_reports_no_widening → search_prose_graded → member_doc_rows |
Source · 11 lines
def test_search_prose_single_token_miss_reports_no_widening(rich_db: Path) -> None:
"""A one-word query has no conjunction to relax, so a miss is a genuine absence and
must NOT be dressed up as a widened search. This is the case where "definitive" is
the honest word — the distinction the emptiness note depends on.
"""
result = q.search_prose_graded(rich_db, "zzqqxwv")
assert result.hits == []
assert result.widened is False
assert result.tokens == ("zzqqxwv",)
Activity · 4 steps
test_search_prose_widens_to_or_when_one_absent_word_empties_the_and
None test_query.test_search_prose_widens_to_or_when_one_absent_word_empties_the_and(Path rich_db)
THE DEFECT THIS IS THE CONTROL FOR, measured on mbedtls: FTS5 joins a bare token list with an implicit AND, so `private accessor` found the migration guide while `private members accessor` found NOTHING — the document says "fields". A graded agent tried five such phrasings, was told each empty result was definitive, and grepped the file the corpus already held.
Checks
assert q.search_prose(rich_db, absent) == [], "the control word must really be absent"assert result.widened is Trueassert result.hits, "the AND was empty, so the OR must recover the 'chime' hits"assert any(h.file_path.endswith(".md") for h in result.hits)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_search_prose_widens_to_or_when_one_absent_word_empties_the_and → search_prose_graded |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_prose_widens_to_or_when_one_absent_word_empties_the_and → search_prose_graded → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_prose_widens_to_or_when_one_absent_word_empties_the_and → search_prose_graded → member_doc_rows |
Source · 20 lines
def test_search_prose_widens_to_or_when_one_absent_word_empties_the_and(rich_db: Path) -> None:
"""THE DEFECT THIS IS THE CONTROL FOR, measured on mbedtls: FTS5 joins a bare token
list with an implicit AND, so `private accessor` found the migration guide while
`private members accessor` found NOTHING — the document says "fields". A graded agent
tried five such phrasings, was told each empty result was definitive, and grepped the
file the corpus already held.
Reproduced here by pairing a term known to be in the fixture with one that cannot be
in any corpus. The AND must be empty and the OR must still find the known term.
"""
absent = "zzqqxwv"
assert q.search_prose(rich_db, absent) == [], "the control word must really be absent"
result = q.search_prose_graded(rich_db, f"chime {absent}")
assert result.widened is True
assert result.hits, "the AND was empty, so the OR must recover the 'chime' hits"
assert any(h.file_path.endswith(".md") for h in result.hits)
Activity · 6 steps
test_search_ranking_is_unchanged_on_a_db_with_no_compounds
None test_query.test_search_ranking_is_unchanged_on_a_db_with_no_compounds(Path rich_db)
The second half of that control, at list level rather than one hit: on an index with no `compounddef` at all the ENTIRE ranked result must be what it was, so the new corpus cannot have perturbed the sort for existing targets.
Checks
assert [h.name for h in q.search(rich_db, "sensor_poll")][0] == "sensor_poll"assert q.search(rich_db, "e", limit=3) == q.search(rich_db, "e", limit=3)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_search_ranking_is_unchanged_on_a_db_with_no_compounds → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_search_ranking_is_unchanged_on_a_db_with_no_compounds → search |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_ranking_is_unchanged_on_a_db_with_no_compounds → search → search_counted → _class_candidates → class_rows → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_ranking_is_unchanged_on_a_db_with_no_compounds → search → search_counted → _class_candidates → class_rows |
| REQ-DDB-QUERY-012 | measured | test_search_ranking_is_unchanged_on_a_db_with_no_compounds → search |
Source · 8 lines
def test_search_ranking_is_unchanged_on_a_db_with_no_compounds(rich_db: Path) -> None:
"""The second half of that control, at list level rather than one hit: on an
index with no `compounddef` at all the ENTIRE ranked result must be what it was,
so the new corpus cannot have perturbed the sort for existing targets."""
assert [h.name for h in q.search(rich_db, "sensor_poll")][0] == "sensor_poll"
assert q.search(rich_db, "e", limit=3) == q.search(rich_db, "e", limit=3)
Activity · 2 steps
test_search_ranks_name_matches_above_prose_matches
None test_query.test_search_ranks_name_matches_above_prose_matches(Path rich_db)
A token in the identifier is stronger evidence than the same token in prose, so an exact name match must not be buried under brief-only hits.
Checks
assert hits and hits[0].name == "sensor_poll"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_search_ranks_name_matches_above_prose_matches → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_search_ranks_name_matches_above_prose_matches → search |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_ranks_name_matches_above_prose_matches → search → search_counted → _class_candidates → class_rows → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_ranks_name_matches_above_prose_matches → search → search_counted → _class_candidates → class_rows |
| REQ-DDB-QUERY-012 | measured | test_search_ranks_name_matches_above_prose_matches → search |
Source · 7 lines
def test_search_ranks_name_matches_above_prose_matches(rich_db: Path) -> None:
"""A token in the identifier is stronger evidence than the same token in
prose, so an exact name match must not be buried under brief-only hits."""
hits = q.search(rich_db, "sensor_poll")
assert hits and hits[0].name == "sensor_poll"
Activity · 2 steps
test_search_still_finds_a_function_unchanged
None test_query.test_search_still_finds_a_function_unchanged(Path tmp_path)
THE SUCCESS-PATH CONTROL. A fix that surfaces classes by demoting functions trades one wrong negative for another, so the function corpus is asserted on the same database that now has classes in it — not on one where the new corpus is trivially empty.
Checks
assert [(h.name, h.kind) for h in hits] == [("redraw", "function")]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_search_still_finds_a_function_unchanged → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_search_still_finds_a_function_unchanged → search |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_search_still_finds_a_function_unchanged → search → search_counted → _class_candidates → class_rows → table_exists |
| REQ-DDB-QUERY-007 | measured | test_search_still_finds_a_function_unchanged → search → search_counted → _class_candidates → class_rows |
| REQ-DDB-QUERY-012 | measured | test_search_still_finds_a_function_unchanged → search |
Source · 9 lines
def test_search_still_finds_a_function_unchanged(tmp_path: Path) -> None:
"""THE SUCCESS-PATH CONTROL. A fix that surfaces classes by demoting functions
trades one wrong negative for another, so the function corpus is asserted on the
same database that now has classes in it — not on one where the new corpus is
trivially empty."""
hits = q.search(_class_db(tmp_path), "redraw")
assert [(h.name, h.kind) for h in hits] == [("redraw", "function")]
Activity · 2 steps
test_source_caps_and_flags_truncation
None test_query.test_source_caps_and_flags_truncation(Path rich_db, Path repo_root)
A comparison query layer shipped an UNBOUNDED source tool and one call returned 26 KB, distorting its own token accounting. The cap is the fix, so it is asserted: at most max_lines, truncated=True, and the reported end_line describes exactly what came back.
Checks
assert full is not None and len(full.lines) > 2assert capped is not Noneassert len(capped.lines) == 2assert capped.truncated is Trueassert capped.start_line == full.start_lineassert capped.end_line == full.start_line + 1assert capped.lines == full.lines[:2]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_source_caps_and_flags_truncation → source → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_source_caps_and_flags_truncation → source |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_source_caps_and_flags_truncation → source → function_candidates |
| REQ-DDB-QUERY-010 | measured | test_source_caps_and_flags_truncation → source → function_candidates |
Source · 17 lines
def test_source_caps_and_flags_truncation(rich_db: Path, repo_root: Path) -> None:
"""A comparison query layer shipped an UNBOUNDED source tool and one call
returned 26 KB, distorting its own token accounting. The cap is the fix, so
it is asserted: at most max_lines, truncated=True, and the reported
end_line describes exactly what came back."""
full = q.source(rich_db, "sensor_poll", repo_root)
assert full is not None and len(full.lines) > 2
capped = q.source(rich_db, "sensor_poll", repo_root, max_lines=2)
assert capped is not None
assert len(capped.lines) == 2
assert capped.truncated is True
assert capped.start_line == full.start_line
assert capped.end_line == full.start_line + 1
assert capped.lines == full.lines[:2]
Activity · 9 steps
test_source_returns_the_verbatim_body
None test_query.test_source_returns_the_verbatim_body(Path rich_db, Path repo_root)
The recorded body extent + the working tree yield the ACTUAL source text, not a reconstruction.
Checks
assert listing is not Noneassert listing.name == "sensor_poll"assert listing.file.endswith("sensor_driver.c")assert listing.truncated is Falseassert listing.end_line == listing.start_line + len(listing.lines) - 1assert "sensor_poll" in bodyassert "hw_read_battery_adc" in bodyassert listing.lines == on_disk[listing.start_line - 1 : listing.end_line]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_source_returns_the_verbatim_body → source → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_source_returns_the_verbatim_body → source |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_source_returns_the_verbatim_body → source → function_candidates |
| REQ-DDB-QUERY-010 | measured | test_source_returns_the_verbatim_body → source → function_candidates |
Source · 17 lines
def test_source_returns_the_verbatim_body(rich_db: Path, repo_root: Path) -> None:
"""The recorded body extent + the working tree yield the ACTUAL source
text, not a reconstruction."""
listing = q.source(rich_db, "sensor_poll", repo_root)
assert listing is not None
assert listing.name == "sensor_poll"
assert listing.file.endswith("sensor_driver.c")
assert listing.truncated is False
assert listing.end_line == listing.start_line + len(listing.lines) - 1
body = "\n".join(listing.lines)
assert "sensor_poll" in body
assert "hw_read_battery_adc" in body
# Verbatim: every returned line is the file's line at that number.
on_disk = (repo_root / listing.file).read_text(encoding="utf-8").splitlines()
assert listing.lines == on_disk[listing.start_line - 1 : listing.end_line]
Activity · 11 steps
test_source_unambiguous_has_no_candidates
None test_query.test_source_unambiguous_has_no_candidates(Path rich_db, Path repo_root)
A uniquely-named function's listing carries an empty `candidates`.
Checks
assert listing is not Noneassert listing.candidates == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_source_unambiguous_has_no_candidates → source → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_source_unambiguous_has_no_candidates → source |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_source_unambiguous_has_no_candidates → source → function_candidates |
| REQ-DDB-QUERY-010 | measured | test_source_unambiguous_has_no_candidates → source → function_candidates |
Source · 7 lines
def test_source_unambiguous_has_no_candidates(rich_db: Path, repo_root: Path) -> None:
"""A uniquely-named function's listing carries an empty `candidates`."""
listing = q.source(rich_db, "sensor_poll", repo_root)
assert listing is not None
assert listing.candidates == []
Activity · 3 steps
test_source_unknown_function_is_none
None test_query.test_source_unknown_function_is_none(Path rich_db, Path repo_root)
Checks
assert q.source(rich_db, "no_such_function_xyz", repo_root) is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_source_unknown_function_is_none → source → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_source_unknown_function_is_none → source |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_source_unknown_function_is_none → source → function_candidates |
| REQ-DDB-QUERY-010 | measured | test_source_unknown_function_is_none → source → function_candidates |
Source · 4 lines
def test_source_unknown_function_is_none(rich_db: Path, repo_root: Path) -> None:
assert q.source(rich_db, "no_such_function_xyz", repo_root) is None
Activity · 1 steps
test_source_unreadable_repo_root_is_none
None test_query.test_source_unreadable_repo_root_is_none(Path rich_db, Path tmp_path)
A wrong/empty working tree reports "no listing", never a traceback.
Checks
assert q.source(rich_db, "sensor_poll", tmp_path) is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_source_unreadable_repo_root_is_none → source → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_source_unreadable_repo_root_is_none → source |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_source_unreadable_repo_root_is_none → source → function_candidates |
| REQ-DDB-QUERY-010 | measured | test_source_unreadable_repo_root_is_none → source → function_candidates |
Source · 5 lines
def test_source_unreadable_repo_root_is_none(rich_db: Path, tmp_path: Path) -> None:
"""A wrong/empty working tree reports "no listing", never a traceback."""
assert q.source(rich_db, "sensor_poll", tmp_path) is None
Activity · 1 steps
test_thread_apis_empty_on_threadless_firmware
None test_query.test_thread_apis_empty_on_threadless_firmware(Path rich_db)
The fixture spawns no threads → an empty roster and an empty thread_of (the populated cases are covered by the unit tier).
Checks
assert roster.threads == ()assert roster.rows == 0assert roster.origin.total == 0assert "predates the thread layer" not in roster.row_meaningassert q.thread_of(rich_db, "sensor_poll") == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_thread_apis_empty_on_threadless_firmware → thread_roster |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_thread_apis_empty_on_threadless_firmware → thread_roster → table_exists |
| REQ-DDB-QUERY-004 | measured | test_thread_apis_empty_on_threadless_firmware → thread_of → threads_for_rowids |
| REQ-DDB-QUERY-011 | measured | test_thread_apis_empty_on_threadless_firmware → thread_roster |
Source · 18 lines
def test_thread_apis_empty_on_threadless_firmware(rich_db: Path) -> None:
"""The fixture spawns no threads → an empty roster and an empty thread_of (the
populated cases are covered by the unit tier).
AND THE EMPTY ROSTER MUST NOT CLAIM THE LAYER IS ABSENT. This index was built by the
current pipeline, so `threads` exists and really holds nothing; an index predating the
layer holds nothing too, and the two are different facts — one is about the code, the other
about the build. `row_meaning` is the only thing that separates them, so a roster that said
"predates the thread layer" here would be the absent-table-reads-as-no-threads failure with
the sentence attached."""
roster = q.thread_roster(rich_db)
assert roster.threads == ()
assert roster.rows == 0
assert roster.origin.total == 0
assert "predates the thread layer" not in roster.row_meaning
assert q.thread_of(rich_db, "sensor_poll") == []
Activity · 6 steps
test_thread_of_bare_ambiguous_name_returns_every_thread
None test_query.test_thread_of_bare_ambiguous_name_returns_every_thread(Path tmp_path)
The membership rows sit on DECLARATION rowids (a header-declared method has file_id != bodyfile_id), while the lone definition row for the name is an unrelated anon-namespace helper with no membership. Definition-preferring resolution therefore picked exactly the wrong rowid and answered "no threads"; a union question must consider every candidate.
Checks
assert sorted(t.name for t in q.thread_of(db, "rx_loop")) == [
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_thread_of_bare_ambiguous_name_returns_every_thread → thread_of |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_thread_of_bare_ambiguous_name_returns_every_thread → thread_of → rowids_for_name |
| REQ-DDB-QUERY-004 | measured | test_thread_of_bare_ambiguous_name_returns_every_thread → thread_of → threads_for_rowids |
Source · 16 lines
def test_thread_of_bare_ambiguous_name_returns_every_thread(tmp_path: Path) -> None:
"""The membership rows sit on DECLARATION rowids (a header-declared method
has file_id != bodyfile_id), while the lone definition row for the name is
an unrelated anon-namespace helper with no membership. Definition-preferring
resolution therefore picked exactly the wrong rowid and answered "no
threads"; a union question must consider every candidate."""
db = tmp_path / "threads.db"
_thread_db(db)
# sorted(), so the expectation must be in ASCII order: "Co..." < "Li..." < "Se...".
assert sorted(t.name for t in q.thread_of(db, "rx_loop")) == [
"CoLinkOwner::rx_loop",
"LinkOwner::rx_loop",
"SensorRuntime::rx_loop",
]
Activity · 3 steps
test_thread_of_qualified_match_respects_identifier_boundaries
None test_query.test_thread_of_qualified_match_respects_identifier_boundaries(Path tmp_path)
`CoLinkOwner::rx_loop` merely CONTAINS `LinkOwner::rx_loop`; a substring match would silently attribute the wrong thread.
Checks
assert [t.name for t in q.thread_of(db, "LinkOwner::rx_loop")] == ["LinkOwner::rx_loop"]assert [t.name for t in q.thread_of(db, "CoLinkOwner::rx_loop")] == ["CoLinkOwner::rx_loop"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_thread_of_qualified_match_respects_identifier_boundaries → thread_of |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_thread_of_qualified_match_respects_identifier_boundaries → thread_of → rowids_for_name |
| REQ-DDB-QUERY-004 | measured | test_thread_of_qualified_match_respects_identifier_boundaries → thread_of → threads_for_rowids |
Source · 9 lines
def test_thread_of_qualified_match_respects_identifier_boundaries(tmp_path: Path) -> None:
"""`CoLinkOwner::rx_loop` merely CONTAINS `LinkOwner::rx_loop`; a
substring match would silently attribute the wrong thread."""
db = tmp_path / "threads.db"
_thread_db(db)
assert [t.name for t in q.thread_of(db, "LinkOwner::rx_loop")] == ["LinkOwner::rx_loop"]
assert [t.name for t in q.thread_of(db, "CoLinkOwner::rx_loop")] == ["CoLinkOwner::rx_loop"]
Activity · 4 steps
test_thread_of_resolves_qualified_roster_names
None test_query.test_thread_of_resolves_qualified_roster_names(Path tmp_path)
Checks
assert [t.name for t in q.thread_of(db, "LinkOwner::rx_loop")] == ["LinkOwner::rx_loop"]assert [t.name for t in q.thread_of(db, "SensorRuntime::rx_loop")] == ["SensorRuntime::rx_loop"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_thread_of_resolves_qualified_roster_names → thread_of |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_thread_of_resolves_qualified_roster_names → thread_of → rowids_for_name |
| REQ-DDB-QUERY-004 | measured | test_thread_of_resolves_qualified_roster_names → thread_of → threads_for_rowids |
Source · 12 lines
def test_thread_of_resolves_qualified_roster_names(tmp_path: Path) -> None:
"""#42: `thread_roster` emits QUALIFIED entry names, but `thread_of`
resolved a single rowid off the UNQUALIFIED `memberdef.name` — so on a C++ codebase 11
of 12 roster names returned count=0, and the MCP envelope told the model
'This is a definitive empty result ... Do not retry'. A tool must be able to
consume the names its own sibling tool emits."""
db = tmp_path / "threads.db"
_thread_db(db)
assert [t.name for t in q.thread_of(db, "LinkOwner::rx_loop")] == ["LinkOwner::rx_loop"]
assert [t.name for t in q.thread_of(db, "SensorRuntime::rx_loop")] == ["SensorRuntime::rx_loop"]
Activity · 4 steps
test_token_hit_counts_sees_the_class_corpus
None test_query.test_token_hit_counts_sees_the_class_corpus(Path tmp_path)
The zero-result diagnosis counts each token over the corpora `search` reads. Leaving classes out of the count would report `0` for a token that matches a class and only a class — advising the caller to drop the one token that was working, which is gh#31's defect reintroduced through the new corpus.
Checks
assert counts["ishapewidget"] == 1assert counts["nosuchtoken"] == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_token_hit_counts_sees_the_class_corpus → token_hit_counts → connect |
| REQ-DDB-QUERY-002 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_token_hit_counts_sees_the_class_corpus → token_hit_counts → _one_token_count → table_exists |
| REQ-DDB-QUERY-007 | measured | test_token_hit_counts_sees_the_class_corpus → token_hit_counts |
Source · 10 lines
def test_token_hit_counts_sees_the_class_corpus(tmp_path: Path) -> None:
"""The zero-result diagnosis counts each token over the corpora `search` reads.
Leaving classes out of the count would report `0` for a token that matches a
class and only a class — advising the caller to drop the one token that was
working, which is gh#31's defect reintroduced through the new corpus."""
counts = q.token_hit_counts(_class_db(tmp_path), ["ishapewidget", "nosuchtoken"])
assert counts["ishapewidget"] == 1
assert counts["nosuchtoken"] == 0