test_self_index.py¶
tests/integration/test_self_index.py
Index THIS checkout with the real pipeline and assert the graph is non-trivial.
test_ast_member_rows_are_qualifier_verified_not_name_keyed
None test_self_index.test_ast_member_rows_are_qualifier_verified_not_name_keyed(Path self_index_db)
ast_member rows are qualifier-verified, never keyed on a bare name.
tests/integration/test_self_index.py:161
Checks
assert observed.get(SOURCE_AST_MEMBER, 0) >= MIN_AST_MEMBER, (f"{observed.get(SOURCE_AST_MEMBER, 0)} ast_member row(s) on this index, floor " f"{MIN_AST_MEMBER}. `self.method()` carries its enclosing class as a qualifier " "(gh#21), so a collapse to zero means that stopped being emitted." )assert set(confidences) <= {"resolved"}, (f"ast_member rows are not all resolved: {confidences}. A fuzzy row here means the " "qualifier left several candidates and something emitted them regardless." )assert ambiguous_names > 0, ("every ast_member edge has a callee whose name is unique in the index, so a " "name-keyed rule could have produced all of them and this test proves nothing. " "The qualifier's whole value is picking among SAME-NAMED candidates." )assert sites > 100, (f"only {sites} ast_member call site(s) harvested from {package.name}/ — the " "walker has stopped recognising member calls, so a thin ast_member layer would be " "a BROKEN HARVEST rather than the resolution rule. Measured 2521 sites at the time " "this was written; the threshold is deliberately far below that, " "because the claim is 'the harvest is alive', not a count." )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_ast_member_rows_are_qualifier_verified_not_name_keyed → _ast_harvest_calls → is_python_tree |
Source · 77 lines
def test_ast_member_rows_are_qualifier_verified_not_name_keyed(self_index_db: Path) -> None:
"""THE SUCCESSOR TO "MUST BE ZERO" (gh#362 -> gh#21), and the reason the assertion had
to change SHAPE rather than get a new number.
Zero was correct while Python wrote no call-site qualifier. `self.method()` names its
class exactly — the enclosing one — so gh#21 emits it as a qualifier and it now takes
the same path a C++ `Ns::Class::method()` takes. The RULE is untouched: an unqualified
`obj.method()` still earns nothing, and a unique bare NAME still is not evidence.
So this pins what actually matters, in three parts:
* ROWS EXIST — a floor, because the layer going silent again is the regression that
matters, and this half used to be unassertable.
* EVERY ROW IS `resolved` — a fuzzy row here would mean the qualifier narrowed to
several and something emitted them anyway.
* THE QUALIFIER, NOT THE NAME, DID THE WORK — asserted by finding rows whose callee
name is borne by MORE THAN ONE indexed function. A name-keyed rule sees several
candidates and refuses, so it could not have produced them; measured, 8 such rows
(`_prepare` by 2, `_raw` by 3, `cull` by 2), each landing in the caller's own class.
This is the falsifiable form of the claim the old zero made by implication, and it
is what would catch gh#347's fabrication coming back.
* A LIVE HARVEST — kept from the original, because the walker must still be FINDING
the sites it declines to resolve.
@brief Rows exist, all resolved, and the ambiguous ones prove the qualifier works.
@version 2
"""
observed = _edges_by_source(self_index_db)
assert observed.get(SOURCE_AST_MEMBER, 0) >= MIN_AST_MEMBER, (
f"{observed.get(SOURCE_AST_MEMBER, 0)} ast_member row(s) on this index, floor "
f"{MIN_AST_MEMBER}. `self.method()` carries its enclosing class as a qualifier "
"(gh#21), so a collapse to zero means that stopped being emitted."
)
conn = sqlite3.connect(str(self_index_db))
try:
confidences = dict(
conn.execute(
"SELECT confidence, COUNT(*) FROM call_edges WHERE source=? GROUP BY confidence",
(SOURCE_AST_MEMBER,),
)
)
ambiguous_names = conn.execute(
"SELECT COUNT(*) FROM call_edges ce JOIN memberdef m ON m.rowid = ce.callee_rowid "
"WHERE ce.source = ? AND (SELECT COUNT(*) FROM memberdef m2 "
"WHERE m2.name = m.name AND m2.kind = 'function') > 1",
(SOURCE_AST_MEMBER,),
).fetchone()[0]
finally:
conn.close()
assert set(confidences) <= {"resolved"}, (
f"ast_member rows are not all resolved: {confidences}. A fuzzy row here means the "
"qualifier left several candidates and something emitted them regardless."
)
assert ambiguous_names > 0, (
"every ast_member edge has a callee whose name is unique in the index, so a "
"name-keyed rule could have produced all of them and this test proves nothing. "
"The qualifier's whole value is picking among SAME-NAMED candidates."
)
parser = SubstrateParser("python")
package = Path(__file__).resolve().parents[2] / "clew"
sites = 0
for source_file in sorted(package.rglob("*.py")):
src = source_file.read_bytes()
for site in _ast_harvest_calls(parser.parse(src), src):
sites += int(len(site) > 2 and site[2] == SOURCE_AST_MEMBER)
assert sites > 100, (
f"only {sites} ast_member call site(s) harvested from {package.name}/ — the "
"walker has stopped recognising member calls, so a thin ast_member layer would be "
"a BROKEN HARVEST rather than the resolution rule. Measured 2521 sites at the time "
"this was written; the threshold is deliberately far below that, "
"because the claim is 'the harvest is alive', not a count."
)