test_body_anchor.py¶
tests/test_body_anchor.py
A colleague's report against valkey 7f1dffed: doxygen's body spans for src/module.c sat three lines early throughout the file, so `dossier("moduleAcquireGIL")` returned the TAIL OF THE PRECEDING FUNCTION as its body, and one candidate named a (file, line) that cannot exist — `src/module.h:9296` in a 252-line header.
test_a_candidate_never_pairs_one_files_name_with_another_files_line
None test_body_anchor.test_a_candidate_never_pairs_one_files_name_with_another_files_line(Path tmp_path)
A candidate's file and line come from the same location.
Checks
assert header, f"the header declaration row is still listed, got {rows}"assert header[0][3] == 2, (f"the header row is at module.h:2, not at a line of module.c; got {header[0][3]}" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-003 | measured | test_a_candidate_never_pairs_one_files_name_with_another_files_line → function_candidates |
| REQ-DDB-QUERY-010 | measured | test_a_candidate_never_pairs_one_files_name_with_another_files_line → function_candidates |
Source · 22 lines
def test_a_candidate_never_pairs_one_files_name_with_another_files_line(tmp_path: Path) -> None:
"""THE IMPOSSIBLE LOCATION. `function_candidates` read the path from `file_id` — the file that
DECLARES the symbol — and the line from `bodystart` — a line in the file that DEFINES it. For a
header declaration those are two different files, so the candidate reported
`src/module.h:<a line in module.c>`: 9296 in a 252-line header on valkey. It needs no shifted
span to happen; any header declaration row listed as a candidate produces it.
@brief A candidate's file and line come from the same location.
@version 1
"""
db, _root = _shifted_db(tmp_path)
conn = sqlite3.connect(db)
rows = function_candidates(conn, "release_gil")
conn.close()
header = [row for row in rows if row[2] == "src/module.h"]
assert header, f"the header declaration row is still listed, got {rows}"
assert header[0][3] == 2, (
f"the header row is at module.h:2, not at a line of module.c; got {header[0][3]}"
)
Activity · 7 steps
test_the_dossier_describes_the_row_whose_span_is_actually_the_function
None test_body_anchor.test_the_dossier_describes_the_row_whose_span_is_actually_the_function(Path tmp_path)
An unanchored pick yields to an anchored sibling of the same identity.
Checks
assert dossier is not Noneassert dossier.body is not Noneassert not dossier.body.anchor_mismatch, (f"an anchored sibling existed and was not used; body was {dossier.body.lines}" )assert "release_gil" in dossier.body.lines[0], (f"the body must open on the function itself, got {dossier.body.lines}" )assert dossier.line_start == 9, (f"the dossier's location follows the row it describes, got {dossier.line_start}" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | measured | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | measured | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → locks_held_for_rowids |
Source · 29 lines
def test_the_dossier_describes_the_row_whose_span_is_actually_the_function(tmp_path: Path) -> None:
"""THE BODY THAT LOOKS LIKE PROOF. The chosen row's span opened three lines early, so the
dossier quoted the end of the PRECEDING function under this function's heading — with
`anchor_mismatch: true`, correctly, but with the text still there to quote, while the exact
span sat one row away as a parser-recovered candidate of the same identity.
Disclosure was the right call when no better row existed. When one does, describing it makes
the wrong body unreachable instead of merely flagged — and the dossier's own line numbers move
with it, so the header and the body cannot disagree.
@brief An unanchored pick yields to an anchored sibling of the same identity.
@version 1
"""
db, root = _shifted_db(tmp_path)
dossier = function_dossier(db, "release_gil", repo_root=root)
assert dossier is not None
assert dossier.body is not None
assert not dossier.body.anchor_mismatch, (
f"an anchored sibling existed and was not used; body was {dossier.body.lines}"
)
assert "release_gil" in dossier.body.lines[0], (
f"the body must open on the function itself, got {dossier.body.lines}"
)
assert dossier.line_start == 9, (
f"the dossier's location follows the row it describes, got {dossier.line_start}"
)
Activity · 7 steps
test_with_no_anchored_sibling_the_mismatch_is_still_disclosed
None test_body_anchor.test_with_no_anchored_sibling_the_mismatch_is_still_disclosed(Path tmp_path)
Without a better row, the flag stays and nothing is invented.
Checks
assert dossier is not None and dossier.body is not Noneassert dossier.body.anchor_mismatch, "the shifted span is still flagged when nothing is better"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | measured | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | measured | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → locks_held_for_rowids |
Source · 19 lines
def test_with_no_anchored_sibling_the_mismatch_is_still_disclosed(tmp_path: Path) -> None:
"""THE CONTROL. Re-anchoring must only ever move to EVIDENCE — a row of the same identity whose
own span opens on the name. With no such row the original behaviour stands: the body is shown
and `anchor_mismatch` says not to trust it. Guessing a nearby line would be a heuristic
wearing the authority of an index row.
@brief Without a better row, the flag stays and nothing is invented.
@version 1
"""
db, root = _shifted_db(tmp_path)
conn = sqlite3.connect(db)
conn.execute("DELETE FROM memberdef WHERE rowid = 3")
conn.commit()
conn.close()
dossier = function_dossier(db, "release_gil", repo_root=root)
assert dossier is not None and dossier.body is not None
assert dossier.body.anchor_mismatch, "the shifted span is still flagged when nothing is better"1 more lines, not shown