test_test_scope.py¶
tests/test_test_scope.py
A bare ambiguous name must prefer the library definition over a test helper.
test_a_repo_with_no_tests_gets_an_empty_table_not_a_missing_one
None test_test_scope.test_a_repo_with_no_tests_gets_an_empty_table_not_a_missing_one(Path tmp_path)
The stage writes an EMPTY table rather than none when nothing matches.
Checks
assert marked == 0, "src/main.c is not test code"assert _common.table_exists(conn, "test_scope"), ("the stage ran and found nothing, but wrote no table — so this index is now " "indistinguishable from one built before the stage existed" )assert conn.execute("SELECT COUNT(*) FROM test_scope").fetchone()[0] == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-003 | measured | test_a_repo_with_no_tests_gets_an_empty_table_not_a_missing_one → table_exists |
Source · 25 lines
def test_a_repo_with_no_tests_gets_an_empty_table_not_a_missing_one(tmp_path: Path) -> None:
"""THE DISTINCTION THE FALLBACK DEPENDS ON. An ABSENT table means "this index predates the
stage"; an EMPTY one means "the stage ran and this repo has no test code". Collapsing them
would make an old index and a test-free repo indistinguishable, and the resolver would
silently behave differently on each while both looked the same to a reader.
@brief Running the stage always creates the table.
@return None.
@version 1
"""
conn = sqlite3.connect(str(tmp_path / "notests.db"))
conn.executescript("CREATE TABLE path (rowid INTEGER PRIMARY KEY, type INTEGER, name TEXT);")
conn.execute("INSERT INTO path (rowid, type, name) VALUES (1, 1, 'src/main.c')")
try:
marked = mark_test_scope(conn, list(TEST_PATH_FACTS))
assert marked == 0, "src/main.c is not test code"
assert _common.table_exists(conn, "test_scope"), (
"the stage ran and found nothing, but wrote no table — so this index is now "
"indistinguishable from one built before the stage existed"
)
assert conn.execute("SELECT COUNT(*) FROM test_scope").fetchone()[0] == 0
finally:
conn.close()
Activity · 8 steps
test_an_index_without_the_table_still_resolves
None test_test_scope.test_an_index_without_the_table_still_resolves(Path tmp_path)
An index built before the stage existed keeps its previous ordering.
Checks
assert not _common.table_exists(conn, "test_scope")assert got == HELPER, ("without the table the resolver must fall back to the in-place ordering, which picks " "the helper here — if this changed, the fallback is not the old behaviour" )assert len(rows) == 2, "candidates must still list every meaning"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-003 | measured | test_an_index_without_the_table_still_resolves → table_exists |
| REQ-DDB-QUERY-010 | measured | test_an_index_without_the_table_still_resolves → resolve_rowid |
Source · 26 lines
def test_an_index_without_the_table_still_resolves(tmp_path: Path) -> None:
"""FORWARD COMPATIBILITY IS THE POINT. Every index built before this stage has no
`test_scope` table, and the query layer must not raise on one — a missing table is missing
knowledge, not a reason to refuse an answer. The old ordering is asserted explicitly
(the helper wins) so this test says WHICH behaviour the fallback is, rather than merely
that it does not crash.
@brief A pre-stage index degrades to the old ranking without raising.
@return None.
@version 1
"""
conn = _fixture(tmp_path, mark=False)
try:
assert not _common.table_exists(conn, "test_scope")
got = _common.resolve_rowid(conn, "run_turn")
rows = _common.function_candidates(conn, "run_turn")
finally:
conn.close()
assert got == HELPER, (
"without the table the resolver must fall back to the in-place ordering, which picks "
"the helper here — if this changed, the fallback is not the old behaviour"
)
assert len(rows) == 2, "candidates must still list every meaning"
Activity · 7 steps
test_the_library_definition_outranks_a_test_helper
None test_test_scope.test_the_library_definition_outranks_a_test_helper(Path tmp_path)
With the stage run, the library definition outranks the test helper.
Checks
assert got == LIBRARY, (f"resolved to rowid {got}: the test helper won. It is IN PLACE while the real method " f"is declared in a header and defined out of line, so the in-place term favours it — " f"the test-scope term has to sort ahead of that one" )assert rows[0][0] == LIBRARY, f"candidates ranked the test helper first: {rows}"assert {r[0] for r in rows} == {LIBRARY, HELPER}, (f"a test-code definition was dropped rather than demoted: {rows}" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-003 | measured | test_the_library_definition_outranks_a_test_helper → resolve_rowid |
| REQ-DDB-QUERY-010 | measured | test_the_library_definition_outranks_a_test_helper → resolve_rowid |
Source · 25 lines
def test_the_library_definition_outranks_a_test_helper(tmp_path: Path) -> None:
"""@brief A bare name resolves to the library definition.
@return None.
@version 1
"""
conn = _fixture(tmp_path, mark=True)
try:
got = _common.resolve_rowid(conn, "run_turn")
rows = _common.function_candidates(conn, "run_turn")
finally:
conn.close()
assert got == LIBRARY, (
f"resolved to rowid {got}: the test helper won. It is IN PLACE while the real method "
f"is declared in a header and defined out of line, so the in-place term favours it — "
f"the test-scope term has to sort ahead of that one"
)
assert rows[0][0] == LIBRARY, f"candidates ranked the test helper first: {rows}"
## STILL LISTED, never filtered. A test-code definition is a real definition: a repo whose
## only definition of a name lives in a test must still resolve to it.
assert {r[0] for r in rows} == {LIBRARY, HELPER}, (
f"a test-code definition was dropped rather than demoted: {rows}"
)