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.

tests/test_query.py:1930

Show on the map →

Called by none

Calls _member_doc_db, prose_emptiness

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_a_prose_miss_is_graded_by_what_the_index_holds_elsewhere → prose_emptiness → has_prose_corpus → connect
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_a_prose_miss_is_graded_by_what_the_index_holds_elsewhere → prose_emptiness → has_prose_corpus → table_exists
REQ-DDB-QUERY-007measuredtest_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
lines 1944–1944from clew.mcp_server.emptiness import prose_emptinesslines 1946–1946db = _member_doc_db(tmp_path)lines 1948–1948elsewhere, extra = prose_emptiness(db, "PROJ_ALLOW_PRIVATE_ACCESS")lines 1949–1949assert "NOT DEFINITIVE" in elsewhere, f"the index holds this name: {elsewhere}"lines 1950–1950assert "token_hits" in extra, "and the claim must be checkable, not merely worded"lines 1953–1953nowhere, _extra = prose_emptiness(db, "zzz_absent_token_qqq")lines 1954–1957assert "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}" )

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.

tests/test_query.py:96

Checks

  • assert {i.name for i in rt.implementers} <= bulk_impl

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_all_req_edges_agrees_with_req_trace → req_trace
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_all_req_edges_agrees_with_req_trace → all_req_edges → table_exists
REQ-DDB-QUERY-004measuredtest_all_req_edges_agrees_with_req_trace → all_req_edges
REQ-DDB-QUERY-010measuredtest_all_req_edges_agrees_with_req_trace → req_trace → _req_implementers → resolve_rowid
REQ-DDB-SCHEMA-006measuredtest_all_req_edges_agrees_with_req_trace → req_trace → _req_failure_modes
REQ-DDB-SCHEMA-015measuredtest_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
lines 98–98rt = q.req_trace(rich_db, "REQ-0621")lines 99–99bulk_impl = {e.fn for e in q.all_req_edges(rich_db) if e.req_id == "REQ-0621"}lines 100–100assert {i.name for i in rt.implementers} <= bulk_impl

test_callees_merge_dataflow_tagged_as_key_not_call

None test_query.test_callees_merge_dataflow_tagged_as_key_not_call(Path rich_db)

tests/test_query.py:134

Show on the map →

Called by none

Calls all, callees

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_callees_merge_dataflow_tagged_as_key_not_call → callees
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_callees_merge_dataflow_tagged_as_key_not_call → callees → _call_edges → _dataflow_edges → resolve_rowid
REQ-DDB-QUERY-009measuredtest_callees_merge_dataflow_tagged_as_key_not_call → callees → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_callees_merge_dataflow_tagged_as_key_not_call → callees
REQ-DDB-WIKI-054inferredtest_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
lines 143–143merged = q.callees(rich_db, "sensor_poll")lines 144–144seam = [c for c in merged if c.name == "telemetry_report"]lines 145–145assert seam, "the dataflow neighbour must be present"lines 146–146assert all(c.edge_class == "key" for c in seam)lines 147–147assert {c.key_name for c in seam} == {"DEMOBOT_POWER_BATTERY_MV"}lines 148–148assert all(c.rowid > 0 for c in seam), "a dataflow neighbour is still name-resolved"lines 153–153assert len({c.source for c in seam}) == len(seam)lines 155–155call = next(c for c in merged if c.name == "hw_read_battery_adc")lines 156–156assert call.edge_class == "call"lines 157–157assert call.key_name is None

test_callees_of_writer

None test_query.test_callees_of_writer(Path rich_db)

tests/test_query.py:125

Show on the map →

Called by none

Calls callees

Checks

  • assert "hw_read_battery_adc" in names
  • assert "DataModel_Set_DEMOBOT_POWER_BATTERY_MV" in names

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_callees_of_writer → callees
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_callees_of_writer → callees → _call_edges → _dataflow_edges → resolve_rowid
REQ-DDB-QUERY-009measuredtest_callees_of_writer → callees → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_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
lines 126–126names = {c.name for c in q.callees(rich_db, "sensor_poll")}lines 127–127assert "hw_read_battery_adc" in nameslines 128–128assert "DataModel_Set_DEMOBOT_POWER_BATTERY_MV" in names

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.

tests/test_query.py:118

Show on the map →

Called by none

Calls callers

Checks

  • assert "event_bus_dispatch" in names

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_callers_includes_fnptr_dispatch → callers
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_callers_includes_fnptr_dispatch → callers → _call_edges → _dataflow_edges → resolve_rowid
REQ-DDB-QUERY-009measuredtest_callers_includes_fnptr_dispatch → callers → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_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
lines 121–121names = {c.name for c in q.callers(rich_db, "handle_cloud_command")}lines 122–122assert "event_bus_dispatch" in names

test_cap_at_depth_taper

None test_query.test_cap_at_depth_taper()

@req REQ-DDB-QUERY-002

tests/test_query.py:1039

Checks

  • 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

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001catalog
REQ-DDB-QUERY-002tagtest_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
lines 1040–1040assert _cap_at_depth(8, 1) == 8lines 1041–1041assert _cap_at_depth(8, 2) == 4lines 1042–1042assert _cap_at_depth(8, 4) == 1lines 1043–1043assert _cap_at_depth(8, 12) == 1lines 1044–1044assert _cap_at_depth(1, 3) == 1

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.

tests/test_query.py:410

Show on the map →

Called by none

Calls chain_trace

Checks

  • assert "sensor_poll" in {n.name for n in chain.nodes}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_chain_trace_backward_reaches_writer → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_chain_trace_backward_reaches_writer → chain_trace → connect
REQ-DDB-QUERY-002measuredtest_chain_trace_backward_reaches_writer → chain_trace
REQ-DDB-QUERY-003measuredtest_chain_trace_backward_reaches_writer → chain_trace → function_candidates
REQ-DDB-QUERY-005measuredtest_chain_trace_backward_reaches_writer → chain_trace → _make_node
REQ-DDB-QUERY-010measuredtest_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
lines 412–412chain = q.chain_trace(rich_db, "telemetry_report", direction="backward", max_depth=3)lines 413–413assert "sensor_poll" in {n.name for n in chain.nodes}

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.

tests/test_query.py:1112

Checks

  • assert len(key_hops) == 1
  • 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"
  • assert d_writer is not None
  • assert write.crosses_thread is True
  • assert write.to_thread == "consumer_thread"
  • assert [t.name for t in roster.threads] == ["consumer_thread"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_chain_trace_crosses_thread_key_hop → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_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-011inferredtest_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-012inferredtest_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-001measuredtest_chain_trace_crosses_thread_key_hop → thread_roster
REQ-DDB-QUERY-002measuredtest_chain_trace_crosses_thread_key_hop → chain_trace
REQ-DDB-QUERY-003measuredtest_chain_trace_crosses_thread_key_hop → thread_roster → table_exists
REQ-DDB-QUERY-004measuredtest_chain_trace_crosses_thread_key_hop → function_dossier
REQ-DDB-QUERY-005measuredtest_chain_trace_crosses_thread_key_hop → chain_trace → _make_node
REQ-DDB-QUERY-006measuredtest_chain_trace_crosses_thread_key_hop → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_chain_trace_crosses_thread_key_hop → function_dossier
REQ-DDB-QUERY-010measuredtest_chain_trace_crosses_thread_key_hop → function_dossier
REQ-DDB-QUERY-011measuredtest_chain_trace_crosses_thread_key_hop → thread_roster
REQ-DDB-QUERY-012measuredtest_chain_trace_crosses_thread_key_hop → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_chain_trace_crosses_thread_key_hop → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_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
lines 1115–1115db = _hand_db(tmp_path, [(1, "producer"), (2, "consumer")])lines 1116–1116conn = sqlite3.connect(str(db))lines 1117–1124conn.execute( """ CREATE TABLE threads ( id INTEGER PRIMARY KEY, name TEXT, entry_memberdef_rowid INTEGER, kind TEXT, source TEXT, confidence TEXT ) """, )lines 1125–1128conn.execute( "INSERT INTO threads (id, name, entry_memberdef_rowid, kind, source, " "confidence) VALUES (7, 'consumer_thread', 2, 'task', 'ast_spawn', 'medium')", )lines 1129–1138conn.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 ) """, )lines 1139–1145conn.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)", )lines 1146–1146conn.commit()lines 1147–1147conn.close()lines 1149–1149chain = q.chain_trace(db, "producer", max_depth=3)lines 1150–1150key_hops = [h for h in chain.hops if h.edge_class == "key"]lines 1151–1151assert len(key_hops) == 1lines 1152–1152hop = key_hops[0]lines 1153–1153assert (hop.from_name, hop.to_name) == ("producer", "consumer")lines 1154–1154assert hop.crosses_thread is Truelines 1155–1155assert hop.dispatch_mode == "queued"lines 1156–1156assert hop.to_thread == "consumer_thread"lines 1159–1159d_writer = q.function_dossier(db, "producer")lines 1160–1160assert d_writer is not Nonelines 1161–1161write = d_writer.writes[0]lines 1162–1162assert write.crosses_thread is Truelines 1163–1163assert write.to_thread == "consumer_thread"lines 1166–1166roster = q.thread_roster(db)lines 1167–1167assert [t.name for t in roster.threads] == ["consumer_thread"]

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.

tests/test_query.py:1047

Show on the map →

Called by none

Calls _hand_db, chain_trace

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

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_chain_trace_cycle_bounded_by_path → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_chain_trace_cycle_bounded_by_path → chain_trace → connect
REQ-DDB-QUERY-002measuredtest_chain_trace_cycle_bounded_by_path → chain_trace
REQ-DDB-QUERY-003measuredtest_chain_trace_cycle_bounded_by_path → chain_trace → function_candidates
REQ-DDB-QUERY-005measuredtest_chain_trace_cycle_bounded_by_path → chain_trace → _make_node
REQ-DDB-QUERY-010measuredtest_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
lines 1050–1054db = _hand_db( tmp_path, [(1, "a"), (2, "b")], call_edges=[(1, 2), (2, 1)], )lines 1055–1055chain = q.chain_trace(db, "a", max_depth=10)lines 1056–1056assert {n.name for n in chain.nodes} == {"a", "b"}lines 1057–1057assert {(h.from_name, h.to_name) for h in chain.hops} == {("a", "b"), ("b", "a")}

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).

tests/test_query.py:1060

Show on the map →

Called by none

Calls _hand_db, chain_trace

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

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_chain_trace_depth_cap → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_chain_trace_depth_cap → chain_trace → connect
REQ-DDB-QUERY-002measuredtest_chain_trace_depth_cap → chain_trace
REQ-DDB-QUERY-003measuredtest_chain_trace_depth_cap → chain_trace → function_candidates
REQ-DDB-QUERY-005measuredtest_chain_trace_depth_cap → chain_trace → _make_node
REQ-DDB-QUERY-010measuredtest_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
lines 1062–1066db = _hand_db( tmp_path, [(1, "a"), (2, "b"), (3, "c"), (4, "d"), (5, "e")], call_edges=[(1, 2), (2, 3), (3, 4), (4, 5)], )lines 1067–1067chain = q.chain_trace(db, "a", max_depth=2)lines 1068–1068by_name = {n.name: n.depth for n in chain.nodes}lines 1069–1069assert set(by_name) == {"a", "b", "c"}lines 1070–1070assert by_name == {"a": 0, "b": 1, "c": 2}lines 1071–1071assert "d" not in by_name

test_chain_trace_direction_aliases_and_rejects_unknown

None test_query.test_chain_trace_direction_aliases_and_rejects_unknown(Path rich_db)

tests/test_query.py:416

Show on the map →

Called by none

Calls chain_trace

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

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_chain_trace_direction_aliases_and_rejects_unknown → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_chain_trace_direction_aliases_and_rejects_unknown → chain_trace → connect
REQ-DDB-QUERY-002measuredtest_chain_trace_direction_aliases_and_rejects_unknown → chain_trace
REQ-DDB-QUERY-003measuredtest_chain_trace_direction_aliases_and_rejects_unknown → chain_trace → function_candidates
REQ-DDB-QUERY-005measuredtest_chain_trace_direction_aliases_and_rejects_unknown → chain_trace → _make_node
REQ-DDB-QUERY-010measuredtest_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
lines 426–426backward = q.chain_trace(rich_db, "telemetry_report", direction="backward", max_depth=3)lines 427–427assert "sensor_poll" in {n.name for n in backward.nodes}lines 430–430◇ for alias in ("backwards", "upstream", "BACKWARD", " Backward ")lines 431–431chain = q.chain_trace(rich_db, "telemetry_report", direction=alias, max_depth=3)lines 432–432assert chain.direction == "backward", f"{alias!r} must normalize, not echo"lines 433–433assert {n.name for n in chain.nodes} == {n.name for n in backward.nodes}lines 435–435forward = q.chain_trace(rich_db, "sensor_poll", direction="forward", max_depth=3)lines 436–436◇ for alias in ("forwards", "downstream", "FORWARD")lines 437–437chain = q.chain_trace(rich_db, "sensor_poll", direction=alias, max_depth=3)lines 438–438assert chain.direction == "forward"lines 439–439assert {n.name for n in chain.nodes} == {n.name for n in forward.nodes}lines 442–442◇ for bogus in ("sideways", "up", "")lines 443–443with pytest.raises(ValueError, match="unknown direction")lines 444–444q.chain_trace(rich_db, "sensor_poll", direction=bogus)

test_chain_trace_forward_crosses_shared_key_seam

None test_query.test_chain_trace_forward_crosses_shared_key_seam(Path rich_db)

Forward from the writer, the chain crosses the shared-key seam (sensor_poll → telemetry_report) as a 'key' hop, not a call hop.

tests/test_query.py:393

Show on the map →

Called by none

Calls chain_trace

Checks

  • assert "telemetry_report" in node_names
  • assert len(key_hops) == 1
  • assert key_hops[0].key_name == "DEMOBOT_POWER_BATTERY_MV"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_chain_trace_forward_crosses_shared_key_seam → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_chain_trace_forward_crosses_shared_key_seam → chain_trace → connect
REQ-DDB-QUERY-002measuredtest_chain_trace_forward_crosses_shared_key_seam → chain_trace
REQ-DDB-QUERY-003measuredtest_chain_trace_forward_crosses_shared_key_seam → chain_trace → function_candidates
REQ-DDB-QUERY-005measuredtest_chain_trace_forward_crosses_shared_key_seam → chain_trace → _make_node
REQ-DDB-QUERY-010measuredtest_chain_trace_forward_crosses_shared_key_seam → chain_trace → function_candidates
Source · 17 lines
def test_chain_trace_forward_crosses_shared_key_seam(rich_db: Path) -> None:
    """Forward from the writer, the chain crosses the shared-key seam
    (sensor_poll → telemetry_report) as a 'key' hop, not a call hop."""
    chain = q.chain_trace(rich_db, "sensor_poll", max_depth=3)
    node_names = {n.name for n in chain.nodes}
    assert "telemetry_report" in node_names
    key_hops = [
        h
        for h in chain.hops
        if h.edge_class == "key"
        and h.from_name == "sensor_poll"
        and h.to_name == "telemetry_report"
    ]
    assert len(key_hops) == 1
    assert key_hops[0].key_name == "DEMOBOT_POWER_BATTERY_MV"

Activity · 6 steps
lines 396–396chain = q.chain_trace(rich_db, "sensor_poll", max_depth=3)lines 397–397node_names = {n.name for n in chain.nodes}lines 398–398assert "telemetry_report" in node_nameslines 399–405key_hops = [ h for h in chain.hops if h.edge_class == "key" and h.from_name == "sensor_poll" and h.to_name == "telemetry_report" ]lines 406–406assert len(key_hops) == 1lines 407–407assert key_hops[0].key_name == "DEMOBOT_POWER_BATTERY_MV"

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.)

tests/test_query.py:532

Show on the map →

Called by none

Calls _overload_db, chain_trace

Checks

  • assert chain.seed == "publish"
  • assert {c.signature for c in chain.candidates} == {"bool A::publish", "bool B::publish"}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_chain_trace_overloaded_seed_surfaces_candidates → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_chain_trace_overloaded_seed_surfaces_candidates → chain_trace → connect
REQ-DDB-QUERY-002measuredtest_chain_trace_overloaded_seed_surfaces_candidates → chain_trace
REQ-DDB-QUERY-003measuredtest_chain_trace_overloaded_seed_surfaces_candidates → chain_trace → function_candidates
REQ-DDB-QUERY-005measuredtest_chain_trace_overloaded_seed_surfaces_candidates → chain_trace → _make_node
REQ-DDB-QUERY-010measuredtest_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
lines 537–543db = _overload_db( tmp_path, [ (30, "publish", "bool A::publish", "src/a.cpp", True), (31, "publish", "bool B::publish", "src/b.cpp", True), ], )lines 544–544chain = q.chain_trace(db, "publish")lines 545–545assert chain.seed == "publish"lines 546–546assert {c.signature for c in chain.candidates} == {"bool A::publish", "bool B::publish"}

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

tests/test_query.py:470

Show on the map →

Called by none

Calls all, chain_trace

Checks

  • assert root.omitted == callees - cap
  • assert len([h for h in chain.hops if h.from_name == "root"]) == cap
  • assert root.omitted + cap == callees
  • assert 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

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_chain_trace_records_what_the_fanout_taper_dropped → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_chain_trace_records_what_the_fanout_taper_dropped → chain_trace → connect
REQ-DDB-QUERY-002tagtest_chain_trace_records_what_the_fanout_taper_dropped → chain_trace
REQ-DDB-QUERY-003measuredtest_chain_trace_records_what_the_fanout_taper_dropped → chain_trace → function_candidates
REQ-DDB-QUERY-005measuredtest_chain_trace_records_what_the_fanout_taper_dropped → chain_trace → _make_node
REQ-DDB-QUERY-010measuredtest_chain_trace_records_what_the_fanout_taper_dropped → chain_trace → function_candidates
REQ-DDB-WIKI-054inferredtest_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
lines 483–483db = tmp_path / "taper.db"lines 484–484conn = sqlite3.connect(str(db))lines 485–485callees = 12lines 486–486cap = 4lines 487–489rows = ", ".join( f"({10 + i}, 'function', 'callee_{i:02d}', 'void callee_{i:02d}()')" for i in range(callees) )lines 490–490edges = ", ".join(f"(1, {10 + i}, 'ast', 'resolved')" for i in range(callees))lines 491–501conn.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};" )lines 502–502conn.commit()lines 503–503conn.close()lines 505–505chain = q.chain_trace(db, "root", direction="forward", max_depth=2, max_neighbors=cap)lines 506–506root = next(n for n in chain.nodes if n.name == "root")lines 510–510assert root.omitted == callees - caplines 511–511assert len([h for h in chain.hops if h.from_name == "root"]) == caplines 512–512assert root.omitted + cap == calleeslines 516–516leaves = [n for n in chain.nodes if n.name != "root"]lines 517–517assert leaves, "the fixture must reach the callees"lines 518–518assert all(n.omitted == 0 for n in leaves)lines 521–521roomy = q.chain_trace(db, "root", direction="forward", max_depth=2, max_neighbors=99)lines 522–522assert next(n for n in roomy.nodes if n.name == "root").omitted == 0

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.

tests/test_query.py:1074

Show on the map →

Called by none

Calls _hand_db, chain_trace

Checks

  • assert "invoke_cb" in names
  • assert "beyond" not in names # branch terminated at the boundary
  • 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"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_chain_trace_terminates_at_external_boundary → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_chain_trace_terminates_at_external_boundary → chain_trace → connect
REQ-DDB-QUERY-002measuredtest_chain_trace_terminates_at_external_boundary → chain_trace
REQ-DDB-QUERY-003measuredtest_chain_trace_terminates_at_external_boundary → chain_trace → function_candidates
REQ-DDB-QUERY-005measuredtest_chain_trace_terminates_at_external_boundary → chain_trace → _make_node
REQ-DDB-QUERY-010measuredtest_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
lines 1077–1082db = _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)], )lines 1083–1083conn = sqlite3.connect(str(db))lines 1084–1092conn.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 ) """, )lines 1093–1097conn.execute( "INSERT INTO external_boundaries (memberdef_rowid, global_name, kind, " "registered_by_rowid, confidence) VALUES " "(2, 'svc_notify_cb', 'unresolved_callback', 4, 'high')", )lines 1098–1098conn.commit()lines 1099–1099conn.close()lines 1101–1101chain = q.chain_trace(db, "entry", max_depth=6)lines 1102–1102names = {n.name for n in chain.nodes}lines 1103–1103assert "invoke_cb" in nameslines 1104–1104assert "beyond" not in nameslines 1105–1105term = next(n for n in chain.nodes if n.name == "invoke_cb")lines 1106–1106assert term.is_terminus is Truelines 1107–1107assert term.termini[0].global_name == "svc_notify_cb"lines 1108–1108assert term.termini[0].registered_by == "register_cb"lines 1109–1109assert term.termini[0].kind == "unresolved_callback"

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.

tests/test_query.py:549

Show on the map →

Called by none

Calls chain_trace

Checks

  • assert chain.candidates == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_chain_trace_unambiguous_seed_has_no_candidates → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_chain_trace_unambiguous_seed_has_no_candidates → chain_trace → connect
REQ-DDB-QUERY-002measuredtest_chain_trace_unambiguous_seed_has_no_candidates → chain_trace
REQ-DDB-QUERY-003measuredtest_chain_trace_unambiguous_seed_has_no_candidates → chain_trace → function_candidates
REQ-DDB-QUERY-005measuredtest_chain_trace_unambiguous_seed_has_no_candidates → chain_trace → _make_node
REQ-DDB-QUERY-010measuredtest_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
lines 551–551chain = q.chain_trace(rich_db, "sensor_poll", max_depth=1)lines 552–552assert chain.candidates == []

test_chain_trace_unknown_seed_is_empty

None test_query.test_chain_trace_unknown_seed_is_empty(Path rich_db)

tests/test_query.py:525

Show on the map →

Called by none

Calls chain_trace

Checks

  • assert chain.nodes == []
  • assert chain.hops == []
  • assert chain.candidates == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_chain_trace_unknown_seed_is_empty → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_chain_trace_unknown_seed_is_empty → chain_trace → connect
REQ-DDB-QUERY-002measuredtest_chain_trace_unknown_seed_is_empty → chain_trace
REQ-DDB-QUERY-003measuredtest_chain_trace_unknown_seed_is_empty → chain_trace → function_candidates
REQ-DDB-QUERY-005inferredtest_chain_trace_unknown_seed_is_empty → chain_trace → _make_node
REQ-DDB-QUERY-010measuredtest_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
lines 526–526chain = q.chain_trace(rich_db, "no_such_function_xyz")lines 527–527assert chain.nodes == []lines 528–528assert chain.hops == []lines 529–529assert chain.candidates == []

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.

tests/test_query.py:1706

Show on the map →

Called by none

Calls _name_collision_db, callees

Checks

  • assert sorted(callees) == ["_classify", "plain"], "an unambiguous caller keeps its fan-out"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_collision_free_names_are_unaffected → callees
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_collision_free_names_are_unaffected → callees → _call_edges → _dataflow_edges → resolve_rowid
REQ-DDB-QUERY-009measuredtest_collision_free_names_are_unaffected → callees → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_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
lines 1711–1711db = tmp_path / "collide.db"lines 1712–1712_name_collision_db(db)lines 1714–1714callees = [c.name for c in q.callees(db, "_guard_scope") if c.edge_class == "call"]lines 1715–1715assert sorted(callees) == ["_classify", "plain"], "an unambiguous caller keeps its fan-out"

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.

tests/test_query.py:185

Show on the map →

Called by none

Calls _all_function_names, callees, callers

Checks

  • assert edge.confidence in CALL_MATCH, edge
  • assert edge.strength is None, edge
  • assert edge.strength in KEY_STRENGTH, edge
  • assert edge.confidence is None, edge
  • assert seen == {"call", "key"}, "the sweep must actually observe both classes"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_confidence_and_strength_are_never_mixed_in_one_field → callers
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_confidence_and_strength_are_never_mixed_in_one_field → callers → _call_edges → _dataflow_edges → resolve_rowid
REQ-DDB-QUERY-009measuredtest_confidence_and_strength_are_never_mixed_in_one_field → callers → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_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
lines 195–195from clew.vocabulary import CALL_MATCH, KEY_STRENGTHlines 197–197seen = set()lines 198–198◇ for name in _all_function_names(rich_db)lines 199–199◇ for edge in q.callers(rich_db, name) + q.callees(rich_db, name)lines 200–200seen.add(edge.edge_class)lines 201–201◇ if edge.edge_class == "call"lines 202–202assert edge.confidence in CALL_MATCH, edgelines 203–203assert edge.strength is None, edgelines 204–204elselines 205–205assert edge.strength in KEY_STRENGTH, edgelines 206–206assert edge.confidence is None, edgelines 207–207assert seen == {"call", "key"}, "the sweep must actually observe both classes"

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

tests/test_query.py:161

Checks

  • assert upstream == {k.other for k in key_edges(conn, "telemetry_report", as_writer=False)}
  • assert "sensor_poll" in upstream
  • assert downstream == {k.other for k in key_edges(conn, "sensor_poll", as_writer=True)}
  • assert "telemetry_report" in downstream

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_dataflow_polarity_is_the_writer_side_of_callers → callers
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_dataflow_polarity_is_the_writer_side_of_callers → key_edges → resolve_rowid
REQ-DDB-QUERY-004tagtest_dataflow_polarity_is_the_writer_side_of_callers → key_edges
REQ-DDB-QUERY-009measuredtest_dataflow_polarity_is_the_writer_side_of_callers → callers → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_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
lines 167–167import sqlite3 as _sqlite3lines 169–169from clew.query.symbols import key_edgeslines 171–171conn = _sqlite3.connect(str(rich_db))lines 172–172trylines 174–174upstream = {c.name for c in q.callers(rich_db, "telemetry_report") if c.edge_class == "key"}lines 175–175assert upstream == {k.other for k in key_edges(conn, "telemetry_report", as_writer=False)}lines 176–176assert "sensor_poll" in upstreamlines 178–178downstream = {c.name for c in q.callees(rich_db, "sensor_poll") if c.edge_class == "key"}lines 179–179assert downstream == {k.other for k in key_edges(conn, "sensor_poll", as_writer=True)}lines 180–180assert "telemetry_report" in downstream

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.

tests/test_query.py:1718

Checks

  • assert len(rowids) == 2, "the decl and the def are ONE function, not two"
  • assert "hw_read_battery_adc" in callees
  • assert "app_run" in callers

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_decl_def_duality_keeps_its_edges → connect
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_decl_def_duality_keeps_its_edges → identity_rowids
REQ-DDB-QUERY-009measuredtest_decl_def_duality_keeps_its_edges → callers → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_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
lines 1733–1733from clew.query._common import connect, identity_rowidslines 1735–1735with connect(rich_db) as connlines 1736–1736rowids = identity_rowids(conn, "sensor_poll")lines 1737–1737assert len(rowids) == 2, "the decl and the def are ONE function, not two"lines 1739–1739callees = {c.name for c in q.callees(rich_db, "sensor_poll") if c.edge_class == "call"}lines 1740–1740assert "hw_read_battery_adc" in calleeslines 1741–1741callers = {c.name for c in q.callers(rich_db, "sensor_poll") if c.edge_class == "call"}lines 1742–1742assert "app_run" in callers

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.

tests/test_query.py:226

Checks

  • 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}
  • assert hits, "the seam must still be reported, under writes"
  • assert len({w.source for w in hits}) == len(hits)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_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-011inferredtest_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-012inferredtest_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-001measuredtest_dossier_does_not_double_report_dataflow → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_dossier_does_not_double_report_dataflow → function_dossier
REQ-DDB-QUERY-006measuredtest_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_dossier_does_not_double_report_dataflow → function_dossier
REQ-DDB-QUERY-010measuredtest_dossier_does_not_double_report_dataflow → function_dossier
REQ-DDB-QUERY-012measuredtest_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_dossier_does_not_double_report_dataflow → function_dossier → _dossier_conn → locks_held_for_rowids
REQ-DDB-WIKI-054inferredtest_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
lines 231–231d = q.function_dossier(rich_db, "sensor_poll")lines 232–232assert d is not Nonelines 233–233assert all(c.edge_class == "call" for c in d.callers + d.callees)lines 234–234assert "telemetry_report" not in {c.name for c in d.callees}lines 235–235hits = [w for w in d.writes if w.other == "telemetry_report"]lines 236–236assert hits, "the seam must still be reported, under writes"lines 239–239assert len({w.source for w in hits}) == len(hits)

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.

tests/test_query.py:86

Checks

  • assert d is not None
  • assert "sensor_poll" in reads
  • assert any(r.req_id == "REQ-0400" for r in d.requirements)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_dossier_reader_and_requirements → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_dossier_reader_and_requirements → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011inferredtest_dossier_reader_and_requirements → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_dossier_reader_and_requirements → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_dossier_reader_and_requirements → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_dossier_reader_and_requirements → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_dossier_reader_and_requirements → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_dossier_reader_and_requirements → function_dossier
REQ-DDB-QUERY-006measuredtest_dossier_reader_and_requirements → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_dossier_reader_and_requirements → function_dossier
REQ-DDB-QUERY-010measuredtest_dossier_reader_and_requirements → function_dossier
REQ-DDB-QUERY-012measuredtest_dossier_reader_and_requirements → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_dossier_reader_and_requirements → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_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
lines 89–89d = q.function_dossier(rich_db, "telemetry_report")lines 90–90assert d is not Nonelines 91–91reads = {r.other for r in d.reads if r.key_name == "DEMOBOT_POWER_BATTERY_MV"}lines 92–92assert "sensor_poll" in readslines 93–93assert any(r.req_id == "REQ-0400" for r in d.requirements)

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.

tests/test_query.py:107

Checks

  • assert d is not None
  • assert d.candidates == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_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-011inferredtest_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-012inferredtest_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_dossier_unambiguous_has_no_candidates → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_dossier_unambiguous_has_no_candidates → function_dossier
REQ-DDB-QUERY-006measuredtest_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_dossier_unambiguous_has_no_candidates → function_dossier
REQ-DDB-QUERY-010measuredtest_dossier_unambiguous_has_no_candidates → function_dossier
REQ-DDB-QUERY-012measuredtest_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_dossier_unambiguous_has_no_candidates → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_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
lines 110–110d = q.function_dossier(rich_db, "sensor_poll")lines 111–111assert d is not Nonelines 112–112assert d.candidates == []

test_dossier_unknown_function_is_none

None test_query.test_dossier_unknown_function_is_none(Path rich_db)

tests/test_query.py:103

Checks

  • assert q.function_dossier(rich_db, "no_such_function_xyz") is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_dossier_unknown_function_is_none → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_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-011inferredtest_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-012inferredtest_dossier_unknown_function_is_none → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_dossier_unknown_function_is_none → function_dossier → connect
REQ-DDB-QUERY-002catalogtest_dossier_unknown_function_is_none → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_dossier_unknown_function_is_none → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_dossier_unknown_function_is_none → function_dossier
REQ-DDB-QUERY-006inferredtest_dossier_unknown_function_is_none → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_dossier_unknown_function_is_none → function_dossier
REQ-DDB-QUERY-010measuredtest_dossier_unknown_function_is_none → function_dossier
REQ-DDB-QUERY-012measuredtest_dossier_unknown_function_is_none → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_dossier_unknown_function_is_none → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011inferredtest_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
lines 104–104assert q.function_dossier(rich_db, "no_such_function_xyz") is None

test_dossier_writer_has_shared_key_and_r1_fields

None test_query.test_dossier_writer_has_shared_key_and_r1_fields(Path rich_db)

sensor_poll writes DEMOBOT_POWER_BATTERY_MV → telemetry_report; the KeyEdge carries the R1 dispatch/thread fields.

tests/test_query.py:67

Checks

  • assert d is not None
  • assert "telemetry_report" in writes
  • assert edge.dispatch_mode == "unknown"
  • assert edge.edge_triggered is None
  • assert edge.crosses_thread is None
  • assert edge.to_thread is None
  • assert ("shared_key_declared", "state") in kinds

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011inferredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier
REQ-DDB-QUERY-006measuredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier
REQ-DDB-QUERY-010measuredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier
REQ-DDB-QUERY-012measuredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_dossier_writer_has_shared_key_and_r1_fields → function_dossier → _dossier_conn → locks_held_for_rowids
Source · 19 lines
def test_dossier_writer_has_shared_key_and_r1_fields(rich_db: Path) -> None:
    """sensor_poll writes DEMOBOT_POWER_BATTERY_MV → telemetry_report; the
    KeyEdge carries the R1 dispatch/thread fields."""
    d = q.function_dossier(rich_db, "sensor_poll")
    assert d is not None
    writes = {w.other: w for w in d.writes if w.key_name == "DEMOBOT_POWER_BATTERY_MV"}
    assert "telemetry_report" in writes
    edge = writes["telemetry_report"]
    # R1 semantic fields present on every KeyEdge (unknown/None here — the
    # fixture declares no dispatch_mode/edge_triggered).
    assert edge.dispatch_mode == "unknown"
    assert edge.edge_triggered is None
    assert edge.crosses_thread is None
    assert edge.to_thread is None
    # A declared (state) edge and an inferred edge both surface.
    kinds = {(w.source, w.edge_kind) for w in d.writes}
    assert ("shared_key_declared", "state") in kinds

Activity · 11 steps
lines 70–70d = q.function_dossier(rich_db, "sensor_poll")lines 71–71assert d is not Nonelines 72–72writes = {w.other: w for w in d.writes if w.key_name == "DEMOBOT_POWER_BATTERY_MV"}lines 73–73assert "telemetry_report" in writeslines 74–74edge = writes["telemetry_report"]lines 77–77assert edge.dispatch_mode == "unknown"lines 78–78assert edge.edge_triggered is Nonelines 79–79assert edge.crosses_thread is Nonelines 80–80assert edge.to_thread is Nonelines 82–82kinds = {(w.source, w.edge_kind) for w in d.writes}lines 83–83assert ("shared_key_declared", "state") in kinds

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).

tests/test_query.py:53

Checks

  • 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 == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_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-011inferredtest_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-012inferredtest_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_dossier_writer_identity_and_liveness → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_dossier_writer_identity_and_liveness → function_dossier
REQ-DDB-QUERY-006measuredtest_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_dossier_writer_identity_and_liveness → function_dossier
REQ-DDB-QUERY-010measuredtest_dossier_writer_identity_and_liveness → function_dossier
REQ-DDB-QUERY-012measuredtest_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_dossier_writer_identity_and_liveness → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_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
lines 57–57d = q.function_dossier(rich_db, "sensor_poll")lines 58–58assert d is not Nonelines 59–59assert d.name == "sensor_poll"lines 60–60assert d.signature == "void sensor_poll(void)"lines 61–61assert d.liveness == "live"lines 62–62assert d.is_terminus is Falselines 63–63assert d.threads == []lines 64–64assert d.termini == []

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.

tests/test_query.py:304

Show on the map →

Called by none

Calls _all_function_names, callees, chain_trace

Checks

  • assert observed <= set(EDGE_CLASS.values)
  • assert observed == {"call", "key"}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_edge_class_is_exactly_the_registered_vocabulary → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_edge_class_is_exactly_the_registered_vocabulary → callees
REQ-DDB-QUERY-002measuredtest_edge_class_is_exactly_the_registered_vocabulary → chain_trace
REQ-DDB-QUERY-003measuredtest_edge_class_is_exactly_the_registered_vocabulary → chain_trace → function_candidates
REQ-DDB-QUERY-005measuredtest_edge_class_is_exactly_the_registered_vocabulary → chain_trace → _make_node
REQ-DDB-QUERY-009measuredtest_edge_class_is_exactly_the_registered_vocabulary → callees → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_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
lines 308–308from clew.vocabulary import EDGE_CLASSlines 310–310observed = {c.edge_class for n in _all_function_names(rich_db) for c in q.callees(rich_db, n)}lines 311–311observed |= {h.edge_class for h in q.chain_trace(rich_db, "sensor_poll", max_depth=4).hops}lines 312–312assert observed <= set(EDGE_CLASS.values)lines 313–313assert observed == {"call", "key"}

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.

tests/test_query.py:447

Show on the map →

Called by none

Calls chain_trace

Checks

  • assert match, "the dossier `direction` parameter description was not found"
  • assert offered, match.group(1)
  • assert chain.direction in ("forward", "backward"), word
  • assert back.direction == "backward"
  • assert "sensor_poll" in {n.name for n in back.nodes}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_every_direction_word_the_served_text_offers_is_accepted → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_every_direction_word_the_served_text_offers_is_accepted → chain_trace → connect
REQ-DDB-QUERY-002measuredtest_every_direction_word_the_served_text_offers_is_accepted → chain_trace
REQ-DDB-QUERY-003measuredtest_every_direction_word_the_served_text_offers_is_accepted → chain_trace → function_candidates
REQ-DDB-QUERY-005measuredtest_every_direction_word_the_served_text_offers_is_accepted → chain_trace → _make_node
REQ-DDB-QUERY-010measuredtest_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
lines 452–452import relines 454–454from clew.mcp_server import tools_querylines 456–456source = Path(tools_query.__file__).read_text(encoding="utf-8")lines 457–457match = re.search(r"Field\(description=\"([^\"]*for downstream[^\"]*)\"\)", source)lines 458–458assert match, "the dossier `direction` parameter description was not found"lines 459–459offered = re.findall(r"'([a-z]+)'", match.group(1))lines 460–460assert offered, match.group(1)lines 461–461◇ for word in offeredlines 462–462chain = q.chain_trace(rich_db, "telemetry_report", direction=word, max_depth=2)lines 463–463assert chain.direction in ("forward", "backward"), wordlines 464–464back = q.chain_trace(rich_db, "telemetry_report", direction="back", max_depth=3)lines 465–465assert back.direction == "backward"lines 466–466assert "sensor_poll" in {n.name for n in back.nodes}

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.

tests/test_query.py:1681

Show on the map →

Called by none

Calls _name_collision_db, callers, connect, identity_rowids

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_genuine_recursion_survives_the_identity_split → connect
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_genuine_recursion_survives_the_identity_split → identity_rowids
REQ-DDB-QUERY-009measuredtest_genuine_recursion_survives_the_identity_split → callers → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_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
lines 1687–1687db = tmp_path / "collide.db"lines 1688–1688_name_collision_db(db)lines 1691–1691scope_callers = q.callers(db, "_classify")lines 1692–1692assert "_guard_scope" not in {c.name for c in scope_callers}lines 1696–1696from clew.query._common import connect, identity_rowidslines 1698–1698with connect(db) as connlines 1699–1699assert identity_rowids(conn, "_classify") == [1], "bare name resolves to ONE identity"lines 1700–1702rows = conn.execute( "SELECT caller_rowid, callee_rowid FROM call_edges WHERE caller_rowid = callee_rowid" ).fetchall()lines 1703–1703assert rows == [(3, 3)], "scope._classify's recursion is untouched in the db"

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.

tests/test_query.py:210

Show on the map →

Called by none

Calls chain_trace

Checks

  • assert hop.confidence in CALL_MATCH and hop.strength is None, hop
  • assert hop.strength in KEY_STRENGTH and hop.confidence is None, hop
  • assert classes == {"call", "key"}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_hop_confidence_and_strength_are_split_too → chain_trace → candidate_rows → symbol_provenance
REQ-DDB-QUERY-001measuredtest_hop_confidence_and_strength_are_split_too → chain_trace → connect
REQ-DDB-QUERY-002measuredtest_hop_confidence_and_strength_are_split_too → chain_trace
REQ-DDB-QUERY-003measuredtest_hop_confidence_and_strength_are_split_too → chain_trace → function_candidates
REQ-DDB-QUERY-005measuredtest_hop_confidence_and_strength_are_split_too → chain_trace → _make_node
REQ-DDB-QUERY-010measuredtest_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
lines 213–213from clew.vocabulary import CALL_MATCH, KEY_STRENGTHlines 215–215chain = q.chain_trace(rich_db, "sensor_poll", max_depth=3)lines 216–216classes = set()lines 217–217◇ for hop in chain.hopslines 218–218classes.add(hop.edge_class)lines 219–219◇ if hop.edge_class == "call"lines 220–220assert hop.confidence in CALL_MATCH and hop.strength is None, hoplines 221–221elselines 222–222assert hop.strength in KEY_STRENGTH and hop.confidence is None, hoplines 223–223assert classes == {"call", "key"}

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.

tests/test_query.py:882

Show on the map →

Called by none

Calls list_files

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_list_files_inventory → list_files
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_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
lines 886–886files = q.list_files(rich_db)lines 887–887paths = [f.path for f in files]lines 888–888assert paths == sorted(paths)lines 889–889assert not [p for p in paths if p.startswith("[")], "synthetic path rows must be excluded"lines 890–890assert any(p.endswith("sensor_driver.c") for p in paths)lines 891–891assert any(f.symbol_count > 0 for f in files)

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.

tests/test_query.py:894

Show on the map →

Called by none

Calls all, list_files

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_list_files_pattern_is_a_glob_over_path_or_filename → list_files
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_list_files_pattern_is_a_glob_over_path_or_filename → list_files → table_exists
REQ-DDB-WIKI-054inferredtest_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
lines 897–897files = q.list_files(rich_db)lines 898–898only_c = q.list_files(rich_db, "*.c")lines 899–899assert only_c, "the fixture tree is C — '*.c' cannot be empty"lines 900–900assert all(f.path.endswith(".c") for f in only_c)lines 901–901assert len(only_c) < len(files)lines 904–904assert [f.path for f in q.list_files(rich_db, "sensor_driver.*")]lines 905–905assert q.list_files(rich_db, "*.no_such_extension") == []

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.

tests/test_query.py:1355

Show on the map →

Called by none

Calls _class_db, lookup_class

Checks

  • assert entry is not None
  • assert entry.name == "demo::shape::PolygonWidget"
  • 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)
  • assert selected is not None
  • assert selected.name == candidate.qualified

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_lookup_class_lists_candidates_when_the_name_is_ambiguous → lookup_class
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_lookup_class_lists_candidates_when_the_name_is_ambiguous → lookup_class → table_exists
REQ-DDB-QUERY-010measuredtest_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
lines 1362–1362db = _class_db(tmp_path)lines 1363–1363entry = q.lookup_class(db, "PolygonWidget")lines 1364–1364assert entry is not Nonelines 1365–1365assert entry.name == "demo::shape::PolygonWidget"lines 1366–1366names = [c.qualified for c in entry.candidates]lines 1367–1367assert "demo::shape::PolygonWidget" in nameslines 1368–1368assert "demo::shape::RoundedPolygonWidget" in nameslines 1369–1369assert "std::PolygonWidget_traits" in nameslines 1370–1370assert [c.kind for c in entry.candidates] == ["class"] * len(names)lines 1374–1374◇ for candidate in entry.candidateslines 1375–1375selected = q.lookup_class(db, candidate.qualified)lines 1376–1376assert selected is not Nonelines 1377–1377assert selected.name == candidate.qualified

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.

tests/test_query.py:1259

Show on the map →

Called by none

Calls _class_db, lookup_class

Checks

  • assert entry is not None
  • 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"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_lookup_class_members_and_hierarchy → lookup_class
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_lookup_class_members_and_hierarchy → lookup_class → table_exists
REQ-DDB-QUERY-010measuredtest_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
lines 1262–1262entry = q.lookup_class(_class_db(tmp_path), "demo::shape::PolygonWidget")lines 1263–1263assert entry is not Nonelines 1264–1264members = {m.name: m for m in entry.members}lines 1265–1265assert members["redraw"].signature == "void redraw() noexcept"lines 1266–1266assert members["redraw"].kind == "function"lines 1267–1267assert members["redraw"].line == 46lines 1268–1268assert members["canvas_"].signature == "render::Canvas & canvas_"lines 1269–1269assert entry.bases == ["demo::shape::IShapeWidget"]lines 1270–1270assert entry.derived == ["demo::shape::RoundedPolygonWidget"]

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 `///&lt;` 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.

tests/test_query.py:1273

Show on the map →

Called by none

Calls _class_db, lookup_class

Checks

  • assert entry is not None
  • assert 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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_lookup_class_members_carry_their_documentation → lookup_class
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_lookup_class_members_carry_their_documentation → lookup_class → table_exists
REQ-DDB-QUERY-010measuredtest_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
lines 1290–1290entry = q.lookup_class(_class_db(tmp_path), "demo::shape::PolygonWidget")lines 1291–1291assert entry is not Nonelines 1292–1292members = {m.name: m for m in entry.members}lines 1293–1293assert members["redraw"].brief == "Redraws the widget outline."lines 1294–1294assert members["redraw"].detail == "Recomputation is deferred until the next paint."lines 1297–1297assert members["canvas_"].brief == ""lines 1298–1298assert members["canvas_"].detail == ""

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.

tests/test_query.py:1301

Checks

  • 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 == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_lookup_class_members_degrade_when_the_description_columns_are_absent → lookup_class
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_lookup_class_members_degrade_when_the_description_columns_are_absent → lookup_class → table_exists
REQ-DDB-QUERY-010measuredtest_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
lines 1311–1311db = tmp_path / "thin.db"lines 1312–1312conn = sqlite3.connect(str(db))lines 1313–1332conn.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); """, )lines 1333–1333conn.commit()lines 1334–1334conn.close()lines 1336–1336entry = q.lookup_class(db, "ThinWidget")lines 1337–1337assert entry is not Nonelines 1338–1338assert [m.name for m in entry.members] == ["extent"]lines 1339–1339assert entry.members[0].signature == "int extent"lines 1340–1340assert entry.members[0].brief == ""lines 1341–1341assert entry.members[0].detail == ""

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.

tests/test_query.py:1244

Show on the map →

Called by none

Calls _class_db, lookup_class

Checks

  • 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."

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_lookup_class_prefers_project_over_std → lookup_class
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_lookup_class_prefers_project_over_std → lookup_class → table_exists
REQ-DDB-QUERY-010measuredtest_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
lines 1249–1249db = _class_db(tmp_path)lines 1250–1250entry = q.lookup_class(db, "PolygonWidget")lines 1251–1251assert entry is not Nonelines 1252–1252assert entry.name == "demo::shape::PolygonWidget"lines 1253–1253assert entry.kind == "class"lines 1254–1254assert entry.file == "src/demo/shape/PolygonWidget.hpp"lines 1255–1255assert entry.line == 38lines 1256–1256assert entry.brief == "Recomputes the cached outline."

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.

tests/test_query.py:1344

Show on the map →

Called by none

Calls _class_db, lookup_class

Checks

  • assert entry is not None
  • assert entry.name == "std::PolygonWidget_traits"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_lookup_class_std_is_still_reachable → lookup_class
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_lookup_class_std_is_still_reachable → lookup_class → table_exists
REQ-DDB-QUERY-010measuredtest_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
lines 1346–1346entry = q.lookup_class(_class_db(tmp_path), "std::PolygonWidget_traits")lines 1347–1347assert entry is not Nonelines 1348–1348assert entry.name == "std::PolygonWidget_traits"

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.

tests/test_query.py:1380

Show on the map →

Called by none

Calls _class_db, lookup_class

Checks

  • assert entry is not None
  • assert entry.candidates == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_lookup_class_unambiguous_name_has_no_candidates → lookup_class
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_lookup_class_unambiguous_name_has_no_candidates → lookup_class → table_exists
REQ-DDB-QUERY-010measuredtest_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
lines 1384–1384entry = q.lookup_class(_class_db(tmp_path), "IShapeWidget")lines 1385–1385assert entry is not Nonelines 1386–1386assert entry.candidates == []

test_lookup_class_unknown_is_none

None test_query.test_lookup_class_unknown_is_none(Path tmp_path)

tests/test_query.py:1351

Show on the map →

Called by none

Calls _class_db, lookup_class

Checks

  • assert q.lookup_class(_class_db(tmp_path), "NoSuchClass") is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_lookup_class_unknown_is_none → lookup_class
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_lookup_class_unknown_is_none → lookup_class → table_exists
REQ-DDB-QUERY-010measuredtest_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
lines 1352–1352assert q.lookup_class(_class_db(tmp_path), "NoSuchClass") is None

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.

tests/test_query.py:270

Show on the map →

Called by none

Calls _all_function_names, _call_edges, _neighbors

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001catalog
REQ-DDB-QUERY-002measuredtest_merged_neighbours_are_a_superset_of_chain_trace_depth_one → _neighbors
REQ-DDB-QUERY-003measuredtest_merged_neighbours_are_a_superset_of_chain_trace_depth_one → _call_edges → _dataflow_edges → resolve_rowid
REQ-DDB-QUERY-009measuredtest_merged_neighbours_are_a_superset_of_chain_trace_depth_one → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_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
lines 277–277import sqlite3 as _sqlite3lines 279–279from clew.query.symbols import _call_edgeslines 280–280from clew.query.traversal import _neighborslines 282–282conn = _sqlite3.connect(str(rich_db))lines 283–283trylines 284–284nodes = _all_function_names(rich_db)lines 285–285checked = 0lines 286–286◇ for name in nodeslines 287–287◇ for want_callers in (True, False)lines 288–291merged = { (e.name, e.edge_class) for e in _call_edges(conn, name, want_callers, include_dataflow=True) }lines 292–294depth1 = { (n, h.edge_class) for n, h in _neighbors(conn, name, forward=not want_callers) }lines 295–295assert depth1 <= merged, (name, want_callers, depth1 - merged)lines 296–296checked += 1 if depth1 else 0lines 299–299assert checked > len(nodes), f"only {checked} non-empty pairs over {len(nodes)} nodes"

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.

tests/test_query.py:242

Show on the map →

Called by none

Calls _call_edges, _neighbors

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001catalog
REQ-DDB-QUERY-002measuredtest_merged_order_is_identical_to_the_traversal_neighbour_order → _neighbors
REQ-DDB-QUERY-003measuredtest_merged_order_is_identical_to_the_traversal_neighbour_order → _call_edges → _dataflow_edges → resolve_rowid
REQ-DDB-QUERY-009measuredtest_merged_order_is_identical_to_the_traversal_neighbour_order → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_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
lines 247–247import sqlite3 as _sqlite3lines 249–249from clew.query.symbols import _call_edgeslines 250–250from clew.query.traversal import _neighborslines 252–252conn = _sqlite3.connect(str(rich_db))lines 253–253trylines 254–254merged = _call_edges(conn, "sensor_poll", want_callers=False, include_dataflow=True)lines 255–255assert {e.edge_class for e in merged} == {"call", "key"}, "fixture must exercise both"lines 256–256neighbours = _neighbors(conn, "sensor_poll", forward=True)lines 257–257merged_keys = [(e.name, e.edge_class, e.key_name or "") for e in merged]lines 258–258neigh_keys = [(n, h.edge_class, h.key_name or "") for n, h in neighbours]lines 261–261assert merged_keys == sorted(merged_keys)lines 262–262assert neigh_keys == sorted(neigh_keys)lines 264–264shared = set(neigh_keys)lines 265–265assert [k for k in dict.fromkeys(merged_keys) if k in shared] == sorted(shared)

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)

tests/test_query.py:1550

Show on the map →

Called by none

Calls _multi_source_db, callees, callers

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_multi_source_edge_collapses_to_one_row_per_endpoint → callers
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_multi_source_edge_collapses_to_one_row_per_endpoint → callers → _call_edges → _dataflow_edges → resolve_rowid
REQ-DDB-QUERY-009measuredtest_multi_source_edge_collapses_to_one_row_per_endpoint → callers → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_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
lines 1558–1558db = tmp_path / "multi.db"lines 1559–1559_multi_source_db(db)lines 1561–1561calls = [c for c in q.callees(db, "driver") if c.edge_class == "call"]lines 1562–1562assert [c.name for c in calls] == ["pump", "solo"], "one row per endpoint, name-ordered"lines 1564–1564pump = next(c for c in calls if c.name == "pump")lines 1568–1568assert (pump.source, pump.confidence) == ("doxygen_sqlite", "exact")lines 1570–1570solo = next(c for c in calls if c.name == "solo")lines 1571–1571assert (solo.source, solo.confidence) == ("ast", "resolved")lines 1574–1574inbound = [c for c in q.callers(db, "pump") if c.edge_class == "call"]lines 1575–1575assert [c.name for c in inbound] == ["driver"]lines 1576–1576assert (inbound[0].source, inbound[0].confidence) == ("doxygen_sqlite", "exact")

test_name_accessors_degrade_gracefully_on_table_less_db

None test_query.test_name_accessors_degrade_gracefully_on_table_less_db(Path tmp_path)

tests/test_query.py:858

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 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

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_name_accessors_degrade_gracefully_on_table_less_db → source → symbol_provenance
REQ-DDB-PIPE-003inferredtest_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-011inferredtest_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-012inferredtest_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-001measuredtest_name_accessors_degrade_gracefully_on_table_less_db → source
REQ-DDB-QUERY-002measuredtest_name_accessors_degrade_gracefully_on_table_less_db → chain_trace
REQ-DDB-QUERY-003measuredtest_name_accessors_degrade_gracefully_on_table_less_db → resolve_symbol
REQ-DDB-QUERY-004measuredtest_name_accessors_degrade_gracefully_on_table_less_db → function_dossier
REQ-DDB-QUERY-005inferredtest_name_accessors_degrade_gracefully_on_table_less_db → chain_trace → _make_node
REQ-DDB-QUERY-006inferredtest_name_accessors_degrade_gracefully_on_table_less_db → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-007measuredtest_name_accessors_degrade_gracefully_on_table_less_db → search → search_counted → _class_candidates → class_rows
REQ-DDB-QUERY-009measuredtest_name_accessors_degrade_gracefully_on_table_less_db → function_dossier
REQ-DDB-QUERY-010measuredtest_name_accessors_degrade_gracefully_on_table_less_db → function_dossier
REQ-DDB-QUERY-012measuredtest_name_accessors_degrade_gracefully_on_table_less_db → search
REQ-DDB-QUERY-013inferredtest_name_accessors_degrade_gracefully_on_table_less_db → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011inferredtest_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
lines 866–866p = tmp_path / "corrupt.db"lines 867–867conn = sqlite3.connect(p)lines 868–868conn.execute("CREATE TABLE junk(x)")lines 869–869conn.commit()lines 870–870conn.close()lines 872–872assert q.callers(p, "x") == []lines 873–873assert q.callees(p, "x") == []lines 874–874assert q.search(p, "x") == []lines 875–875assert q.thread_of(p, "x") == []lines 876–876assert q.function_dossier(p, "x") is Nonelines 877–877assert q.source(p, "x", tmp_path) is Nonelines 878–878assert q.resolve_symbol(p, "x") is Nonelines 879–879assert q.chain_trace(p, "x") is not None

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.

tests/test_query.py:1801

Show on the map →

Called by none

Calls _fanout_collision_db, function_dossier

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

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_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-011inferredtest_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-012inferredtest_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-001measuredtest_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier
REQ-DDB-QUERY-006measuredtest_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier
REQ-DDB-QUERY-010measuredtest_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier
REQ-DDB-QUERY-012measuredtest_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_namesake_fanout_is_no_longer_laundered_into_exact → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_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
lines 1824–1824db = tmp_path / "fanout.db"lines 1825–1825_fanout_collision_db(db)lines 1827–1827d = q.function_dossier(db, "_classify")lines 1828–1828assert d is not None and d.file == "pkg/guidance.py"lines 1830–1830by_name = {c.name: c for c in d.callers if c.edge_class == "call"}lines 1833–1833assert by_name["plan_guidance"].confidence == "exact"lines 1834–1834assert by_name["plan_guidance"].source == "doxygen_sqlite"lines 1837–1837◇ for fabricated in ("_guard_scope", "plan_merge", "_classify")lines 1838–1841assert by_name[fabricated].confidence == "fuzzy", ( f"{fabricated} reaches a DIFFERENT module's _classify; " "reporting it as 'exact' is the gh#26 defect" )lines 1842–1842assert by_name[fabricated].source == "ast"lines 1846–1846assert [c.name for c in d.callees if c.edge_class == "call"] == []

test_pre_r1_shared_key_schema_degrades_instead_of_raising

None test_query.test_pre_r1_shared_key_schema_degrades_instead_of_raising(Path tmp_path)

Extends #41's graceful-degradation contract from a missing TABLE to a missing COLUMN. `shared_key_edges` GREW the R1 columns after build_version 2, and every query naming one raised a raw OperationalError on an older database — verified live: key_edges, chain_trace and dossier all died on `no such column: s.dispatch_mode`.

tests/test_query.py:356

Show on the map →

Called by none

Calls _pre_r1_key_db, callees, callers, chain_trace, function_dossier

Checks

  • assert len(downstream) == 1
  • assert edge.name == "consumer"
  • assert edge.key_name == "STATE_KEY"
  • assert edge.dispatch_mode == "unknown"
  • assert edge.edge_triggered is None
  • assert edge.crosses_thread is None
  • assert edge.to_thread is None
  • assert {c.name for c in q.callers(db, "consumer") if c.edge_class == "key"} == {"producer"}
  • assert d is not None and [w.other for w in d.writes] == ["consumer"]
  • assert "consumer" in {n.name for n in q.chain_trace(db, "producer", max_depth=2).nodes}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011inferredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → callers
REQ-DDB-QUERY-002measuredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → chain_trace
REQ-DDB-QUERY-003measuredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → chain_trace → function_candidates
REQ-DDB-QUERY-004measuredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → function_dossier
REQ-DDB-QUERY-005measuredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → chain_trace → _make_node
REQ-DDB-QUERY-006measuredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → function_dossier
REQ-DDB-QUERY-010measuredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → function_dossier
REQ-DDB-QUERY-012measuredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_pre_r1_shared_key_schema_degrades_instead_of_raising → function_dossier → _dossier_conn → locks_held_for_rowids
Source · 37 lines
def test_pre_r1_shared_key_schema_degrades_instead_of_raising(tmp_path: Path) -> None:
    """Extends #41's graceful-degradation contract from a missing TABLE to a
    missing COLUMN. `shared_key_edges` GREW the R1 columns after build_version 2,
    and every query naming one raised a raw OperationalError on an older
    database — verified live: key_edges, chain_trace and dossier all died on
    `no such column: s.dispatch_mode`.

    This is a hard prerequisite for the #46 merge, not a nicety: callers/callees
    were the last two tools that still WORKED on such a database, and merging the
    shared-key JOIN into them would have imported the crash into them too.

    Degradation must land on values that already mean "not known": dispatch_mode
    is the schema's own default 'unknown', the rest are None. Nothing plausible
    is fabricated."""
    db = tmp_path / "pre_r1.db"
    _pre_r1_key_db(db)

    downstream = [c for c in q.callees(db, "producer") if c.edge_class == "key"]
    assert len(downstream) == 1
    edge = downstream[0]
    assert edge.name == "consumer"
    assert edge.key_name == "STATE_KEY"
    assert edge.dispatch_mode == "unknown"
    assert edge.edge_triggered is None
    assert edge.crosses_thread is None
    assert edge.to_thread is None
    assert {c.name for c in q.callers(db, "consumer") if c.edge_class == "key"} == {"producer"}

    # ...and every sibling surface over the same JOIN survives it too.
    d = q.function_dossier(db, "producer")
    assert d is not None and [w.other for w in d.writes] == ["consumer"]
    assert "consumer" in {n.name for n in q.chain_trace(db, "producer", max_depth=2).nodes}


# ─── integration: chain_trace crosses the shared-key seam ────────────────────

Activity · 15 steps
lines 370–370db = tmp_path / "pre_r1.db"lines 371–371_pre_r1_key_db(db)lines 373–373downstream = [c for c in q.callees(db, "producer") if c.edge_class == "key"]lines 374–374assert len(downstream) == 1lines 375–375edge = downstream[0]lines 376–376assert edge.name == "consumer"lines 377–377assert edge.key_name == "STATE_KEY"lines 378–378assert edge.dispatch_mode == "unknown"lines 379–379assert edge.edge_triggered is Nonelines 380–380assert edge.crosses_thread is Nonelines 381–381assert edge.to_thread is Nonelines 382–382assert {c.name for c in q.callers(db, "consumer") if c.edge_class == "key"} == {"producer"}lines 385–385d = q.function_dossier(db, "producer")lines 386–386assert d is not None and [w.other for w in d.writes] == ["consumer"]lines 387–387assert "consumer" in {n.name for n in q.chain_trace(db, "producer", max_depth=2).nodes}

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.

tests/test_query.py:1907

Show on the map →

Called by none

Calls _member_doc_db, search_prose_graded

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_prose_search_reaches_documentation_attached_to_a_member → search_prose_graded
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_prose_search_reaches_documentation_attached_to_a_member → search_prose_graded → table_exists
REQ-DDB-QUERY-007measuredtest_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
lines 1920–1920db = _member_doc_db(tmp_path)lines 1921–1921found = q.search_prose_graded(db, "private members", limit=5)lines 1922–1922assert found.hits, "the member's documentation is the only prose here and must be found"lines 1923–1923hit = found.hits[0]lines 1924–1924assert hit.file_path == "library/common.h"lines 1925–1925assert "member documentation" in hit.heading, "the heading must say where the prose came from"lines 1926–1926assert "<para>" not in hit.snippet, f"doxygen's XML must be stripped: {hit.snippet!r}"lines 1927–1927assert "their members are private" in hit.snippet

test_read_body_refuses_paths_escaping_repo_root

None test_query.test_read_body_refuses_paths_escaping_repo_root(Path tmp_path)

tests/test_query.py:746

Show on the map →

Called by none

Calls _read_body

Checks

  • 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

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001catalog
REQ-DDB-QUERY-002catalog
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
lines 753–753from clew.query.source import _read_bodylines 755–755root = tmp_path / "repo"lines 756–756root.mkdir()lines 757–757(root / "src.c").write_text("line1\nline2\n", encoding="utf-8")lines 758–758outside = tmp_path / "secret.txt"lines 759–759outside.write_text("TOP SECRET\n", encoding="utf-8")lines 761–761ok = _read_body(root, "src.c", 1, 2, 10)lines 762–762assert ok is not None and ok[0] == ["line1", "line2"]lines 763–763assert _read_body(root, str(outside), 1, 1, 10) is Nonelines 764–764assert _read_body(root, "../secret.txt", 1, 1, 10) is None

test_req_trace_findme

None test_query.test_req_trace_findme(Path rich_db)

tests/test_query.py:558

Show on the map →

Called by none

Calls req_trace

Checks

  • assert rt.title == "Find-my-robot audible ping"
  • assert rt.priority == "P1"
  • assert "sound_play_findme" in impls
  • assert impls["sound_play_findme"].liveness == "live"
  • assert "test_findme_chime_plays" in rt.tests
  • assert "test_findme_chime_plays" not in impls

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_req_trace_findme → req_trace
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_req_trace_findme → req_trace → table_exists
REQ-DDB-QUERY-010measuredtest_req_trace_findme → req_trace → _req_implementers → resolve_rowid
REQ-DDB-SCHEMA-006measuredtest_req_trace_findme → req_trace → _req_failure_modes
REQ-DDB-SCHEMA-015measuredtest_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
lines 559–559rt = q.req_trace(rich_db, "REQ-0621")lines 560–560assert rt.title == "Find-my-robot audible ping"lines 561–561assert rt.priority == "P1"lines 562–562impls = {i.name: i for i in rt.implementers}lines 563–563assert "sound_play_findme" in implslines 564–564assert impls["sound_play_findme"].liveness == "live"lines 565–565assert "test_findme_chime_plays" in rt.testslines 567–567assert "test_findme_chime_plays" not in impls

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.

tests/test_query.py:676

Show on the map →

Called by none

Calls _overload_db, resolve_symbol

Checks

  • assert ref is not None
  • assert ref.rowid == 20 # definition-preferring
  • assert ref.candidates == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_resolve_symbol_decl_def_duality_is_not_an_overload → resolve_symbol → symbol_provenance
REQ-DDB-QUERY-001measuredtest_resolve_symbol_decl_def_duality_is_not_an_overload → resolve_symbol → connect
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_resolve_symbol_decl_def_duality_is_not_an_overload → resolve_symbol
REQ-DDB-QUERY-010measuredtest_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
lines 680–686db = _overload_db( tmp_path, [ (20, "solo", "void solo", "src/s.cpp", True), # definition (21, "solo", "void solo", "include/s.hpp", False), # declaration ], )lines 687–687ref = q.resolve_symbol(db, "solo")lines 688–688assert ref is not Nonelines 689–689assert ref.rowid == 20lines 690–690assert ref.candidates == []

test_resolve_symbol_definition_preferring

None test_query.test_resolve_symbol_definition_preferring(Path rich_db)

tests/test_query.py:596

Checks

  • assert ref is not None
  • assert ref.kind == "function"
  • assert ref.file.endswith("sensor_driver.c")
  • assert ref.candidates == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_resolve_symbol_definition_preferring → resolve_symbol → symbol_provenance
REQ-DDB-QUERY-001measuredtest_resolve_symbol_definition_preferring → resolve_symbol → connect
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_resolve_symbol_definition_preferring → resolve_symbol
REQ-DDB-QUERY-010measuredtest_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
lines 597–597ref = q.resolve_symbol(rich_db, "sensor_poll")lines 598–598assert ref is not Nonelines 599–599assert ref.kind == "function"lines 600–600assert ref.file.endswith("sensor_driver.c")lines 603–603assert ref.candidates == []

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.

tests/test_query.py:651

Show on the map →

Called by none

Calls _overload_db, resolve_symbol

Checks

  • assert ref is not None
  • assert ref.rowid == 10
  • assert 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

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_resolve_symbol_flags_genuine_overload → resolve_symbol → symbol_provenance
REQ-DDB-QUERY-001measuredtest_resolve_symbol_flags_genuine_overload → resolve_symbol → connect
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_resolve_symbol_flags_genuine_overload → resolve_symbol
REQ-DDB-QUERY-010measuredtest_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
lines 656–663db = _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), ], )lines 664–664ref = q.resolve_symbol(db, "react")lines 665–665assert ref is not Nonelines 667–667assert ref.rowid == 10lines 668–668sigs = {c.signature for c in ref.candidates}lines 669–669assert sigs == {"void A::react", "void B::react", "void C::react"}lines 670–670files = {c.file for c in ref.candidates}lines 671–671assert files == {"src/a.cpp", "src/b.cpp", "include/c.hpp"}lines 673–673assert any(c.file.endswith("c.hpp") and c.has_body is False for c in ref.candidates)

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.

tests/test_query.py:1745

Show on the map →

Called by none

Calls callees

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_same_named_c_statics_in_different_files_still_merge → callees
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_same_named_c_statics_in_different_files_still_merge → callees → _call_edges → _dataflow_edges → resolve_rowid
REQ-DDB-QUERY-009measuredtest_same_named_c_statics_in_different_files_still_merge → callees → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_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
lines 1763–1763callees = {c.name for c in q.callees(rich_db, "main") if c.edge_class == "call"}lines 1764–1764assert "app_run" in callees, "src/main.c's main"lines 1765–1765assert "test_findme_chime_plays" in callees, "the test file's main -- STILL merged"

test_same_named_module_private_helpers_do_not_share_edges

None test_query.test_same_named_module_private_helpers_do_not_share_edges(Path tmp_path)

gh#26. Name-based resolution collapsed three unrelated `_classify` functions into ONE graph node, so `dossier` described one of them and then reported the UNION of all three functions' neighbours — 3 of 4 callers fabricated, including a self-edge claiming recursion that belongs to a DIFFERENT module's function. Every fabricated row came back `confidence: exact`, because all three extraction layers resolve by name and therefore all three reached the same wrong function.

tests/test_query.py:1645

Show on the map →

Called by none

Calls _name_collision_db, function_dossier

Checks

  • assert d is not None
  • assert d.file == "pkg/guidance.py"
  • assert len(d.candidates) == 3, "the ambiguity signal must still fire"
  • assert [c.name for c in d.callers if c.edge_class == "call"] == ["plan_guidance"]
  • assert [c.name for c in d.callees if c.edge_class == "call"] == [], ("guidance._classify calls nothing; a self-edge here belongs to scope._classify" )
  • assert "_guard_scope" not in caller_names, "belongs to scope._classify"
  • assert "plan_merge" not in caller_names, "belongs to mcp_config._classify"
  • assert "_classify" not in caller_names, "fabricated recursion"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003inferredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011inferredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier
REQ-DDB-QUERY-006measuredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier
REQ-DDB-QUERY-010measuredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier
REQ-DDB-QUERY-012measuredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_same_named_module_private_helpers_do_not_share_edges → function_dossier → _dossier_conn → locks_held_for_rowids
Source · 36 lines
def test_same_named_module_private_helpers_do_not_share_edges(tmp_path: Path) -> None:
    """gh#26. Name-based resolution collapsed three unrelated `_classify`
    functions into ONE graph node, so `dossier` described one of them and then
    reported the UNION of all three functions' neighbours — 3 of 4 callers
    fabricated, including a self-edge claiming recursion that belongs to a
    DIFFERENT module's function. Every fabricated row came back
    `confidence: exact`, because all three extraction layers resolve by name and
    therefore all three reached the same wrong function.

    `candidates` already fired on this input, but it disambiguates the IDENTITY
    of the described symbol while nothing disambiguated the EDGES attributed to
    it — so a caller who checked `candidates` and then read `callers` was still
    misled. This pins the edges, not the candidate list."""
    db = tmp_path / "collide.db"
    _name_collision_db(db)

    # The definition-preferring pick is guidance._classify (lowest rowid, has body).
    d = q.function_dossier(db, "_classify")
    assert d is not None
    assert d.file == "pkg/guidance.py"
    assert len(d.candidates) == 3, "the ambiguity signal must still fire"

    # It has exactly ONE caller, and calls NOTHING. The issue's stated
    # acceptance check: guidance._classify has zero callees.
    assert [c.name for c in d.callers if c.edge_class == "call"] == ["plan_guidance"]
    assert [c.name for c in d.callees if c.edge_class == "call"] == [], (
        "guidance._classify calls nothing; a self-edge here belongs to scope._classify"
    )

    # And the fabricated neighbours are gone by name, not merely reordered.
    caller_names = {c.name for c in d.callers}
    assert "_guard_scope" not in caller_names, "belongs to scope._classify"
    assert "plan_merge" not in caller_names, "belongs to mcp_config._classify"
    assert "_classify" not in caller_names, "fabricated recursion"

Activity · 12 steps
lines 1658–1658db = tmp_path / "collide.db"lines 1659–1659_name_collision_db(db)lines 1662–1662d = q.function_dossier(db, "_classify")lines 1663–1663assert d is not Nonelines 1664–1664assert d.file == "pkg/guidance.py"lines 1665–1665assert len(d.candidates) == 3, "the ambiguity signal must still fire"lines 1669–1669assert [c.name for c in d.callers if c.edge_class == "call"] == ["plan_guidance"]lines 1670–1672assert [c.name for c in d.callees if c.edge_class == "call"] == [], ( "guidance._classify calls nothing; a self-edge here belongs to scope._classify" )lines 1675–1675caller_names = {c.name for c in d.callers}lines 1676–1676assert "_guard_scope" not in caller_names, "belongs to scope._classify"lines 1677–1677assert "plan_merge" not in caller_names, "belongs to mcp_config._classify"lines 1678–1678assert "_classify" not in caller_names, "fabricated recursion"

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.

tests/test_query.py:1492

Show on the map →

Called by none

Calls search

Checks

  • assert q.search(rich_db, " ") == []
  • assert q.search(rich_db, "zzz_definitely_absent_xyz") == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_search_empty_and_unmatched_queries_stay_empty → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance
REQ-DDB-QUERY-001measuredtest_search_empty_and_unmatched_queries_stay_empty → search
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_empty_and_unmatched_queries_stay_empty → search → search_counted → _class_candidates → class_rows → table_exists
REQ-DDB-QUERY-007measuredtest_search_empty_and_unmatched_queries_stay_empty → search → search_counted → _class_candidates → class_rows
REQ-DDB-QUERY-012measuredtest_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
lines 1495–1495assert q.search(rich_db, " ") == []lines 1496–1496assert q.search(rich_db, "zzz_definitely_absent_xyz") == []

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.

tests/test_query.py:1428

Show on the map →

Called by none

Calls _class_db, lookup_class, search

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

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_search_excludes_stl_compounds_but_lookup_class_still_reaches_them → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance
REQ-DDB-QUERY-001measuredtest_search_excludes_stl_compounds_but_lookup_class_still_reaches_them → lookup_class
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_excludes_stl_compounds_but_lookup_class_still_reaches_them → lookup_class → table_exists
REQ-DDB-QUERY-007measuredtest_search_excludes_stl_compounds_but_lookup_class_still_reaches_them → search → search_counted → _class_candidates → class_rows
REQ-DDB-QUERY-010measuredtest_search_excludes_stl_compounds_but_lookup_class_still_reaches_them → lookup_class
REQ-DDB-QUERY-012measuredtest_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
lines 1436–1436db = _class_db(tmp_path)lines 1437–1437assert "std::PolygonWidget_traits" not in [h.name for h in q.search(db, "PolygonWidget")]lines 1438–1438assert q.search(db, "PolygonWidget_traits") == []lines 1439–1439entry = q.lookup_class(db, "std::PolygonWidget_traits")lines 1440–1440assert entry is not None and entry.name == "std::PolygonWidget_traits"

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.

tests/test_query.py:1404

Show on the map →

Called by none

Calls _class_db, search

Checks

  • assert [h.name for h in hits] == ["demo::shape::IShapeWidget"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_search_finds_a_class_by_its_brief → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance
REQ-DDB-QUERY-001measuredtest_search_finds_a_class_by_its_brief → search
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_finds_a_class_by_its_brief → search → search_counted → _class_candidates → class_rows → table_exists
REQ-DDB-QUERY-007measuredtest_search_finds_a_class_by_its_brief → search → search_counted → _class_candidates → class_rows
REQ-DDB-QUERY-012measuredtest_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
lines 1407–1407hits = q.search(_class_db(tmp_path), "base interface")lines 1408–1408assert [h.name for h in hits] == ["demo::shape::IShapeWidget"]

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.

tests/test_query.py:1389

Show on the map →

Called by none

Calls _class_db, search

Checks

  • 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."

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_search_finds_a_class_by_name → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance
REQ-DDB-QUERY-001measuredtest_search_finds_a_class_by_name → search
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_finds_a_class_by_name → search → search_counted → _class_candidates → class_rows → table_exists
REQ-DDB-QUERY-007measuredtest_search_finds_a_class_by_name → search → search_counted → _class_candidates → class_rows
REQ-DDB-QUERY-012measuredtest_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
lines 1396–1396hits = q.search(_class_db(tmp_path), "PolygonWidget")lines 1397–1397by_name = {h.name: h for h in hits}lines 1398–1398assert "demo::shape::PolygonWidget" in by_namelines 1399–1399assert by_name["demo::shape::PolygonWidget"].kind == "class"lines 1400–1400assert by_name["demo::shape::PolygonWidget"].file == "src/demo/shape/PolygonWidget.hpp"lines 1401–1401assert by_name["demo::shape::PolygonWidget"].brief == "Recomputes the cached outline."

test_search_finds_known_symbol

None test_query.test_search_finds_known_symbol(Path rich_db)

tests/test_query.py:588

Show on the map →

Called by none

Calls search

Checks

  • assert "sensor_poll" in hits
  • assert any(h.name == "telemetry_report" for h in tele)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_search_finds_known_symbol → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance
REQ-DDB-QUERY-001measuredtest_search_finds_known_symbol → search
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_finds_known_symbol → search → search_counted → _class_candidates → class_rows → table_exists
REQ-DDB-QUERY-007measuredtest_search_finds_known_symbol → search → search_counted → _class_candidates → class_rows
REQ-DDB-QUERY-012measuredtest_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
lines 589–589hits = {h.name for h in q.search(rich_db, "sensor_poll")}lines 590–590assert "sensor_poll" in hitslines 592–592tele = q.search(rich_db, "telemetry")lines 593–593assert any(h.name == "telemetry_report" for h in tele)

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.

tests/test_query.py:1443

Show on the map →

Called by none

Calls _class_db, search

Checks

  • assert q.search(_class_db(tmp_path), "NoSuchWidgetAnywhere") == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_search_for_an_absent_class_name_is_still_empty → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance
REQ-DDB-QUERY-001measuredtest_search_for_an_absent_class_name_is_still_empty → search
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_for_an_absent_class_name_is_still_empty → search → search_counted → _class_candidates → class_rows → table_exists
REQ-DDB-QUERY-007measuredtest_search_for_an_absent_class_name_is_still_empty → search → search_counted → _class_candidates → class_rows
REQ-DDB-QUERY-012measuredtest_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
lines 1446–1446assert q.search(_class_db(tmp_path), "NoSuchWidgetAnywhere") == []

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.

tests/test_query.py:1485

Show on the map →

Called by none

Calls search

Checks

  • assert len(q.search(rich_db, "e", limit=3)) <= 3
  • assert len(q.search(rich_db, "e", limit=1)) == 1

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_search_is_capped_and_the_cap_is_caller_controlled → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance
REQ-DDB-QUERY-001measuredtest_search_is_capped_and_the_cap_is_caller_controlled → search
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_is_capped_and_the_cap_is_caller_controlled → search → search_counted → _class_candidates → class_rows → table_exists
REQ-DDB-QUERY-007measuredtest_search_is_capped_and_the_cap_is_caller_controlled → search → search_counted → _class_candidates → class_rows
REQ-DDB-QUERY-012measuredtest_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
lines 1488–1488assert len(q.search(rich_db, "e", limit=3)) <= 3lines 1489–1489assert len(q.search(rich_db, "e", limit=1)) == 1

test_search_matches_every_token_not_the_literal_phrase

None test_query.test_search_matches_every_token_not_the_literal_phrase(Path rich_db)

tests/test_query.py:1459

Show on the map →

Called by none

Calls search

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

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_search_matches_every_token_not_the_literal_phrase → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance
REQ-DDB-QUERY-001measuredtest_search_matches_every_token_not_the_literal_phrase → search
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_matches_every_token_not_the_literal_phrase → search → search_counted → _class_candidates → class_rows → table_exists
REQ-DDB-QUERY-007measuredtest_search_matches_every_token_not_the_literal_phrase → search → search_counted → _class_candidates → class_rows
REQ-DDB-QUERY-012measuredtest_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
lines 1467–1467single = q.search(rich_db, "sensor")lines 1468–1468assert single, "single-token search must still work"lines 1471–1471both = q.search(rich_db, "sensor poll")lines 1472–1472assert any(h.name == "sensor_poll" for h in both)lines 1475–1475assert {h.name for h in q.search(rich_db, "poll sensor")} == {h.name for h in both}

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.

tests/test_query.py:976

Checks

  • assert q.search_prose(db, "anything") == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_search_prose_absent_table_is_empty → search_prose
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_prose_absent_table_is_empty → search_prose → search_prose_graded → table_exists
REQ-DDB-QUERY-007measuredtest_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
lines 978–978db = tmp_path / "noprose.db"lines 979–979conn = sqlite3.connect(str(db))lines 980–980conn.execute("CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, name TEXT)")lines 981–981conn.commit()lines 982–982conn.close()lines 983–983assert q.search_prose(db, "anything") == []

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.

tests/test_query.py:945

Checks

  • assert result.hits
  • assert result.widened is False

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_search_prose_does_not_widen_a_query_that_already_matched → search_prose_graded
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_prose_does_not_widen_a_query_that_already_matched → search_prose_graded → table_exists
REQ-DDB-QUERY-007measuredtest_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
lines 950–950result = q.search_prose_graded(rich_db, "chime")lines 951–951assert result.hitslines 952–952assert result.widened is False

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.

tests/test_query.py:918

Checks

  • assert len(q.search_prose(rich_db, "the OR robot OR key", limit=2)) <= 2

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_search_prose_limit_and_bad_expression → search_prose
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_prose_limit_and_bad_expression → search_prose → search_prose_graded → table_exists
REQ-DDB-QUERY-007measuredtest_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
lines 921–921assert len(q.search_prose(rich_db, "the OR robot OR key", limit=2)) <= 2lines 922–922q.search_prose(rich_db, 'unbalanced " quote')

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.

tests/test_query.py:966

Checks

  • assert result.tokens == ("chime",)
  • assert result.hits

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_search_prose_punctuation_only_tokens_never_reach_fts5 → search_prose_graded
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_prose_punctuation_only_tokens_never_reach_fts5 → search_prose_graded → table_exists
REQ-DDB-QUERY-007measuredtest_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
lines 971–971result = q.search_prose_graded(rich_db, "chime _ ' -")lines 972–972assert result.tokens == ("chime",)lines 973–973assert result.hits

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.

tests/test_query.py:908

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_search_prose_returns_a_snippet → search_prose
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_prose_returns_a_snippet → search_prose → search_prose_graded → table_exists
REQ-DDB-QUERY-007measuredtest_search_prose_returns_a_snippet → search_prose → search_prose_graded → member_doc_rows
REQ-DDB-WIKI-054inferredtest_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
lines 911–911hits = q.search_prose(rich_db, "chime")lines 912–912assert hits, "'chime' is in the fixture tree's docs/architecture.md"lines 913–913assert any(h.file_path.endswith(".md") for h in hits)lines 914–914assert all(h.snippet for h in hits)lines 915–915assert any(">>" in h.snippet for h in hits), "snippet() must mark the match"

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.

tests/test_query.py:955

Checks

  • assert result.hits == []
  • assert result.widened is False
  • assert result.tokens == ("zzqqxwv",)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_search_prose_single_token_miss_reports_no_widening → search_prose_graded
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_prose_single_token_miss_reports_no_widening → search_prose_graded → table_exists
REQ-DDB-QUERY-007measuredtest_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
lines 960–960result = q.search_prose_graded(rich_db, "zzqqxwv")lines 961–961assert result.hits == []lines 962–962assert result.widened is Falselines 963–963assert result.tokens == ("zzqqxwv",)

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.

tests/test_query.py:925

Checks

  • assert q.search_prose(rich_db, absent) == [], "the control word must really be 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)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_search_prose_widens_to_or_when_one_absent_word_empties_the_and → search_prose_graded
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_prose_widens_to_or_when_one_absent_word_empties_the_and → search_prose_graded → table_exists
REQ-DDB-QUERY-007measuredtest_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
lines 935–935absent = "zzqqxwv"lines 936–936assert q.search_prose(rich_db, absent) == [], "the control word must really be absent"lines 938–938result = q.search_prose_graded(rich_db, f"chime {absent}")lines 940–940assert result.widened is Truelines 941–941assert result.hits, "the AND was empty, so the OR must recover the 'chime' hits"lines 942–942assert any(h.file_path.endswith(".md") for h in result.hits)

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.

tests/test_query.py:1420

Show on the map →

Called by none

Calls search

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

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_search_ranking_is_unchanged_on_a_db_with_no_compounds → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance
REQ-DDB-QUERY-001measuredtest_search_ranking_is_unchanged_on_a_db_with_no_compounds → search
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_ranking_is_unchanged_on_a_db_with_no_compounds → search → search_counted → _class_candidates → class_rows → table_exists
REQ-DDB-QUERY-007measuredtest_search_ranking_is_unchanged_on_a_db_with_no_compounds → search → search_counted → _class_candidates → class_rows
REQ-DDB-QUERY-012measuredtest_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
lines 1424–1424assert [h.name for h in q.search(rich_db, "sensor_poll")][0] == "sensor_poll"lines 1425–1425assert q.search(rich_db, "e", limit=3) == q.search(rich_db, "e", limit=3)

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.

tests/test_query.py:1478

Show on the map →

Called by none

Calls search

Checks

  • assert hits and hits[0].name == "sensor_poll"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_search_ranks_name_matches_above_prose_matches → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance
REQ-DDB-QUERY-001measuredtest_search_ranks_name_matches_above_prose_matches → search
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_ranks_name_matches_above_prose_matches → search → search_counted → _class_candidates → class_rows → table_exists
REQ-DDB-QUERY-007measuredtest_search_ranks_name_matches_above_prose_matches → search → search_counted → _class_candidates → class_rows
REQ-DDB-QUERY-012measuredtest_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
lines 1481–1481hits = q.search(rich_db, "sensor_poll")lines 1482–1482assert hits and hits[0].name == "sensor_poll"

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.

tests/test_query.py:1411

Show on the map →

Called by none

Calls _class_db, search

Checks

  • assert [(h.name, h.kind) for h in hits] == [("redraw", "function")]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_search_still_finds_a_function_unchanged → search → search_counted → _memberdef_corpora → _memberdef_candidates → symbol_provenance
REQ-DDB-QUERY-001measuredtest_search_still_finds_a_function_unchanged → search
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_search_still_finds_a_function_unchanged → search → search_counted → _class_candidates → class_rows → table_exists
REQ-DDB-QUERY-007measuredtest_search_still_finds_a_function_unchanged → search → search_counted → _class_candidates → class_rows
REQ-DDB-QUERY-012measuredtest_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
lines 1416–1416hits = q.search(_class_db(tmp_path), "redraw")lines 1417–1417assert [(h.name, h.kind) for h in hits] == [("redraw", "function")]

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.

tests/test_query.py:713

Show on the map →

Called by none

Calls source

Checks

  • assert full is not None and len(full.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]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_source_caps_and_flags_truncation → source → symbol_provenance
REQ-DDB-QUERY-001measuredtest_source_caps_and_flags_truncation → source
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_source_caps_and_flags_truncation → source → function_candidates
REQ-DDB-QUERY-010measuredtest_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
lines 718–718full = q.source(rich_db, "sensor_poll", repo_root)lines 719–719assert full is not None and len(full.lines) > 2lines 721–721capped = q.source(rich_db, "sensor_poll", repo_root, max_lines=2)lines 722–722assert capped is not Nonelines 723–723assert len(capped.lines) == 2lines 724–724assert capped.truncated is Truelines 725–725assert capped.start_line == full.start_linelines 726–726assert capped.end_line == full.start_line + 1lines 727–727assert capped.lines == full.lines[:2]

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.

tests/test_query.py:696

Show on the map →

Called by none

Calls source

Checks

  • 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
  • assert "sensor_poll" in body
  • assert "hw_read_battery_adc" in body
  • assert listing.lines == on_disk[listing.start_line - 1 : listing.end_line]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_source_returns_the_verbatim_body → source → symbol_provenance
REQ-DDB-QUERY-001measuredtest_source_returns_the_verbatim_body → source
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_source_returns_the_verbatim_body → source → function_candidates
REQ-DDB-QUERY-010measuredtest_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
lines 699–699listing = q.source(rich_db, "sensor_poll", repo_root)lines 700–700assert listing is not Nonelines 701–701assert listing.name == "sensor_poll"lines 702–702assert listing.file.endswith("sensor_driver.c")lines 703–703assert listing.truncated is Falselines 704–704assert listing.end_line == listing.start_line + len(listing.lines) - 1lines 705–705body = "\n".join(listing.lines)lines 706–706assert "sensor_poll" in bodylines 707–707assert "hw_read_battery_adc" in bodylines 709–709on_disk = (repo_root / listing.file).read_text(encoding="utf-8").splitlines()lines 710–710assert listing.lines == on_disk[listing.start_line - 1 : listing.end_line]

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`.

tests/test_query.py:734

Show on the map →

Called by none

Calls source

Checks

  • assert listing is not None
  • assert listing.candidates == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_source_unambiguous_has_no_candidates → source → symbol_provenance
REQ-DDB-QUERY-001measuredtest_source_unambiguous_has_no_candidates → source
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_source_unambiguous_has_no_candidates → source → function_candidates
REQ-DDB-QUERY-010measuredtest_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
lines 736–736listing = q.source(rich_db, "sensor_poll", repo_root)lines 737–737assert listing is not Nonelines 738–738assert listing.candidates == []

test_source_unknown_function_is_none

None test_query.test_source_unknown_function_is_none(Path rich_db, Path repo_root)

tests/test_query.py:730

Show on the map →

Called by none

Calls source

Checks

  • assert q.source(rich_db, "no_such_function_xyz", repo_root) is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004inferredtest_source_unknown_function_is_none → source → symbol_provenance
REQ-DDB-QUERY-001measuredtest_source_unknown_function_is_none → source
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_source_unknown_function_is_none → source → function_candidates
REQ-DDB-QUERY-010measuredtest_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
lines 731–731assert q.source(rich_db, "no_such_function_xyz", repo_root) is None

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.

tests/test_query.py:741

Show on the map →

Called by none

Calls source

Checks

  • assert q.source(rich_db, "sensor_poll", tmp_path) is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_source_unreadable_repo_root_is_none → source → symbol_provenance
REQ-DDB-QUERY-001measuredtest_source_unreadable_repo_root_is_none → source
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_source_unreadable_repo_root_is_none → source → function_candidates
REQ-DDB-QUERY-010measuredtest_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
lines 743–743assert q.source(rich_db, "sensor_poll", tmp_path) is None

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).

tests/test_query.py:570

Checks

  • 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") == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_thread_apis_empty_on_threadless_firmware → thread_roster
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_thread_apis_empty_on_threadless_firmware → thread_roster → table_exists
REQ-DDB-QUERY-004measuredtest_thread_apis_empty_on_threadless_firmware → thread_of → threads_for_rowids
REQ-DDB-QUERY-011measuredtest_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
lines 580–580roster = q.thread_roster(rich_db)lines 581–581assert roster.threads == ()lines 582–582assert roster.rows == 0lines 583–583assert roster.origin.total == 0lines 584–584assert "predates the thread layer" not in roster.row_meaninglines 585–585assert q.thread_of(rich_db, "sensor_poll") == []

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.

tests/test_query.py:842

Show on the map →

Called by none

Calls _thread_db, thread_of

Checks

  • assert sorted(t.name for t in q.thread_of(db, "rx_loop")) == [

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_thread_of_bare_ambiguous_name_returns_every_thread → thread_of
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_thread_of_bare_ambiguous_name_returns_every_thread → thread_of → rowids_for_name
REQ-DDB-QUERY-004measuredtest_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
lines 848–848db = tmp_path / "threads.db"lines 849–849_thread_db(db)lines 851–855assert sorted(t.name for t in q.thread_of(db, "rx_loop")) == [ "CoLinkOwner::rx_loop", "LinkOwner::rx_loop", "SensorRuntime::rx_loop", ]

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.

tests/test_query.py:833

Show on the map →

Called by none

Calls _thread_db, thread_of

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_thread_of_qualified_match_respects_identifier_boundaries → thread_of
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_thread_of_qualified_match_respects_identifier_boundaries → thread_of → rowids_for_name
REQ-DDB-QUERY-004measuredtest_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
lines 836–836db = tmp_path / "threads.db"lines 837–837_thread_db(db)lines 838–838assert [t.name for t in q.thread_of(db, "LinkOwner::rx_loop")] == ["LinkOwner::rx_loop"]lines 839–839assert [t.name for t in q.thread_of(db, "CoLinkOwner::rx_loop")] == ["CoLinkOwner::rx_loop"]

test_thread_of_resolves_qualified_roster_names

None test_query.test_thread_of_resolves_qualified_roster_names(Path tmp_path)

tests/test_query.py:821

Show on the map →

Called by none

Calls _thread_db, thread_of

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_thread_of_resolves_qualified_roster_names → thread_of
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_thread_of_resolves_qualified_roster_names → thread_of → rowids_for_name
REQ-DDB-QUERY-004measuredtest_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
lines 827–827db = tmp_path / "threads.db"lines 828–828_thread_db(db)lines 829–829assert [t.name for t in q.thread_of(db, "LinkOwner::rx_loop")] == ["LinkOwner::rx_loop"]lines 830–830assert [t.name for t in q.thread_of(db, "SensorRuntime::rx_loop")] == ["SensorRuntime::rx_loop"]

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.

tests/test_query.py:1449

Show on the map →

Called by none

Calls _class_db, token_hit_counts

Checks

  • assert counts["ishapewidget"] == 1
  • assert counts["nosuchtoken"] == 0

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_token_hit_counts_sees_the_class_corpus → token_hit_counts → connect
REQ-DDB-QUERY-002catalog
REQ-DDB-QUERY-003measuredtest_token_hit_counts_sees_the_class_corpus → token_hit_counts → _one_token_count → table_exists
REQ-DDB-QUERY-007measuredtest_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

Activity · 3 steps
lines 1454–1454counts = q.token_hit_counts(_class_db(tmp_path), ["ishapewidget", "nosuchtoken"])lines 1455–1455assert counts["ishapewidget"] == 1lines 1456–1456assert counts["nosuchtoken"] == 0