test_extra_seeds_rescue_a_self_loop_false_orphan¶
Tests › tests/test_python_ast.py
What this test is for
Why it exists
The exact shape measured on `a Python codebase`: doxygen attributes a `__main__` guard's call to the guarded function ITSELF, so the function has a non-fuzzy incoming edge (excluding it from the zero-incoming source) and its only caller is itself. Without a structural seed it is a FALSE orphan; with one it is live. `dead_helper` must stay orphan either way, proving the seed does not simply mark everything live.
Given
db = tmp_path / "clew.db"conn = sqlite3.connect(str(db))
5 more
conn.executescript( """ CREATE TABLE memberdef ( rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, file_id INTEGER, bodyfile_id INTEGER, bodystart INTEGER, bodyend INTEGER ); CREATE TABLE call_edges (caller_rowid INTEGER, callee_rowid INTEGER, source TEXT, confidence TEXT); """, )conn.executemany( "INSERT INTO memberdef (rowid, kind, name, file_id, bodyfile_id, bodystart, " "bodyend) VALUES (?, 'function', ?, 1, 1, ?, ?)", [(1, "guarded", 1, 2), (2, "reached", 3, 4), (3, "dead_helper", 5, 6), (4, "dead2", 7, 8)], )conn.executemany( "INSERT INTO call_edges VALUES (?, ?, 'ast', 'resolved')", # guarded -> guarded (the doxygen self-loop), guarded -> reached, # and a dead mutually-recursive pair so neither is zero-incoming. [(1, 1), (1, 2), (3, 4), (4, 3)], )conn.commit()conn.close()
When
mark_reachability(db, entry_patterns=["nothing_matches"])conn = sqlite3.connect(str(db))before = dict(conn.execute("SELECT memberdef_rowid, status FROM symbol_liveness"))
5 more
conn.close()mark_reachability(db, entry_patterns=["nothing_matches"], extra_seeds={1})conn = sqlite3.connect(str(db))after = dict(conn.execute("SELECT memberdef_rowid, status FROM symbol_liveness"))conn.close()
Then
- ✓ before[1] equals "orphan"
- ✓ after[1] equals "live"
- ✓ after[2] equals "live"
- ✓ after[3] equals "orphan"
- ✓ after[4] equals "orphan"
tests/test_python_ast.py:688 · its file's page
What it checks (5)
assert before[1] == "orphan", "expected the self-loop entry to be a false orphan"not attributedassert after[1] == "live", "structural seed did not rescue the entry point"not attributedassert after[2] == "live", "the entry's callee should now be reachable"not attributedassert after[3] == "orphan", "a genuinely dead function must stay orphan"not attributedassert after[4] == "orphan"not attributed
Where the product reaches it
No product flow reaches this code: no product entry point's flow calls any of the functions this test calls.
Call flow
What it reaches
Each row runs from this test, through the calls it makes, to the code a requirement names. If that code breaks, the test's checks are what should catch it. Reaching is not proving: a check only proves what it observes. No mutation records were given, so these rows say what the test REACHES.
Also reaches 2 requirements
Its run touches their code; that is reach, not proof.
- REQ-DDB-PIPE-004 measured
- REQ-DDB-SCHEMA-012 measured