test_binding_edges.py

tests/test_binding_edges.py

gh#1: a statically visible function-pointer BINDING must produce a call edge.

test_a_branch_resolved_binding_emits_only_the_live_branchs_edge

None test_binding_edges.test_a_branch_resolved_binding_emits_only_the_live_branchs_edge(Path tmp_path)

gh#35's whole point. With `THREADING_PTHREAD` declared, `critical` reaches `impl_pthread` and MUST NOT reach `impl_fail` — the dead branch's binding does not exist in this build, and before gh#35 both were emitted at 'resolved', so the graph asserted a call to a failure stub as fact.

tests/test_binding_edges.py:321

Show on the map →

Called by none

Calls _c_edges_with_config

Checks

  • assert ("critical", "impl_pthread", "fnptr", "resolved") in edges
  • assert not [e for e in edges if e[1] == "impl_fail"], "the dead branch must emit nothing"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_a_branch_resolved_binding_emits_only_the_live_branchs_edge → _c_edges_with_config → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_a_branch_resolved_binding_emits_only_the_live_branchs_edge → _c_edges_with_config → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_a_branch_resolved_binding_emits_only_the_live_branchs_edge → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_branch_resolved_binding_emits_only_the_live_branchs_edge → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_a_branch_resolved_binding_emits_only_the_live_branchs_edge → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_a_branch_resolved_binding_emits_only_the_live_branchs_edge → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_branch_resolved_binding_emits_only_the_live_branchs_edge → _c_edges_with_config → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 12 lines
def test_a_branch_resolved_binding_emits_only_the_live_branchs_edge(tmp_path: Path) -> None:
    """gh#35's whole point. With `THREADING_PTHREAD` declared, `critical` reaches
    `impl_pthread` and MUST NOT reach `impl_fail` — the dead branch's binding does
    not exist in this build, and before gh#35 both were emitted at 'resolved', so
    the graph asserted a call to a failure stub as fact."""
    edges = _c_edges_with_config(
        tmp_path, _C_TWO_BRANCHES, _TWO_BRANCH_FUNCS, ["THREADING_PTHREAD"]
    )
    assert ("critical", "impl_pthread", "fnptr", "resolved") in edges
    assert not [e for e in edges if e[1] == "impl_fail"], "the dead branch must emit nothing"

Activity · 3 steps
lines 326–328edges = _c_edges_with_config( tmp_path, _C_TWO_BRANCHES, _TWO_BRANCH_FUNCS, ["THREADING_PTHREAD"] )lines 329–329assert ("critical", "impl_pthread", "fnptr", "resolved") in edgeslines 330–330assert not [e for e in edges if e[1] == "impl_fail"], "the dead branch must emit nothing"

test_a_config_that_selects_no_branch_weakens_rather_than_erases

None test_binding_edges.test_a_config_that_selects_no_branch_weakens_rather_than_erases(Path tmp_path)

Branch selection is a SELECTION AMONG ALTERNATIVES, not an eraser. When a declared configuration eliminates EVERY binding of one global, nothing was selected — the configuration did not say which implementation is live, it said this variant binds none of them, while the index still carries every one of the bound functions. Emitting nothing there states a certainty the configuration never supplied, and it is the same fallback-to-False that `evaluate_condition` refuses one level down.

tests/test_binding_edges.py:456

Show on the map →

Called by none

Calls _c_edges_with_config

Checks

  • assert ("impl_pthread", "fuzzy") in through, "an eliminated alternative must survive as fuzzy"
  • assert ("impl_fail", "fuzzy") in through, "an eliminated alternative must survive as fuzzy"
  • assert not [c for c, conf in through if conf == "resolved"], ("a configuration that selected nothing must not grade anything 'resolved'" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_a_config_that_selects_no_branch_weakens_rather_than_erases → _c_edges_with_config → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_a_config_that_selects_no_branch_weakens_rather_than_erases → _c_edges_with_config → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_a_config_that_selects_no_branch_weakens_rather_than_erases → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_config_that_selects_no_branch_weakens_rather_than_erases → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_a_config_that_selects_no_branch_weakens_rather_than_erases → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_a_config_that_selects_no_branch_weakens_rather_than_erases → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_config_that_selects_no_branch_weakens_rather_than_erases → _c_edges_with_config → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 24 lines
def test_a_config_that_selects_no_branch_weakens_rather_than_erases(tmp_path: Path) -> None:
    """Branch selection is a SELECTION AMONG ALTERNATIVES, not an eraser. When a
    declared configuration eliminates EVERY binding of one global, nothing was
    selected — the configuration did not say which implementation is live, it said
    this variant binds none of them, while the index still carries every one of the
    bound functions. Emitting nothing there states a certainty the configuration
    never supplied, and it is the same fallback-to-False that
    `evaluate_condition` refuses one level down.

    So the global falls back to the undecided grading: every eliminated binding is
    restored at 'fuzzy', never 'resolved'. 'fuzzy' is skipped by both
    `mark_reachability` and the thread BFS, so nothing downstream reads a branch
    this build cannot compile as fact."""
    edges = _c_edges_with_config(
        tmp_path, _C_TWO_BRANCHES, _TWO_BRANCH_FUNCS, ["SOMETHING_UNRELATED"]
    )
    through = {(callee, conf) for _caller, callee, src, conf in edges if src == "fnptr"}
    assert ("impl_pthread", "fuzzy") in through, "an eliminated alternative must survive as fuzzy"
    assert ("impl_fail", "fuzzy") in through, "an eliminated alternative must survive as fuzzy"
    assert not [c for c, conf in through if conf == "resolved"], (
        "a configuration that selected nothing must not grade anything 'resolved'"
    )

Activity · 5 steps
lines 469–471edges = _c_edges_with_config( tmp_path, _C_TWO_BRANCHES, _TWO_BRANCH_FUNCS, ["SOMETHING_UNRELATED"] )lines 472–472through = {(callee, conf) for _caller, callee, src, conf in edges if src == "fnptr"}lines 473–473assert ("impl_pthread", "fuzzy") in through, "an eliminated alternative must survive as fuzzy"lines 474–474assert ("impl_fail", "fuzzy") in through, "an eliminated alternative must survive as fuzzy"lines 475–477assert not [c for c, conf in through if conf == "resolved"], ( "a configuration that selected nothing must not grade anything 'resolved'" )

test_a_guard_the_evaluator_cannot_read_weakens_rather_than_drops

None test_binding_edges.test_a_guard_the_evaluator_cannot_read_weakens_rather_than_drops(Path tmp_path)

The fail-closed direction, stated as an edge outcome rather than as a unit verdict. `#if _POSIX_VERSION >= 200809L` is real `#if` grammar and outside a `defined`-only evaluator, and the binding under it must be WEAKENED, never dropped — dropping would delete the live edge of a binding we simply could not read, which is strictly worse than the over-complete graph gh#35 fixes.

tests/test_binding_edges.py:388

Show on the map →

Called by none

Calls _c_edges_with_config

Checks

  • assert ("critical", "impl_lock", "fnptr", "fuzzy") in edges
  • assert ("critical", "impl_lock", "fnptr", "resolved") not in edges

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_a_guard_the_evaluator_cannot_read_weakens_rather_than_drops → _c_edges_with_config → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_a_guard_the_evaluator_cannot_read_weakens_rather_than_drops → _c_edges_with_config → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_a_guard_the_evaluator_cannot_read_weakens_rather_than_drops → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_guard_the_evaluator_cannot_read_weakens_rather_than_drops → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_a_guard_the_evaluator_cannot_read_weakens_rather_than_drops → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_a_guard_the_evaluator_cannot_read_weakens_rather_than_drops → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_a_guard_the_evaluator_cannot_read_weakens_rather_than_drops → _c_edges_with_config → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 20 lines
def test_a_guard_the_evaluator_cannot_read_weakens_rather_than_drops(tmp_path: Path) -> None:
    """The fail-closed direction, stated as an edge outcome rather than as a unit
    verdict. `#if _POSIX_VERSION >= 200809L` is real `#if` grammar and outside a
    `defined`-only evaluator, and the binding under it must be WEAKENED, never
    dropped — dropping would delete the live edge of a binding we simply could not
    read, which is strictly worse than the over-complete graph gh#35 fixes."""
    source = """\
int impl_lock(int *m) { return *m; }
#if _POSIX_VERSION >= 200809L
int (*mutex_lock)(int *) = impl_lock;
#endif
void critical(void) { mutex_lock(0); }
"""
    edges = _c_edges_with_config(
        tmp_path, source, [(1, "impl_lock", 1, 1), (2, "critical", 5, 5)], ["THREADING_PTHREAD"]
    )
    assert ("critical", "impl_lock", "fnptr", "fuzzy") in edges
    assert ("critical", "impl_lock", "fnptr", "resolved") not in edges

Activity · 4 steps
lines 394–400source = """\ int impl_lock(int *m) { return *m; } #if _POSIX_VERSION >= 200809L int (*mutex_lock)(int *) = impl_lock; #endif void critical(void) { mutex_lock(0); } """lines 401–403edges = _c_edges_with_config( tmp_path, source, [(1, "impl_lock", 1, 1), (2, "critical", 5, 5)], ["THREADING_PTHREAD"] )lines 404–404assert ("critical", "impl_lock", "fnptr", "fuzzy") in edgeslines 405–405assert ("critical", "impl_lock", "fnptr", "resolved") not in edges

test_an_else_arm_binding_is_selected_by_the_negated_guard

None test_binding_edges.test_an_else_arm_binding_is_selected_by_the_negated_guard(Path tmp_path)

The `#else` spelling of the same alternation. A node in the else arm is a DESCENDANT of the `preproc_else`, which is a child of the `#if` it negates, so the chain walk has to flip the polarity of the guard it then reaches. Without that, an else-arm binding reads as sharing the `#if`'s own condition and BOTH branches select together — which looks exactly like the bug being fixed.

tests/test_binding_edges.py:373

Show on the map →

Called by none

Calls _c_edges_with_config

Checks

  • assert ("critical", "impl_pthread", "fnptr", "resolved") in edges
  • assert not [e for e in edges if e[1] == "impl_fail"]
  • assert ("critical", "impl_fail", "fnptr", "resolved") in other
  • assert not [e for e in other if e[1] == "impl_pthread"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_an_else_arm_binding_is_selected_by_the_negated_guard → _c_edges_with_config → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_an_else_arm_binding_is_selected_by_the_negated_guard → _c_edges_with_config → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_an_else_arm_binding_is_selected_by_the_negated_guard → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_an_else_arm_binding_is_selected_by_the_negated_guard → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_an_else_arm_binding_is_selected_by_the_negated_guard → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_an_else_arm_binding_is_selected_by_the_negated_guard → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_an_else_arm_binding_is_selected_by_the_negated_guard → _c_edges_with_config → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 15 lines
def test_an_else_arm_binding_is_selected_by_the_negated_guard(tmp_path: Path) -> None:
    """The `#else` spelling of the same alternation. A node in the else arm is a
    DESCENDANT of the `preproc_else`, which is a child of the `#if` it negates, so the
    chain walk has to flip the polarity of the guard it then reaches. Without that, an
    else-arm binding reads as sharing the `#if`'s own condition and BOTH branches
    select together — which looks exactly like the bug being fixed."""
    edges = _c_edges_with_config(tmp_path, _C_IF_ELSE, _IF_ELSE_FUNCS, ["THREADING_PTHREAD"])
    assert ("critical", "impl_pthread", "fnptr", "resolved") in edges
    assert not [e for e in edges if e[1] == "impl_fail"]

    other = _c_edges_with_config(tmp_path / "b", _C_IF_ELSE, _IF_ELSE_FUNCS, ["SOMETHING_ELSE"])
    assert ("critical", "impl_fail", "fnptr", "resolved") in other
    assert not [e for e in other if e[1] == "impl_pthread"]

Activity · 6 steps
lines 379–379edges = _c_edges_with_config(tmp_path, _C_IF_ELSE, _IF_ELSE_FUNCS, ["THREADING_PTHREAD"])lines 380–380assert ("critical", "impl_pthread", "fnptr", "resolved") in edgeslines 381–381assert not [e for e in edges if e[1] == "impl_fail"]lines 383–383other = _c_edges_with_config(tmp_path / "b", _C_IF_ELSE, _IF_ELSE_FUNCS, ["SOMETHING_ELSE"])lines 384–384assert ("critical", "impl_fail", "fnptr", "resolved") in otherlines 385–385assert not [e for e in other if e[1] == "impl_pthread"]

test_an_unconditional_binding_is_unaffected_by_branch_selection

None test_binding_edges.test_an_unconditional_binding_is_unaffected_by_branch_selection(Path tmp_path)

THE REGRESSION CONTROL, and the one that matters most: gh#35 must change nothing for a binding that has no `#if` around it. A branch-free binding grades 'resolved' with no configuration declared, exactly as it did before — otherwise the fix silently weakens every fnptr edge in every repository that declares no preprocessor configuration, which is most of them.

tests/test_binding_edges.py:361

Show on the map →

Called by none

Calls _c_edges_with_config

Checks

  • assert ("critical", "impl_lock", "fnptr", "resolved") in edges

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004inferredtest_an_unconditional_binding_is_unaffected_by_branch_selection → _c_edges_with_config → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_an_unconditional_binding_is_unaffected_by_branch_selection → _c_edges_with_config → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_an_unconditional_binding_is_unaffected_by_branch_selection → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_an_unconditional_binding_is_unaffected_by_branch_selection → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_an_unconditional_binding_is_unaffected_by_branch_selection → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_an_unconditional_binding_is_unaffected_by_branch_selection → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_an_unconditional_binding_is_unaffected_by_branch_selection → _c_edges_with_config → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 12 lines
def test_an_unconditional_binding_is_unaffected_by_branch_selection(tmp_path: Path) -> None:
    """THE REGRESSION CONTROL, and the one that matters most: gh#35 must change
    nothing for a binding that has no `#if` around it. A branch-free binding grades
    'resolved' with no configuration declared, exactly as it did before — otherwise
    the fix silently weakens every fnptr edge in every repository that declares no
    preprocessor configuration, which is most of them."""
    edges = _c_edges_with_config(
        tmp_path, _C_FILE_SCOPE, [(1, "impl_lock", 1, 1), (2, "critical", 3, 3)], None
    )
    assert ("critical", "impl_lock", "fnptr", "resolved") in edges

Activity · 2 steps
lines 367–369edges = _c_edges_with_config( tmp_path, _C_FILE_SCOPE, [(1, "impl_lock", 1, 1), (2, "critical", 3, 3)], None )lines 370–370assert ("critical", "impl_lock", "fnptr", "resolved") in edges

test_an_undeclared_branch_is_not_resolved

None test_binding_edges.test_an_undeclared_branch_is_not_resolved(Path tmp_path)

gh#35 requirement 2. With NO configuration declared, the pipeline cannot know which branch is live, so both edges may still be emitted — but neither may claim 'resolved'. Both `mark_reachability` and the thread BFS traverse non-fuzzy edges, so a 'resolved' here propagates one of two mutually exclusive premises as fact.

tests/test_binding_edges.py:343

Show on the map →

Called by none

Calls _c_edges_with_config

Checks

  • assert ("impl_pthread", "fuzzy") in through
  • assert ("impl_fail", "fuzzy") in through
  • assert not [c for c, conf in through if conf == "resolved"], ("an undecidable branch must never grade 'resolved'" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_an_undeclared_branch_is_not_resolved → _c_edges_with_config → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_an_undeclared_branch_is_not_resolved → _c_edges_with_config → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_an_undeclared_branch_is_not_resolved → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_an_undeclared_branch_is_not_resolved → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_an_undeclared_branch_is_not_resolved → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_an_undeclared_branch_is_not_resolved → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_an_undeclared_branch_is_not_resolved → _c_edges_with_config → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 18 lines
def test_an_undeclared_branch_is_not_resolved(tmp_path: Path) -> None:
    """gh#35 requirement 2. With NO configuration declared, the pipeline cannot know
    which branch is live, so both edges may still be emitted — but neither may claim
    'resolved'. Both `mark_reachability` and the thread BFS traverse non-fuzzy edges,
    so a 'resolved' here propagates one of two mutually exclusive premises as fact.

    Both alternatives ARE still present: dropping them would trade an over-complete
    graph for an empty one, and the caller side of the dispatch was empty before
    gh#1 fixed exactly that."""
    edges = _c_edges_with_config(tmp_path, _C_TWO_BRANCHES, _TWO_BRANCH_FUNCS, None)
    through = {(callee, conf) for _caller, callee, src, conf in edges if src == "fnptr"}
    assert ("impl_pthread", "fuzzy") in through
    assert ("impl_fail", "fuzzy") in through
    assert not [c for c, conf in through if conf == "resolved"], (
        "an undecidable branch must never grade 'resolved'"
    )

Activity · 5 steps
lines 352–352edges = _c_edges_with_config(tmp_path, _C_TWO_BRANCHES, _TWO_BRANCH_FUNCS, None)lines 353–353through = {(callee, conf) for _caller, callee, src, conf in edges if src == "fnptr"}lines 354–354assert ("impl_pthread", "fuzzy") in throughlines 355–355assert ("impl_fail", "fuzzy") in throughlines 356–358assert not [c for c, conf in through if conf == "resolved"], ( "an undecidable branch must never grade 'resolved'" )

test_c_binding_edge_is_resolved_and_never_exact

None test_binding_edges.test_c_binding_edge_is_resolved_and_never_exact(Path tmp_path)

Same grading rule on the C half, which reaches `call_edges` by a different route (Layer 4's bind-then-visit-call-sites) and so could regress alone.

tests/test_binding_edges.py:236

Show on the map →

Called by none

Calls _c_edges, all

Checks

  • assert graded, "expected at least one fnptr edge to grade"
  • assert all(conf == "resolved" for conf in graded)
  • assert all(conf != "exact" for conf in graded)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004inferredtest_c_binding_edge_is_resolved_and_never_exact → _c_edges → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_c_binding_edge_is_resolved_and_never_exact → _c_edges → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_c_binding_edge_is_resolved_and_never_exact → _c_edges → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_c_binding_edge_is_resolved_and_never_exact → _c_edges → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_c_binding_edge_is_resolved_and_never_exact → _c_edges → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_c_binding_edge_is_resolved_and_never_exact → _c_edges → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_c_binding_edge_is_resolved_and_never_exact → all
Source · 14 lines
def test_c_binding_edge_is_resolved_and_never_exact(tmp_path: Path) -> None:
    """Same grading rule on the C half, which reaches `call_edges` by a different
    route (Layer 4's bind-then-visit-call-sites) and so could regress alone."""
    edges = _c_edges(
        tmp_path,
        _C_FILE_SCOPE,
        [(1, "impl_lock", 1, 1), (2, "critical", 3, 3)],
    )
    graded = [conf for _caller, _callee, src, conf in edges if src == "fnptr"]
    assert graded, "expected at least one fnptr edge to grade"
    assert all(conf == "resolved" for conf in graded)
    assert all(conf != "exact" for conf in graded)

Activity · 5 steps
lines 239–243edges = _c_edges( tmp_path, _C_FILE_SCOPE, [(1, "impl_lock", 1, 1), (2, "critical", 3, 3)], )lines 244–244graded = [conf for _caller, _callee, src, conf in edges if src == "fnptr"]lines 245–245assert graded, "expected at least one fnptr edge to grade"lines 246–246assert all(conf == "resolved" for conf in graded)lines 247–247assert all(conf != "exact" for conf in graded)

test_c_file_scope_pointer_binding_produces_a_call_edge

None test_binding_edges.test_c_file_scope_pointer_binding_produces_a_call_edge(Path tmp_path)

The Mbed-TLS instance. `int (*mutex_lock)(int *) = impl_lock;` is a `declaration`, so before gh#1 the binding was never harvested at all and `critical`'s indirect call resolved to nothing.

tests/test_binding_edges.py:127

Show on the map →

Called by none

Calls _c_edges

Checks

  • assert ("critical", "impl_lock", "fnptr", "resolved") in edges

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004inferredtest_c_file_scope_pointer_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_c_file_scope_pointer_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_c_file_scope_pointer_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_c_file_scope_pointer_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_c_file_scope_pointer_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_c_file_scope_pointer_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_c_file_scope_pointer_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 12 lines
def test_c_file_scope_pointer_binding_produces_a_call_edge(tmp_path: Path) -> None:
    """The Mbed-TLS instance. `int (*mutex_lock)(int *) = impl_lock;` is a
    `declaration`, so before gh#1 the binding was never harvested at all and
    `critical`'s indirect call resolved to nothing."""
    edges = _c_edges(
        tmp_path,
        _C_FILE_SCOPE,
        [(1, "impl_lock", 1, 1), (2, "critical", 3, 3)],
    )
    assert ("critical", "impl_lock", "fnptr", "resolved") in edges

Activity · 2 steps
lines 131–135edges = _c_edges( tmp_path, _C_FILE_SCOPE, [(1, "impl_lock", 1, 1), (2, "critical", 3, 3)], )lines 136–136assert ("critical", "impl_lock", "fnptr", "resolved") in edges

test_c_in_function_direct_binding_produces_a_call_edge

None test_binding_edges.test_c_in_function_direct_binding_produces_a_call_edge(Path tmp_path)

The half that WAS harvested and then dropped by the fold: an assignment whose RHS names a function rather than one of `wire`'s own parameters.

tests/test_binding_edges.py:139

Show on the map →

Called by none

Calls _c_edges

Checks

  • assert ("critical", "impl_lock", "fnptr", "resolved") in edges

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004inferredtest_c_in_function_direct_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_c_in_function_direct_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_c_in_function_direct_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_c_in_function_direct_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_c_in_function_direct_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_c_in_function_direct_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_c_in_function_direct_binding_produces_a_call_edge → _c_edges → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 11 lines
def test_c_in_function_direct_binding_produces_a_call_edge(tmp_path: Path) -> None:
    """The half that WAS harvested and then dropped by the fold: an assignment
    whose RHS names a function rather than one of `wire`'s own parameters."""
    edges = _c_edges(
        tmp_path,
        _C_IN_FUNCTION,
        [(1, "impl_lock", 1, 1), (2, "wire", 3, 3), (3, "critical", 4, 4)],
    )
    assert ("critical", "impl_lock", "fnptr", "resolved") in edges

Activity · 2 steps
lines 142–146edges = _c_edges( tmp_path, _C_IN_FUNCTION, [(1, "impl_lock", 1, 1), (2, "wire", 3, 3), (3, "critical", 4, 4)], )lines 147–147assert ("critical", "impl_lock", "fnptr", "resolved") in edges

test_c_scalar_initialiser_does_not_fabricate_an_edge

None test_binding_edges.test_c_scalar_initialiser_does_not_fabricate_an_edge(Path tmp_path)

The fail-closed control for harvesting EVERY `init_declarator` rather than only function-pointer ones. `int not_a_pointer = impl_lock;` is harvested, but nothing calls `not_a_pointer(...)`, so no edge may be written. This is what makes the deliberately type-blind harvest safe.

tests/test_binding_edges.py:150

Show on the map →

Called by none

Calls _c_edges

Checks

  • assert edges == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004inferredtest_c_scalar_initialiser_does_not_fabricate_an_edge → _c_edges → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_c_scalar_initialiser_does_not_fabricate_an_edge → _c_edges → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_c_scalar_initialiser_does_not_fabricate_an_edge → _c_edges → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_c_scalar_initialiser_does_not_fabricate_an_edge → _c_edges → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_c_scalar_initialiser_does_not_fabricate_an_edge → _c_edges → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_c_scalar_initialiser_does_not_fabricate_an_edge → _c_edges → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_c_scalar_initialiser_does_not_fabricate_an_edge → _c_edges → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 13 lines
def test_c_scalar_initialiser_does_not_fabricate_an_edge(tmp_path: Path) -> None:
    """The fail-closed control for harvesting EVERY `init_declarator` rather than
    only function-pointer ones. `int not_a_pointer = impl_lock;` is harvested, but
    nothing calls `not_a_pointer(...)`, so no edge may be written. This is what
    makes the deliberately type-blind harvest safe."""
    edges = _c_edges(
        tmp_path,
        _C_SCALAR_CONTROL,
        [(1, "impl_lock", 1, 1), (2, "critical", 3, 3)],
    )
    assert edges == []

Activity · 2 steps
lines 155–159edges = _c_edges( tmp_path, _C_SCALAR_CONTROL, [(1, "impl_lock", 1, 1), (2, "critical", 3, 3)], )lines 160–160assert edges == []

test_direct_binding_to_a_non_function_still_records_the_terminus

None test_binding_edges.test_direct_binding_to_a_non_function_still_records_the_terminus(Path tmp_path)

The guard that a mutation control proved NOTHING else pins: the whole suite passed with the `_is_known_function` filter deleted from the emission, because an unresolvable name produces no edge either way. What it silently destroys is the TERMINUS.

tests/test_binding_edges.py:163

Checks

  • assert rows == [(2, "my_cb", "unresolved_callback")]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004inferredtest_direct_binding_to_a_non_function_still_records_the_terminus → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_direct_binding_to_a_non_function_still_records_the_terminus → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_direct_binding_to_a_non_function_still_records_the_terminus → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_direct_binding_to_a_non_function_still_records_the_terminus → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_direct_binding_to_a_non_function_still_records_the_terminus → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_direct_binding_to_a_non_function_still_records_the_terminus → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_direct_binding_to_a_non_function_still_records_the_terminus → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 36 lines
def test_direct_binding_to_a_non_function_still_records_the_terminus(tmp_path: Path) -> None:
    """The guard that a mutation control proved NOTHING else pins: the whole suite
    passed with the `_is_known_function` filter deleted from the emission, because
    an unresolvable name produces no edge either way. What it silently destroys is
    the TERMINUS.

    `my_cb` is registered from `register_cb`'s parameter and that chain forwards out
    of repo, so it must be recorded as an `unresolved_callback` boundary. It is ALSO
    assigned `some_extern_thing`, which no indexed function bears. Unfiltered, that
    junk name makes `bound` non-empty, the `if not bound` branch is skipped, and the
    boundary row vanishes — a layer losing data while every test stays green."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text(_C_TERMINUS_WITH_JUNK_BINDING)
    db = _make_db(
        tmp_path,
        [
            (1, "register_cb", 2, 5),
            (2, "invoke_cb", 6, 8),
            (3, "app_layer", 9, 11),
            (4, "reset_cb", 12, 14),
        ],
        call_edges=[],
    )
    import_callback_registration_edges(db, tmp_path)
    conn = sqlite3.connect(str(db))
    rows = conn.execute(
        "SELECT memberdef_rowid, global_name, kind FROM external_boundaries",
    ).fetchall()
    conn.close()
    assert rows == [(2, "my_cb", "unresolved_callback")]


# ─── instance 2: Python ─────────────────────────────────────────────────────

Activity · 9 steps
lines 174–174src = tmp_path / "src"lines 175–175src.mkdir()lines 176–176(src / "foo.c").write_text(_C_TERMINUS_WITH_JUNK_BINDING)lines 177–186db = _make_db( tmp_path, [ (1, "register_cb", 2, 5), (2, "invoke_cb", 6, 8), (3, "app_layer", 9, 11), (4, "reset_cb", 12, 14), ], call_edges=[], )lines 187–187import_callback_registration_edges(db, tmp_path)lines 188–188conn = sqlite3.connect(str(db))lines 189–191rows = conn.execute( "SELECT memberdef_rowid, global_name, kind FROM external_boundaries", ).fetchall()lines 192–192conn.close()lines 193–193assert rows == [(2, "my_cb", "unresolved_callback")]

test_ifdef_and_ifndef_are_normalised_to_opposite_polarities

None test_binding_edges.test_ifdef_and_ifndef_are_normalised_to_opposite_polarities(Path tmp_path)

`#ifdef X` and `#ifndef X` are the SAME tree-sitter node type (`preproc_ifdef`) and differ only in the directive token, so the polarity has to be read off that token. Getting it backwards selects the wrong implementation while still emitting exactly one confident edge — the most dangerous possible outcome, because it looks like the fix working.

tests/test_binding_edges.py:408

Show on the map →

Called by none

Calls _c_edges_with_config

Checks

  • assert ("critical", "impl_a", "fnptr", "resolved") in on
  • assert not [e for e in on if e[1] == "impl_b"], "#ifndef PICK_A is dead when PICK_A is set"
  • assert ("critical", "impl_b", "fnptr", "resolved") in off
  • assert not [e for e in off if e[1] == "impl_a"], "#ifdef PICK_A is dead when PICK_A is unset"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_ifdef_and_ifndef_are_normalised_to_opposite_polarities → _c_edges_with_config → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_ifdef_and_ifndef_are_normalised_to_opposite_polarities → _c_edges_with_config → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_ifdef_and_ifndef_are_normalised_to_opposite_polarities → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_ifdef_and_ifndef_are_normalised_to_opposite_polarities → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_ifdef_and_ifndef_are_normalised_to_opposite_polarities → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_ifdef_and_ifndef_are_normalised_to_opposite_polarities → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_ifdef_and_ifndef_are_normalised_to_opposite_polarities → _c_edges_with_config → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 48 lines
def test_ifdef_and_ifndef_are_normalised_to_opposite_polarities(tmp_path: Path) -> None:
    """`#ifdef X` and `#ifndef X` are the SAME tree-sitter node type
    (`preproc_ifdef`) and differ only in the directive token, so the polarity has to
    be read off that token. Getting it backwards selects the wrong implementation
    while still emitting exactly one confident edge — the most dangerous possible
    outcome, because it looks like the fix working."""
    source = """\
int impl_a(int *m) { return *m; }
int impl_b(int *m) { return -1; }
#ifdef PICK_A
int (*mutex_lock)(int *) = impl_a;
#endif
#ifndef PICK_A
int (*mutex_lock)(int *) = impl_b;
#endif
void critical(void) { mutex_lock(0); }
"""
    funcs = [(1, "impl_a", 1, 1), (2, "impl_b", 2, 2), (3, "critical", 9, 9)]
    on = _c_edges_with_config(tmp_path / "on", source, funcs, ["PICK_A"])
    assert ("critical", "impl_a", "fnptr", "resolved") in on
    assert not [e for e in on if e[1] == "impl_b"], "#ifndef PICK_A is dead when PICK_A is set"

    off = _c_edges_with_config(tmp_path / "off", source, funcs, ["OTHER"])
    assert ("critical", "impl_b", "fnptr", "resolved") in off
    assert not [e for e in off if e[1] == "impl_a"], "#ifdef PICK_A is dead when PICK_A is unset"


# ─── gh#35 follow-up: selection must SELECT, never erase ─────────────────────
#
# The case a declared configuration reaches on a REAL target and no synthetic
# fixture reached before: the config names neither alternative, so every one of a
# global's bindings grades dead and the layer empties for that global.
#
# Measured on Mbed-TLS v3.6.7 with the 142 macros harvested from its own
# `include/mbedtls/mbedtls_config.h` — the configuration gh#17 exists to read.
# That header ships `MBEDTLS_THREADING_C` COMMENTED OUT, so neither
# `MBEDTLS_THREADING_PTHREAD` nor `MBEDTLS_THREADING_ALT` is declared and all 8
# bindings of the four `mbedtls_mutex_*` pointers were dropped:
#
#   no PREDEFINED           157 fnptr rows,   0 external boundaries
#   142-macro PREDEFINED      0 fnptr rows,   3 external boundaries
#
# 38 of those rows were the callers of `threading_mutex_lock_pthread`, which the
# gh#11 AST recovery still indexes as a function in the same build. So one build
# said "this code exists, reason about it" and "nothing can reach it" about the
# same `#if`.

Activity · 8 steps
lines 414–424source = """\ int impl_a(int *m) { return *m; } int impl_b(int *m) { return -1; } #ifdef PICK_A int (*mutex_lock)(int *) = impl_a; #endif #ifndef PICK_A int (*mutex_lock)(int *) = impl_b; #endif void critical(void) { mutex_lock(0); } """lines 425–425funcs = [(1, "impl_a", 1, 1), (2, "impl_b", 2, 2), (3, "critical", 9, 9)]lines 426–426on = _c_edges_with_config(tmp_path / "on", source, funcs, ["PICK_A"])lines 427–427assert ("critical", "impl_a", "fnptr", "resolved") in onlines 428–428assert not [e for e in on if e[1] == "impl_b"], "#ifndef PICK_A is dead when PICK_A is set"lines 430–430off = _c_edges_with_config(tmp_path / "off", source, funcs, ["OTHER"])lines 431–431assert ("critical", "impl_b", "fnptr", "resolved") in offlines 432–432assert not [e for e in off if e[1] == "impl_a"], "#ifdef PICK_A is dead when PICK_A is unset"

test_python_binding_edge_is_resolved_and_never_exact

None test_binding_edges.test_python_binding_edge_is_resolved_and_never_exact(Path tmp_path)

The test a future refactor will silently break. 'exact' is reserved for an edge doxygen itself observed; a binding is a static reference to an INDIRECT call, and both `mark_reachability` and the thread BFS traverse non-fuzzy edges, so calling it 'exact' would propagate a weaker premise as fact.

tests/test_binding_edges.py:222

Show on the map →

Called by none

Calls _binding_edges, _make_py_db, all, import_ast_call_edges

Checks

  • assert graded, "expected at least one binding edge to grade"
  • assert all(conf == "resolved" for _callee, conf in graded)
  • assert all(conf != "exact" for _callee, conf in graded)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_python_binding_edge_is_resolved_and_never_exact → import_ast_call_edges → run_harvest
REQ-DDB-PIPE-011measuredtest_python_binding_edge_is_resolved_and_never_exact → _make_py_db → _parse → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_python_binding_edge_is_resolved_and_never_exact → _make_py_db → _parse → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-WIKI-054inferredtest_python_binding_edge_is_resolved_and_never_exact → all
Source · 14 lines
def test_python_binding_edge_is_resolved_and_never_exact(tmp_path: Path) -> None:
    """The test a future refactor will silently break. 'exact' is reserved for an
    edge doxygen itself observed; a binding is a static reference to an INDIRECT
    call, and both `mark_reachability` and the thread BFS traverse non-fuzzy
    edges, so calling it 'exact' would propagate a weaker premise as fact."""
    (tmp_path / "bench.py").write_text(_PY_ARGPARSE)
    db = _make_py_db(tmp_path, root=tmp_path, rel="bench.py")
    import_ast_call_edges(db, tmp_path)
    graded = [(callee, conf) for _c, callee, src, conf in _binding_edges(db) if src == "binding"]
    assert graded, "expected at least one binding edge to grade"
    assert all(conf == "resolved" for _callee, conf in graded)
    assert all(conf != "exact" for _callee, conf in graded)

Activity · 7 steps
lines 227–227(tmp_path / "bench.py").write_text(_PY_ARGPARSE)lines 228–228db = _make_py_db(tmp_path, root=tmp_path, rel="bench.py")lines 229–229import_ast_call_edges(db, tmp_path)lines 230–230graded = [(callee, conf) for _c, callee, src, conf in _binding_edges(db) if src == "binding"]lines 231–231assert graded, "expected at least one binding edge to grade"lines 232–232assert all(conf == "resolved" for _callee, conf in graded)lines 233–233assert all(conf != "exact" for _callee, conf in graded)

test_python_keyword_argument_binding_is_harvested

None test_binding_edges.test_python_keyword_argument_binding_is_harvested(Path tmp_path)

`rubric.set_defaults(func=cmd_rubric)` must yield a harvested site for `cmd_rubric` tagged 'binding'. Before gh#1 the walk recorded only the `set_defaults` / `add_parser` callees and the bound reference vanished.

tests/test_binding_edges.py:199

Show on the map →

Called by none

Calls _ast_harvest_calls

Checks

  • assert ("cmd_rubric", "binding") in sites

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_python_keyword_argument_binding_is_harvested → _ast_harvest_calls → is_python_tree
REQ-DDB-PIPE-011measured
Source · 10 lines
def test_python_keyword_argument_binding_is_harvested(tmp_path: Path) -> None:
    """`rubric.set_defaults(func=cmd_rubric)` must yield a harvested site for
    `cmd_rubric` tagged 'binding'. Before gh#1 the walk recorded only the
    `set_defaults` / `add_parser` callees and the bound reference vanished."""
    (tmp_path / "bench.py").write_text(_PY_ARGPARSE)
    tree, data = _parse(tmp_path, "bench.py")
    sites = {(s[0], s[2]) for s in _ast_harvest_calls(tree, data)}
    assert ("cmd_rubric", "binding") in sites

Activity · 4 steps
lines 203–203(tmp_path / "bench.py").write_text(_PY_ARGPARSE)lines 204–204tree, data = _parse(tmp_path, "bench.py")lines 205–205sites = {(s[0], s[2]) for s in _ast_harvest_calls(tree, data)}lines 206–206assert ("cmd_rubric", "binding") in sites

test_python_keyword_argument_binding_lands_in_db

None test_binding_edges.test_python_keyword_argument_binding_lands_in_db(Path tmp_path)

End-to-end, because the harvest alone proves nothing a consumer can read: `build_parser` must become a CALLER of `cmd_rubric` in `call_edges`.

tests/test_binding_edges.py:209

Show on the map →

Called by none

Calls _binding_edges, _make_py_db, import_ast_call_edges

Checks

  • assert ("build_parser", "cmd_rubric", "binding", "resolved") in edges

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_python_keyword_argument_binding_lands_in_db → import_ast_call_edges → run_harvest
REQ-DDB-PIPE-011measuredtest_python_keyword_argument_binding_lands_in_db → _make_py_db → _parse → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_python_keyword_argument_binding_lands_in_db → _make_py_db → _parse → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-WIKI-054inferredtest_python_keyword_argument_binding_lands_in_db → import_ast_call_edges → _fold_all_files → _fold_call_payload → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 13 lines
def test_python_keyword_argument_binding_lands_in_db(tmp_path: Path) -> None:
    """End-to-end, because the harvest alone proves nothing a consumer can read:
    `build_parser` must become a CALLER of `cmd_rubric` in `call_edges`."""
    (tmp_path / "bench.py").write_text(_PY_ARGPARSE)
    db = _make_py_db(tmp_path, root=tmp_path, rel="bench.py")
    import_ast_call_edges(db, tmp_path)
    edges = _binding_edges(db)
    assert ("build_parser", "cmd_rubric", "binding", "resolved") in edges


# ─── grading ────────────────────────────────────────────────────────────────

Activity · 5 steps
lines 212–212(tmp_path / "bench.py").write_text(_PY_ARGPARSE)lines 213–213db = _make_py_db(tmp_path, root=tmp_path, rel="bench.py")lines 214–214import_ast_call_edges(db, tmp_path)lines 215–215edges = _binding_edges(db)lines 216–216assert ("build_parser", "cmd_rubric", "binding", "resolved") in edges

test_the_fallback_does_not_cost_the_out_of_repo_terminus

None test_binding_edges.test_the_fallback_does_not_cost_the_out_of_repo_terminus(Path tmp_path)

The regression the fix could most easily cause, and the reason the fallback is applied AFTER the terminus is recorded rather than instead of it.

tests/test_binding_edges.py:529

Show on the map →

Called by none

Calls _binding_edges, import_callback_registration_edges

Checks

  • assert ("mutex_lock",) in boundaries, ("the forwarded-parameter registration still dead-ends out of repo" )
  • assert ("impl_pthread", "fuzzy") in through
  • assert ("impl_fail", "fuzzy") in through

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_the_fallback_does_not_cost_the_out_of_repo_terminus → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_the_fallback_does_not_cost_the_out_of_repo_terminus → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_the_fallback_does_not_cost_the_out_of_repo_terminus → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_the_fallback_does_not_cost_the_out_of_repo_terminus → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_the_fallback_does_not_cost_the_out_of_repo_terminus → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_the_fallback_does_not_cost_the_out_of_repo_terminus → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_the_fallback_does_not_cost_the_out_of_repo_terminus → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 30 lines
def test_the_fallback_does_not_cost_the_out_of_repo_terminus(tmp_path: Path) -> None:
    """The regression the fix could most easily cause, and the reason the fallback
    is applied AFTER the terminus is recorded rather than instead of it.

    On the real target the same three globals are BOTH bound behind a dead `#if`
    AND settable from outside through a forwarding registration. Both facts are
    true at once and a reader wants both: the terminus says an application supplies
    the implementation, the fuzzy edges say which implementations ship in this
    repository. A fallback that made `bound` non-empty BEFORE the `if not bound`
    test would silently delete the terminus — the layer would look repaired while
    quietly losing the 3 boundary rows the erasing build did produce."""
    src = tmp_path / "src"
    src.mkdir(parents=True, exist_ok=True)
    (src / "foo.c").write_text(_C_ALL_DEAD_WITH_REGISTRATION)
    db = _make_db(tmp_path, _ALL_DEAD_FUNCS, call_edges=[])
    config = PreprocessorConfig(macros=('"SOMETHING_UNRELATED"',), source=SOURCE_DECLARED)
    import_callback_registration_edges(db, tmp_path, None, config)

    conn = sqlite3.connect(str(db))
    boundaries = conn.execute("SELECT global_name FROM external_boundaries").fetchall()
    conn.close()
    assert ("mutex_lock",) in boundaries, (
        "the forwarded-parameter registration still dead-ends out of repo"
    )

    through = {
        (callee, conf) for _caller, callee, src_, conf in _binding_edges(db) if src_ == "fnptr"
    }
    assert ("impl_pthread", "fuzzy") in through
    assert ("impl_fail", "fuzzy") in through

1 more lines, not shown

Activity · 13 steps
lines 540–540src = tmp_path / "src"lines 541–541src.mkdir(parents=True, exist_ok=True)lines 542–542(src / "foo.c").write_text(_C_ALL_DEAD_WITH_REGISTRATION)lines 543–543db = _make_db(tmp_path, _ALL_DEAD_FUNCS, call_edges=[])lines 544–544config = PreprocessorConfig(macros=('"SOMETHING_UNRELATED"',), source=SOURCE_DECLARED)lines 545–545import_callback_registration_edges(db, tmp_path, None, config)lines 547–547conn = sqlite3.connect(str(db))lines 548–548boundaries = conn.execute("SELECT global_name FROM external_boundaries").fetchall()lines 549–549conn.close()lines 550–552assert ("mutex_lock",) in boundaries, ( "the forwarded-parameter registration still dead-ends out of repo" )lines 554–556through = { (callee, conf) for _caller, callee, src_, conf in _binding_edges(db) if src_ == "fnptr" }lines 557–557assert ("impl_pthread", "fuzzy") in throughlines 558–558assert ("impl_fail", "fuzzy") in through

test_the_fallback_never_resurrects_a_losing_alternative

None test_binding_edges.test_the_fallback_never_resurrects_a_losing_alternative(Path tmp_path)

The negative half, and the one that would let the fix ship broken. The fallback must fire ONLY when selection left the global with nothing. A version keyed on "any binding was dropped" rather than on "every binding was dropped" passes the test above and silently undoes gh#35's whole result — `impl_fail` would come back at 'fuzzy' in the configuration that positively selects `impl_pthread`, which is the failure stub gh#35 exists to keep out of the graph.

tests/test_binding_edges.py:480

Show on the map →

Called by none

Calls _c_edges_with_config

Checks

  • assert ("critical", "impl_pthread", "fnptr", "resolved") in edges
  • assert not [e for e in edges if e[1] == "impl_fail"], ("a live alternative exists, so the dead one must still emit nothing — at any confidence" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_the_fallback_never_resurrects_a_losing_alternative → _c_edges_with_config → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_the_fallback_never_resurrects_a_losing_alternative → _c_edges_with_config → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_the_fallback_never_resurrects_a_losing_alternative → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_the_fallback_never_resurrects_a_losing_alternative → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_the_fallback_never_resurrects_a_losing_alternative → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_the_fallback_never_resurrects_a_losing_alternative → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_the_fallback_never_resurrects_a_losing_alternative → _c_edges_with_config → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 21 lines
def test_the_fallback_never_resurrects_a_losing_alternative(tmp_path: Path) -> None:
    """The negative half, and the one that would let the fix ship broken. The
    fallback must fire ONLY when selection left the global with nothing. A version
    keyed on "any binding was dropped" rather than on "every binding was dropped"
    passes the test above and silently undoes gh#35's whole result — `impl_fail`
    would come back at 'fuzzy' in the configuration that positively selects
    `impl_pthread`, which is the failure stub gh#35 exists to keep out of the
    graph.

    Written as its own test rather than trusted to the gh#35 tests above because
    those assert on `impl_fail` at 'resolved'; a resurrected FUZZY row would pass
    every one of them."""
    edges = _c_edges_with_config(
        tmp_path, _C_TWO_BRANCHES, _TWO_BRANCH_FUNCS, ["THREADING_PTHREAD"]
    )
    assert ("critical", "impl_pthread", "fnptr", "resolved") in edges
    assert not [e for e in edges if e[1] == "impl_fail"], (
        "a live alternative exists, so the dead one must still emit nothing — at any confidence"
    )

Activity · 3 steps
lines 492–494edges = _c_edges_with_config( tmp_path, _C_TWO_BRANCHES, _TWO_BRANCH_FUNCS, ["THREADING_PTHREAD"] )lines 495–495assert ("critical", "impl_pthread", "fnptr", "resolved") in edgeslines 496–498assert not [e for e in edges if e[1] == "impl_fail"], ( "a live alternative exists, so the dead one must still emit nothing — at any confidence" )

test_the_other_configuration_selects_the_other_branch

None test_binding_edges.test_the_other_configuration_selects_the_other_branch(Path tmp_path)

The control that shows the selection is READING the configuration rather than preferring the first binding it folded. Same source, other macro, opposite answer — and this is the direction that catches a rule accidentally hardcoded to whichever branch appears first in the file.

tests/test_binding_edges.py:333

Show on the map →

Called by none

Calls _c_edges_with_config

Checks

  • assert ("critical", "impl_fail", "fnptr", "resolved") in edges
  • assert not [e for e in edges if e[1] == "impl_pthread"], "the dead branch must emit nothing"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_the_other_configuration_selects_the_other_branch → _c_edges_with_config → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_the_other_configuration_selects_the_other_branch → _c_edges_with_config → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_the_other_configuration_selects_the_other_branch → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_the_other_configuration_selects_the_other_branch → _c_edges_with_config → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-003measuredtest_the_other_configuration_selects_the_other_branch → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-007measuredtest_the_other_configuration_selects_the_other_branch → _c_edges_with_config → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_the_other_configuration_selects_the_other_branch → _c_edges_with_config → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 10 lines
def test_the_other_configuration_selects_the_other_branch(tmp_path: Path) -> None:
    """The control that shows the selection is READING the configuration rather
    than preferring the first binding it folded. Same source, other macro, opposite
    answer — and this is the direction that catches a rule accidentally hardcoded
    to whichever branch appears first in the file."""
    edges = _c_edges_with_config(tmp_path, _C_TWO_BRANCHES, _TWO_BRANCH_FUNCS, ["THREADING_ALT"])
    assert ("critical", "impl_fail", "fnptr", "resolved") in edges
    assert not [e for e in edges if e[1] == "impl_pthread"], "the dead branch must emit nothing"

Activity · 3 steps
lines 338–338edges = _c_edges_with_config(tmp_path, _C_TWO_BRANCHES, _TWO_BRANCH_FUNCS, ["THREADING_ALT"])lines 339–339assert ("critical", "impl_fail", "fnptr", "resolved") in edgeslines 340–340assert not [e for e in edges if e[1] == "impl_pthread"], "the dead branch must emit nothing"