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.

tests/test_body_anchor.py:97

Show on the map →

Called by none

Calls _shifted_db, function_candidates

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-003measuredtest_a_candidate_never_pairs_one_files_name_with_another_files_line → function_candidates
REQ-DDB-QUERY-010measuredtest_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
lines 107–107db, _root = _shifted_db(tmp_path)lines 108–108conn = sqlite3.connect(db)lines 109–109rows = function_candidates(conn, "release_gil")lines 110–110conn.close()lines 112–112header = [row for row in rows if row[2] == "src/module.h"]lines 113–113assert header, f"the header declaration row is still listed, got {rows}"lines 114–116assert header[0][3] == 2, ( f"the header row is at module.h:2, not at a line of module.c; got {header[0][3]}" )

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.

tests/test_body_anchor.py:119

Show on the map →

Called by none

Calls _shifted_db, function_dossier

Checks

  • 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}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003measuredtest_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-011measuredtest_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-012inferredtest_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-001measuredtest_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier
REQ-DDB-QUERY-006measuredtest_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier
REQ-DDB-QUERY-010measuredtest_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier
REQ-DDB-QUERY-012measuredtest_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_the_dossier_describes_the_row_whose_span_is_actually_the_function → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_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
lines 132–132db, root = _shifted_db(tmp_path)lines 133–133dossier = function_dossier(db, "release_gil", repo_root=root)lines 135–135assert dossier is not Nonelines 136–136assert dossier.body is not Nonelines 137–139assert not dossier.body.anchor_mismatch, ( f"an anchored sibling existed and was not used; body was {dossier.body.lines}" )lines 140–142assert "release_gil" in dossier.body.lines[0], ( f"the body must open on the function itself, got {dossier.body.lines}" )lines 143–145assert dossier.line_start == 9, ( f"the dossier's location follows the row it describes, got {dossier.line_start}" )

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.

tests/test_body_anchor.py:148

Show on the map →

Called by none

Calls _shifted_db, function_dossier

Checks

  • 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"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-PIPE-003measuredtest_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-011measuredtest_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-012inferredtest_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-001measuredtest_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier
REQ-DDB-QUERY-006measuredtest_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier
REQ-DDB-QUERY-010measuredtest_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier
REQ-DDB-QUERY-012measuredtest_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_with_no_anchored_sibling_the_mismatch_is_still_disclosed → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_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

Activity · 8 steps
lines 157–157db, root = _shifted_db(tmp_path)lines 158–158conn = sqlite3.connect(db)lines 159–159conn.execute("DELETE FROM memberdef WHERE rowid = 3")lines 160–160conn.commit()lines 161–161conn.close()lines 163–163dossier = function_dossier(db, "release_gil", repo_root=root)lines 165–165assert dossier is not None and dossier.body is not Nonelines 166–166assert dossier.body.anchor_mismatch, "the shifted span is still flagged when nothing is better"