test_self_edges.py¶
tests/test_self_edges.py
The self-edge guard (#61): genuine recursion kept, fabrications dropped.
test_attribute_call_on_another_object_is_dropped
None test_self_edges.test_attribute_call_on_another_object_is_dropped(tmp_path)
Mechanism 2, and the one that proves uniqueness is the wrong test: `IndexCache.close` is the ONLY `close` memberdef in clew's index, yet `self.conn.close()` is sqlite3's method on a different object. Bound back to the wrapper, it reads to a consumer as infinite recursion.
Checks
assert _prune(db, tmp_path) == set()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_attribute_call_on_another_object_is_dropped → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_attribute_call_on_another_object_is_dropped → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 10 lines
def test_attribute_call_on_another_object_is_dropped(tmp_path) -> None:
"""Mechanism 2, and the one that proves uniqueness is the wrong test:
`IndexCache.close` is the ONLY `close` memberdef in clew's index, yet
`self.conn.close()` is sqlite3's method on a different object. Bound back to
the wrapper, it reads to a consumer as infinite recursion."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
_seed_self_edges(db, rowids, ["close"])
assert _prune(db, tmp_path) == set()
Activity · 3 steps
test_bare_c_recursion_is_kept
None test_self_edges.test_bare_c_recursion_is_kept(tmp_path)
a C++ codebase's one genuine self-edge shape, kept alongside 442 fabricated rows in the same database — the reason the guard has to judge per caller.
Checks
assert _prune(db, tmp_path) == {rowids["brace_expand"]}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_bare_c_recursion_is_kept → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_bare_c_recursion_is_kept → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 8 lines
def test_bare_c_recursion_is_kept(tmp_path) -> None:
"""a C++ codebase's one genuine self-edge shape, kept alongside 442 fabricated rows in
the same database — the reason the guard has to judge per caller."""
db, rowids = _make_db(tmp_path, "fixture.cpp", _CPP_FIXTURE)
_seed_self_edges(db, rowids, ["brace_expand"])
assert _prune(db, tmp_path) == {rowids["brace_expand"]}
Activity · 3 steps
test_bare_call_in_a_cpp_method_is_kept
None test_self_edges.test_bare_call_in_a_cpp_method_is_kept(tmp_path)
The rule is conditional on the LANGUAGE, not on method-ness: C++ DOES have an implicit `this`, so a bare `compact(n - 1)` inside `Buffer::compact` is genuine recursion. Dropping it would regress the language the bare-name rule was always correct for, which is the risk this whole change carries.
Checks
assert _prune(db, tmp_path) == {rowids["compact"]}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_bare_call_in_a_cpp_method_is_kept → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_bare_call_in_a_cpp_method_is_kept → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 10 lines
def test_bare_call_in_a_cpp_method_is_kept(tmp_path) -> None:
"""The rule is conditional on the LANGUAGE, not on method-ness: C++ DOES
have an implicit `this`, so a bare `compact(n - 1)` inside `Buffer::compact`
is genuine recursion. Dropping it would regress the language the bare-name
rule was always correct for, which is the risk this whole change carries."""
db, rowids = _make_db(tmp_path, "fixture.cpp", _CPP_FIXTURE)
_seed_self_edges(db, rowids, ["compact"])
assert _prune(db, tmp_path) == {rowids["compact"]}
Activity · 3 steps
test_bare_call_in_a_decorated_python_method_is_dropped
None test_self_edges.test_bare_call_in_a_decorated_python_method_is_dropped(tmp_path)
A `@property`/`@staticmethod` sits under an extra `decorated_definition` node, so the walk from the function to its owning scope has to step over it. Without that step a decorated method reads as module-level and gh#30's rule silently stops applying to it — which is most of a real class's surface.
Checks
assert _prune(db, tmp_path) == set()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_bare_call_in_a_decorated_python_method_is_dropped → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_bare_call_in_a_decorated_python_method_is_dropped → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 10 lines
def test_bare_call_in_a_decorated_python_method_is_dropped(tmp_path) -> None:
"""A `@property`/`@staticmethod` sits under an extra `decorated_definition`
node, so the walk from the function to its owning scope has to step over it.
Without that step a decorated method reads as module-level and gh#30's rule
silently stops applying to it — which is most of a real class's surface."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
_seed_self_edges(db, rowids, ["refresh"])
assert _prune(db, tmp_path) == set()
Activity · 3 steps
test_bare_call_in_a_python_method_is_dropped
None test_self_edges.test_bare_call_in_a_python_method_is_dropped(tmp_path)
gh#30. Python has NO implicit `this`, so a bare `cull(...)` inside a method named `cull` cannot reach the method — it names a module-level or imported `cull`. `DocsDbServer.cull` is the measured instance: its body's bare `cull(self.registry, ...)` is the `state.cull` it imports, and the guard kept that self-edge as the eighth of eight "genuine" recursions when the other seven were real.
Checks
assert _prune(db, tmp_path) == set()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_bare_call_in_a_python_method_is_dropped → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_bare_call_in_a_python_method_is_dropped → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 15 lines
def test_bare_call_in_a_python_method_is_dropped(tmp_path) -> None:
"""gh#30. Python has NO implicit `this`, so a bare `cull(...)` inside a
method named `cull` cannot reach the method — it names a module-level or
imported `cull`. `DocsDbServer.cull` is the measured instance: its body's
bare `cull(self.registry, ...)` is the `state.cull` it imports, and the
guard kept that self-edge as the eighth of eight "genuine" recursions when
the other seven were real.
This is the ONE shape the language-conditional rule removes. Every other
test in this file pins something it must NOT remove."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
_seed_self_edges(db, rowids, ["cull"])
assert _prune(db, tmp_path) == set()
Activity · 3 steps
test_bare_self_call_is_kept
None test_self_edges.test_bare_self_call_is_kept(tmp_path)
Mechanism 1. `scope._classify` really does contain `_classify(child)`; deleting that edge would delete a true fact, which is why a blanket drop of self-edges is wrong however much noise sits beside it.
Checks
assert _prune(db, tmp_path) == {rowids["descend"]}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_bare_self_call_is_kept → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_bare_self_call_is_kept → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 9 lines
def test_bare_self_call_is_kept(tmp_path) -> None:
"""Mechanism 1. `scope._classify` really does contain `_classify(child)`;
deleting that edge would delete a true fact, which is why a blanket drop of
self-edges is wrong however much noise sits beside it."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
_seed_self_edges(db, rowids, ["descend"])
assert _prune(db, tmp_path) == {rowids["descend"]}
Activity · 3 steps
test_caller_with_no_same_named_call_site_is_dropped
None test_self_edges.test_caller_with_no_same_named_call_site_is_dropped(tmp_path)
The DOMINANT mechanism, and one the original three-way split missed: 442 of a C++ codebase's 458 self-edge rows are anonymous-namespace functions that never name themselves anywhere, and 21 of clew's 70 are a `main()` invoked from a `if __name__ == "__main__":` guard which doxygen files inside `main`. Both carry source='doxygen_sqlite', so no change to the AST extractor could have reached them.
Checks
assert _prune(py_db, tmp_path / "py") == set()assert _prune(cpp_db, tmp_path / "cpp") == set()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_caller_with_no_same_named_call_site_is_dropped → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_caller_with_no_same_named_call_site_is_dropped → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 16 lines
def test_caller_with_no_same_named_call_site_is_dropped(tmp_path) -> None:
"""The DOMINANT mechanism, and one the original three-way split missed: 442
of a C++ codebase's 458 self-edge rows are anonymous-namespace functions that never
name themselves anywhere, and 21 of clew's 70 are a `main()` invoked from
a `if __name__ == "__main__":` guard which doxygen files inside `main`. Both
carry source='doxygen_sqlite', so no change to the AST
extractor could have reached them."""
py_db, py_rowids = _make_db(tmp_path / "py", "fixture.py", _PY_FIXTURE)
_seed_self_edges(py_db, py_rowids, ["main"])
assert _prune(py_db, tmp_path / "py") == set()
cpp_db, cpp_rowids = _make_db(tmp_path / "cpp", "fixture.cpp", _CPP_FIXTURE)
_seed_self_edges(cpp_db, cpp_rowids, ["warn_failure"])
assert _prune(cpp_db, tmp_path / "cpp") == set()
Activity · 6 steps
test_caller_without_a_body_range_is_left_alone
None test_self_edges.test_caller_without_a_body_range_is_left_alone(tmp_path)
A declaration-only memberdef has no usable body range, so there is nowhere to look for a call site. That is UNVERIFIABLE, not fabricated.
Checks
assert _prune(db, tmp_path) == {declared_only}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_caller_without_a_body_range_is_left_alone → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_caller_without_a_body_range_is_left_alone → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 19 lines
def test_caller_without_a_body_range_is_left_alone(tmp_path) -> None:
"""A declaration-only memberdef has no usable body range, so there is
nowhere to look for a call site. That is UNVERIFIABLE, not fabricated."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
conn = sqlite3.connect(str(db))
conn.execute(
"INSERT INTO memberdef (kind, name, file_id, bodyfile_id, bodystart, bodyend) "
"VALUES ('function', 'declared_only', 1, 1, 0, 0)"
)
conn.commit()
declared_only = conn.execute(
"SELECT rowid FROM memberdef WHERE name = 'declared_only'"
).fetchone()[0]
conn.close()
rowids["declared_only"] = declared_only
_seed_self_edges(db, rowids, ["declared_only"])
assert _prune(db, tmp_path) == {declared_only}
Activity · 9 steps
test_end_to_end_layer3_prunes_what_it_and_doxygen_wrote
None test_self_edges.test_end_to_end_layer3_prunes_what_it_and_doxygen_wrote(tmp_path)
The wiring: `import_ast_call_edges` runs the guard itself, so a build that reaches Layer 3 is guarded with no pipeline-driver change — and a build without tree-sitter skips both together rather than pruning unguarded.
Checks
assert survivors == {rowids["descend"], rowids["walk"], rowids["prune"]}assert rowids["cull"] not in survivors, "a bare call in a Python method is not recursion"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_end_to_end_layer3_prunes_what_it_and_doxygen_wrote → import_ast_call_edges → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_end_to_end_layer3_prunes_what_it_and_doxygen_wrote → import_ast_call_edges → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_end_to_end_layer3_prunes_what_it_and_doxygen_wrote → import_ast_call_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-WIKI-054 | inferred | test_end_to_end_layer3_prunes_what_it_and_doxygen_wrote → import_ast_call_edges → _fold_all_files → _fold_call_payload → _ast_record_call_edge → _narrow_by_receiver → _one_class → all |
Source · 26 lines
def test_end_to_end_layer3_prunes_what_it_and_doxygen_wrote(tmp_path) -> None:
"""The wiring: `import_ast_call_edges` runs the guard itself, so a build
that reaches Layer 3 is guarded with no pipeline-driver change — and a build
without tree-sitter skips both together rather than pruning unguarded.
Also the end-to-end statement of gh#30: Layer 3 does not merely INHERIT the
fabricated `cull` self-edge from doxygen, it MANUFACTURES one, because the
bare `cull(registry)` resolves by name straight back onto the method. So the
guard is the only thing standing between that call site and a self-edge, and
`cull` must be absent from the survivors while `prune` — which really does
call `self.prune` — is present."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
_seed_self_edges(db, rowids, ["main", "close", "__init__", "descend", "walk", "cull", "prune"])
import_ast_call_edges(db, tmp_path, None)
conn = sqlite3.connect(str(db))
survivors = {
r[0]
for r in conn.execute(
"SELECT DISTINCT caller_rowid FROM call_edges WHERE caller_rowid = callee_rowid"
).fetchall()
}
conn.close()
assert survivors == {rowids["descend"], rowids["walk"], rowids["prune"]}
assert rowids["cull"] not in survivors, "a bare call in a Python method is not recursion"
Activity · 8 steps
test_global_scope_qualified_call_is_dropped
None test_self_edges.test_global_scope_qualified_call_is_dropped(tmp_path)
`::close(fd_)` inside a member named `close` calls POSIX close, not the member. Accepting any qualified shape as self-directed would have kept all ten of a C++ codebase's `::close()`/`::open()` rows as recursion.
Checks
assert _prune(db, tmp_path) == set()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_global_scope_qualified_call_is_dropped → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_global_scope_qualified_call_is_dropped → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 9 lines
def test_global_scope_qualified_call_is_dropped(tmp_path) -> None:
"""`::close(fd_)` inside a member named `close` calls POSIX close, not the
member. Accepting any qualified shape as self-directed would have kept all
ten of a C++ codebase's `::close()`/`::open()` rows as recursion."""
db, rowids = _make_db(tmp_path, "fixture.cpp", _CPP_FIXTURE)
_seed_self_edges(db, rowids, ["close"])
assert _prune(db, tmp_path) == set()
Activity · 3 steps
test_indirection_layers_are_outside_the_guards_jurisdiction
None test_self_edges.test_indirection_layers_are_outside_the_guards_jurisdiction(tmp_path)
`fnptr` and `declared_dispatch` assert an INDIRECTION no call site names — a stored function pointer, an author-declared virtual seam — so the call-shape rule has no evidence to apply and must not delete them. Neither produced a self-edge on either codebase; this pins the intent.
Checks
assert _prune(db, tmp_path) == {rowids["close"], rowids["main"]}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-011 | measured | test_indirection_layers_are_outside_the_guards_jurisdiction → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_indirection_layers_are_outside_the_guards_jurisdiction → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 19 lines
def test_indirection_layers_are_outside_the_guards_jurisdiction(tmp_path) -> None:
"""`fnptr` and `declared_dispatch` assert an INDIRECTION no call site names —
a stored function pointer, an author-declared virtual seam — so the
call-shape rule has no evidence to apply and must not delete them. Neither
produced a self-edge on either codebase; this pins the intent."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
conn = sqlite3.connect(str(db))
conn.executemany(
"INSERT INTO call_edges VALUES (?, ?, ?, 'resolved')",
[
(rowids["close"], rowids["close"], CALL_SOURCE_FNPTR),
(rowids["main"], rowids["main"], CALL_SOURCE_DECLARED_DISPATCH),
],
)
conn.commit()
conn.close()
assert _prune(db, tmp_path) == {rowids["close"], rowids["main"]}
Activity · 6 steps
test_non_self_edges_are_untouched
None test_self_edges.test_non_self_edges_are_untouched(tmp_path)
The guard's whole jurisdiction is the diagonal. An ordinary edge in the same layers must survive byte for byte, including a `main -> descend` edge whose caller IS a pruned self-edge caller.
Checks
assert remaining == [(rowids["main"], rowids["descend"], CALL_SOURCE_DOXYGEN_SQLITE)]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_non_self_edges_are_untouched → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_non_self_edges_are_untouched → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 20 lines
def test_non_self_edges_are_untouched(tmp_path) -> None:
"""The guard's whole jurisdiction is the diagonal. An ordinary edge in the
same layers must survive byte for byte, including a `main -> descend` edge
whose caller IS a pruned self-edge caller."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
_seed_self_edges(db, rowids, ["main", "close"])
conn = sqlite3.connect(str(db))
conn.execute(
"INSERT INTO call_edges VALUES (?, ?, ?, 'exact')",
(rowids["main"], rowids["descend"], CALL_SOURCE_DOXYGEN_SQLITE),
)
conn.commit()
conn.close()
_prune(db, tmp_path)
conn = sqlite3.connect(str(db))
remaining = conn.execute("SELECT caller_rowid, callee_rowid, source FROM call_edges").fetchall()
conn.close()
assert remaining == [(rowids["main"], rowids["descend"], CALL_SOURCE_DOXYGEN_SQLITE)]
Activity · 11 steps
test_python_module_level_bare_recursion_is_still_kept
None test_self_edges.test_python_module_level_bare_recursion_is_still_kept(tmp_path)
The other half of the guard against over-reach: the rule keys on the enclosing function being a METHOD, not on the file being Python. A module-level `descend(child)` is still recursion, so a rule that keyed on the file's language alone would delete every recursive free function in every Python codebase.
Checks
assert _prune(db, tmp_path) == {rowids["descend"]}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_python_module_level_bare_recursion_is_still_kept → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_python_module_level_bare_recursion_is_still_kept → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 11 lines
def test_python_module_level_bare_recursion_is_still_kept(tmp_path) -> None:
"""The other half of the guard against over-reach: the rule keys on the
enclosing function being a METHOD, not on the file being Python. A
module-level `descend(child)` is still recursion, so a rule that keyed on
the file's language alone would delete every recursive free function in
every Python codebase."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
_seed_self_edges(db, rowids, ["descend"])
assert _prune(db, tmp_path) == {rowids["descend"]}
Activity · 3 steps
test_self_directed_sites_reads_shape_not_name
None test_self_edges.test_self_directed_sites_reads_shape_not_name(tmp_path)
Unit-level statement of the rule the mechanisms above exercise: a bare call and a `self.`-rooted call are self-directed; `self.conn.close()`, `super().__init__()` and `::close()` are not.
Checks
assert {"descend", "walk"} <= namesassert "close" not in names, "self.conn.close() has a receiver of its own"assert "__init__" not in names, "super().__init__() is not rooted at self"assert {"walk", "brace_expand", "log_warn"} <= namesassert "close" not in names, "::close() is the global-scope function"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured |
Source · 16 lines
def test_self_directed_sites_reads_shape_not_name(tmp_path) -> None:
"""Unit-level statement of the rule the mechanisms above exercise: a bare
call and a `self.`-rooted call are self-directed; `self.conn.close()`,
`super().__init__()` and `::close()` are not."""
tree, src = _parse(tmp_path, "fixture.py", _PY_FIXTURE)
names = {name for name, _line in _self_directed_sites(tree, src)}
assert {"descend", "walk"} <= names
assert "close" not in names, "self.conn.close() has a receiver of its own"
assert "__init__" not in names, "super().__init__() is not rooted at self"
tree, src = _parse(tmp_path, "fixture.cpp", _CPP_FIXTURE)
names = {name for name, _line in _self_directed_sites(tree, src)}
assert {"walk", "brace_expand", "log_warn"} <= names
assert "close" not in names, "::close() is the global-scope function"
Activity · 9 steps
test_self_rooted_method_recursion_is_kept
None test_self_edges.test_self_rooted_method_recursion_is_kept(tmp_path)
`self.walk(child)` is the ONLY way a Python method can recurse — a bare `walk(child)` inside a method does not resolve to the method at all. A rule that accepted only bare calls would therefore discard every recursive method in every Python codebase, so the receiver has to be inspected, not just the presence of a dot.
Checks
assert _prune(db, tmp_path) == {rowids["walk"]}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_self_rooted_method_recursion_is_kept → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_self_rooted_method_recursion_is_kept → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 11 lines
def test_self_rooted_method_recursion_is_kept(tmp_path) -> None:
"""`self.walk(child)` is the ONLY way a Python method can recurse — a bare
`walk(child)` inside a method does not resolve to the method at all. A rule
that accepted only bare calls would therefore discard every recursive method
in every Python codebase, so the receiver has to be inspected, not just the
presence of a dot."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
_seed_self_edges(db, rowids, ["walk"])
assert _prune(db, tmp_path) == {rowids["walk"]}
Activity · 3 steps
test_self_rooted_recursion_survives_a_bare_call_in_the_same_method
None test_self_edges.test_self_rooted_recursion_survives_a_bare_call_in_the_same_method(tmp_path)
Per CALL SITE, not per function. `prune` makes both a bare `prune(node)` and a real `self.prune(node.next)`; the bare one proves nothing and the self-rooted one proves recursion, so the edge stays. A rule that rejected the whole method on seeing a bare call would drop a true fact.
Checks
assert _prune(db, tmp_path) == {rowids["prune"]}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_self_rooted_recursion_survives_a_bare_call_in_the_same_method → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_self_rooted_recursion_survives_a_bare_call_in_the_same_method → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 10 lines
def test_self_rooted_recursion_survives_a_bare_call_in_the_same_method(tmp_path) -> None:
"""Per CALL SITE, not per function. `prune` makes both a bare `prune(node)`
and a real `self.prune(node.next)`; the bare one proves nothing and the
self-rooted one proves recursion, so the edge stays. A rule that rejected
the whole method on seeing a bare call would drop a true fact."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
_seed_self_edges(db, rowids, ["prune"])
assert _prune(db, tmp_path) == {rowids["prune"]}
Activity · 3 steps
test_super_init_is_dropped
None test_self_edges.test_super_init_is_dropped(tmp_path)
Mechanism 3. `super().__init__()` is DOUBLE damage — it fabricates the self-edge and loses the real subclass->baseclass edge — so the drop removes a false claim without removing a true one that was ever present.
Checks
assert _prune(db, tmp_path) == set()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_super_init_is_dropped → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_super_init_is_dropped → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 9 lines
def test_super_init_is_dropped(tmp_path) -> None:
"""Mechanism 3. `super().__init__()` is DOUBLE damage — it fabricates the
self-edge and loses the real subclass->baseclass edge — so the drop removes
a false claim without removing a true one that was ever present."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
_seed_self_edges(db, rowids, ["__init__"])
assert _prune(db, tmp_path) == set()
Activity · 3 steps
test_the_guard_does_not_reparse_a_file_whose_sites_are_cached
None test_self_edges.test_the_guard_does_not_reparse_a_file_whose_sites_are_cached(Path tmp_path, monkeypatch)
A second guarded run with a warm cache parses nothing.
Called by none
Calls _build_function_indexes, _seed_self_edges, prune_fabricated_self_edges
Checks
assert after_cold > 0, "the cold run must actually parse, or this asserts nothing"assert parsed["n"] == after_cold, (f"a warm run must parse nothing; it parsed {parsed['n'] - after_cold} more file(s)" )assert second_survivors == first_survivors, "the cached verdict must match the parsed one"assert rowids["cull"] not in second_survivors, "the guard must still delete a bare call"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_the_guard_does_not_reparse_a_file_whose_sites_are_cached → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_the_guard_does_not_reparse_a_file_whose_sites_are_cached → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 69 lines
def test_the_guard_does_not_reparse_a_file_whose_sites_are_cached(
tmp_path: Path, monkeypatch
) -> None:
"""gh#34. THE GUARD WAS THE LAST PARSER IN A REFRESH THAT PARSES NOTHING ELSE. Measured on
a 6.8 GB repository with every call payload served from cache, `prune_fabricated_self_edges`
cost 1,225 ms of a 2,968 ms stage, re-parsing 138 files to ask which of their calls are
self-rooted.
THE DOCSTRING WEIGHED TWO OPTIONS AND BOTH WERE WORSE. Widening the shared `ast_calls`
payload would invalidate every file's cached extraction on every repository for a question
that concerns under 1% of call sites; parsing here keeps that payload untouched. What it did
not consider is a payload of this pass's OWN — its own stage tag, its own version — which
keeps the shared key untouched AND stops re-reading a file nothing changed. The site list is
`(name, line)` pairs, which is all `_file_self_edge_verdicts` ever took from the tree.
ASSERTED ON PARSER INVOCATIONS, not on time: a timing assertion in a unit test measures the
machine, while a parse that did not happen is the mechanism itself.
@brief A second guarded run with a warm cache parses nothing.
@version 1
"""
from clew import call_edges as ce
from clew.indexcache import IndexCache
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
_seed_self_edges(db, rowids, ["descend", "walk", "cull", "prune"])
cache_path = tmp_path / "clew.db.idxcache"
parsed = {"n": 0}
original = ce._ast_parse_one_file
def counting(*args, **kwargs): # noqa: ANN002, ANN003, ANN202
parsed["n"] += 1
return original(*args, **kwargs)
monkeypatch.setattr(ce, "_ast_parse_one_file", counting)
def guarded(run: int) -> set[int]:
"""COPIES THE SEEDED DATABASE so both runs start from identical rows and share only the
cache — re-seeding in place would re-insert the self-edges the first run deleted."""
import shutil
working = tmp_path / f"guarded-{run}.db"
shutil.copy(db, working)
conn = sqlite3.connect(str(working))
_names, file_funcs = _build_function_indexes(conn)
cache = IndexCache(cache_path, tmp_path)
prune_fabricated_self_edges(conn, tmp_path, file_funcs, cache=cache)
conn.commit()
cache.commit()
survivors = {
r[0]
for r in conn.execute(
"SELECT DISTINCT caller_rowid FROM call_edges WHERE caller_rowid = callee_rowid"
).fetchall()
}
conn.close()
return survivors
first_survivors = guarded(1)
after_cold = parsed["n"]
second_survivors = guarded(2)
assert after_cold > 0, "the cold run must actually parse, or this asserts nothing"
assert parsed["n"] == after_cold, (
f"a warm run must parse nothing; it parsed {parsed['n'] - after_cold} more file(s)"
)
assert second_survivors == first_survivors, "the cached verdict must match the parsed one"
assert rowids["cull"] not in second_survivors, "the guard must still delete a bare call"1 more lines, not shown
Activity · 17 steps
test_this_rooted_method_recursion_is_kept
None test_self_edges.test_this_rooted_method_recursion_is_kept(tmp_path)
The C++ half of the same rule: `this->walk(...)` inside `Tree::walk`.
Checks
assert _prune(db, tmp_path) == {rowids["walk"]}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_this_rooted_method_recursion_is_kept → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_this_rooted_method_recursion_is_kept → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 7 lines
def test_this_rooted_method_recursion_is_kept(tmp_path) -> None:
"""The C++ half of the same rule: `this->walk(...)` inside `Tree::walk`."""
db, rowids = _make_db(tmp_path, "fixture.cpp", _CPP_FIXTURE)
_seed_self_edges(db, rowids, ["walk"])
assert _prune(db, tmp_path) == {rowids["walk"]}
Activity · 3 steps
test_unreadable_caller_file_leaves_its_edges_alone
None test_self_edges.test_unreadable_caller_file_leaves_its_edges_alone(tmp_path)
FAIL CLOSED, and in the direction that matters: a file that will not parse is a fact about the DETECTOR, not about the code, so its self-edges survive unjudged rather than being deleted on absence of evidence.
Checks
assert _prune(db, tmp_path) == {rowids["close"], rowids["main"]}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-011 | measured | test_unreadable_caller_file_leaves_its_edges_alone → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_unreadable_caller_file_leaves_its_edges_alone → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 10 lines
def test_unreadable_caller_file_leaves_its_edges_alone(tmp_path) -> None:
"""FAIL CLOSED, and in the direction that matters: a file that will not
parse is a fact about the DETECTOR, not about the code, so its self-edges
survive unjudged rather than being deleted on absence of evidence."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
_seed_self_edges(db, rowids, ["close", "main"])
(tmp_path / "fixture.py").unlink()
assert _prune(db, tmp_path) == {rowids["close"], rowids["main"]}
Activity · 4 steps
test_verdict_log_identifies_callers_by_rowid
None test_self_edges.test_verdict_log_identifies_callers_by_rowid(tmp_path, caplog)
gh#30's third requirement. The verdict log used to print BARE names, and this repo holds three unrelated `_classify` functions — so `KEPT ... _classify` named a symbol a reader could not locate, and was mistaken for evidence of gh#26, a different defect in a different layer.
Checks
assert f"descend#{rowids['descend']}" in text, "a kept caller must carry its rowid"assert f"cull#{rowids['cull']}" in text, "a dropped caller must carry its rowid"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | measured | test_verdict_log_identifies_callers_by_rowid → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_verdict_log_identifies_callers_by_rowid → _prune → prune_fabricated_self_edges → _gather_self_call_evidence → _self_sites_for → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language |
Source · 18 lines
def test_verdict_log_identifies_callers_by_rowid(tmp_path, caplog) -> None:
"""gh#30's third requirement. The verdict log used to print BARE names, and
this repo holds three unrelated `_classify` functions — so `KEPT ...
_classify` named a symbol a reader could not locate, and was mistaken for
evidence of gh#26, a different defect in a different layer.
`name#rowid` is checkable against `memberdef`. Asserting the rowid is
PRESENT is the whole point: a bare name would satisfy any test that only
looked for the name."""
db, rowids = _make_db(tmp_path, "fixture.py", _PY_FIXTURE)
_seed_self_edges(db, rowids, ["descend", "cull"])
with caplog.at_level(logging.DEBUG, logger="clew"):
_prune(db, tmp_path)
text = caplog.text
assert f"descend#{rowids['descend']}" in text, "a kept caller must carry its rowid"
assert f"cull#{rowids['cull']}" in text, "a dropped caller must carry its rowid"