test_ast_symbols.py

tests/test_ast_symbols.py

gh#11 — the function definitions doxygen never emitted, and their provenance.

test_a_declaration_only_header_contributes_no_phantom_body

None test_ast_symbols.test_a_declaration_only_header_contributes_no_phantom_body(tuple[Path, Path] barren_index)

`public.h` DECLARES `split_api` and defines nothing. The harvester keys on `function_definition`, which a declaration is not — so no body span is invented for a header, and `public.h` never gains a recovered row.

tests/test_ast_symbols.py:707

Checks

  • assert (conn.execute(f"SELECT COUNT(*) FROM memberdef WHERE bodyfile_id = 12 " f"AND {SYMBOL_SOURCE_COLUMN} = '{SYMBOL_SOURCE_AST}'" ).fetchone()[0] == 0 )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_declaration_only_header_contributes_no_phantom_body → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_a_declaration_only_header_contributes_no_phantom_body → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_a_declaration_only_header_contributes_no_phantom_body → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_declaration_only_header_contributes_no_phantom_body → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_declaration_only_header_contributes_no_phantom_body → recover_ast_symbols → _recover_into → all
Source · 25 lines
def test_a_declaration_only_header_contributes_no_phantom_body(
    barren_index: tuple[Path, Path],
) -> None:
    """`public.h` DECLARES `split_api` and defines nothing. The harvester keys on
    `function_definition`, which a declaration is not — so no body span is invented
    for a header, and `public.h` never gains a recovered row."""
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)

    conn = sqlite3.connect(str(db))
    try:
        assert (
            conn.execute(
                f"SELECT COUNT(*) FROM memberdef WHERE bodyfile_id = 12 "
                f"AND {SYMBOL_SOURCE_COLUMN} = '{SYMBOL_SOURCE_AST}'"
            ).fetchone()[0]
            == 0
        )
    finally:
        conn.close()


# ─── gh#372: global and file-scope variables ─────────────────────────────────

Activity · 5 steps
lines 713–713db, repo = barren_indexlines 714–714recover_ast_symbols(db, repo, None)lines 716–716conn = sqlite3.connect(str(db))lines 717–717trylines 718–724assert ( conn.execute( f"SELECT COUNT(*) FROM memberdef WHERE bodyfile_id = 12 " f"AND {SYMBOL_SOURCE_COLUMN} = '{SYMBOL_SOURCE_AST}'" ).fetchone()[0] == 0 )

test_a_defaulted_or_deleted_special_member_is_not_recovered

None test_ast_symbols.test_a_defaulted_or_deleted_special_member_is_not_recovered()

FOUND BY MEASUREMENT, not by reading the grammar. `W(W&&) = default;` IS a `function_definition` in tree-sitter-cpp — the `= default;` sits where a body would — so the first cut recovered a row for a member that has no body and that doxygen had already emitted a declaration for.

tests/test_ast_symbols.py:337

Checks

  • assert [f.name for f in harvest_function_definitions(tree, src)] == ["real"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_defaulted_or_deleted_special_member_is_not_recovered → harvest_function_definitions
REQ-DDB-PIPE-003measured
Source · 29 lines
def test_a_defaulted_or_deleted_special_member_is_not_recovered() -> None:
    """FOUND BY MEASUREMENT, not by reading the grammar. `W(W&&) = default;` IS a
    `function_definition` in tree-sitter-cpp — the `= default;` sits where a body
    would — so the first cut recovered a row for a member that has no body and that
    doxygen had already emitted a declaration for.

    Measured on entropic: 18 of 20 recovered rows were defaulted or deleted special
    members. Worse than merely redundant — their `definition` is the bare declarator,
    so `qualified_name_of` keyed them to a different identity than doxygen's
    `entropic::SandboxManager::SandboxManager`, giving one function two graph nodes,
    which is gh#26 reintroduced by the fix for gh#11. It also made the spurious row
    outrank the real constructor in `function_candidates`, because a recovered row
    has `file_id == bodyfile_id` and an out-of-line constructor does not.

    Pinned on the grammar's own discriminator — a real definition has a `body`
    field, a defaulted one does not — rather than on the clause node's name.
    """
    from clew.tsnode import Parser as SubstrateParser

    src = (
        b"class W {\n public:\n  W() = default;\n  W(W&&) = default;\n"
        b"  W(const W&) = delete;\n  int real() { return 1; }\n};\n"
        b"W::~W() = default;\n"
    )
    tree = SubstrateParser("cpp").parse(src)

    assert [f.name for f in harvest_function_definitions(tree, src)] == ["real"]

Activity · 4 steps
lines 354–354from clew.tsnode import Parser as SubstrateParserlines 356–360src = ( b"class W {\n public:\n W() = default;\n W(W&&) = default;\n" b" W(const W&) = delete;\n int real() { return 1; }\n};\n" b"W::~W() = default;\n" )lines 361–361tree = SubstrateParser("cpp").parse(src)lines 363–363assert [f.name for f in harvest_function_definitions(tree, src)] == ["real"]

test_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered

None test_ast_symbols.test_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered(tuple[Path, Path] barren_index)

THE DOCUMENTATION REGRESSION THE FIRST CUT SHIPPED. `function_candidates` orders body rows first, so after recovery the function_dossier's chosen row is the parser's — which has no brief. Reading the brief from that row alone reported a documented function as undocumented, i.e. a change whose purpose is to ADD information destroyed some.

tests/test_ast_symbols.py:525

Checks

  • assert d is not None
  • assert d.brief == "Doubles a value.", "the header's brief must survive"
  • assert d.version == "4", "and so must its @version"
  • assert d.file == "public.c"
  • assert d.provenance == SYMBOL_SOURCE_AST

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → function_dossier
REQ-DDB-QUERY-006measuredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → function_dossier
REQ-DDB-QUERY-010measuredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → function_dossier
REQ-DDB-QUERY-012measuredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → function_dossier → _dossier_conn → locks_held_for_rowids
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered → recover_ast_symbols → _recover_into → all
Source · 23 lines
def test_a_documented_declaration_keeps_its_brief_when_its_body_is_recovered(
    barren_index: tuple[Path, Path],
) -> None:
    """THE DOCUMENTATION REGRESSION THE FIRST CUT SHIPPED. `function_candidates`
    orders body rows first, so after recovery the function_dossier's chosen row is the
    parser's — which has no brief. Reading the brief from that row alone reported a
    documented function as undocumented, i.e. a change whose purpose is to ADD
    information destroyed some."""
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)

    d = function_dossier(db, "split_api")
    assert d is not None
    assert d.brief == "Doubles a value.", "the header's brief must survive"
    assert d.version == "4", "and so must its @version"
    ## The location comes from the parser, which is the only thing that knows it.
    assert d.file == "public.c"
    assert d.provenance == SYMBOL_SOURCE_AST


# ─── provenance at every symbol-returning surface ────────────────────────────

Activity · 8 steps
lines 533–533db, repo = barren_indexlines 534–534recover_ast_symbols(db, repo, None)lines 536–536d = function_dossier(db, "split_api")lines 537–537assert d is not Nonelines 538–538assert d.brief == "Doubles a value.", "the header's brief must survive"lines 539–539assert d.version == "4", "and so must its @version"lines 541–541assert d.file == "public.c"lines 542–542assert d.provenance == SYMBOL_SOURCE_AST

test_a_function_doxygen_already_emitted_is_never_duplicated

None test_ast_symbols.test_a_function_doxygen_already_emitted_is_never_duplicated(tuple[Path, Path] barren_index)

THE DOUBLE-COUNT GUARD, and the likeliest way this change goes wrong. A recovered row for a function doxygen already has would corrupt every count and every name resolution built on it.

tests/test_ast_symbols.py:404

Checks

  • assert (conn.execute("SELECT COUNT(*) FROM memberdef WHERE name='documented_add'").fetchone()[0] == 1 )
  • assert (conn.execute(f"SELECT {SYMBOL_SOURCE_COLUMN} FROM memberdef WHERE name='documented_add'" ).fetchone()[0] == SYMBOL_SOURCE_DOXYGEN )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_function_doxygen_already_emitted_is_never_duplicated → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_a_function_doxygen_already_emitted_is_never_duplicated → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_a_function_doxygen_already_emitted_is_never_duplicated → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_function_doxygen_already_emitted_is_never_duplicated → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_function_doxygen_already_emitted_is_never_duplicated → recover_ast_symbols → _recover_into → all
Source · 26 lines
def test_a_function_doxygen_already_emitted_is_never_duplicated(
    barren_index: tuple[Path, Path],
) -> None:
    """THE DOUBLE-COUNT GUARD, and the likeliest way this change goes wrong. A
    recovered row for a function doxygen already has would corrupt every count and
    every name resolution built on it."""
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)

    conn = sqlite3.connect(str(db))
    try:
        assert (
            conn.execute("SELECT COUNT(*) FROM memberdef WHERE name='documented_add'").fetchone()[0]
            == 1
        )
        ## And the surviving row is still doxygen's, with its brief intact.
        assert (
            conn.execute(
                f"SELECT {SYMBOL_SOURCE_COLUMN} FROM memberdef WHERE name='documented_add'"
            ).fetchone()[0]
            == SYMBOL_SOURCE_DOXYGEN
        )
    finally:
        conn.close()

Activity · 6 steps
lines 410–410db, repo = barren_indexlines 411–411recover_ast_symbols(db, repo, None)lines 413–413conn = sqlite3.connect(str(db))lines 414–414trylines 415–418assert ( conn.execute("SELECT COUNT(*) FROM memberdef WHERE name='documented_add'").fetchone()[0] == 1 )lines 420–425assert ( conn.execute( f"SELECT {SYMBOL_SOURCE_COLUMN} FROM memberdef WHERE name='documented_add'" ).fetchone()[0] == SYMBOL_SOURCE_DOXYGEN )

test_a_function_local_never_becomes_a_global

None test_ast_symbols.test_a_function_local_never_becomes_a_global(tuple[Path, Path] barren_index)

`not_a_global` is declared inside `demo_body_local_is_not_a_global`'s body. A `compound_statement` is full of `declaration` nodes, so a walk that did not refuse to enter a `function_definition` would flood the index with every `i`, `ret` and `len` in the repo — and each one would be searchable, which is worse than the gap this change closes.

tests/test_ast_symbols.py:835

Show on the map →

Called by none

Calls _variable_rows, recover_ast_symbols

Checks

  • assert "not_a_global" not in _variable_rows(db)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_function_local_never_becomes_a_global → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_a_function_local_never_becomes_a_global → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_a_function_local_never_becomes_a_global → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_function_local_never_becomes_a_global → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_function_local_never_becomes_a_global → recover_ast_symbols → _recover_into → all
Source · 15 lines
def test_a_function_local_never_becomes_a_global(
    barren_index: tuple[Path, Path],
) -> None:
    """`not_a_global` is declared inside `demo_body_local_is_not_a_global`'s body.
    A `compound_statement` is full of `declaration` nodes, so a walk that did not
    refuse to enter a `function_definition` would flood the index with every `i`,
    `ret` and `len` in the repo — and each one would be searchable, which is worse
    than the gap this change closes.
    """
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)

    assert "not_a_global" not in _variable_rows(db)

Activity · 3 steps
lines 844–844db, repo = barren_indexlines 845–845recover_ast_symbols(db, repo, None)lines 847–847assert "not_a_global" not in _variable_rows(db)

test_a_function_pointer_global_is_a_variable_and_a_prototype_is_not

None test_ast_symbols.test_a_function_pointer_global_is_a_variable_and_a_prototype_is_not(tuple[Path, Path] barren_index)

THE ONE JUDGEMENT A WRONG ANSWER MAKES HARMFUL RATHER THAN INCOMPLETE.

tests/test_ast_symbols.py:797

Show on the map →

Called by none

Calls _variable_rows, recover_ast_symbols

Checks

  • assert "demo_mutex_lock" in rows, "a function-pointer global IS a variable"
  • assert "demo_prototype_not_a_variable" not in rows, "a prototype is NOT a variable"
  • assert rows["demo_mutex_lock"][2] == "int (*demo_mutex_lock)(demo_mutex_t *)"
  • assert rows["demo_readdir_mutex"][2] == "demo_mutex_t demo_readdir_mutex"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_function_pointer_global_is_a_variable_and_a_prototype_is_not → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_a_function_pointer_global_is_a_variable_and_a_prototype_is_not → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_a_function_pointer_global_is_a_variable_and_a_prototype_is_not → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_function_pointer_global_is_a_variable_and_a_prototype_is_not → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_function_pointer_global_is_a_variable_and_a_prototype_is_not → recover_ast_symbols → _recover_into → all
Source · 38 lines
def test_a_function_pointer_global_is_a_variable_and_a_prototype_is_not(
    barren_index: tuple[Path, Path],
) -> None:
    """THE ONE JUDGEMENT A WRONG ANSWER MAKES HARMFUL RATHER THAN INCOMPLETE.

    Both shapes present a `function_declarator`, so that node cannot decide it:

        int demo_prototype_not_a_variable(int x);   function_declarator → identifier
        int (*demo_mutex_lock)(demo_mutex_t *);     function_declarator
                                                    → parenthesized_declarator
                                                    → pointer_declarator → identifier

    Getting it backwards puts a function prototype in the index as a variable, which
    is precisely the "a variable where a caller expected a function" failure. Both
    directions are asserted here — a test naming only the function pointer would pass
    against an implementation that recovered every prototype in the repo.

    mbedtls's lock PRIMITIVE is the function-pointer case, which is why the
    permissive half matters and cannot simply be dropped to stay safe.
    """
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)
    rows = _variable_rows(db)

    assert "demo_mutex_lock" in rows, "a function-pointer global IS a variable"
    assert "demo_prototype_not_a_variable" not in rows, "a prototype is NOT a variable"

    ## THE `definition` MUST SPELL THE POINTER, and this was caught on the real index
    ## rather than here. A C declaration's `type` field holds only the BASE type, so
    ## the first cut published mbedtls's lock primitive as `int mbedtls_mutex_lock` —
    ## indistinguishable from an integer counter, on the one row whose entire value is
    ## saying "this is a function pointer, not a mutex object". Asserted against the
    ## object row too, because the fix must not smear the two together: telling the
    ## objects from the primitive is the graded distinction.
    assert rows["demo_mutex_lock"][2] == "int (*demo_mutex_lock)(demo_mutex_t *)"
    assert rows["demo_readdir_mutex"][2] == "demo_mutex_t demo_readdir_mutex"

Activity · 7 steps
lines 817–817db, repo = barren_indexlines 818–818recover_ast_symbols(db, repo, None)lines 819–819rows = _variable_rows(db)lines 821–821assert "demo_mutex_lock" in rows, "a function-pointer global IS a variable"lines 822–822assert "demo_prototype_not_a_variable" not in rows, "a prototype is NOT a variable"lines 831–831assert rows["demo_mutex_lock"][2] == "int (*demo_mutex_lock)(demo_mutex_t *)"lines 832–832assert rows["demo_readdir_mutex"][2] == "demo_mutex_t demo_readdir_mutex"

test_a_guarded_body_is_parsed_even_though_doxygen_saw_nothing

None test_ast_symbols.test_a_guarded_body_is_parsed_even_though_doxygen_saw_nothing()

The premise of the whole issue: the parser does not care about the preprocessor. Asserted on the harvest alone, so a failure here separates "we cannot see these functions" from "we cannot store them".

tests/test_ast_symbols.py:260

Checks

  • assert set(found) == {
  • assert "demo_prototype_not_a_variable" not in found
  • assert found["mutex_lock_pthread"].static is True
  • assert found["mutex_unlock_pthread"].static is False
  • assert found["mutex_unlock_pthread"].args == "(void *mutex, int flags)"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_guarded_body_is_parsed_even_though_doxygen_saw_nothing → harvest_function_definitions
REQ-DDB-PIPE-003measured
Source · 23 lines
def test_a_guarded_body_is_parsed_even_though_doxygen_saw_nothing() -> None:
    """The premise of the whole issue: the parser does not care about the
    preprocessor. Asserted on the harvest alone, so a failure here separates "we
    cannot see these functions" from "we cannot store them"."""
    from clew.tsnode import Parser as SubstrateParser

    tree = SubstrateParser("c").parse(_GUARDED_C.encode())
    found = {f.name: f for f in harvest_function_definitions(tree, _GUARDED_C.encode())}

    assert set(found) == {
        "mutex_lock_pthread",
        "mutex_unlock_pthread",
        "demo_body_local_is_not_a_global",
    }
    ## gh#372 put a prototype in this file. It must not become a FUNCTION either —
    ## function recovery keys on `function_definition` and a prototype is a
    ## `declaration`, so this is the other half of the same discriminator.
    assert "demo_prototype_not_a_variable" not in found
    assert found["mutex_lock_pthread"].static is True
    assert found["mutex_unlock_pthread"].static is False
    assert found["mutex_unlock_pthread"].args == "(void *mutex, int flags)"

Activity · 8 steps
lines 264–264from clew.tsnode import Parser as SubstrateParserlines 266–266tree = SubstrateParser("c").parse(_GUARDED_C.encode())lines 267–267found = {f.name: f for f in harvest_function_definitions(tree, _GUARDED_C.encode())}lines 269–273assert set(found) == { "mutex_lock_pthread", "mutex_unlock_pthread", "demo_body_local_is_not_a_global", }lines 277–277assert "demo_prototype_not_a_variable" not in foundlines 278–278assert found["mutex_lock_pthread"].static is Truelines 279–279assert found["mutex_unlock_pthread"].static is Falselines 280–280assert found["mutex_unlock_pthread"].args == "(void *mutex, int flags)"

test_a_guarded_global_is_recovered_with_its_declared_type

None test_ast_symbols.test_a_guarded_global_is_recovered_with_its_declared_type(tuple[Path, Path] barren_index)

THE MEASURED GAP. mbedtls declares five global mutex OBJECTS behind `#if defined(MBEDTLS_FS_IO)` and friends; doxygen's preprocessor strips them, so `search` returned a confident zero for every one and the only route to the repo's mutex list was reading `mbedtls_threading_set_alt`'s BODY.

tests/test_ast_symbols.py:758

Show on the map →

Called by none

Calls _variable_rows, recover_ast_symbols

Checks

  • assert rows["demo_readdir_mutex"][1] == "demo_mutex_t"
  • assert rows["demo_readdir_mutex"][2] == "demo_mutex_t demo_readdir_mutex"
  • assert rows["demo_lock_depth"][3] == 1, "the `static` storage class is recorded"
  • assert rows["demo_readdir_mutex"][3] == 0

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_guarded_global_is_recovered_with_its_declared_type → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_a_guarded_global_is_recovered_with_its_declared_type → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_a_guarded_global_is_recovered_with_its_declared_type → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_guarded_global_is_recovered_with_its_declared_type → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_guarded_global_is_recovered_with_its_declared_type → recover_ast_symbols → _recover_into → all
Source · 22 lines
def test_a_guarded_global_is_recovered_with_its_declared_type(
    barren_index: tuple[Path, Path],
) -> None:
    """THE MEASURED GAP. mbedtls declares five global mutex OBJECTS behind
    `#if defined(MBEDTLS_FS_IO)` and friends; doxygen's preprocessor strips them, so
    `search` returned a confident zero for every one and the only route to the repo's
    mutex list was reading `mbedtls_threading_set_alt`'s BODY.

    The declared TYPE is asserted, not just the name, because that is what lets a
    reader separate the mutex objects from the lock primitive — the exact distinction
    a rubric mark grades.
    """
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)
    rows = _variable_rows(db)

    assert rows["demo_readdir_mutex"][1] == "demo_mutex_t"
    assert rows["demo_readdir_mutex"][2] == "demo_mutex_t demo_readdir_mutex"
    assert rows["demo_lock_depth"][3] == 1, "the `static` storage class is recorded"
    assert rows["demo_readdir_mutex"][3] == 0

Activity · 7 steps
lines 770–770db, repo = barren_indexlines 771–771recover_ast_symbols(db, repo, None)lines 772–772rows = _variable_rows(db)lines 774–774assert rows["demo_readdir_mutex"][1] == "demo_mutex_t"lines 775–775assert rows["demo_readdir_mutex"][2] == "demo_mutex_t demo_readdir_mutex"lines 776–776assert rows["demo_lock_depth"][3] == 1, "the `static` storage class is recorded"lines 777–777assert rows["demo_readdir_mutex"][3] == 0

test_a_guarded_typedef_is_recovered_as_a_typedef_row

None test_ast_symbols.test_a_guarded_typedef_is_recovered_as_a_typedef_row()

gh#395, and it is gh#11 one kind over. THE MEASURED GAP: `function_dossier("mbedtls_threading_mutex_t")` returned the alt-dummy `struct { int dummy; }` at `tests/include/alt-dummy/threading_alt.h`, while the real pthread-backed type at `include/mbedtls/threading.h:29` produced NO ROW IN ANY TABLE — it sits behind `MBEDTLS_THREADING_PTHREAD`. Exactly one `compounddef` row existed for that name, so resolution picked the only row there was and was RIGHT to.

tests/test_ast_symbols.py:1053

Checks

  • assert "demo_mutex_t" in found
  • assert "tag_differs_t" in found
  • assert "tag_differs_s" not in found, "the struct tag is not what a caller types"
  • assert "local_alias" not in found, "a function-local typedef is not a file-scope type"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_a_guarded_typedef_is_recovered_as_a_typedef_row → harvest_type_definitions
Source · 40 lines
def test_a_guarded_typedef_is_recovered_as_a_typedef_row() -> None:
    """gh#395, and it is gh#11 one kind over. THE MEASURED GAP:
    `function_dossier("mbedtls_threading_mutex_t")` returned the alt-dummy
    `struct { int dummy; }` at `tests/include/alt-dummy/threading_alt.h`, while the real
    pthread-backed type at `include/mbedtls/threading.h:29` produced NO ROW IN ANY TABLE —
    it sits behind `MBEDTLS_THREADING_PTHREAD`. Exactly one `compounddef` row existed for
    that name, so resolution picked the only row there was and was RIGHT to.

    That is why this was nearly misfiled as a ranking bug: a test-path demotion tier would
    have produced a green test proving the tier worked while the real type stayed invisible.

    NODE SHAPE PROBED, NOT ASSUMED, per the gh#11 lesson that the grammar is its own
    discriminator: tree-sitter shapes `typedef struct X { ... } X;` as a `type_definition`
    wrapping a `struct_specifier`, confirmed against the real mbedtls header.

    THE LAST `type_identifier` IS THE NAME, and the negative below is why that matters:
    `typedef struct foo_s foo_t;` has a struct TAG and a typedef NAME that differ, and it is
    the declarator a caller types.
    """
    from clew.tsnode import Parser as SubstrateParser

    src = (
        b"#if defined(DEMO_GUARD)\n"
        b"typedef struct demo_mutex_t {\n  int held;\n} demo_mutex_t;\n"
        b"#endif\n"
        b"typedef struct tag_differs_s tag_differs_t;\n"
        b"int demo_fn(void) {\n  typedef int local_alias;\n  return 0;\n}\n"
    )
    tree = SubstrateParser("c").parse(src)
    found = {t.name for t in harvest_type_definitions(tree, src)}

    ## Behind an unsatisfied guard, which is the whole point.
    assert "demo_mutex_t" in found
    ## The DECLARATOR name, not the struct tag.
    assert "tag_differs_t" in found
    assert "tag_differs_s" not in found, "the struct tag is not what a caller types"
    ## A typedef inside a function body is a local, like every other local this walk skips.
    assert "local_alias" not in found, "a function-local typedef is not a file-scope type"

Activity · 8 steps
lines 1072–1072from clew.tsnode import Parser as SubstrateParserlines 1074–1080src = ( b"#if defined(DEMO_GUARD)\n" b"typedef struct demo_mutex_t {\n int held;\n} demo_mutex_t;\n" b"#endif\n" b"typedef struct tag_differs_s tag_differs_t;\n" b"int demo_fn(void) {\n typedef int local_alias;\n return 0;\n}\n" )lines 1081–1081tree = SubstrateParser("c").parse(src)lines 1082–1082found = {t.name for t in harvest_type_definitions(tree, src)}lines 1085–1085assert "demo_mutex_t" in foundlines 1087–1087assert "tag_differs_t" in foundlines 1088–1088assert "tag_differs_s" not in found, "the struct tag is not what a caller types"lines 1090–1090assert "local_alias" not in found, "a function-local typedef is not a file-scope type"

test_a_nested_definition_is_not_recorded_as_a_second_symbol

None test_ast_symbols.test_a_nested_definition_is_not_recorded_as_a_second_symbol()

A GNU nested function sits INSIDE its parent's span, so recording both would make the span-overlap dedup order-dependent — whichever was seen second would lose. The walk stops descending at a definition instead.

tests/test_ast_symbols.py:283

Checks

  • assert [f.name for f in harvest_function_definitions(tree, src)] == ["outer"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_nested_definition_is_not_recorded_as_a_second_symbol → harvest_function_definitions
REQ-DDB-PIPE-003measured
Source · 12 lines
def test_a_nested_definition_is_not_recorded_as_a_second_symbol() -> None:
    """A GNU nested function sits INSIDE its parent's span, so recording both would
    make the span-overlap dedup order-dependent — whichever was seen second would
    lose. The walk stops descending at a definition instead."""
    from clew.tsnode import Parser as SubstrateParser

    src = b"int outer(void) {\n  int inner(void) { return 1; }\n  return inner();\n}\n"
    tree = SubstrateParser("c").parse(src)

    assert [f.name for f in harvest_function_definitions(tree, src)] == ["outer"]

Activity · 4 steps
lines 287–287from clew.tsnode import Parser as SubstrateParserlines 289–289src = b"int outer(void) {\n int inner(void) { return 1; }\n return inner();\n}\n"lines 290–290tree = SubstrateParser("c").parse(src)lines 292–292assert [f.name for f in harvest_function_definitions(tree, src)] == ["outer"]

test_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise

None test_ast_symbols.test_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise(tuple[Path, Path] barren_index)

A preprocessor that skipped the code skipped its doc comment, so there is no prose to recover and inventing any — a synthesized brief, a placeholder, the function's own name — would be worse than an empty one. Checked at the ROW and at the surfaces, because a mapper could fabricate one on the way out.

tests/test_ast_symbols.py:574

Checks

  • assert row == (None, None, None), "a recovered row must carry no description at all"
  • assert d.brief == ""
  • assert d.version == ""
  • assert d.requirements == [], "and no @req tags, since those live in the prose"
  • assert hit.brief == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → function_dossier
REQ-DDB-QUERY-006measuredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-009measuredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → function_dossier
REQ-DDB-QUERY-010measuredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → function_dossier
REQ-DDB-QUERY-012measuredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → function_dossier → _dossier_conn → locks_held_for_rowids
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise → recover_ast_symbols → _recover_into → all
Source · 29 lines
def test_a_parsed_row_carries_no_brief_and_nothing_pretends_otherwise(
    barren_index: tuple[Path, Path],
) -> None:
    """A preprocessor that skipped the code skipped its doc comment, so there is no
    prose to recover and inventing any — a synthesized brief, a placeholder, the
    function's own name — would be worse than an empty one. Checked at the ROW and
    at the surfaces, because a mapper could fabricate one on the way out."""
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)

    conn = sqlite3.connect(str(db))
    try:
        row = conn.execute(
            "SELECT briefdescription, detaileddescription, inbodydescription FROM memberdef "
            "WHERE name='mutex_lock_pthread'"
        ).fetchone()
    finally:
        conn.close()
    assert row == (None, None, None), "a recovered row must carry no description at all"

    d = function_dossier(db, "mutex_lock_pthread")
    assert d.brief == ""
    assert d.version == ""
    assert d.requirements == [], "and no @req tags, since those live in the prose"

    hit = {h.name: h for h in search(db, "mutex_lock_pthread")}["mutex_lock_pthread"]
    assert hit.brief == ""

Activity · 12 steps
lines 581–581db, repo = barren_indexlines 582–582recover_ast_symbols(db, repo, None)lines 584–584conn = sqlite3.connect(str(db))lines 585–585trylines 586–589row = conn.execute( "SELECT briefdescription, detaileddescription, inbodydescription FROM memberdef " "WHERE name='mutex_lock_pthread'" ).fetchone()lines 592–592assert row == (None, None, None), "a recovered row must carry no description at all"lines 594–594d = function_dossier(db, "mutex_lock_pthread")lines 595–595assert d.brief == ""lines 596–596assert d.version == ""lines 597–597assert d.requirements == [], "and no @req tags, since those live in the prose"lines 599–599hit = {h.name: h for h in search(db, "mutex_lock_pthread")}["mutex_lock_pthread"]lines 600–600assert hit.brief == ""

test_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface

None test_ast_symbols.test_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface(tuple[Path, Path] barren_index)

The issue's third bullet. A consumer must be able to tell a documented symbol from a parsed one WITHOUT reading the brief and guessing, because an absent brief is ambiguous between 'undocumented' and 'unparsed' — and one of those two means the tool cannot see the code at all.

tests/test_ast_symbols.py:548

Checks

  • assert resolve_symbol(db, parsed).provenance == SYMBOL_SOURCE_AST
  • assert resolve_symbol(db, documented).provenance is None
  • assert function_dossier(db, parsed).provenance == SYMBOL_SOURCE_AST
  • assert function_dossier(db, documented).provenance is None
  • assert hits[parsed].provenance == SYMBOL_SOURCE_AST
  • assert {h.name: h for h in search(db, documented)}[documented].provenance is None
  • assert source(db, parsed, repo).provenance == SYMBOL_SOURCE_AST
  • assert source(db, documented, repo).provenance is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → source
REQ-DDB-QUERY-002measuredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → resolve_symbol
REQ-DDB-QUERY-004measuredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → function_dossier
REQ-DDB-QUERY-006measuredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-009measuredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → function_dossier
REQ-DDB-QUERY-010measuredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → function_dossier
REQ-DDB-QUERY-012measuredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-011measuredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → function_dossier → _dossier_conn → locks_held_for_rowids
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface → recover_ast_symbols → _recover_into → all
Source · 26 lines
def test_a_parsed_row_is_distinguishable_from_a_doxygen_row_at_every_surface(
    barren_index: tuple[Path, Path],
) -> None:
    """The issue's third bullet. A consumer must be able to tell a documented symbol
    from a parsed one WITHOUT reading the brief and guessing, because an absent brief
    is ambiguous between 'undocumented' and 'unparsed' — and one of those two means
    the tool cannot see the code at all."""
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)

    parsed, documented = "mutex_lock_pthread", "documented_add"

    assert resolve_symbol(db, parsed).provenance == SYMBOL_SOURCE_AST
    assert resolve_symbol(db, documented).provenance is None

    assert function_dossier(db, parsed).provenance == SYMBOL_SOURCE_AST
    assert function_dossier(db, documented).provenance is None

    hits = {h.name: h for h in search(db, parsed)}
    assert hits[parsed].provenance == SYMBOL_SOURCE_AST
    assert {h.name: h for h in search(db, documented)}[documented].provenance is None

    assert source(db, parsed, repo).provenance == SYMBOL_SOURCE_AST
    assert source(db, documented, repo).provenance is None

Activity · 12 steps
lines 555–555db, repo = barren_indexlines 556–556recover_ast_symbols(db, repo, None)lines 558–558parsed, documented = "mutex_lock_pthread", "documented_add"lines 560–560assert resolve_symbol(db, parsed).provenance == SYMBOL_SOURCE_ASTlines 561–561assert resolve_symbol(db, documented).provenance is Nonelines 563–563assert function_dossier(db, parsed).provenance == SYMBOL_SOURCE_ASTlines 564–564assert function_dossier(db, documented).provenance is Nonelines 566–566hits = {h.name: h for h in search(db, parsed)}lines 567–567assert hits[parsed].provenance == SYMBOL_SOURCE_ASTlines 568–568assert {h.name: h for h in search(db, documented)}[documented].provenance is Nonelines 570–570assert source(db, parsed, repo).provenance == SYMBOL_SOURCE_ASTlines 571–571assert source(db, documented, repo).provenance is None

test_a_recovered_global_is_findable_through_search_and_typed_as_a_variable

None test_ast_symbols.test_a_recovered_global_is_findable_through_search_and_typed_as_a_variable(tuple[Path, Path] barren_index)

THE END-TO-END CLAIM, and the only test here that exercises the query half.

tests/test_ast_symbols.py:907

Checks

  • assert "demo_readdir_mutex" in hits, "a global must be findable by its own name"
  • assert hits["demo_readdir_mutex"].kind == "variable"
  • assert hits["demo_readdir_mutex"].file == "guarded.c"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_recovered_global_is_findable_through_search_and_typed_as_a_variable → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_a_recovered_global_is_findable_through_search_and_typed_as_a_variable → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_a_recovered_global_is_findable_through_search_and_typed_as_a_variable → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_recovered_global_is_findable_through_search_and_typed_as_a_variable → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-012measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_recovered_global_is_findable_through_search_and_typed_as_a_variable → recover_ast_symbols → _recover_into → all
Source · 23 lines
def test_a_recovered_global_is_findable_through_search_and_typed_as_a_variable(
    barren_index: tuple[Path, Path],
) -> None:
    """THE END-TO-END CLAIM, and the only test here that exercises the query half.

    Storing the row is worthless if `search` still filters `kind='function'` — which
    it did, and which is why the 902 `kind='variable'` rows doxygen already writes on
    mbedtls unaided were just as unfindable as the ones it never wrote. The gap was
    never only a pipeline gap.

    `kind` is asserted because it is the whole safety story: a caller must be able to
    see that this hit has no body, no callers and no callees before treating it as
    callable.
    """
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)

    hits = {h.name: h for h in search(db, "demo_readdir_mutex")}
    assert "demo_readdir_mutex" in hits, "a global must be findable by its own name"
    assert hits["demo_readdir_mutex"].kind == "variable"
    assert hits["demo_readdir_mutex"].file == "guarded.c"

Activity · 6 steps
lines 921–921db, repo = barren_indexlines 922–922recover_ast_symbols(db, repo, None)lines 924–924hits = {h.name: h for h in search(db, "demo_readdir_mutex")}lines 925–925assert "demo_readdir_mutex" in hits, "a global must be findable by its own name"lines 926–926assert hits["demo_readdir_mutex"].kind == "variable"lines 927–927assert hits["demo_readdir_mutex"].file == "guarded.c"

test_a_recovered_variable_carries_no_body_and_no_bodyfile

None test_ast_symbols.test_a_recovered_variable_carries_no_body_and_no_bodyfile(tuple[Path, Path] barren_index)

A variable is not executable. `bodystart`/`bodyend` stay unset so `_covered_body_spans` cannot see the row and no function recovery is ever blocked by a global's span, and `bodyfile_id` stays NULL so `graph_stats`'s files-with-bodies count does not grow by a file that only declares one.

tests/test_ast_symbols.py:850

Show on the map →

Called by none

Calls _variable_rows, recover_ast_symbols

Checks

  • assert not row[5], f"{name} must carry no body span, got bodystart={row[5]!r}"
  • assert row[6] is None, f"{name} must carry no bodyfile_id, got {row[6]!r}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_a_recovered_variable_carries_no_body_and_no_bodyfile → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_a_recovered_variable_carries_no_body_and_no_bodyfile → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_a_recovered_variable_carries_no_body_and_no_bodyfile → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_recovered_variable_carries_no_body_and_no_bodyfile → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_recovered_variable_carries_no_body_and_no_bodyfile → recover_ast_symbols → _recover_into → all
Source · 20 lines
def test_a_recovered_variable_carries_no_body_and_no_bodyfile(
    barren_index: tuple[Path, Path],
) -> None:
    """A variable is not executable. `bodystart`/`bodyend` stay unset so
    `_covered_body_spans` cannot see the row and no function recovery is ever blocked
    by a global's span, and `bodyfile_id` stays NULL so `graph_stats`'s
    files-with-bodies count does not grow by a file that only declares one.

    A payload implying a variable has a body is worse than its absence — it invites a
    caller to trace into something that cannot be traced.
    """
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)
    rows = _variable_rows(db)

    for name, row in rows.items():
        assert not row[5], f"{name} must carry no body span, got bodystart={row[5]!r}"
        assert row[6] is None, f"{name} must carry no bodyfile_id, got {row[6]!r}"

Activity · 6 steps
lines 861–861db, repo = barren_indexlines 862–862recover_ast_symbols(db, repo, None)lines 863–863rows = _variable_rows(db)lines 865–865◇ for name, row in rows.items()lines 866–866assert not row[5], f"{name} must carry no body span, got bodystart={row[5]!r}"lines 867–867assert row[6] is None, f"{name} must carry no bodyfile_id, got {row[6]!r}"

test_decl_def_duality_survives_and_the_two_rows_stay_one_function

None test_ast_symbols.test_decl_def_duality_survives_and_the_two_rows_stay_one_function(tuple[Path, Path] barren_index)

gh#26's identity key is `qualified_name_of`, and a recovered row has to land on the SAME identity as doxygen's declaration of the same function — otherwise `split_api` becomes two unrelated graph nodes, which is how 957 entropic declarations were once torn from their definitions.

tests/test_ast_symbols.py:495

Checks

  • assert len(rowids) == 2
  • assert kinds[SYMBOL_SOURCE_DOXYGEN] == 0, "the declaration still has no body"
  • assert kinds[SYMBOL_SOURCE_AST] > 0, "the definition now has one"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_decl_def_duality_survives_and_the_two_rows_stay_one_function → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_decl_def_duality_survives_and_the_two_rows_stay_one_function → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_decl_def_duality_survives_and_the_two_rows_stay_one_function → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_decl_def_duality_survives_and_the_two_rows_stay_one_function → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_decl_def_duality_survives_and_the_two_rows_stay_one_function → identity_rowids
REQ-DDB-QUERY-010measuredtest_decl_def_duality_survives_and_the_two_rows_stay_one_function → identity_rowids
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_decl_def_duality_survives_and_the_two_rows_stay_one_function → recover_ast_symbols → _recover_into → all
Source · 30 lines
def test_decl_def_duality_survives_and_the_two_rows_stay_one_function(
    barren_index: tuple[Path, Path],
) -> None:
    """gh#26's identity key is `qualified_name_of`, and a recovered row has to land
    on the SAME identity as doxygen's declaration of the same function — otherwise
    `split_api` becomes two unrelated graph nodes, which is how 957 entropic
    declarations were once torn from their definitions."""
    from clew.query._common import identity_rowids

    db, repo = barren_index
    recover_ast_symbols(db, repo, None)

    conn = sqlite3.connect(str(db))
    try:
        rowids = identity_rowids(conn, "split_api")
        ## Two rows — doxygen's header declaration and the parser's definition — and
        ## they are ONE identity, not two.
        assert len(rowids) == 2
        kinds = dict(
            conn.execute(
                f"SELECT {SYMBOL_SOURCE_COLUMN}, bodystart FROM memberdef "
                "WHERE name='split_api' ORDER BY rowid"
            )
        )
        assert kinds[SYMBOL_SOURCE_DOXYGEN] == 0, "the declaration still has no body"
        assert kinds[SYMBOL_SOURCE_AST] > 0, "the definition now has one"
    finally:
        conn.close()

Activity · 10 steps
lines 502–502from clew.query._common import identity_rowidslines 504–504db, repo = barren_indexlines 505–505recover_ast_symbols(db, repo, None)lines 507–507conn = sqlite3.connect(str(db))lines 508–508trylines 509–509rowids = identity_rowids(conn, "split_api")lines 512–512assert len(rowids) == 2lines 513–518kinds = dict( conn.execute( f"SELECT {SYMBOL_SOURCE_COLUMN}, bodystart FROM memberdef " "WHERE name='split_api' ORDER BY rowid" ) )lines 519–519assert kinds[SYMBOL_SOURCE_DOXYGEN] == 0, "the declaration still has no body"lines 520–520assert kinds[SYMBOL_SOURCE_AST] > 0, "the definition now has one"

test_every_cpp_declarator_shape_that_has_a_name_is_recovered

None test_ast_symbols.test_every_cpp_declarator_shape_that_has_a_name_is_recovered()

A SECOND GAP THE TEST ABOVE EXPOSED. `_declared_names` accepted only `identifier` and `qualified_identifier`, and tree-sitter-cpp names a method defined inside its class body `field_identifier` — so EVERY in-class method definition was silently skipped. Nothing failed; those symbols were simply never recovered, which is the same shape as the defect gh#11 exists to fix, one level down. The accepted set is now enumerated from a grammar probe.

tests/test_ast_symbols.py:295

Checks

  • assert set(found) == {
  • assert found["out_of_line"].qualified == "W::out_of_line"
  • assert found["free_fn"].static is True
  • assert found["static_method"].static is True

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_every_cpp_declarator_shape_that_has_a_name_is_recovered → harvest_function_definitions
REQ-DDB-PIPE-003measured
Source · 42 lines
def test_every_cpp_declarator_shape_that_has_a_name_is_recovered() -> None:
    """A SECOND GAP THE TEST ABOVE EXPOSED. `_declared_names` accepted only
    `identifier` and `qualified_identifier`, and tree-sitter-cpp names a method
    defined inside its class body `field_identifier` — so EVERY in-class method
    definition was silently skipped. Nothing failed; those symbols were simply never
    recovered, which is the same shape as the defect gh#11 exists to fix, one level
    down. The accepted set is now enumerated from a grammar probe.

    `operator=` stays refused on purpose: its declarator is a `reference_declarator`
    with no `function_declarator` beneath it, so there is no name node to read, and
    inventing one would put a guess into every downstream resolution."""
    from clew.tsnode import Parser as SubstrateParser

    src = (
        b"namespace ns {\nclass W {\n public:\n"
        b"  int inline_method() { return 1; }\n"
        b"  ~W() { }\n"
        b"  W& operator=(int) { return *this; }\n"
        b"  static int static_method() { return 2; }\n"
        b"};\n"
        b"int W::out_of_line() { return 4; }\n"
        b"static int free_fn(int a) { return a; }\n"
        b"template <typename T> T tmpl(T v) { return v; }\n}\n"
    )
    tree = SubstrateParser("cpp").parse(src)
    found = {f.name: f for f in harvest_function_definitions(tree, src)}

    assert set(found) == {
        "inline_method",
        "~W",
        "static_method",
        "out_of_line",
        "free_fn",
        "tmpl",
    }
    ## The out-of-line definition keeps its QUALIFIED name, which is what
    ## `qualified_name_of` needs to key it to doxygen's declaration row.
    assert found["out_of_line"].qualified == "W::out_of_line"
    assert found["free_fn"].static is True
    assert found["static_method"].static is True

Activity · 8 steps
lines 306–306from clew.tsnode import Parser as SubstrateParserlines 308–318src = ( b"namespace ns {\nclass W {\n public:\n" b" int inline_method() { return 1; }\n" b" ~W() { }\n" b" W& operator=(int) { return *this; }\n" b" static int static_method() { return 2; }\n" b"};\n" b"int W::out_of_line() { return 4; }\n" b"static int free_fn(int a) { return a; }\n" b"template <typename T> T tmpl(T v) { return v; }\n}\n" )lines 319–319tree = SubstrateParser("cpp").parse(src)lines 320–320found = {f.name: f for f in harvest_function_definitions(tree, src)}lines 322–329assert set(found) == { "inline_method", "~W", "static_method", "out_of_line", "free_fn", "tmpl", }lines 332–332assert found["out_of_line"].qualified == "W::out_of_line"lines 333–333assert found["free_fn"].static is Truelines 334–334assert found["static_method"].static is True

test_every_doxygen_row_is_labelled_doxygen_without_an_update_sweep

None test_ast_symbols.test_every_doxygen_row_is_labelled_doxygen_without_an_update_sweep(tuple[Path, Path] barren_index)

The `NOT NULL DEFAULT` is what makes the column honest about rows that existed before it did. If the default were absent (or NULL-able) doxygen's own rows would read as provenance-unknown until some later pass filled them in, and there would be a window in which a query could see an unlabelled row.

tests/test_ast_symbols.py:455

Checks

  • assert ensure_symbol_provenance(conn) is True
  • assert ensure_symbol_provenance(conn) is False, "must be idempotent"
  • assert sources == {SYMBOL_SOURCE_DOXYGEN}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_every_doxygen_row_is_labelled_doxygen_without_an_update_sweep → ensure_symbol_provenance
REQ-DDB-SCHEMA-012measured
Source · 20 lines
def test_every_doxygen_row_is_labelled_doxygen_without_an_update_sweep(
    barren_index: tuple[Path, Path],
) -> None:
    """The `NOT NULL DEFAULT` is what makes the column honest about rows that
    existed before it did. If the default were absent (or NULL-able) doxygen's own
    rows would read as provenance-unknown until some later pass filled them in, and
    there would be a window in which a query could see an unlabelled row."""
    db, _repo = barren_index
    conn = sqlite3.connect(str(db))
    try:
        assert ensure_symbol_provenance(conn) is True
        assert ensure_symbol_provenance(conn) is False, "must be idempotent"
        sources = {
            r[0] for r in conn.execute(f"SELECT DISTINCT {SYMBOL_SOURCE_COLUMN} FROM memberdef")
        }
        assert sources == {SYMBOL_SOURCE_DOXYGEN}
    finally:
        conn.close()

Activity · 7 steps
lines 462–462db, _repo = barren_indexlines 463–463conn = sqlite3.connect(str(db))lines 464–464trylines 465–465assert ensure_symbol_provenance(conn) is Truelines 466–466assert ensure_symbol_provenance(conn) is False, "must be idempotent"lines 467–469sources = { r[0] for r in conn.execute(f"SELECT DISTINCT {SYMBOL_SOURCE_COLUMN} FROM memberdef") }lines 470–470assert sources == {SYMBOL_SOURCE_DOXYGEN}

test_one_declaration_declaring_two_names_yields_two_rows

None test_ast_symbols.test_one_declaration_declaring_two_names_yields_two_rows(tuple[Path, Path] barren_index)

`demo_mutex_t demo_key_slot_mutex, demo_gmtime_mutex;` is ONE `declaration` node with TWO `declarator`-field children. Reading `child_by_field_name` — singular — would index the first and silently drop the second, which is a whole global missing with nothing to indicate it. Both share the declaration's type.

tests/test_ast_symbols.py:780

Show on the map →

Called by none

Calls _variable_rows, recover_ast_symbols

Checks

  • assert "demo_key_slot_mutex" in rows
  • assert "demo_gmtime_mutex" in rows
  • assert rows["demo_key_slot_mutex"][1] == rows["demo_gmtime_mutex"][1] == "demo_mutex_t"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_one_declaration_declaring_two_names_yields_two_rows → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_one_declaration_declaring_two_names_yields_two_rows → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_one_declaration_declaring_two_names_yields_two_rows → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_one_declaration_declaring_two_names_yields_two_rows → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_one_declaration_declaring_two_names_yields_two_rows → recover_ast_symbols → _recover_into → all
Source · 17 lines
def test_one_declaration_declaring_two_names_yields_two_rows(
    barren_index: tuple[Path, Path],
) -> None:
    """`demo_mutex_t demo_key_slot_mutex, demo_gmtime_mutex;` is ONE `declaration`
    node with TWO `declarator`-field children. Reading `child_by_field_name` —
    singular — would index the first and silently drop the second, which is a whole
    global missing with nothing to indicate it. Both share the declaration's type.
    """
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)
    rows = _variable_rows(db)

    assert "demo_key_slot_mutex" in rows
    assert "demo_gmtime_mutex" in rows
    assert rows["demo_key_slot_mutex"][1] == rows["demo_gmtime_mutex"][1] == "demo_mutex_t"

Activity · 6 steps
lines 788–788db, repo = barren_indexlines 789–789recover_ast_symbols(db, repo, None)lines 790–790rows = _variable_rows(db)lines 792–792assert "demo_key_slot_mutex" in rowslines 793–793assert "demo_gmtime_mutex" in rowslines 794–794assert rows["demo_key_slot_mutex"][1] == rows["demo_gmtime_mutex"][1] == "demo_mutex_t"

test_overlaps_collapses_a_malformed_end_to_its_start_line

None test_ast_symbols.test_overlaps_collapses_a_malformed_end_to_its_start_line()

doxygen records `bodyend = -1` for a body it never saw closed. Treating that literally makes the interval `[start, -1]`, which an unguarded comparison reads as matching everything after `start` — silencing recovery for the whole file.

tests/test_ast_symbols.py:366

Show on the map →

Called by none

Calls none

Checks

  • assert fn.overlaps(55, -1) is True
  • assert fn.overlaps(10, -1) is False

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
Source · 13 lines
def test_overlaps_collapses_a_malformed_end_to_its_start_line() -> None:
    """doxygen records `bodyend = -1` for a body it never saw closed. Treating that
    literally makes the interval `[start, -1]`, which an unguarded comparison reads
    as matching everything after `start` — silencing recovery for the whole file."""
    fn = ParsedFunction(name="f", qualified="f", args="()", static=False, start=50, end=60)

    assert fn.overlaps(55, -1) is True
    assert fn.overlaps(10, -1) is False


# ─── storage + the duplicate that must not happen ────────────────────────────

Activity · 3 steps
lines 370–370fn = ParsedFunction(name="f", qualified="f", args="()", static=False, start=50, end=60)lines 372–372assert fn.overlaps(55, -1) is Truelines 373–373assert fn.overlaps(10, -1) is False

test_python_definitions_are_recovered_with_class_qualification

None test_ast_symbols.test_python_definitions_are_recovered_with_class_qualification()

WHY THIS EXISTS, having been refused for the life of the module. The harvester returned `{}` for every Python tree, on the stated ground that "doxygen indexes Python fully — a Doxyfile-less Python codebase measured 4,739 functions — so there is nothing to recover there".

tests/test_ast_symbols.py:976

Checks

  • assert "top_level_plain" in found
  • assert "top_level_decorated" in found, "a decorated def must not be skipped"
  • assert "method_one" in found
  • assert "method_two" in found, "a @property is a decorated method"
  • assert "closure_helper" not in found, "a nested def is a LOCAL, not a symbol"
  • assert found["method_one"].qualified == "Holder.method_one"
  • assert found["top_level_plain"].qualified == "top_level_plain"
  • assert all(f.static is False for f in found.values())

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_python_definitions_are_recovered_with_class_qualification → harvest_python_definitions
REQ-DDB-WIKI-054inferredtest_python_definitions_are_recovered_with_class_qualification → all
Source · 48 lines
def test_python_definitions_are_recovered_with_class_qualification() -> None:
    """WHY THIS EXISTS, having been refused for the life of the module. The harvester
    returned `{}` for every Python tree, on the stated ground that "doxygen indexes Python
    fully — a Doxyfile-less Python codebase measured 4,739 functions — so there is nothing
    to recover there".

    THAT PREMISE IS FALSE, measured on this repository's own index at build 42:
    `tests/test_mcp_server.py` declares 93 top-level functions and doxygen emitted 41. The
    other 52 were absent from every table — not truncated (rows reached the file's last
    line), not misattributed (zero rows anywhere), and not predicted by the presence of a
    `##` block. So the backstop for doxygen's misses was switched off because doxygen was
    believed not to miss.

    The second stated ground — that a def inside a Python class "would need scope handling
    this stage does not do" — was true of this module and false of the package:
    `pyast.class_ranges`/`enclosing_class` already do it for the call-edge layer, and are
    reused rather than reimplemented.

    FOUR SHAPES, because three of them were the ones that would silently not work:
    a bare def; a DECORATED def (wrapped in `decorated_definition`, so a walk accepting only
    a bare `function_definition` skips every fixture and every property — most of a test
    suite); a METHOD, which must be qualified by its class; and a CLOSURE, which must NOT
    appear, because a nested def sits inside its parent's span and recording both makes the
    span-overlap dedup order-dependent.
    """
    from clew.tsnode import Parser as SubstrateParser

    src = _PY_SOURCE.encode()
    tree = SubstrateParser("python").parse(src)
    found = {f.name: f for f in harvest_python_definitions(tree, src)}

    assert "top_level_plain" in found
    assert "top_level_decorated" in found, "a decorated def must not be skipped"
    assert "method_one" in found
    assert "method_two" in found, "a @property is a decorated method"
    ## THE NEGATIVE HALF. Without it this test would pass on a walk that recorded
    ## everything, and the dedup would then be order-dependent on every real file.
    assert "closure_helper" not in found, "a nested def is a LOCAL, not a symbol"

    ## Methods carry their class; module-level functions do not invent one.
    assert found["method_one"].qualified == "Holder.method_one"
    assert found["top_level_plain"].qualified == "top_level_plain"

    ## `static` is C's internal linkage and Python has no such thing. A @staticmethod
    ## reported as static=True would make symbol_liveness call a public method file-private.
    assert all(f.static is False for f in found.values())

Activity · 12 steps
lines 1001–1001from clew.tsnode import Parser as SubstrateParserlines 1003–1003src = _PY_SOURCE.encode()lines 1004–1004tree = SubstrateParser("python").parse(src)lines 1005–1005found = {f.name: f for f in harvest_python_definitions(tree, src)}lines 1007–1007assert "top_level_plain" in foundlines 1008–1008assert "top_level_decorated" in found, "a decorated def must not be skipped"lines 1009–1009assert "method_one" in foundlines 1010–1010assert "method_two" in found, "a @property is a decorated method"lines 1013–1013assert "closure_helper" not in found, "a nested def is a LOCAL, not a symbol"lines 1016–1016assert found["method_one"].qualified == "Holder.method_one"lines 1017–1017assert found["top_level_plain"].qualified == "top_level_plain"lines 1021–1021assert all(f.static is False for f in found.values())

test_python_recovers_functions_and_still_no_module_variables

None test_ast_symbols.test_python_recovers_functions_and_still_no_module_variables(Path tmp_path)

INVERTED, NOT DELETED (gh#397). This test used to assert that Python is REFUSED, on the ground its own name gave: "because doxygen already indexes it". Its docstring said "Pinned so that enabling Python later is a decision rather than a side effect" — this is that decision, and the premise it rested on was MEASURED FALSE:

tests/test_ast_symbols.py:665

Show on the map →

Called by none

Calls none

Checks

  • assert [row[0] for row in payload.get(_PAYLOAD_FUNCTIONS, [])] == ["top"]
  • assert payload.get(_PAYLOAD_VARIABLES, []) == [], ("TOP_LEVEL is a module-level assignment doxygen already indexes; recovering it " "would double-count every Python constant in the repo" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-PIPE-003measured
Source · 42 lines
def test_python_recovers_functions_and_still_no_module_variables(tmp_path: Path) -> None:
    """INVERTED, NOT DELETED (gh#397). This test used to assert that Python is REFUSED, on
    the ground its own name gave: "because doxygen already indexes it". Its docstring said
    "Pinned so that enabling Python later is a decision rather than a side effect" — this is
    that decision, and the premise it rested on was MEASURED FALSE:

    On this repository's own index at build 42, `tests/test_mcp_server.py` declares 93
    top-level functions and doxygen emitted 41. The other 52 were absent from every table:
    not truncated (rows reached the file's last line), not misattributed (zero rows anywhere
    for sampled names), and not predicted by whether a `##` block was present. Enabling
    recovery took that file from 52 missing to 1, and the repo from 158 to 160 of 172 files
    indexing >=95% of their defs.

    THE VARIABLE HALF STILL HOLDS, and it is kept for the reason the original gave: a Python
    module's assignments are exactly what a careless widening of the walk would start
    harvesting, and doxygen already indexes them. That half would break silently, so it stays
    asserted alongside the inverted half.

    INVARIANCE CONTROL, run outside the suite because it needs a real target: rebuilding
    mbedtls across this change left all 36 tables byte-identical, so the widening is a strict
    no-op on C. On the self-index, doxygen rows moved 4,493 -> 4,497 and the four were
    verified to be exactly this change's own new code, not disturbed rows.
    """
    from clew.tsnode import Parser as SubstrateParser

    src = b"TOP_LEVEL = 3\n\n\ndef top():\n    return 1\n"
    tree = SubstrateParser("python").parse(src)

    from clew.ast_symbols import (
        _PAYLOAD_FUNCTIONS,
        _PAYLOAD_VARIABLES,
        _FunctionDefinitionHarvester,
    )

    payload = _FunctionDefinitionHarvester().harvest(tree, src)
    assert [row[0] for row in payload.get(_PAYLOAD_FUNCTIONS, [])] == ["top"]
    assert payload.get(_PAYLOAD_VARIABLES, []) == [], (
        "TOP_LEVEL is a module-level assignment doxygen already indexes; recovering it "
        "would double-count every Python constant in the repo"
    )

Activity · 7 steps
lines 688–688from clew.tsnode import Parser as SubstrateParserlines 690–690src = b"TOP_LEVEL = 3\n\n\ndef top():\n return 1\n"lines 691–691tree = SubstrateParser("python").parse(src)lines 693–697from clew.ast_symbols import ( _PAYLOAD_FUNCTIONS, _PAYLOAD_VARIABLES, _FunctionDefinitionHarvester, )lines 699–699payload = _FunctionDefinitionHarvester().harvest(tree, src)lines 700–700assert [row[0] for row in payload.get(_PAYLOAD_FUNCTIONS, [])] == ["top"]lines 701–704assert payload.get(_PAYLOAD_VARIABLES, []) == [], ( "TOP_LEVEL is a module-level assignment doxygen already indexes; recovering it " "would double-count every Python constant in the repo" )

test_recovery_inserts_the_guarded_functions_and_marks_them_ast

None test_ast_symbols.test_recovery_inserts_the_guarded_functions_and_marks_them_ast(tuple[Path, Path] barren_index)

THE GUARD IS RECOVERED DELIBERATELY, not tolerated.

tests/test_ast_symbols.py:379

Show on the map →

Called by none

Calls _rows_by_name, recover_ast_symbols

Checks

  • assert inserted == 11
  • assert rows["mutex_lock_pthread"][0] == SYMBOL_SOURCE_AST
  • assert rows["mutex_unlock_pthread"][0] == SYMBOL_SOURCE_AST
  • assert rows["mutex_lock_pthread"][4] == 1
  • assert rows["mutex_unlock_pthread"][4] == 0

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_recovery_inserts_the_guarded_functions_and_marks_them_ast → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_recovery_inserts_the_guarded_functions_and_marks_them_ast → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_recovery_inserts_the_guarded_functions_and_marks_them_ast → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_recovery_inserts_the_guarded_functions_and_marks_them_ast → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_recovery_inserts_the_guarded_functions_and_marks_them_ast → recover_ast_symbols → _recover_into → all
Source · 25 lines
def test_recovery_inserts_the_guarded_functions_and_marks_them_ast(
    barren_index: tuple[Path, Path],
) -> None:
    """The headline. Functions doxygen never emitted become rows, and every one
    of them says so."""
    db, repo = barren_index
    inserted = recover_ast_symbols(db, repo, None)
    rows = _rows_by_name(db)

    ## 5 functions (three in guarded.c, two in public.c) + 5 gh#372 globals + gh#403's
    ## one macro, `public.h`'s `#define PUBLIC_H` include guard. The return value covers
    ## EVERY kind, which is why this is not 5.
    ##
    ## THE GUARD IS RECOVERED DELIBERATELY, not tolerated. doxygen skips an include guard
    ## and a rule that skipped it here would need to recognise the idiom — one more
    ## heuristic, on a walk whose value is that a `#define` is the least ambiguous thing
    ## in a C file. A row saying `PUBLIC_H` is defined at that line is true.
    assert inserted == 11
    assert rows["mutex_lock_pthread"][0] == SYMBOL_SOURCE_AST
    assert rows["mutex_unlock_pthread"][0] == SYMBOL_SOURCE_AST
    ## Static-ness is one of the four things the issue says a recovered row carries.
    assert rows["mutex_lock_pthread"][4] == 1
    assert rows["mutex_unlock_pthread"][4] == 0

Activity · 8 steps
lines 384–384db, repo = barren_indexlines 385–385inserted = recover_ast_symbols(db, repo, None)lines 386–386rows = _rows_by_name(db)lines 396–396assert inserted == 11lines 397–397assert rows["mutex_lock_pthread"][0] == SYMBOL_SOURCE_ASTlines 398–398assert rows["mutex_unlock_pthread"][0] == SYMBOL_SOURCE_ASTlines 400–400assert rows["mutex_lock_pthread"][4] == 1lines 401–401assert rows["mutex_unlock_pthread"][4] == 0

test_recovery_lowers_the_barren_ratio_and_leaves_the_documented_gap_visible

None test_ast_symbols.test_recovery_lowers_the_barren_ratio_and_leaves_the_documented_gap_visible(tuple[Path, Path] barren_index)

gh#6's metric is gh#11's acceptance criterion, so it has to move. But making it move must NOT silence the advice to declare PREDEFINED, because that recovers the DOCUMENTATION this cannot. Both halves are asserted: the graph gap closes and the prose gap stays measured.

tests/test_ast_symbols.py:624

Checks

  • assert before.barren_files == 2, "guarded.c and public.c yield nothing"
  • assert before.undocumented_files == 2
  • assert after.barren_files == 0, "the graph gap is closed"
  • assert after.barren_ratio < before.barren_ratio
  • assert after.undocumented_files == 2, "the prose gap is untouched"
  • assert after.undocumented_ratio > after.barren_ratio

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_recovery_lowers_the_barren_ratio_and_leaves_the_documented_gap_visible → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_recovery_lowers_the_barren_ratio_and_leaves_the_documented_gap_visible → measure_index_coverage
REQ-DDB-INDEX-004measuredtest_recovery_lowers_the_barren_ratio_and_leaves_the_documented_gap_visible → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_recovery_lowers_the_barren_ratio_and_leaves_the_documented_gap_visible → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_recovery_lowers_the_barren_ratio_and_leaves_the_documented_gap_visible → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_recovery_lowers_the_barren_ratio_and_leaves_the_documented_gap_visible → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_recovery_lowers_the_barren_ratio_and_leaves_the_documented_gap_visible → recover_ast_symbols → _recover_into → all
Source · 25 lines
def test_recovery_lowers_the_barren_ratio_and_leaves_the_documented_gap_visible(
    barren_index: tuple[Path, Path],
) -> None:
    """gh#6's metric is gh#11's acceptance criterion, so it has to move. But making
    it move must NOT silence the advice to declare PREDEFINED, because that recovers
    the DOCUMENTATION this cannot. Both halves are asserted: the graph gap closes
    and the prose gap stays measured."""
    db, repo = barren_index

    before = measure_index_coverage(db, repo)
    assert before.barren_files == 2, "guarded.c and public.c yield nothing"
    assert before.undocumented_files == 2

    recover_ast_symbols(db, repo, None)
    after = measure_index_coverage(db, repo)

    assert after.barren_files == 0, "the graph gap is closed"
    assert after.barren_ratio < before.barren_ratio
    ## guarded.c's two functions have no documentation anywhere; public.c's one is
    ## documented in its header, and the metric attributes prose per FILE, so
    ## public.c reads undocumented too. Both stay visible.
    assert after.undocumented_files == 2, "the prose gap is untouched"
    assert after.undocumented_ratio > after.barren_ratio

Activity · 10 steps
lines 631–631db, repo = barren_indexlines 633–633before = measure_index_coverage(db, repo)lines 634–634assert before.barren_files == 2, "guarded.c and public.c yield nothing"lines 635–635assert before.undocumented_files == 2lines 637–637recover_ast_symbols(db, repo, None)lines 638–638after = measure_index_coverage(db, repo)lines 640–640assert after.barren_files == 0, "the graph gap is closed"lines 641–641assert after.barren_ratio < before.barren_ratiolines 645–645assert after.undocumented_files == 2, "the prose gap is untouched"lines 646–646assert after.undocumented_ratio > after.barren_ratio

test_reference_returning_definitions_are_recovered

None test_ast_symbols.test_reference_returning_definitions_are_recovered()

A reference-returning definition must be recovered, not silently skipped.

tests/test_ast_symbols.py:1191

Checks

  • assert "const_ref_return" in found, (f"a `const T&`-returning definition was skipped — this is the reported shape; got {found}" )
  • assert "plain_ref_return" in found, f"a `T&`-returning definition was skipped; got {found}"
  • assert "ptr_return" in found, "pointer returns were already recovered and must remain so"
  • assert "value_return" in found, "plain value returns must remain so"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_reference_returning_definitions_are_recovered → harvest_function_definitions
REQ-DDB-PIPE-003measured
Source · 46 lines
def test_reference_returning_definitions_are_recovered() -> None:
    """FOUND WHILE FIXING gh#9, AND IT IS THE LARGER OF THE TWO BUGS. `_function_declarator`
    followed `child_by_field_name("declarator")` only, and a `reference_declarator` does NOT
    expose its inner declarator under that field — so the walk returned None and EVERY
    reference-returning definition was absent from the recovery layer whose whole job is
    recovering what doxygen did not emit.

    In C++ that is not an edge case. `const T& accessor()`, `T& operator[]()`, `begin()`/`end()`
    — the shape is everywhere, and all of it was being dropped in silence. The helper's own
    docstring said "pointer/parenthesized"; reference was never in the set.

    HOW IT SURFACED IS THE PART WORTH KEEPING. The macro-reference recovery reused this helper,
    passed five of six measured cases, and failed the ONE that had been reported. A test asserting
    "recovery works" on any single non-reference case would have passed throughout.

    Both the plain and the `const` reference shapes are asserted, plus a pointer return as the
    control that the original behaviour is intact.

    @brief Reference-returning functions reach the recovery layer.
    @return None.
    @version 1
    """

    from clew.tsnode import Parser as SubstrateParser

    src = (
        b"#include <array>\n"
        b"struct Row { int a; };\n"
        b"static Row g_row;\n"
        b"static Row g_rows[4];\n"
        b"const std::array<Row, 4>& const_ref_return() { static std::array<Row, 4> k{}; return k; }\n"
        b"Row& plain_ref_return() { return g_row; }\n"
        b"Row* ptr_return() { return &g_row; }\n"
        b"int value_return() { return 1; }\n"
    )
    tree = SubstrateParser("cpp").parse(src)
    found = {f.name for f in harvest_function_definitions(tree, src)}

    assert "const_ref_return" in found, (
        f"a `const T&`-returning definition was skipped — this is the reported shape; got {found}"
    )
    assert "plain_ref_return" in found, f"a `T&`-returning definition was skipped; got {found}"
    ## THE CONTROLS: the shapes that already worked must keep working, or a fix that recovered
    ## references by loosening the walk into accepting anything would pass the two above.
    assert "ptr_return" in found, "pointer returns were already recovered and must remain so"
    assert "value_return" in found, "plain value returns must remain so"

1 more lines, not shown

Activity · 8 steps
lines 1214–1214from clew.tsnode import Parser as SubstrateParserlines 1216–1225src = ( b"#include <array>\n" b"struct Row { int a; };\n" b"static Row g_row;\n" b"static Row g_rows[4];\n" b"const std::array<Row, 4>& const_ref_return() { static std::array<Row, 4> k{}; return k; }\n" b"Row& plain_ref_return() { return g_row; }\n" b"Row* ptr_return() { return &g_row; }\n" b"int value_return() { return 1; }\n" )lines 1226–1226tree = SubstrateParser("cpp").parse(src)lines 1227–1227found = {f.name for f in harvest_function_definitions(tree, src)}lines 1229–1231assert "const_ref_return" in found, ( f"a `const T&`-returning definition was skipped — this is the reported shape; got {found}" )lines 1232–1232assert "plain_ref_return" in found, f"a `T&`-returning definition was skipped; got {found}"lines 1235–1235assert "ptr_return" in found, "pointer returns were already recovered and must remain so"lines 1236–1236assert "value_return" in found, "plain value returns must remain so"

test_running_recovery_twice_inserts_nothing_the_second_time

None test_ast_symbols.test_running_recovery_twice_inserts_nothing_the_second_time(tuple[Path, Path] barren_index)

A smoke run caught the first cut doing the opposite: the dedup compared only against doxygen-sourced spans, so a second pass re-inserted the whole recovered set. It surfaced as a UNIQUE violation on the synthetic refid; without that index it would have silently doubled the graph.

tests/test_ast_symbols.py:430

Checks

  • assert recover_ast_symbols(db, repo, None) == 11
  • assert recover_ast_symbols(db, repo, None) == 0

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_running_recovery_twice_inserts_nothing_the_second_time → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_running_recovery_twice_inserts_nothing_the_second_time → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_running_recovery_twice_inserts_nothing_the_second_time → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_running_recovery_twice_inserts_nothing_the_second_time → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_running_recovery_twice_inserts_nothing_the_second_time → recover_ast_symbols → _recover_into → all
Source · 25 lines
def test_running_recovery_twice_inserts_nothing_the_second_time(
    barren_index: tuple[Path, Path],
) -> None:
    """A smoke run caught the first cut doing the opposite: the dedup compared only
    against doxygen-sourced spans, so a second pass re-inserted the whole recovered
    set. It surfaced as a UNIQUE violation on the synthetic refid; without that
    index it would have silently doubled the graph.

    Covers BOTH kinds since gh#372, and the variable half has its own way to fail:
    its dedup key is `(file, name)` read back from `memberdef`, so a second pass
    that queried the wrong provenance or the wrong kind would re-insert all five
    globals. The `== 0` below is the only assertion that catches it.

    THREE KINDS SINCE gh#403, and the macro half has a THIRD way to fail that neither
    other kind can reach: its key is `(file, name, LINE)`, deliberately finer than the
    variable rule so a conditional `#define`'s second branch survives. A key that finer
    is a key with more ways to miss — read back the wrong column, or compare a
    tree-sitter line against a `bodystart`, and every macro in the repository is
    re-inserted on every build. Only the `== 0` catches it."""
    db, repo = barren_index

    assert recover_ast_symbols(db, repo, None) == 11
    assert recover_ast_symbols(db, repo, None) == 0

Activity · 3 steps
lines 449–449db, repo = barren_indexlines 451–451assert recover_ast_symbols(db, repo, None) == 11lines 452–452assert recover_ast_symbols(db, repo, None) == 0

test_search_discloses_a_dropped_row_only_when_provenance_DIFFERS

None test_ast_symbols.test_search_discloses_a_dropped_row_only_when_provenance_DIFFERS(tuple[Path, Path] barren_index)

gh#392, and the narrowing is the whole point of the test.

tests/test_ast_symbols.py:1115

Show on the map →

Called by none

Calls _memberdef, recover_ast_symbols

Checks

  • assert "split_api" in hits
  • assert hits["split_api"].file == "public.h"
  • assert hits["split_api"].also_in == ("public.c",)
  • assert plain["documented_add"].also_in == ()
  • assert both_doxygen["documented_add"].also_in == (), ("a decl/def pair is BOTH doxygen's — `documented_first` decided nothing across " "provenance, so there is nothing to disclose and firing here is pure noise" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_search_discloses_a_dropped_row_only_when_provenance_DIFFERS → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_search_discloses_a_dropped_row_only_when_provenance_DIFFERS → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_search_discloses_a_dropped_row_only_when_provenance_DIFFERS → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_search_discloses_a_dropped_row_only_when_provenance_DIFFERS → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-012measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_search_discloses_a_dropped_row_only_when_provenance_DIFFERS → recover_ast_symbols → _recover_into → all
Source · 73 lines
def test_search_discloses_a_dropped_row_only_when_provenance_DIFFERS(
    barren_index: tuple[Path, Path],
) -> None:
    """gh#392, and the narrowing is the whole point of the test.

    `search` collapses per NAME and `documented_first` keeps doxygen's row, so a bare
    recovered row can never hide a documented one. Right in general, and MEASURED WRONG once:
    after gh#395 recovered mbedtls's guarded `mbedtls_threading_mutex_t`, the surviving row
    was the TEST FIXTURE at `tests/include/alt-dummy/threading_alt.h` and the dropped one was
    the shipping type at `include/mbedtls/threading.h`.

    MY FIRST CUT DISCLOSED EVERY DROPPED FILE and was wrong in the way this project warns
    about most: it fired on 22.0% of mbedtls's 7,864 distinct names, including plain
    decl/def pairs, which is a guard firing on the ordinary case and burying the one case
    that matters. Narrowing to a PROVENANCE-CROSSING drop — the event `documented_first`
    actually decided — takes it to 12.7%, and every firing then says something: the row you
    got is doxygen's declaration, and the parser found this name somewhere else too.

    `split_api` is that shape in the fixture: DECLARED in `public.h` where doxygen read it,
    DEFINED in `public.c` behind a guard doxygen could not satisfy. `documented_add` is the
    control — one row, one provenance, nothing to disclose.

    Disclosing rather than re-ranking: inverting the order would let every bare recovered row
    hide a documented one, and preferring a non-test path would hardcode a convention.
    """
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)

    hits = {h.name: h for h in search(db, "split_api")}
    assert "split_api" in hits
    ## The kept row is doxygen's header declaration ...
    assert hits["split_api"].file == "public.h"
    ## ... and the recovered definition's file is NAMED rather than silently dropped.
    assert hits["split_api"].also_in == ("public.c",)

    ## THE CONTROL. A name with a single row must disclose nothing, or the field is noise.
    plain = {h.name: h for h in search(db, "documented_add")}
    assert plain["documented_add"].also_in == ()

    ## THE NARROWING, and it needs its own row because MUTATION SHOWED THE TEST DID NOT
    ## COVER IT: replacing the provenance comparison with `True` left everything above green,
    ## since the fixture had no same-provenance duplicate to be silent about. A plain
    ## decl/def pair — BOTH doxygen's, in two files — is the ordinary case that must stay
    ## quiet, and it is the 22.0% of mbedtls names my first cut fired on.
    conn = sqlite3.connect(str(db))
    try:
        _memberdef(
            conn,
            900,
            name="documented_add",
            definition="int documented_add",
            argsstring="(int a)",
            kind="function",
            static=0,
            bodystart=0,
            bodyend=0,
            bodyfile_id=None,
            file_id=12,
            line=9,
            column=1,
            briefdescription="<para>The header declaration. </para>",
        )
        conn.commit()
    finally:
        conn.close()

    both_doxygen = {h.name: h for h in search(db, "documented_add")}
    assert both_doxygen["documented_add"].also_in == (), (
        "a decl/def pair is BOTH doxygen's — `documented_first` decided nothing across "
        "provenance, so there is nothing to disclose and firing here is pure noise"
    )

Activity · 14 steps
lines 1140–1140db, repo = barren_indexlines 1141–1141recover_ast_symbols(db, repo, None)lines 1143–1143hits = {h.name: h for h in search(db, "split_api")}lines 1144–1144assert "split_api" in hitslines 1146–1146assert hits["split_api"].file == "public.h"lines 1148–1148assert hits["split_api"].also_in == ("public.c",)lines 1151–1151plain = {h.name: h for h in search(db, "documented_add")}lines 1152–1152assert plain["documented_add"].also_in == ()lines 1159–1159conn = sqlite3.connect(str(db))lines 1160–1160trylines 1161–1176_memberdef( conn, 900, name="documented_add", definition="int documented_add", argsstring="(int a)", kind="function", static=0, bodystart=0, bodyend=0, bodyfile_id=None, file_id=12, line=9, column=1, briefdescription="<para>The header declaration. </para>", )lines 1177–1177conn.commit()lines 1181–1181both_doxygen = {h.name: h for h in search(db, "documented_add")}lines 1182–1185assert both_doxygen["documented_add"].also_in == (), ( "a decl/def pair is BOTH doxygen's — `documented_first` decided nothing across " "provenance, so there is nothing to disclose and firing here is pure noise" )

test_search_still_prefers_a_function_when_a_name_scores_equally

None test_ast_symbols.test_search_still_prefers_a_function_when_a_name_scores_equally(tuple[Path, Path] barren_index)

THE REGRESSION CONTROL. Adding a corpus must not reorder the old one: a variable appearing where a caller expected a function is the failure mode.

tests/test_ast_symbols.py:930

Checks

  • assert "mutex_lock_pthread" in names
  • assert names.index("mutex_lock_pthread") < names.index("demo_mutex_lock")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_search_still_prefers_a_function_when_a_name_scores_equally → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_search_still_prefers_a_function_when_a_name_scores_equally → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_search_still_prefers_a_function_when_a_name_scores_equally → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_search_still_prefers_a_function_when_a_name_scores_equally → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-012measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_search_still_prefers_a_function_when_a_name_scores_equally → recover_ast_symbols → _recover_into → all
Source · 18 lines
def test_search_still_prefers_a_function_when_a_name_scores_equally(
    barren_index: tuple[Path, Path],
) -> None:
    """THE REGRESSION CONTROL. Adding a corpus must not reorder the old one: a
    variable appearing where a caller expected a function is the failure mode.

    Variables sit in the lowest tie-break tier, so a function wins every score TIE.
    `demo_mutex_lock` (a global) and `mutex_lock_pthread` (a function) both carry the
    token, and the function must not be displaced from the results.
    """
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)

    names = [h.name for h in search(db, "mutex_lock")]
    assert "mutex_lock_pthread" in names
    assert names.index("mutex_lock_pthread") < names.index("demo_mutex_lock")

Activity · 5 steps
lines 940–940db, repo = barren_indexlines 941–941recover_ast_symbols(db, repo, None)lines 943–943names = [h.name for h in search(db, "mutex_lock")]lines 944–944assert "mutex_lock_pthread" in nameslines 945–945assert names.index("mutex_lock_pthread") < names.index("demo_mutex_lock")

test_the_coverage_meta_publishes_both_ratios

None test_ast_symbols.test_the_coverage_meta_publishes_both_ratios(tuple[Path, Path] barren_index)

A number that lives only in a warning is gone by query time — the defect this project has now fixed three times. The documented ratio has to be persisted for the same reason the barren one is.

tests/test_ast_symbols.py:649

Checks

  • assert "barren_ratio" in meta
  • assert "undocumented_ratio" in meta
  • assert meta["undocumented_files"] == "2"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_the_coverage_meta_publishes_both_ratios → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_the_coverage_meta_publishes_both_ratios → measure_index_coverage
REQ-DDB-INDEX-004measuredtest_the_coverage_meta_publishes_both_ratios → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_the_coverage_meta_publishes_both_ratios → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_the_coverage_meta_publishes_both_ratios → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_the_coverage_meta_publishes_both_ratios → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_the_coverage_meta_publishes_both_ratios → recover_ast_symbols → _recover_into → all
Source · 16 lines
def test_the_coverage_meta_publishes_both_ratios(barren_index: tuple[Path, Path]) -> None:
    """A number that lives only in a warning is gone by query time — the defect this
    project has now fixed three times. The documented ratio has to be persisted for
    the same reason the barren one is."""
    db, repo = barren_index
    recover_ast_symbols(db, repo, None)
    meta = measure_index_coverage(db, repo).as_meta()

    assert "barren_ratio" in meta
    assert "undocumented_ratio" in meta
    assert meta["undocumented_files"] == "2"


# ─── the deliberate limits, pinned so they are choices and not accidents ─────

Activity · 6 steps
lines 653–653db, repo = barren_indexlines 654–654recover_ast_symbols(db, repo, None)lines 655–655meta = measure_index_coverage(db, repo).as_meta()lines 657–657assert "barren_ratio" in metalines 658–658assert "undocumented_ratio" in metalines 659–659assert meta["undocumented_files"] == "2"

test_the_harvester_ITSELF_returns_python_functions_not_an_empty_payload

None test_ast_symbols.test_the_harvester_ITSELF_returns_python_functions_not_an_empty_payload()

The harvester's own payload carries Python functions.

tests/test_ast_symbols.py:1024

Checks

  • assert payload, "an empty payload means the Python branch is unwired"
  • assert "top_level_plain" in names
  • assert "top_level_decorated" in names
  • assert payload["variables"] == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-PIPE-003measuredtest_the_harvester_ITSELF_returns_python_functions_not_an_empty_payload → function_definition_harvester
Source · 29 lines
def test_the_harvester_ITSELF_returns_python_functions_not_an_empty_payload() -> None:
    """THE WIRING, and it needs its own test because the one above does not cover it. That
    test calls `harvest_python_definitions` directly, so it passes whether or not anything
    CALLS that function — proven by mutation: restoring the harvester's
    `if is_python_tree(tree): return {}` early-out left it green.

    That is the exact failure this project names "a capability existing is not a capability
    used", and it is how a fix ships with a passing test and no effect. So this drives
    `_FunctionDefinitionHarvester.harvest`, which is what the pipeline actually invokes.

    @brief The harvester's own payload carries Python functions.
    @version 1
    """
    from clew.tsnode import Parser as SubstrateParser

    src = _PY_SOURCE.encode()
    tree = SubstrateParser("python").parse(src)
    payload = function_definition_harvester().harvest(tree, src)

    assert payload, "an empty payload means the Python branch is unwired"
    names = {row[0] for row in payload["functions"]}
    assert "top_level_plain" in names
    assert "top_level_decorated" in names
    ## Variables stay empty for Python: `harvest_variable_declarations` reads C declarator
    ## shapes the Python grammar does not produce, and a module-level assignment is already
    ## indexed by doxygen.
    assert payload["variables"] == []

Activity · 9 steps
lines 1037–1037from clew.tsnode import Parser as SubstrateParserlines 1039–1039src = _PY_SOURCE.encode()lines 1040–1040tree = SubstrateParser("python").parse(src)lines 1041–1041payload = function_definition_harvester().harvest(tree, src)lines 1043–1043assert payload, "an empty payload means the Python branch is unwired"lines 1044–1044names = {row[0] for row in payload["functions"]}lines 1045–1045assert "top_level_plain" in nameslines 1046–1046assert "top_level_decorated" in nameslines 1050–1050assert payload["variables"] == []

test_the_harvester_payload_carries_typedefs_separately_from_variables

None test_ast_symbols.test_the_harvester_payload_carries_typedefs_separately_from_variables()

THE WIRING, which needs its own test for the reason the Python one did: a test that calls `harvest_type_definitions` directly passes whether or not anything CALLS it. Mutation proved that on gh#397 — the direct-call test stayed green with the early-out restored.

tests/test_ast_symbols.py:1093

Checks

  • assert [row[0] for row in payload["typedefs"]] == ["only_a_type_t"]
  • assert [row[0] for row in payload["variables"]] == ["only_a_var"], ("the two kinds must not bleed into one another's list" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-PIPE-003measuredtest_the_harvester_payload_carries_typedefs_separately_from_variables → function_definition_harvester
Source · 22 lines
def test_the_harvester_payload_carries_typedefs_separately_from_variables() -> None:
    """THE WIRING, which needs its own test for the reason the Python one did: a test that
    calls `harvest_type_definitions` directly passes whether or not anything CALLS it.
    Mutation proved that on gh#397 — the direct-call test stayed green with the early-out
    restored.

    A SEPARATE KEY rather than folding typedefs into `variables`, because the two are written
    with different `memberdef.kind` values and a shared list would have to carry the kind per
    row — the shape that lets one loop write the wrong one.
    """
    from clew.tsnode import Parser as SubstrateParser

    src = b"typedef struct only_a_type_t { int x; } only_a_type_t;\nint only_a_var;\n"
    tree = SubstrateParser("c").parse(src)
    payload = function_definition_harvester().harvest(tree, src)

    assert [row[0] for row in payload["typedefs"]] == ["only_a_type_t"]
    assert [row[0] for row in payload["variables"]] == ["only_a_var"], (
        "the two kinds must not bleed into one another's list"
    )

Activity · 6 steps
lines 1103–1103from clew.tsnode import Parser as SubstrateParserlines 1105–1105src = b"typedef struct only_a_type_t { int x; } only_a_type_t;\nint only_a_var;\n"lines 1106–1106tree = SubstrateParser("c").parse(src)lines 1107–1107payload = function_definition_harvester().harvest(tree, src)lines 1109–1109assert [row[0] for row in payload["typedefs"]] == ["only_a_type_t"]lines 1110–1112assert [row[0] for row in payload["variables"]] == ["only_a_var"], ( "the two kinds must not bleed into one another's list" )

test_the_provenance_column_refuses_an_unregistered_value

None test_ast_symbols.test_the_provenance_column_refuses_an_unregistered_value(tuple[Path, Path] barren_index)

The CHECK is generated from `vocabulary.SYMBOL_SOURCE`, so this pins that the ALTER actually carried it — SQLite permits a CHECK in ADD COLUMN, but silently dropping one would leave an unconstrained free-text provenance column, which is the exact defect `external_boundaries.source` was fixed for.

tests/test_ast_symbols.py:475

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_the_provenance_column_refuses_an_unregistered_value → ensure_symbol_provenance
REQ-DDB-SCHEMA-012measured
Source · 20 lines
def test_the_provenance_column_refuses_an_unregistered_value(
    barren_index: tuple[Path, Path],
) -> None:
    """The CHECK is generated from `vocabulary.SYMBOL_SOURCE`, so this pins that the
    ALTER actually carried it — SQLite permits a CHECK in ADD COLUMN, but silently
    dropping one would leave an unconstrained free-text provenance column, which is
    the exact defect `external_boundaries.source` was fixed for."""
    db, _repo = barren_index
    conn = sqlite3.connect(str(db))
    try:
        ensure_symbol_provenance(conn)
        with pytest.raises(sqlite3.IntegrityError):
            conn.execute(f"UPDATE memberdef SET {SYMBOL_SOURCE_COLUMN} = 'guessed' WHERE rowid = 1")
    finally:
        conn.close()


# ─── decl/def duality: the highest-risk regression ───────────────────────────

Activity · 6 steps
lines 482–482db, _repo = barren_indexlines 483–483conn = sqlite3.connect(str(db))lines 484–484trylines 485–485ensure_symbol_provenance(conn)lines 486–486with pytest.raises(sqlite3.IntegrityError)lines 487–487conn.execute(f"UPDATE memberdef SET {SYMBOL_SOURCE_COLUMN} = 'guessed' WHERE rowid = 1")

test_the_recovered_body_is_readable_source_which_it_previously_was_not

None test_ast_symbols.test_the_recovered_body_is_readable_source_which_it_previously_was_not(tuple[Path, Path] barren_index)

`source` needs `bodystart`/`bodyend`, and before recovery a guarded-out function had neither — so the tool answered nothing. This is the capability the issue's 'done means' clause is about.

tests/test_ast_symbols.py:603

Checks

  • assert source(db, "mutex_unlock_pthread", repo) is None
  • assert listing is not None
  • assert listing.file == "guarded.c"
  • assert "mutex_unlock_pthread" in listing.lines[0]
  • assert any("return mutex_lock_pthread(mutex);" in line for line in listing.lines)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_the_recovered_body_is_readable_source_which_it_previously_was_not → recover_ast_symbols
REQ-DDB-PIPE-003measuredtest_the_recovered_body_is_readable_source_which_it_previously_was_not → recover_ast_symbols → _recover_into → function_definition_harvester
REQ-DDB-PIPE-011measuredtest_the_recovered_body_is_readable_source_which_it_previously_was_not → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_the_recovered_body_is_readable_source_which_it_previously_was_not → recover_ast_symbols → _recover_into → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-001measuredtest_the_recovered_body_is_readable_source_which_it_previously_was_not → source
REQ-DDB-QUERY-003measuredtest_the_recovered_body_is_readable_source_which_it_previously_was_not → source → function_candidates
REQ-DDB-QUERY-010measuredtest_the_recovered_body_is_readable_source_which_it_previously_was_not → source → function_candidates
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_the_recovered_body_is_readable_source_which_it_previously_was_not → recover_ast_symbols → _recover_into → all
Source · 21 lines
def test_the_recovered_body_is_readable_source_which_it_previously_was_not(
    barren_index: tuple[Path, Path],
) -> None:
    """`source` needs `bodystart`/`bodyend`, and before recovery a guarded-out
    function had neither — so the tool answered nothing. This is the capability the
    issue's 'done means' clause is about."""
    db, repo = barren_index
    assert source(db, "mutex_unlock_pthread", repo) is None

    recover_ast_symbols(db, repo, None)
    listing = source(db, "mutex_unlock_pthread", repo)

    assert listing is not None
    assert listing.file == "guarded.c"
    assert "mutex_unlock_pthread" in listing.lines[0]
    assert any("return mutex_lock_pthread(mutex);" in line for line in listing.lines)


# ─── the metric the issue asks to be judged by ───────────────────────────────

Activity · 8 steps
lines 609–609db, repo = barren_indexlines 610–610assert source(db, "mutex_unlock_pthread", repo) is Nonelines 612–612recover_ast_symbols(db, repo, None)lines 613–613listing = source(db, "mutex_unlock_pthread", repo)lines 615–615assert listing is not Nonelines 616–616assert listing.file == "guarded.c"lines 617–617assert "mutex_unlock_pthread" in listing.lines[0]lines 618–618assert any("return mutex_lock_pthread(mutex);" in line for line in listing.lines)