test_outofline_definitions.py

tests/test_outofline_definitions.py

An out-of-line C++ definition IS a definition, and must be labelled as one.

test_a_qualified_lookup_reaches_an_out_of_line_definition

None test_outofline_definitions.test_a_qualified_lookup_reaches_an_out_of_line_definition(Path tmp_path)

A qualified lookup must reach the out-of-line definition.

tests/test_outofline_definitions.py:101

Show on the map →

Called by none

Calls _fixture, resolve_rowid

Checks

  • assert got == OUT_OF_LINE, ("a qualified lookup could not reach the out-of-line definition, so there is no way " "to name the real method at all" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-003measuredtest_a_qualified_lookup_reaches_an_out_of_line_definition → resolve_rowid
REQ-DDB-QUERY-010measuredtest_a_qualified_lookup_reaches_an_out_of_line_definition → resolve_rowid
Source · 26 lines
def test_a_qualified_lookup_reaches_an_out_of_line_definition(tmp_path: Path) -> None:
    """WHAT IS NOT ASSERTED HERE, AND WHY. A BARE `run_turn` still resolves to the in-place
    test helper, because once both rows are correctly recognised as definitions they TIE and
    `rowid` ascending decides. Making the class method win would need a new preference — "not
    under tests/", or "prefer a qualified definition" — and that is a policy choice, not
    something the measurement settles. Inventing it here would be this repo's own
    anti-pattern: a heuristic whose real purpose is to make an assertion pass.

    What the fix does establish is that the out-of-line definition is no longer MISLABELLED
    as bodiless, so it is a real candidate at all, and that naming it qualified reaches it.

    @brief A qualified name resolves to the real method.
    @return None.
    @version 1
    """
    conn = _fixture(tmp_path)
    try:
        got = _common.resolve_rowid(conn, "run_turn", "lib::Engine::run_turn")
    finally:
        conn.close()
    assert got == OUT_OF_LINE, (
        "a qualified lookup could not reach the out-of-line definition, so there is no way "
        "to name the real method at all"
    )

Activity · 4 steps
lines 116–116conn = _fixture(tmp_path)lines 117–117trylines 118–118got = _common.resolve_rowid(conn, "run_turn", "lib::Engine::run_turn")lines 121–124assert got == OUT_OF_LINE, ( "a qualified lookup could not reach the out-of-line definition, so there is no way " "to name the real method at all" )

test_candidates_report_a_body_that_lives_in_another_file

None test_outofline_definitions.test_candidates_report_a_body_that_lives_in_another_file(Path tmp_path)

has_body must be true for a body that lives in another file.

tests/test_outofline_definitions.py:132

Show on the map →

Called by none

Calls _fixture, function_candidates

Checks

  • assert OUT_OF_LINE in by_rowid, "the out-of-line definition is missing from candidates"
  • assert by_rowid[OUT_OF_LINE][-1], ("the out-of-line definition is reported as having NO body, so a reader is told the " "real method is a declaration when its body spans 2826-2841 of another file" )
  • assert {row[0] for row in rows} == {OUT_OF_LINE, TEST_HELPER}, (f"candidates did not surface both meanings of the name: {rows}" )
  • assert by_rowid[TEST_HELPER][-1], "the in-place helper genuinely has a body too"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-003measuredtest_candidates_report_a_body_that_lives_in_another_file → function_candidates
REQ-DDB-QUERY-010measuredtest_candidates_report_a_body_that_lives_in_another_file → function_candidates
Source · 33 lines
def test_candidates_report_a_body_that_lives_in_another_file(tmp_path: Path) -> None:
    """`has_body` is published in `dossier`'s `candidates`, so a wrong value does not merely
    mis-sort — it TELLS the reader the real method has no body. Observed on entropic:
    `has_body: false` for a row whose body spans lines 2826-2841.

    ORDER IS DELIBERATELY NOT ASSERTED. Both rows are genuine definitions once labelled
    correctly, so which one leads is the unresolved policy question recorded on the sibling
    test — pinning an order here would freeze a choice nobody has made.

    @brief Candidates label an out-of-line body correctly and surface both meanings.
    @return None.
    @version 1
    """
    conn = _fixture(tmp_path)
    try:
        rows = _common.function_candidates(conn, "run_turn")
    finally:
        conn.close()

    by_rowid = {row[0]: row for row in rows}
    assert OUT_OF_LINE in by_rowid, "the out-of-line definition is missing from candidates"
    assert by_rowid[OUT_OF_LINE][-1], (
        "the out-of-line definition is reported as having NO body, so a reader is told the "
        "real method is a declaration when its body spans 2826-2841 of another file"
    )
    ## BOTH must be listed. Silently collapsing to one is the failure `candidates` exists to
    ## prevent, and it is what let a test helper stand in for the real method unremarked.
    assert {row[0] for row in rows} == {OUT_OF_LINE, TEST_HELPER}, (
        f"candidates did not surface both meanings of the name: {rows}"
    )
    assert by_rowid[TEST_HELPER][-1], "the in-place helper genuinely has a body too"

Activity · 8 steps
lines 145–145conn = _fixture(tmp_path)lines 146–146trylines 147–147rows = _common.function_candidates(conn, "run_turn")lines 151–151by_rowid = {row[0]: row for row in rows}lines 152–152assert OUT_OF_LINE in by_rowid, "the out-of-line definition is missing from candidates"lines 153–156assert by_rowid[OUT_OF_LINE][-1], ( "the out-of-line definition is reported as having NO body, so a reader is told the " "real method is a declaration when its body spans 2826-2841 of another file" )lines 159–161assert {row[0] for row in rows} == {OUT_OF_LINE, TEST_HELPER}, ( f"candidates did not surface both meanings of the name: {rows}" )lines 162–162assert by_rowid[TEST_HELPER][-1], "the in-place helper genuinely has a body too"

test_the_decl_def_duality_still_elects_the_definition

None test_outofline_definitions.test_the_decl_def_duality_still_elects_the_definition(Path tmp_path)

The decl/def duality must still elect the definition row.

tests/test_outofline_definitions.py:224

Show on the map →

Called by none

Calls _duality_fixture, function_candidates, resolve_rowid

Checks

  • assert got == DUAL_DEF, (f"resolved to rowid {got}; the header DECLARATION row was elected over the definition " f"because both carry the same body span and the tiebreak is rowid ascending" )
  • assert rows[0][0] == DUAL_DEF, (f"candidates ranked the declaration first: {rows}. `resolve_symbol` joins path on " f"file_id but takes bodystart, so this publishes a header path with the .c's line" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-003measuredtest_the_decl_def_duality_still_elects_the_definition → resolve_rowid
REQ-DDB-QUERY-010measuredtest_the_decl_def_duality_still_elects_the_definition → resolve_rowid
Source · 31 lines
def test_the_decl_def_duality_still_elects_the_definition(tmp_path: Path) -> None:
    """THE REGRESSION THIS PINS. Widening the definition test to "carries a body" made it TRUE
    for BOTH rows of a duality pair, so the `rowid` tiebreak elected the header DECLARATION —
    which doxygen emits first. Measured on mbedtls before this test existed: 37 multi-row names
    flipped their resolved rowid, and `resolve_symbol` joins `path` on `file_id` while taking
    `bodystart`, so the elected row published a HEADER path with the .c's body line — a
    fabricated file:line an agent would go read.

    The sort key therefore needs BOTH terms, most specific first: a true in-place definition
    wins, an out-of-line definition still beats a bodiless declaration, and the duality no
    longer inverts.

    @brief A declaration enriched with the definition's body does not outrank the definition.
    @return None.
    @version 1
    """
    conn = _duality_fixture(tmp_path)
    try:
        got = _common.resolve_rowid(conn, "u128_eq")
        rows = _common.function_candidates(conn, "u128_eq")
    finally:
        conn.close()

    assert got == DUAL_DEF, (
        f"resolved to rowid {got}; the header DECLARATION row was elected over the definition "
        f"because both carry the same body span and the tiebreak is rowid ascending"
    )
    assert rows[0][0] == DUAL_DEF, (
        f"candidates ranked the declaration first: {rows}. `resolve_symbol` joins path on "
        f"file_id but takes bodystart, so this publishes a header path with the .c's line"
    )

1 more lines, not shown

Activity · 6 steps
lines 240–240conn = _duality_fixture(tmp_path)lines 241–241trylines 242–242got = _common.resolve_rowid(conn, "u128_eq")lines 243–243rows = _common.function_candidates(conn, "u128_eq")lines 247–250assert got == DUAL_DEF, ( f"resolved to rowid {got}; the header DECLARATION row was elected over the definition " f"because both carry the same body span and the tiebreak is rowid ascending" )lines 251–254assert rows[0][0] == DUAL_DEF, ( f"candidates ranked the declaration first: {rows}. `resolve_symbol` joins path on " f"file_id but takes bodystart, so this publishes a header path with the .c's line" )