test_gate_coverage_integration.py

tests/integration/test_gate_coverage_integration.py

A function's PRECONDITIONS survive a real build, with the polarity intact.

test_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently

None test_gate_coverage_integration.test_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently(Path tmp_path)

A moved body is disclosed rather than passed off as the function's own.

tests/integration/test_gate_coverage_integration.py:247

Checks

  • assert fresh is not None and fresh.body is not None, "the fixture must produce a body"
  • assert fresh.body.anchor_mismatch is False, (f"the tree is untouched, so the excerpt is the function's own — a mismatch here means the " f"check fires on ordinary code: {fresh.body.lines}" )
  • assert any("drift_subject" in line for line in fresh.body.lines), ("and the excerpt really is anchored at the signature, which is what makes the check work" )
  • assert moved is not None and moved.body is not None
  • assert moved.body.anchor_mismatch is True, (f"the recorded span no longer holds this function, and saying nothing is what sent a " f"reader to the file: {moved.body.lines}" )
  • assert moved.body.lines, ("the lines must still be returned — withholding the evidence is worse than labelling it, " "and a reader may still recognise what they are looking at" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-009measured
REQ-DDB-INDEX-001measured
REQ-DDB-INDEX-002measured
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measuredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-INDEX-005measured
REQ-DDB-INDEX-006measured
REQ-DDB-INDEX-007measured
REQ-DDB-INDEX-008measured
REQ-DDB-INDEX-009measured
REQ-DDB-INDEX-010measured
REQ-DDB-INDEX-011measured
REQ-DDB-MCP-001measured
REQ-DDB-MCP-004measured
REQ-DDB-PIPE-001measured
REQ-DDB-PIPE-003measuredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-004measured
REQ-DDB-PIPE-005measured
REQ-DDB-PIPE-006measured
REQ-DDB-PIPE-007measured
REQ-DDB-PIPE-008measured
REQ-DDB-PIPE-009measured
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measuredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012measuredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-013measured
REQ-DDB-PIPE-014measured
REQ-DDB-PIPE-015measured
REQ-DDB-QUERY-001measuredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier
REQ-DDB-QUERY-006measuredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier
REQ-DDB-QUERY-010measuredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier
REQ-DDB-QUERY-011measured
REQ-DDB-QUERY-012measuredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-001measured
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-003measured
REQ-DDB-SCHEMA-004measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-006measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-009measured
REQ-DDB-SCHEMA-011measuredtest_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently → function_dossier → _dossier_conn → locks_held_for_rowids
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measured
REQ-DDB-SCHEMA-014measured
REQ-DDB-SCHEMA-015measured
Source · 58 lines
def test_a_body_read_after_the_file_moved_is_disclosed_not_returned_silently(
    tmp_path: Path,
) -> None:
    """THE DEFECT THIS REPRODUCES WAS FOUND BY USING THE TOOL, not by reading the code. A function_dossier
    reported `line_start: 896` and returned 55 lines of a DIFFERENT function; `line_start`,
    `line_end` and `total_lines` were all self-consistent, so nothing in the payload contradicted
    it, and the reader went and read the file instead — a miss the tool caused and then concealed.

    THE MECHANISM IS NOT STALENESS IN GENERAL. `body_excerpt` reads the LIVE working tree at the
    span the INDEX recorded. Same rowid, same identity, correct name, correct file — and text that
    has since moved. `body_excerpt`'s own docstring already called quoting another function's
    source "the worst possible version of that bug, because a body looks like proof", and guarded
    only the re-resolution route to it; this is the other route.

    BOTH DIRECTIONS ARE ASSERTED IN ONE TEST so they cannot drift apart. Before the edit the
    excerpt must report `anchor_mismatch is False` — a check that fires on an untouched tree is
    worse than no check — and after prepending enough lines to push a different function into the
    recorded span it must report True. The lines are still returned either way: withholding
    evidence is worse than labelling it.

    @brief A moved body is disclosed rather than passed off as the function's own.
    @version 1
    """
    root = tmp_path / "drift"
    (root / "src").mkdir(parents=True)
    source = root / "src" / "drift.c"
    source.write_text(DRIFT_SOURCE, encoding="utf-8")
    doxyfile = root / "Doxyfile"
    doxyfile.write_text(DOXYFILE, encoding="utf-8")
    db = tmp_path / "drift.db"

    build_index(output=db, repo_root=root, doxyfile=doxyfile)

    fresh = function_dossier(db, "drift_subject", repo_root=root)
    assert fresh is not None and fresh.body is not None, "the fixture must produce a body"
    assert fresh.body.anchor_mismatch is False, (
        f"the tree is untouched, so the excerpt is the function's own — a mismatch here means the "
        f"check fires on ordinary code: {fresh.body.lines}"
    )
    assert any("drift_subject" in line for line in fresh.body.lines), (
        "and the excerpt really is anchored at the signature, which is what makes the check work"
    )

    ## THE EDIT. Prepending nine lines pushes `drift_neighbour` into the span recorded for
    ## `drift_subject`, which is the shape measured in the wild rather than a truncation.
    source.write_text("/* nine\n * added\n * lines\n * of\n * new\n * leading\n * comment\n"
                      " * text\n */\n" + DRIFT_SOURCE, encoding="utf-8")  # fmt: skip

    moved = function_dossier(db, "drift_subject", repo_root=root)
    assert moved is not None and moved.body is not None
    assert moved.body.anchor_mismatch is True, (
        f"the recorded span no longer holds this function, and saying nothing is what sent a "
        f"reader to the file: {moved.body.lines}"
    )
    assert moved.body.lines, (
        "the lines must still be returned — withholding the evidence is worse than labelling it, "
        "and a reader may still recognise what they are looking at"
    )

1 more lines, not shown

Activity · 17 steps
lines 270–270root = tmp_path / "drift"lines 271–271(root / "src").mkdir(parents=True)lines 272–272source = root / "src" / "drift.c"lines 273–273source.write_text(DRIFT_SOURCE, encoding="utf-8")lines 274–274doxyfile = root / "Doxyfile"lines 275–275doxyfile.write_text(DOXYFILE, encoding="utf-8")lines 276–276db = tmp_path / "drift.db"lines 278–278build_index(output=db, repo_root=root, doxyfile=doxyfile)lines 280–280fresh = function_dossier(db, "drift_subject", repo_root=root)lines 281–281assert fresh is not None and fresh.body is not None, "the fixture must produce a body"lines 282–285assert fresh.body.anchor_mismatch is False, ( f"the tree is untouched, so the excerpt is the function's own — a mismatch here means the " f"check fires on ordinary code: {fresh.body.lines}" )lines 286–288assert any("drift_subject" in line for line in fresh.body.lines), ( "and the excerpt really is anchored at the signature, which is what makes the check work" )lines 292–293source.write_text("/* nine\n * added\n * lines\n * of\n * new\n * leading\n * comment\n" " * text\n */\n" + DRIFT_SOURCE, encoding="utf-8")lines 295–295moved = function_dossier(db, "drift_subject", repo_root=root)lines 296–296assert moved is not None and moved.body is not Nonelines 297–300assert moved.body.anchor_mismatch is True, ( f"the recorded span no longer holds this function, and saying nothing is what sent a " f"reader to the file: {moved.body.lines}" )lines 301–304assert moved.body.lines, ( "the lines must still be returned — withholding the evidence is worse than labelling it, " "and a reader may still recognise what they are looking at" )

test_a_dossier_reports_the_gates_covering_the_function

None test_gate_coverage_integration.test_a_dossier_reports_the_gates_covering_the_function(Path tmp_path)

Gate coverage survives a real build and keeps its polarity.

tests/integration/test_gate_coverage_integration.py:99

Show on the map →

Called by none

Calls _gated_by

Checks

  • assert fast_unplaceable == 0, ("every gate in this file was harvested with an extent, so an empty gate list here would " "mean ungated rather than unknown — the count is what separates those two answers" )
  • assert ("FIXTURE_FAST_PATH", KCONFIG_GATE_IFDEF) in fast, (f"the true branch must report the symbol as required: {sorted(fast)}" )
  • assert ("FIXTURE_FAST_PATH", KCONFIG_GATE_IFNDEF) not in fast, (f"and must not ALSO report the inverse — that is the node-extent bug: {sorted(fast)}" )
  • assert ("FIXTURE_FAST_PATH", KCONFIG_GATE_IFNDEF) in slow, (f"the else branch is present when the symbol is NOT set: {sorted(slow)}" )
  • assert ("FIXTURE_FAST_PATH", KCONFIG_GATE_IFDEF) not in slow, (f"reporting the else branch as gated ON the symbol inverts the variant: {sorted(slow)}" )
  • assert not always, (f"a function outside every conditional must report no preconditions: {sorted(always)}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-009measured
REQ-DDB-INDEX-001measured
REQ-DDB-INDEX-002measured
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measuredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-INDEX-005measured
REQ-DDB-INDEX-006measured
REQ-DDB-INDEX-007measured
REQ-DDB-INDEX-008measured
REQ-DDB-INDEX-009measured
REQ-DDB-INDEX-010measured
REQ-DDB-INDEX-011measured
REQ-DDB-MCP-001measured
REQ-DDB-MCP-004measured
REQ-DDB-PIPE-001measured
REQ-DDB-PIPE-003measuredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-004measured
REQ-DDB-PIPE-005measured
REQ-DDB-PIPE-006measured
REQ-DDB-PIPE-007measured
REQ-DDB-PIPE-008measured
REQ-DDB-PIPE-009measured
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measuredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012measuredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-013measured
REQ-DDB-PIPE-014measured
REQ-DDB-PIPE-015measured
REQ-DDB-QUERY-001measuredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier
REQ-DDB-QUERY-006measuredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier
REQ-DDB-QUERY-010measuredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier
REQ-DDB-QUERY-011measured
REQ-DDB-QUERY-012measuredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-001measured
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-003measured
REQ-DDB-SCHEMA-004measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-006measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-009measured
REQ-DDB-SCHEMA-011measuredtest_a_dossier_reports_the_gates_covering_the_function → _gated_by → function_dossier → _dossier_conn → locks_held_for_rowids
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measured
REQ-DDB-SCHEMA-014measured
REQ-DDB-SCHEMA-015measured
Source · 51 lines
def test_a_dossier_reports_the_gates_covering_the_function(tmp_path: Path) -> None:
    """ONE REAL BUILD, THREE FUNCTIONS, TWO-SIDED THROUGHOUT.

    `fixture_fast` must be reported as requiring the symbol and NOT as requiring its absence;
    `fixture_slow` the other way round; `fixture_always` as neither. A one-sided version of any
    of these passes against an implementation that attributes every gate in the file to every
    line — which is what storing the conditional's whole extent produces, and it is the natural
    thing to write.

    NOTE WHAT IS NOT ASSERTED: whether the symbol is actually DEFINED for this build. That is a
    different question (`preprocessor`/`predefined` answers it) and conflating them is how "the
    text is present" gets read as "the code is compiled in". This field says what the presence
    DEPENDS ON, which is the fact a grep cannot supply at any cost.

    @brief Gate coverage survives a real build and keeps its polarity.
    @version 1
    """
    root = tmp_path / "gated"
    (root / "src").mkdir(parents=True)
    (root / "src" / "fixture.c").write_text(SOURCE, encoding="utf-8")
    doxyfile = root / "Doxyfile"
    doxyfile.write_text(DOXYFILE, encoding="utf-8")
    db = tmp_path / "gates.db"

    build_index(output=db, repo_root=root, doxyfile=doxyfile)

    fast, fast_unplaceable = _gated_by(db, "fixture_fast")
    slow, _ = _gated_by(db, "fixture_slow")
    always, _ = _gated_by(db, "fixture_always")

    assert fast_unplaceable == 0, (
        "every gate in this file was harvested with an extent, so an empty gate list here would "
        "mean ungated rather than unknown — the count is what separates those two answers"
    )
    assert ("FIXTURE_FAST_PATH", KCONFIG_GATE_IFDEF) in fast, (
        f"the true branch must report the symbol as required: {sorted(fast)}"
    )
    assert ("FIXTURE_FAST_PATH", KCONFIG_GATE_IFNDEF) not in fast, (
        f"and must not ALSO report the inverse — that is the node-extent bug: {sorted(fast)}"
    )
    assert ("FIXTURE_FAST_PATH", KCONFIG_GATE_IFNDEF) in slow, (
        f"the else branch is present when the symbol is NOT set: {sorted(slow)}"
    )
    assert ("FIXTURE_FAST_PATH", KCONFIG_GATE_IFDEF) not in slow, (
        f"reporting the else branch as gated ON the symbol inverts the variant: {sorted(slow)}"
    )
    assert not always, (
        f"a function outside every conditional must report no preconditions: {sorted(always)}"
    )

Activity · 16 steps
lines 116–116root = tmp_path / "gated"lines 117–117(root / "src").mkdir(parents=True)lines 118–118(root / "src" / "fixture.c").write_text(SOURCE, encoding="utf-8")lines 119–119doxyfile = root / "Doxyfile"lines 120–120doxyfile.write_text(DOXYFILE, encoding="utf-8")lines 121–121db = tmp_path / "gates.db"lines 123–123build_index(output=db, repo_root=root, doxyfile=doxyfile)lines 125–125fast, fast_unplaceable = _gated_by(db, "fixture_fast")lines 126–126slow, _ = _gated_by(db, "fixture_slow")lines 127–127always, _ = _gated_by(db, "fixture_always")lines 129–132assert fast_unplaceable == 0, ( "every gate in this file was harvested with an extent, so an empty gate list here would " "mean ungated rather than unknown — the count is what separates those two answers" )lines 133–135assert ("FIXTURE_FAST_PATH", KCONFIG_GATE_IFDEF) in fast, ( f"the true branch must report the symbol as required: {sorted(fast)}" )lines 136–138assert ("FIXTURE_FAST_PATH", KCONFIG_GATE_IFNDEF) not in fast, ( f"and must not ALSO report the inverse — that is the node-extent bug: {sorted(fast)}" )lines 139–141assert ("FIXTURE_FAST_PATH", KCONFIG_GATE_IFNDEF) in slow, ( f"the else branch is present when the symbol is NOT set: {sorted(slow)}" )lines 142–144assert ("FIXTURE_FAST_PATH", KCONFIG_GATE_IFDEF) not in slow, ( f"reporting the else branch as gated ON the symbol inverts the variant: {sorted(slow)}" )lines 145–147assert not always, ( f"a function outside every conditional must report no preconditions: {sorted(always)}" )

test_a_gate_says_whether_this_build_satisfied_it

None test_gate_coverage_integration.test_a_gate_says_whether_this_build_satisfied_it(Path tmp_path)

One build distinguishes a satisfied gate from an unsatisfied one.

tests/integration/test_gate_coverage_integration.py:165

Checks

  • assert doss is not None, ("the function must be INDEXED even though the build does not satisfy its gates — that is " "gh#11's recovery, and it is what makes 'index the union, label the branches' possible " "without running the preprocessor twice" )
  • assert origins.get("FIXTURE_DECLARED") == GATE_ORIGIN_DECLARED, (f"the build declared this macro, so the gate must say so: {origins}" )
  • assert origins.get("FIXTURE_ABSENT") == GATE_ORIGIN_UNDECLARED, (f"the build did NOT declare this one, and that is the half that says the code is absent " f"from this variant: {origins}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-009measured
REQ-DDB-INDEX-001measured
REQ-DDB-INDEX-002measured
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measuredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier → _dossier_conn → symbol_provenance
REQ-DDB-INDEX-005measured
REQ-DDB-INDEX-006measured
REQ-DDB-INDEX-007measured
REQ-DDB-INDEX-008measured
REQ-DDB-INDEX-009measured
REQ-DDB-INDEX-010measured
REQ-DDB-INDEX-011measured
REQ-DDB-MCP-001measured
REQ-DDB-MCP-004measured
REQ-DDB-PIPE-001measured
REQ-DDB-PIPE-003measuredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-004measured
REQ-DDB-PIPE-005measured
REQ-DDB-PIPE-006measured
REQ-DDB-PIPE-007measured
REQ-DDB-PIPE-008measured
REQ-DDB-PIPE-009measured
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measuredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012measuredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-013measured
REQ-DDB-PIPE-014measured
REQ-DDB-PIPE-015measured
REQ-DDB-QUERY-001measuredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier → connect
REQ-DDB-QUERY-002measuredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier → _dossier_conn → unresolved_inbound_for_rowids
REQ-DDB-QUERY-003measuredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier → _dossier_conn → function_candidates
REQ-DDB-QUERY-004measuredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier
REQ-DDB-QUERY-006measuredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier → _dossier_conn → gates_covering
REQ-DDB-QUERY-009measuredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier
REQ-DDB-QUERY-010measuredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier
REQ-DDB-QUERY-011measured
REQ-DDB-QUERY-012measuredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier → _dossier_conn → _macro_dossier
REQ-DDB-QUERY-013inferredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier → _dossier_conn → config_defaults_conn
REQ-DDB-SCHEMA-001measured
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-003measured
REQ-DDB-SCHEMA-004measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-006measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-009measured
REQ-DDB-SCHEMA-011measuredtest_a_gate_says_whether_this_build_satisfied_it → function_dossier → _dossier_conn → locks_held_for_rowids
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measured
REQ-DDB-SCHEMA-014measured
REQ-DDB-SCHEMA-015measured
Source · 57 lines
def test_a_gate_says_whether_this_build_satisfied_it(tmp_path: Path) -> None:
    """PLAN ITEM 2.8, AND THE ANSWER TURNED OUT TO BE A COMPOSITION RATHER THAN A NEW LAYER. The
    item asked to make `--predefined` ADDITIVE — to LABEL what is on and off instead of deciding
    what is indexed — and left open "whether doxygen alone can do this or the tree-sitter path
    must supply the excluded branches". The tree-sitter path ALREADY supplies them: gh#11 recovers
    a function doxygen never emitted, precisely BECAUSE the preprocessor skipped it. So what was
    missing was never the rows; it was the label, and three fields on one row now carry it:

      * `macro` — which flag decides this code
      * `form`  — which way (`ifdef` present-when-set, `ifndef` present-when-unset)
      * `origin` — whether THIS BUILD's declared configuration supplies that macro

    That triple answers "is it compiled in, and under what flag" from a single row, which is what
    both graded questions ask and what `grep` cannot answer at any price.

    THE WIRING IS THE THING UNDER TEST, not the vocabulary. `origin` is computed from the
    `declared` set that `cli` passes as `preprocessor.macros`; if that argument were ever dropped
    or defaulted, every gate would come back `undeclared` and the field would still look
    plausible — a whole configuration reported as absent, confidently. This repo has shipped
    exactly that shape before (a check that could not read its input reported nothing, which
    looked like passing), so the control is that ONE BUILD produces BOTH labels: `FIXTURE_DECLARED`
    must read `declared` and `FIXTURE_ABSENT` `undeclared`. A single-label assertion passes
    against a hardcoded constant.

    @brief One build distinguishes a satisfied gate from an unsatisfied one.
    @version 1
    """
    root = tmp_path / "twoflag"
    (root / "src").mkdir(parents=True)
    (root / "src" / "twoflag.c").write_text(TWO_FLAG_SOURCE, encoding="utf-8")
    doxyfile = root / "Doxyfile"
    doxyfile.write_text(DOXYFILE, encoding="utf-8")
    db = tmp_path / "twoflag.db"

    build_index(
        output=db,
        repo_root=root,
        doxyfile=doxyfile,
        options={"predefined": ["FIXTURE_DECLARED"]},
    )

    doss = function_dossier(db, "fixture_two_flags")
    assert doss is not None, (
        "the function must be INDEXED even though the build does not satisfy its gates — that is "
        "gh#11's recovery, and it is what makes 'index the union, label the branches' possible "
        "without running the preprocessor twice"
    )
    origins = {gate.macro: gate.origin for gate in doss.gated_by}
    assert origins.get("FIXTURE_DECLARED") == GATE_ORIGIN_DECLARED, (
        f"the build declared this macro, so the gate must say so: {origins}"
    )
    assert origins.get("FIXTURE_ABSENT") == GATE_ORIGIN_UNDECLARED, (
        f"the build did NOT declare this one, and that is the half that says the code is absent "
        f"from this variant: {origins}"
    )

Activity · 12 steps
lines 192–192root = tmp_path / "twoflag"lines 193–193(root / "src").mkdir(parents=True)lines 194–194(root / "src" / "twoflag.c").write_text(TWO_FLAG_SOURCE, encoding="utf-8")lines 195–195doxyfile = root / "Doxyfile"lines 196–196doxyfile.write_text(DOXYFILE, encoding="utf-8")lines 197–197db = tmp_path / "twoflag.db"lines 199–204build_index( output=db, repo_root=root, doxyfile=doxyfile, options={"predefined": ["FIXTURE_DECLARED"]}, )lines 206–206doss = function_dossier(db, "fixture_two_flags")lines 207–211assert doss is not None, ( "the function must be INDEXED even though the build does not satisfy its gates — that is " "gh#11's recovery, and it is what makes 'index the union, label the branches' possible " "without running the preprocessor twice" )lines 212–212origins = {gate.macro: gate.origin for gate in doss.gated_by}lines 213–215assert origins.get("FIXTURE_DECLARED") == GATE_ORIGIN_DECLARED, ( f"the build declared this macro, so the gate must say so: {origins}" )lines 216–219assert origins.get("FIXTURE_ABSENT") == GATE_ORIGIN_UNDECLARED, ( f"the build did NOT declare this one, and that is the half that says the code is absent " f"from this variant: {origins}" )