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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_candidate_without_a_line_is_left_alone → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-003 | measured | test_a_candidate_without_a_line_is_left_alone → candidate_rows |
| REQ-DDB-QUERY-010 | measured | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_a_capped_candidate_list_discloses_the_real_total → _distinct_identities → connect |
| REQ-DDB-QUERY-003 | measured | test_a_capped_candidate_list_discloses_the_real_total → _distinct_identities → table_exists |
| REQ-DDB-QUERY-010 | catalog |
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
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 Noneassert ref.rowid == OVERRIDE_Aassert {c.qualified for c in ref.candidates} == {BASE_QUALIFIED, A_QUALIFIED, B_QUALIFIED}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_disambiguated_reply_still_reports_the_alternatives → resolve_symbol → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_a_disambiguated_reply_still_reports_the_alternatives → resolve_symbol → connect |
| REQ-DDB-QUERY-003 | measured | test_a_disambiguated_reply_still_reports_the_alternatives → resolve_symbol |
| REQ-DDB-QUERY-010 | measured | test_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
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, qualifiedassert ref.rowid == expect_rowid, qualifiedassert ref.file == expect_file, qualified
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_qualified_selector_returns_the_one_identity_asked_for → resolve_symbol → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_a_qualified_selector_returns_the_one_identity_asked_for → resolve_symbol → connect |
| REQ-DDB-QUERY-003 | measured | test_a_qualified_selector_returns_the_one_identity_asked_for → resolve_symbol |
| REQ-DDB-QUERY-010 | measured | test_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
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 Noneassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_an_ambiguous_call_without_a_selector_behaves_as_before → resolve_symbol → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_an_ambiguous_call_without_a_selector_behaves_as_before → resolve_symbol → connect |
| REQ-DDB-QUERY-003 | measured | test_an_ambiguous_call_without_a_selector_behaves_as_before → resolve_symbol |
| REQ-DDB-QUERY-010 | measured | test_an_ambiguous_call_without_a_selector_behaves_as_before → resolve_symbol |
| REQ-DDB-WIKI-054 | inferred | test_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
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
Called by none
Calls callees, callers, function_dossier, overridden_by, overrides_of, resolve_symbol, source
Checks
assert q.resolve_symbol(shared_name_db, "harvest", bogus) is Noneassert q.function_dossier(shared_name_db, "harvest", bogus) is Noneassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_an_unmatched_selector_returns_nothing_rather_than_the_union → source → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_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-011 | inferred | test_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-012 | inferred | test_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-001 | measured | test_an_unmatched_selector_returns_nothing_rather_than_the_union → source |
| REQ-DDB-QUERY-002 | inferred | test_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_an_unmatched_selector_returns_nothing_rather_than_the_union → resolve_symbol |
| REQ-DDB-QUERY-004 | measured | test_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier |
| REQ-DDB-QUERY-006 | inferred | test_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_an_unmatched_selector_returns_nothing_rather_than_the_union → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | inferred | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_candidates_does_not_list_one_declaration_twice → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-003 | measured | test_candidates_does_not_list_one_declaration_twice → candidate_rows |
| REQ-DDB-QUERY-010 | measured | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_candidates_keeps_two_real_overloads_apart → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-003 | measured | test_candidates_keeps_two_real_overloads_apart → candidate_rows |
| REQ-DDB-QUERY-010 | measured | test_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
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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_neighbour_lists_narrow_to_the_selected_identity → callers |
| REQ-DDB-QUERY-003 | measured | test_neighbour_lists_narrow_to_the_selected_identity → callers → _call_edges → _dataflow_edges → resolve_rowid |
| REQ-DDB-QUERY-009 | measured | test_neighbour_lists_narrow_to_the_selected_identity → callers → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_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
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
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 Falseassert "overridden_by" not in missed
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-MCP-003 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-002 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-004 | measured | |
| REQ-DDB-QUERY-006 | measured | |
| REQ-DDB-QUERY-009 | measured | |
| REQ-DDB-QUERY-010 | measured | |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-QUERY-013 | measured | |
| REQ-DDB-QUERY-014 | measured | |
| REQ-DDB-SCHEMA-011 | measured |
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
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 Noneassert (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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_two_identities_in_one_file_are_still_distinguishable → resolve_symbol → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_two_identities_in_one_file_are_still_distinguishable → resolve_symbol → connect |
| REQ-DDB-QUERY-003 | measured | test_two_identities_in_one_file_are_still_distinguishable → resolve_symbol |
| REQ-DDB-QUERY-010 | measured | test_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"