test_disambiguation.py

tests/test_disambiguation.py

gh#37 — `candidates` made actionable: an ambiguous name is addressable, not just reported.

test_a_candidate_without_a_line_is_left_alone

None test_disambiguation.test_a_candidate_without_a_line_is_left_alone()

A row with no line is never merged, because nothing distinguishes it.

tests/test_disambiguation.py:443

Checks

  • assert len(candidate_rows(conn, "f", unpositioned)) == 2

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_candidate_without_a_line_is_left_alone → candidate_rows → symbol_provenance
REQ-DDB-QUERY-003measuredtest_a_candidate_without_a_line_is_left_alone → candidate_rows
REQ-DDB-QUERY-010measuredtest_a_candidate_without_a_line_is_left_alone → candidate_rows
Source · 19 lines
def test_a_candidate_without_a_line_is_left_alone() -> None:
    """FAILS OPEN. A row whose `line` is NULL carries no position, so two such rows cannot be
    SHOWN to be the same declaration — only to be indistinguishable in this tuple. Merging them
    would be a guess in the direction that loses information, and the pre-gh#19 behaviour
    (report both) is the safe one.

    @brief Null-line rows are reported separately.
    @return None.
    @version 1
    """
    conn = sqlite3.connect(":memory:")
    conn.executescript("CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, name TEXT, kind TEXT);")
    unpositioned = [
        (10, "void C::f", "include/c.h", None, False),
        (11, "void C::f", "include/c.h", None, False),
    ]
    assert len(candidate_rows(conn, "f", unpositioned)) == 2

Activity · 4 steps
lines 453–453conn = sqlite3.connect(":memory:")lines 454–454conn.executescript("CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, name TEXT, kind TEXT);")lines 455–458unpositioned = [ (10, "void C::f", "include/c.h", None, False), (11, "void C::f", "include/c.h", None, False), ]lines 459–459assert len(candidate_rows(conn, "f", unpositioned)) == 2

test_a_capped_candidate_list_discloses_the_real_total

None test_disambiguation.test_a_capped_candidate_list_discloses_the_real_total(Path tmp_path)

A capped candidate list must disclose how many identities really exist.

tests/test_disambiguation.py:466

Checks

  • assert _distinct_identities(db, "main") == over, "the total must be counted, not estimated"
  • assert capped is not None, "a list AT the cap with more rows behind it must disclose"
  • assert capped["total_available"] == over, f"the total must be the real count; got {capped}"
  • assert "policy" in capped["reason"], ("the reason must say it is a policy cap — attributing it to response size sends a reader " "to shrink a payload that was never too big" )
  • assert "SAMPLE" in capped["how_to_narrow"], "it must say the rows are a sample, not the set"
  • assert _candidates_capped(db, {"subject": "main", "candidates": [{}] * 2}) is None, ("below the cap nothing was dropped, so nothing may be disclosed" )
  • assert (_candidates_capped(db, {"subject": "solo", "candidates": [{}] * _MAX_CANDIDATES}) is None ), "a name AT the cap with no further rows behind it has lost nothing"
  • assert (_candidates_capped(None, {"subject": "main", "candidates": [{}] * _MAX_CANDIDATES}) is None ), "with no database the total is unknowable and must not be invented"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_a_capped_candidate_list_discloses_the_real_total → _distinct_identities → connect
REQ-DDB-QUERY-003measuredtest_a_capped_candidate_list_discloses_the_real_total → _distinct_identities → table_exists
REQ-DDB-QUERY-010catalog
Source · 64 lines
def test_a_capped_candidate_list_discloses_the_real_total(tmp_path: Path) -> None:
    """SILENT TRUNCATION ON THE ONE FIELD WHOSE JOB IS DISAMBIGUATION. `MAX_CANDIDATES` is 8 and
    `candidate_rows` sliced to it with no disclosure, so `dossier("main")` on mbedtls returned 8 of
    143 `main` rows — and the one that mattered, the stub `main` a non-threading build compiles, was
    not among them. No `_limited` entry, no count, nothing saying a choice had been made, while
    `candidates` reads as "the identities this name has".

    NOT REUSING `_limited_block`: that states "the full response exceeded the 65,536-byte cap",
    which here is false. This list is capped by policy regardless of size, and a disclosure that
    misattributes its cause sends a reader to shrink a payload that was never too big.

    BOTH HALVES. Below the cap it must stay SILENT — a disclosure on every reply is one nobody
    reads, and this repo's record is that a warning firing on the ordinary case gets switched off.

    @brief Over the cap discloses the total; under the cap says nothing.
    @return None.
    @version 1
    """
    from clew.mcp_server.tools_query import (
        _MAX_CANDIDATES,
        _candidates_capped,
        _distinct_identities,
    )

    db = tmp_path / "many.db"
    conn = sqlite3.connect(str(db))
    conn.execute(
        "CREATE TABLE memberdef (rowid_ INTEGER, name TEXT, kind TEXT, definition TEXT, "
        "file_id INTEGER, bodyfile_id INTEGER, bodystart INTEGER)"
    )
    over = _MAX_CANDIDATES + 5
    conn.executemany(
        "INSERT INTO memberdef(name, kind, definition, file_id, bodyfile_id, bodystart) "
        "VALUES('main', 'function', ?, ?, ?, 1)",
        [(f"int main{i}(void)", i, i) for i in range(over)],
    )
    conn.execute(
        "INSERT INTO memberdef(name, kind, definition, file_id, bodyfile_id, bodystart) "
        "VALUES('solo', 'function', 'int solo(void)', 1, 1, 1)"
    )
    conn.commit()
    conn.close()

    assert _distinct_identities(db, "main") == over, "the total must be counted, not estimated"

    capped = _candidates_capped(db, {"subject": "main", "candidates": [{}] * _MAX_CANDIDATES})
    assert capped is not None, "a list AT the cap with more rows behind it must disclose"
    assert capped["total_available"] == over, f"the total must be the real count; got {capped}"
    assert "policy" in capped["reason"], (
        "the reason must say it is a policy cap — attributing it to response size sends a reader "
        "to shrink a payload that was never too big"
    )
    assert "SAMPLE" in capped["how_to_narrow"], "it must say the rows are a sample, not the set"

    ## THE SILENCE HALF, three ways:
    assert _candidates_capped(db, {"subject": "main", "candidates": [{}] * 2}) is None, (
        "below the cap nothing was dropped, so nothing may be disclosed"
    )
    assert (
        _candidates_capped(db, {"subject": "solo", "candidates": [{}] * _MAX_CANDIDATES}) is None
    ), "a name AT the cap with no further rows behind it has lost nothing"
    assert (
        _candidates_capped(None, {"subject": "main", "candidates": [{}] * _MAX_CANDIDATES}) is None
    ), "with no database the total is unknowable and must not be invented"

1 more lines, not shown

Activity · 18 steps
lines 484–488from clew.mcp_server.tools_query import ( _MAX_CANDIDATES, _candidates_capped, _distinct_identities, )lines 490–490db = tmp_path / "many.db"lines 491–491conn = sqlite3.connect(str(db))lines 492–495conn.execute( "CREATE TABLE memberdef (rowid_ INTEGER, name TEXT, kind TEXT, definition TEXT, " "file_id INTEGER, bodyfile_id INTEGER, bodystart INTEGER)" )lines 496–496over = _MAX_CANDIDATES + 5lines 497–501conn.executemany( "INSERT INTO memberdef(name, kind, definition, file_id, bodyfile_id, bodystart) " "VALUES('main', 'function', ?, ?, ?, 1)", [(f"int main{i}(void)", i, i) for i in range(over)], )lines 502–505conn.execute( "INSERT INTO memberdef(name, kind, definition, file_id, bodyfile_id, bodystart) " "VALUES('solo', 'function', 'int solo(void)', 1, 1, 1)" )lines 506–506conn.commit()lines 507–507conn.close()lines 509–509assert _distinct_identities(db, "main") == over, "the total must be counted, not estimated"lines 511–511capped = _candidates_capped(db, {"subject": "main", "candidates": [{}] * _MAX_CANDIDATES})lines 512–512assert capped is not None, "a list AT the cap with more rows behind it must disclose"lines 513–513assert capped["total_available"] == over, f"the total must be the real count; got {capped}"lines 514–517assert "policy" in capped["reason"], ( "the reason must say it is a policy cap — attributing it to response size sends a reader " "to shrink a payload that was never too big" )lines 518–518assert "SAMPLE" in capped["how_to_narrow"], "it must say the rows are a sample, not the set"lines 521–523assert _candidates_capped(db, {"subject": "main", "candidates": [{}] * 2}) is None, ( "below the cap nothing was dropped, so nothing may be disclosed" )lines 524–526assert ( _candidates_capped(db, {"subject": "solo", "candidates": [{}] * _MAX_CANDIDATES}) is None ), "a name AT the cap with no further rows behind it has lost nothing"lines 527–529assert ( _candidates_capped(None, {"subject": "main", "candidates": [{}] * _MAX_CANDIDATES}) is None ), "with no database the total is unknowable and must not be invented"

test_a_disambiguated_reply_still_reports_the_alternatives

None test_disambiguation.test_a_disambiguated_reply_still_reports_the_alternatives(Path shared_name_db)

A disambiguated reply still discloses that the name is ambiguous.

tests/test_disambiguation.py:197

Checks

  • assert ref is not None
  • assert ref.rowid == OVERRIDE_A
  • assert {c.qualified for c in ref.candidates} == {BASE_QUALIFIED, A_QUALIFIED, B_QUALIFIED}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_disambiguated_reply_still_reports_the_alternatives → resolve_symbol → symbol_provenance
REQ-DDB-QUERY-001measuredtest_a_disambiguated_reply_still_reports_the_alternatives → resolve_symbol → connect
REQ-DDB-QUERY-003measuredtest_a_disambiguated_reply_still_reports_the_alternatives → resolve_symbol
REQ-DDB-QUERY-010measuredtest_a_disambiguated_reply_still_reports_the_alternatives → resolve_symbol
Source · 11 lines
def test_a_disambiguated_reply_still_reports_the_alternatives(shared_name_db: Path) -> None:
    """Ambiguity is a property of the NAME, not of the call. Measuring `candidates` against
    the FILTERED rows would make every disambiguated reply look unique, so a consumer could
    not tell "this name has one meaning" from "I picked one of three" — and the second is the
    situation in which it most needs to know."""
    ref = q.resolve_symbol(shared_name_db, "harvest", A_QUALIFIED)
    assert ref is not None
    assert ref.rowid == OVERRIDE_A
    assert {c.qualified for c in ref.candidates} == {BASE_QUALIFIED, A_QUALIFIED, B_QUALIFIED}

Activity · 4 steps
lines 202–202ref = q.resolve_symbol(shared_name_db, "harvest", A_QUALIFIED)lines 203–203assert ref is not Nonelines 204–204assert ref.rowid == OVERRIDE_Alines 205–205assert {c.qualified for c in ref.candidates} == {BASE_QUALIFIED, A_QUALIFIED, B_QUALIFIED}

test_a_qualified_selector_returns_the_one_identity_asked_for

None test_disambiguation.test_a_qualified_selector_returns_the_one_identity_asked_for(Path shared_name_db)

A disambiguated resolve returns the ONE identity asked for.

tests/test_disambiguation.py:149

Checks

  • assert ref is not None, qualified
  • assert ref.rowid == expect_rowid, qualified
  • assert ref.file == expect_file, qualified

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_qualified_selector_returns_the_one_identity_asked_for → resolve_symbol → symbol_provenance
REQ-DDB-QUERY-001measuredtest_a_qualified_selector_returns_the_one_identity_asked_for → resolve_symbol → connect
REQ-DDB-QUERY-003measuredtest_a_qualified_selector_returns_the_one_identity_asked_for → resolve_symbol
REQ-DDB-QUERY-010measuredtest_a_qualified_selector_returns_the_one_identity_asked_for → resolve_symbol
Source · 21 lines
def test_a_qualified_selector_returns_the_one_identity_asked_for(shared_name_db: Path) -> None:
    """THE ROUND TRIP. Every one of the three identities must be reachable, including the two
    that are NOT the definition-preferring first row — those are the ones that were
    unreachable by any string before gh#37, and a test that only checked the first would pass
    against the old code.

    Asserted on `file` as well as `rowid`, because `rowid` alone would also be satisfied by an
    implementation that returned some arbitrary row of the right identity.
    """
    wanted = {
        BASE_QUALIFIED: ("pkg/harvest.py", BASE),
        A_QUALIFIED: ("pkg/locks.py", OVERRIDE_A),
        B_QUALIFIED: ("pkg/threads.py", OVERRIDE_B),
    }
    for qualified, (expect_file, expect_rowid) in wanted.items():
        ref = q.resolve_symbol(shared_name_db, "harvest", qualified)
        assert ref is not None, qualified
        assert ref.rowid == expect_rowid, qualified
        assert ref.file == expect_file, qualified

Activity · 6 steps
lines 158–162wanted = { BASE_QUALIFIED: ("pkg/harvest.py", BASE), A_QUALIFIED: ("pkg/locks.py", OVERRIDE_A), B_QUALIFIED: ("pkg/threads.py", OVERRIDE_B), }lines 163–163◇ for qualified, (expect_file, expect_rowid) in wanted.items()lines 164–164ref = q.resolve_symbol(shared_name_db, "harvest", qualified)lines 165–165assert ref is not None, qualifiedlines 166–166assert ref.rowid == expect_rowid, qualifiedlines 167–167assert ref.file == expect_file, qualified

test_an_ambiguous_call_without_a_selector_behaves_as_before

None test_disambiguation.test_an_ambiguous_call_without_a_selector_behaves_as_before(Path shared_name_db)

The bare-name path is unchanged, so the disambiguator is additive.

tests/test_disambiguation.py:174

Checks

  • assert ref is not None
  • assert ref.rowid == OVERRIDE_A, "the definition-preferring pick must not have moved"
  • assert {c.qualified for c in ref.candidates} == {BASE_QUALIFIED, A_QUALIFIED, B_QUALIFIED}
  • assert all(c.qualified for c in ref.candidates)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_an_ambiguous_call_without_a_selector_behaves_as_before → resolve_symbol → symbol_provenance
REQ-DDB-QUERY-001measuredtest_an_ambiguous_call_without_a_selector_behaves_as_before → resolve_symbol → connect
REQ-DDB-QUERY-003measuredtest_an_ambiguous_call_without_a_selector_behaves_as_before → resolve_symbol
REQ-DDB-QUERY-010measuredtest_an_ambiguous_call_without_a_selector_behaves_as_before → resolve_symbol
REQ-DDB-WIKI-054inferredtest_an_ambiguous_call_without_a_selector_behaves_as_before → all
Source · 19 lines
def test_an_ambiguous_call_without_a_selector_behaves_as_before(shared_name_db: Path) -> None:
    """The control on the whole change. `qualified` must be OPTIONAL and omitting it must
    reproduce the previous behaviour exactly — the definition-preferring first row, with the
    alternatives listed in `candidates`. Without this assertion the change could be a breaking
    one and every other test here would still pass.

    Also pins that a bare call REMAINS ambiguous rather than being made to fail: the common
    case is a unique name, and forcing a selector on the ambiguous one would break callers to
    fix a case they mostly do not have.
    """
    ref = q.resolve_symbol(shared_name_db, "harvest")
    assert ref is not None
    assert ref.rowid == OVERRIDE_A, "the definition-preferring pick must not have moved"
    assert {c.qualified for c in ref.candidates} == {BASE_QUALIFIED, A_QUALIFIED, B_QUALIFIED}
    ## Every candidate carries the string that selects it — the field gh#37 added, and the
    ## reason the list is actionable rather than advisory.
    assert all(c.qualified for c in ref.candidates)

Activity · 5 steps
lines 184–184ref = q.resolve_symbol(shared_name_db, "harvest")lines 185–185assert ref is not Nonelines 186–186assert ref.rowid == OVERRIDE_A, "the definition-preferring pick must not have moved"lines 187–187assert {c.qualified for c in ref.candidates} == {BASE_QUALIFIED, A_QUALIFIED, B_QUALIFIED}lines 190–190assert all(c.qualified for c in ref.candidates)

test_an_unmatched_selector_returns_nothing_rather_than_the_union

None test_disambiguation.test_an_unmatched_selector_returns_nothing_rather_than_the_union(Path shared_name_db, Path tmp_path)

An unmatched selector finds nothing; it never widens to the bare-name union.

tests/test_disambiguation.py:212

Checks

  • assert q.resolve_symbol(shared_name_db, "harvest", bogus) is None
  • assert q.function_dossier(shared_name_db, "harvest", bogus) is None
  • assert q.callers(shared_name_db, "harvest", bogus) == []
  • assert q.callees(shared_name_db, "harvest", bogus) == []
  • assert q.overrides_of(shared_name_db, "harvest", bogus) == []
  • assert q.overridden_by(shared_name_db, "harvest", bogus) == []
  • assert q.source(shared_name_db, "harvest", tmp_path, qualified=bogus) is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → source → symbol_provenance
REQ-DDB-PIPE-003inferredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011inferredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → source
REQ-DDB-QUERY-002inferredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → resolve_symbol
REQ-DDB-QUERY-004measuredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier
REQ-DDB-QUERY-006inferredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier
REQ-DDB-QUERY-010measuredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier
REQ-DDB-QUERY-012measuredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011inferredtest_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier → _dossier_conn → locks_held_for_rowids
Source · 20 lines
def test_an_unmatched_selector_returns_nothing_rather_than_the_union(
    shared_name_db: Path, tmp_path: Path
) -> None:
    """FAIL CLOSED. A selector that fell back to every same-named row on no match would be the
    worst available behaviour: the caller asked a narrow question, got a wide answer, and has
    no signal that the narrowing failed. A typo must read as "no such identity".

    Checked across the whole accessor surface rather than on one function, because a fallback
    would most likely be introduced in one place by someone making a single accessor
    "friendlier"."""
    bogus = "pkg.nowhere.NotAClass.harvest"
    assert q.resolve_symbol(shared_name_db, "harvest", bogus) is None
    assert q.function_dossier(shared_name_db, "harvest", bogus) is None
    assert q.callers(shared_name_db, "harvest", bogus) == []
    assert q.callees(shared_name_db, "harvest", bogus) == []
    assert q.overrides_of(shared_name_db, "harvest", bogus) == []
    assert q.overridden_by(shared_name_db, "harvest", bogus) == []
    assert q.source(shared_name_db, "harvest", tmp_path, qualified=bogus) is None

Activity · 8 steps
lines 222–222bogus = "pkg.nowhere.NotAClass.harvest"lines 223–223assert q.resolve_symbol(shared_name_db, "harvest", bogus) is Nonelines 224–224assert q.function_dossier(shared_name_db, "harvest", bogus) is Nonelines 225–225assert q.callers(shared_name_db, "harvest", bogus) == []lines 226–226assert q.callees(shared_name_db, "harvest", bogus) == []lines 227–227assert q.overrides_of(shared_name_db, "harvest", bogus) == []lines 228–228assert q.overridden_by(shared_name_db, "harvest", bogus) == []lines 229–229assert q.source(shared_name_db, "harvest", tmp_path, qualified=bogus) is None

test_candidates_does_not_list_one_declaration_twice

None test_disambiguation.test_candidates_does_not_list_one_declaration_twice()

test_chain_trace_does_not_accept_the_selector LIVED HERE and said: "Delete it only together with making the traversal identity-scoped.

tests/test_disambiguation.py:370

Checks

  • assert len(rows) == 1, f"one declaration, one candidate: {[r.signature for r in rows]}"
  • assert rows[0].rowid == 4647, "the first row wins, preserving the definition-preferring order"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_candidates_does_not_list_one_declaration_twice → candidate_rows → symbol_provenance
REQ-DDB-QUERY-003measuredtest_candidates_does_not_list_one_declaration_twice → candidate_rows
REQ-DDB-QUERY-010measuredtest_candidates_does_not_list_one_declaration_twice → candidate_rows
Source · 37 lines
def test_candidates_does_not_list_one_declaration_twice() -> None:
    """gh#19. `dossier("register_server")` on entropic returned three candidates, two of them
    identical in signature, file, line AND has_body:

        ' int register_server'                           python/src/entropic/mcp.py:53
        'void entropic::ServerManager::register_server'  include/.../server_manager.h:142
        'void entropic::ServerManager::register_server'  include/.../server_manager.h:142

    doxygen emits the same member under two scope spellings, so `memberdef` holds two rowids
    for one physical declaration. Nothing here deduped them.

    IT MAKES AN AMBIGUITY LOOK WORSE THAN IT IS, on the one field whose entire job is to
    measure ambiguity. Both duplicates round-trip through `qualified` to the same function, so
    a consumer counting identities counts one that does not exist, and cannot tell the
    duplicate from a genuine overload — which is the distinction the panel exists to draw.

    THE KEY IS (signature, file, line), NOT the signature alone. `signature` here is doxygen's
    `definition`, which two genuine overloads SHARE — `void C::f` for both `f(int)` and
    `f(char)` — so deduping on it would merge the very rows this list must keep apart. They
    differ in `line`, and one physical declaration cannot be at two lines.

    @brief Two rows for one declaration collapse; two overloads do not.
    @return None.
    @version 1
    """
    conn = sqlite3.connect(":memory:")
    conn.executescript("CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, name TEXT, kind TEXT);")

    duplicated = [
        (4647, "void C::register_server", "include/c.h", 142, True),
        (4717, "void C::register_server", "include/c.h", 142, True),
    ]
    rows = candidate_rows(conn, "register_server", duplicated)
    assert len(rows) == 1, f"one declaration, one candidate: {[r.signature for r in rows]}"
    assert rows[0].rowid == 4647, "the first row wins, preserving the definition-preferring order"

Activity · 6 steps
lines 395–395conn = sqlite3.connect(":memory:")lines 396–396conn.executescript("CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, name TEXT, kind TEXT);")lines 398–401duplicated = [ (4647, "void C::register_server", "include/c.h", 142, True), (4717, "void C::register_server", "include/c.h", 142, True), ]lines 402–402rows = candidate_rows(conn, "register_server", duplicated)lines 403–403assert len(rows) == 1, f"one declaration, one candidate: {[r.signature for r in rows]}"lines 404–404assert rows[0].rowid == 4647, "the first row wins, preserving the definition-preferring order"

test_candidates_keeps_two_real_overloads_apart

None test_disambiguation.test_candidates_keeps_two_real_overloads_apart()

Genuine overloads must survive the dedupe.

tests/test_disambiguation.py:410

Checks

  • assert len(candidate_rows(conn, "f", overloads)) == 2, "two overloads are two identities"
  • assert len(candidate_rows(conn, "f", across_files)) == 2

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_candidates_keeps_two_real_overloads_apart → candidate_rows → symbol_provenance
REQ-DDB-QUERY-003measuredtest_candidates_keeps_two_real_overloads_apart → candidate_rows
REQ-DDB-QUERY-010measuredtest_candidates_keeps_two_real_overloads_apart → candidate_rows
Source · 30 lines
def test_candidates_keeps_two_real_overloads_apart() -> None:
    """THE CONTROL, and the reason the key includes `line`. Two overloads of one class share a
    doxygen `definition` string exactly — the parameter list lives in `argsstring`, which this
    tuple does not carry — so a signature-keyed dedupe would silently collapse them and report
    one identity where the caller genuinely has to choose between two.

    That would be worse than the duplication it fixes: a consumer would be told the name is
    unambiguous and pick the wrong function with no signal at all.

    @brief Same signature, different lines, two candidates.
    @return None.
    @version 1
    """
    conn = sqlite3.connect(":memory:")
    conn.executescript("CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, name TEXT, kind TEXT);")

    overloads = [
        (10, "void C::f", "include/c.h", 10, True),
        (11, "void C::f", "include/c.h", 11, True),
    ]
    assert len(candidate_rows(conn, "f", overloads)) == 2, "two overloads are two identities"

    ## Same line, DIFFERENT file — a header and its inline twin, or two unrelated statics.
    across_files = [
        (10, "void C::f", "a/c.h", 10, True),
        (11, "void C::f", "b/c.h", 10, True),
    ]
    assert len(candidate_rows(conn, "f", across_files)) == 2

Activity · 6 steps
lines 423–423conn = sqlite3.connect(":memory:")lines 424–424conn.executescript("CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, name TEXT, kind TEXT);")lines 426–429overloads = [ (10, "void C::f", "include/c.h", 10, True), (11, "void C::f", "include/c.h", 11, True), ]lines 430–430assert len(candidate_rows(conn, "f", overloads)) == 2, "two overloads are two identities"lines 433–436across_files = [ (10, "void C::f", "a/c.h", 10, True), (11, "void C::f", "b/c.h", 10, True), ]lines 437–437assert len(candidate_rows(conn, "f", across_files)) == 2

test_neighbour_lists_narrow_to_the_selected_identity

None test_disambiguation.test_neighbour_lists_narrow_to_the_selected_identity(Path shared_name_db)

Neighbour lists narrow to the selected identity, decl rows included.

tests/test_disambiguation.py:261

Show on the map →

Called by none

Calls callers

Checks

  • assert {e.name for e in q.callers(shared_name_db, "harvest", BASE_QUALIFIED)} == {
  • assert {e.name for e in q.callers(shared_name_db, "harvest", A_QUALIFIED)} == {"run_a"}
  • assert {e.name for e in q.callers(shared_name_db, "harvest", B_QUALIFIED)} == {"run_b"}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_neighbour_lists_narrow_to_the_selected_identity → callers
REQ-DDB-QUERY-003measuredtest_neighbour_lists_narrow_to_the_selected_identity → callers → _call_edges → _dataflow_edges → resolve_rowid
REQ-DDB-QUERY-009measuredtest_neighbour_lists_narrow_to_the_selected_identity → callers → _call_edges → _direct_call_edges → _implementors_by_identity
REQ-DDB-QUERY-010measuredtest_neighbour_lists_narrow_to_the_selected_identity → callers
Source · 15 lines
def test_neighbour_lists_narrow_to_the_selected_identity(shared_name_db: Path) -> None:
    """The selector has to reach `identity_rowids`, not merely the identity lookup, or a
    disambiguated dossier would describe one function and list another's edges — which is the
    gh#26 defect gh#37 must not reintroduce in a new place.

    `run_decl` is the load-bearing row: it calls the base's DECLARATION, so a selector that
    narrowed to a single rowid instead of the identity's union would drop it."""
    assert {e.name for e in q.callers(shared_name_db, "harvest", BASE_QUALIFIED)} == {
        "run_base",
        "run_decl",
    }
    assert {e.name for e in q.callers(shared_name_db, "harvest", A_QUALIFIED)} == {"run_a"}
    assert {e.name for e in q.callers(shared_name_db, "harvest", B_QUALIFIED)} == {"run_b"}

Activity · 3 steps
lines 268–271assert {e.name for e in q.callers(shared_name_db, "harvest", BASE_QUALIFIED)} == { "run_base", "run_decl", }lines 272–272assert {e.name for e in q.callers(shared_name_db, "harvest", A_QUALIFIED)} == {"run_a"}lines 273–273assert {e.name for e in q.callers(shared_name_db, "harvest", B_QUALIFIED)} == {"run_b"}

test_overridden_by_reaches_a_base_whose_name_is_shared_with_its_overrides

None test_disambiguation.test_overridden_by_reaches_a_base_whose_name_is_shared_with_its_overrides(Path shared_name_db)

gh#37's motivating case: overridden_by on a base sharing its overrides' bare name.

tests/test_disambiguation.py:236

Checks

  • assert q.overridden_by(shared_name_db, "harvest") == [], ("the bare name resolves to an OVERRIDE (lowest-rowid body row), and an override has " "no overriders -- so the pre-gh#37 answer is a confident, wrong empty list" )
  • assert {ref.file for ref in got} == {"pkg/locks.py", "pkg/threads.py"}
  • assert [ref.file for ref in bases] == ["pkg/harvest.pyi"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_overridden_by_reaches_a_base_whose_name_is_shared_with_its_overrides → overridden_by
REQ-DDB-QUERY-003measuredtest_overridden_by_reaches_a_base_whose_name_is_shared_with_its_overrides → overridden_by → _override_refs → table_exists
REQ-DDB-QUERY-009measuredtest_overridden_by_reaches_a_base_whose_name_is_shared_with_its_overrides → overridden_by
REQ-DDB-QUERY-010measuredtest_overridden_by_reaches_a_base_whose_name_is_shared_with_its_overrides → overridden_by
Source · 21 lines
def test_overridden_by_reaches_a_base_whose_name_is_shared_with_its_overrides(
    shared_name_db: Path,
) -> None:
    """WHY gh#8 MADE gh#37 LOAD-BEARING. `override` MEANS sharing the base's name, so the
    direction a consumer actually wants — what runs when this virtual call dispatches — is
    precisely the direction bare-name resolution cannot reach. On this repo's own self-index
    the bare call returns ZERO while ten `reimplements` rows name the base.

    The bare assertion is half the test: without it this could pass on an implementation that
    ignored `qualified` and happened to resolve to the base."""
    assert q.overridden_by(shared_name_db, "harvest") == [], (
        "the bare name resolves to an OVERRIDE (lowest-rowid body row), and an override has "
        "no overriders -- so the pre-gh#37 answer is a confident, wrong empty list"
    )
    got = q.overridden_by(shared_name_db, "harvest", BASE_QUALIFIED)
    assert {ref.file for ref in got} == {"pkg/locks.py", "pkg/threads.py"}
    ## And the opposite direction, from an override up to its base.
    bases = q.overrides_of(shared_name_db, "harvest", A_QUALIFIED)
    assert [ref.file for ref in bases] == ["pkg/harvest.pyi"]

Activity · 5 steps
lines 246–249assert q.overridden_by(shared_name_db, "harvest") == [], ( "the bare name resolves to an OVERRIDE (lowest-rowid body row), and an override has " "no overriders -- so the pre-gh#37 answer is a confident, wrong empty list" )lines 250–250got = q.overridden_by(shared_name_db, "harvest", BASE_QUALIFIED)lines 251–251assert {ref.file for ref in got} == {"pkg/locks.py", "pkg/threads.py"}lines 253–253bases = q.overrides_of(shared_name_db, "harvest", A_QUALIFIED)lines 254–254assert [ref.file for ref in bases] == ["pkg/harvest.pyi"]

test_the_selector_reaches_the_mcp_tool_surface

None test_disambiguation.test_the_selector_reaches_the_mcp_tool_surface(Path shared_name_db, Path tmp_path)

The selector reaches the MCP wire, and a miss stays a miss there.

tests/test_disambiguation.py:281

Show on the map →

Called by none

Calls none

Checks

  • assert bare["overridden_by"] == [], "the bare name reaches no override relation"
  • assert {ref["file"] for ref in picked["overridden_by"]} == {"pkg/locks.py", "pkg/threads.py"}
  • assert picked["file"] == "pkg/harvest.py"
  • assert {c["qualified"] for c in picked["candidates"]} == {
  • assert missed["found"] is False
  • assert "overridden_by" not in missed

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-MCP-003measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-002measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-009measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-013measured
REQ-DDB-QUERY-014measured
REQ-DDB-SCHEMA-011measured
Source · 35 lines
def test_the_selector_reaches_the_mcp_tool_surface(shared_name_db: Path, tmp_path: Path) -> None:
    """gh#37's "done means" clause asks for a call REACHABLE FROM THE TOOL SURFACE that returns
    the implementors of a shared-name base. `overridden_by` is not itself a tool — it rides on
    `dossier` — so this is the assertion that the capability is reachable by a model and not
    only by the library.

    A bogus selector must produce the ordinary miss envelope rather than a widened answer, for
    the same reason the library-level test checks it: the wire is where a model's typo lands.

    KEYWORD, NOT POSITIONAL, since gh#372. `dossier`'s second positional slot is now `kind`,
    and `qualified` moved behind a bare `*` precisely so this call could not be silently
    reinterpreted — a selector read as a subject-kind filter is a wrong answer, where a
    TypeError is a caller-side fix."""
    tools = QueryTools(lambda: shared_name_db, lambda: tmp_path)

    bare = tools.dossier("harvest")
    assert bare["overridden_by"] == [], "the bare name reaches no override relation"

    with pytest.raises(TypeError):
        tools.dossier("harvest", BASE_QUALIFIED)  # type: ignore[misc]

    picked = tools.dossier("harvest", qualified=BASE_QUALIFIED)
    assert {ref["file"] for ref in picked["overridden_by"]} == {"pkg/locks.py", "pkg/threads.py"}
    assert picked["file"] == "pkg/harvest.py"
    assert {c["qualified"] for c in picked["candidates"]} == {
        BASE_QUALIFIED,
        A_QUALIFIED,
        B_QUALIFIED,
    }

    missed = tools.dossier("harvest", qualified="pkg.nowhere.NotAClass.harvest")
    assert missed["found"] is False
    assert "overridden_by" not in missed

Activity · 12 steps
lines 294–294tools = QueryTools(lambda: shared_name_db, lambda: tmp_path)lines 296–296bare = tools.dossier("harvest")lines 297–297assert bare["overridden_by"] == [], "the bare name reaches no override relation"lines 299–299with pytest.raises(TypeError)lines 300–300tools.dossier("harvest", BASE_QUALIFIED)lines 302–302picked = tools.dossier("harvest", qualified=BASE_QUALIFIED)lines 303–303assert {ref["file"] for ref in picked["overridden_by"]} == {"pkg/locks.py", "pkg/threads.py"}lines 304–304assert picked["file"] == "pkg/harvest.py"lines 305–309assert {c["qualified"] for c in picked["candidates"]} == { BASE_QUALIFIED, A_QUALIFIED, B_QUALIFIED, }lines 311–311missed = tools.dossier("harvest", qualified="pkg.nowhere.NotAClass.harvest")lines 312–312assert missed["found"] is Falselines 313–313assert "overridden_by" not in missed

test_two_identities_in_one_file_are_still_distinguishable

None test_disambiguation.test_two_identities_in_one_file_are_still_distinguishable(Path tmp_path)

Two same-named identities in ONE file are still told apart.

tests/test_disambiguation.py:320

Checks

  • assert first is not None and second is not None
  • assert (first.rowid, first.line_start) == (1, 10)
  • assert (second.rowid, second.line_start) == (2, 30)
  • assert first.file == second.file == "pkg/both.py", "same file — only the identity differs"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_two_identities_in_one_file_are_still_distinguishable → resolve_symbol → symbol_provenance
REQ-DDB-QUERY-001measuredtest_two_identities_in_one_file_are_still_distinguishable → resolve_symbol → connect
REQ-DDB-QUERY-003measuredtest_two_identities_in_one_file_are_still_distinguishable → resolve_symbol
REQ-DDB-QUERY-010measuredtest_two_identities_in_one_file_are_still_distinguishable → resolve_symbol
Source · 42 lines
def test_two_identities_in_one_file_are_still_distinguishable(tmp_path: Path) -> None:
    """WHY THE SELECTOR IS NOT THE `file` SUBSTRING `Candidate` used to promise. Two classes in
    one module, each with a `harvest`, is ordinary Python — and a file substring cannot separate
    them, so it would have resolved gh#37's motivating example and failed the general case.

    This is the control on the DESIGN CHOICE, not on the plumbing, which is why it exists
    separately from the tests above: they would all pass against a file-substring
    implementation."""
    db = tmp_path / "onefile.db"
    conn = sqlite3.connect(str(db))
    conn.executescript(
        """
        CREATE TABLE path (name TEXT);
        CREATE TABLE memberdef (
            rowid INTEGER PRIMARY KEY,
            kind TEXT, name TEXT, file_id INTEGER, bodyfile_id INTEGER,
            bodystart INTEGER, bodyend INTEGER, definition TEXT, argsstring TEXT,
            briefdescription TEXT, detaileddescription TEXT, static INTEGER
        );
        """
    )
    conn.execute("INSERT INTO path (rowid, name) VALUES (1, 'pkg/both.py')")
    conn.executemany(
        "INSERT INTO memberdef (rowid, kind, name, file_id, bodyfile_id, bodystart, bodyend, "
        "definition, argsstring, briefdescription, detaileddescription, static) "
        "VALUES (?, 'function', 'harvest', 1, 1, ?, ?, ?, '(self)', '', '', 0)",
        [
            (1, 10, 20, "Any pkg.both.First.harvest"),
            (2, 30, 40, "Any pkg.both.Second.harvest"),
        ],
    )
    conn.commit()
    conn.close()

    first = q.resolve_symbol(db, "harvest", "pkg.both.First.harvest")
    second = q.resolve_symbol(db, "harvest", "pkg.both.Second.harvest")
    assert first is not None and second is not None
    assert (first.rowid, first.line_start) == (1, 10)
    assert (second.rowid, second.line_start) == (2, 30)
    assert first.file == second.file == "pkg/both.py", "same file — only the identity differs"

Activity · 13 steps
lines 328–328db = tmp_path / "onefile.db"lines 329–329conn = sqlite3.connect(str(db))lines 330–340conn.executescript( """ CREATE TABLE path (name TEXT); CREATE TABLE memberdef ( rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, file_id INTEGER, bodyfile_id INTEGER, bodystart INTEGER, bodyend INTEGER, definition TEXT, argsstring TEXT, briefdescription TEXT, detaileddescription TEXT, static INTEGER ); """ )lines 341–341conn.execute("INSERT INTO path (rowid, name) VALUES (1, 'pkg/both.py')")lines 342–350conn.executemany( "INSERT INTO memberdef (rowid, kind, name, file_id, bodyfile_id, bodystart, bodyend, " "definition, argsstring, briefdescription, detaileddescription, static) " "VALUES (?, 'function', 'harvest', 1, 1, ?, ?, ?, '(self)', '', '', 0)", [ (1, 10, 20, "Any pkg.both.First.harvest"), (2, 30, 40, "Any pkg.both.Second.harvest"), ], )lines 351–351conn.commit()lines 352–352conn.close()lines 354–354first = q.resolve_symbol(db, "harvest", "pkg.both.First.harvest")lines 355–355second = q.resolve_symbol(db, "harvest", "pkg.both.Second.harvest")lines 356–356assert first is not None and second is not Nonelines 357–357assert (first.rowid, first.line_start) == (1, 10)lines 358–358assert (second.rowid, second.line_start) == (2, 30)lines 359–359assert first.file == second.file == "pkg/both.py", "same file — only the identity differs"