test_kconfig.py

tests/test_kconfig.py

gh#18 — the Kconfig configuration space, its help text, and its gating sites.

test_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared

None test_kconfig.test_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared(Path repo, Path tmp_path)

`CONFIG_X` is Kconfig's whatever else a target declares — the prefix is a universal convention, not a per-repo statement. Reading it the other way would relabel a Zephyr tree the moment it also shipped a config header.

tests/test_kconfig.py:561

Show on the map →

Called by none

Calls _db_with_paths, import_kconfig_gates, kconfig_space

Checks

  • assert origin["WIDGET_MOTOR_BETA"] == GATE_ORIGIN_KCONFIG

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → kconfig_space
REQ-DDB-QUERY-013inferredtest_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → import_kconfig_gates → ensure_kconfig_gates_table
Source · 15 lines
def test_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared(
    repo: Path, tmp_path: Path
) -> None:
    """`CONFIG_X` is Kconfig's whatever else a target declares — the prefix is a universal
    convention, not a per-repo statement. Reading it the other way would relabel a Zephyr
    tree the moment it also shipped a config header.
    """
    db = tmp_path / "clew.db"
    _db_with_paths(db, ("src/motor.c",))
    import_kconfig_gates(db, repo, declared=["CONFIG_WIDGET_MOTOR_BETA"])

    origin = {g.symbol: g.origin for g in kconfig_space(db).gates}
    assert origin["WIDGET_MOTOR_BETA"] == GATE_ORIGIN_KCONFIG

Activity · 5 steps
lines 568–568db = tmp_path / "clew.db"lines 569–569_db_with_paths(db, ("src/motor.c",))lines 570–570import_kconfig_gates(db, repo, declared=["CONFIG_WIDGET_MOTOR_BETA"])lines 572–572origin = {g.symbol: g.origin for g in kconfig_space(db).gates}lines 573–573assert origin["WIDGET_MOTOR_BETA"] == GATE_ORIGIN_KCONFIG

test_a_config_symbol_does_not_outrank_a_function_it_gates

None test_kconfig.test_a_config_symbol_does_not_outrank_a_function_it_gates(Path tmp_path)

THE COST OF THE NEW CORPUS, bounded. A gating symbol habitually shares every token with the function it gates, and the function is the row a caller can read a body for. The config tier breaks a TIE only, so a query that spells neither name exactly must still put the function first — otherwise adding the corpus degrades every existing query, which is how the neighbour-cap experiment cost 48% in tokens.

tests/test_kconfig.py:665

Show on the map →

Called by none

Calls _add_functions, _no_kconfig_repo, import_kconfig_gates

Checks

  • assert "function" in kinds, "the fixture's functions must still be findable"
  • assert CONFIG_SYMBOL_KIND in kinds, "and a gating symbol must be in the same reply"
  • assert kinds.index("function") < kinds.index(CONFIG_SYMBOL_KIND)
  • assert exact[0].kind == CONFIG_SYMBOL_KIND

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_a_config_symbol_does_not_outrank_a_function_it_gates → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-INDEX-004measured
REQ-DDB-PIPE-003measuredtest_a_config_symbol_does_not_outrank_a_function_it_gates → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_a_config_symbol_does_not_outrank_a_function_it_gates → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_a_config_symbol_does_not_outrank_a_function_it_gates → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_config_symbol_does_not_outrank_a_function_it_gates → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-006catalog
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-012measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_a_config_symbol_does_not_outrank_a_function_it_gates → import_kconfig_gates → ensure_kconfig_gates_table
Source · 26 lines
def test_a_config_symbol_does_not_outrank_a_function_it_gates(tmp_path: Path) -> None:
    """THE COST OF THE NEW CORPUS, bounded. A gating symbol habitually shares every token
    with the function it gates, and the function is the row a caller can read a body for.
    The config tier breaks a TIE only, so a query that spells neither name exactly must
    still put the function first — otherwise adding the corpus degrades every existing
    query, which is how the neighbour-cap experiment cost 48% in tokens.
    """
    root, db = _no_kconfig_repo(tmp_path)
    _add_functions(db, ("widget_lock", "widget_telemetry"))
    import_kconfig_gates(db, root)

    ## "telemetry" is carried by BOTH `widget_telemetry` (function) and `PROJ_OMIT_TELEMETRY`
    ## (gate), and is an exact match for neither — which is the collision this tier exists to
    ## settle. A query matching only one corpus would pass whatever the tiers were.
    hits = search(db, "telemetry")
    kinds = [h.kind for h in hits]
    assert "function" in kinds, "the fixture's functions must still be findable"
    assert CONFIG_SYMBOL_KIND in kinds, "and a gating symbol must be in the same reply"
    assert kinds.index("function") < kinds.index(CONFIG_SYMBOL_KIND)

    ## AND THE EXACT NAME STILL WINS, or the tier has become a demotion rather than a
    ## tie-break and the corpus is unusable for the query it was added for.
    exact = search(db, "PROJ_OMIT_TELEMETRY")
    assert exact[0].kind == CONFIG_SYMBOL_KIND

Activity · 10 steps
lines 672–672root, db = _no_kconfig_repo(tmp_path)lines 673–673_add_functions(db, ("widget_lock", "widget_telemetry"))lines 674–674import_kconfig_gates(db, root)lines 679–679hits = search(db, "telemetry")lines 680–680kinds = [h.kind for h in hits]lines 681–681assert "function" in kinds, "the fixture's functions must still be findable"lines 682–682assert CONFIG_SYMBOL_KIND in kinds, "and a gating symbol must be in the same reply"lines 683–683assert kinds.index("function") < kinds.index(CONFIG_SYMBOL_KIND)lines 687–687exact = search(db, "PROJ_OMIT_TELEMETRY")lines 688–688assert exact[0].kind == CONFIG_SYMBOL_KIND

test_a_declared_but_missing_root_is_not_silently_replaced_by_convention

None test_kconfig.test_a_declared_but_missing_root_is_not_silently_replaced_by_convention(Path repo)

A typo'd declaration must NOT fall through to the root file. Falling through would index a different configuration space than the one declared and report success — the quiet substitution the no-hardcoding mandate exists to prevent.

tests/test_kconfig.py:174

Checks

  • assert location.path is None
  • assert location.searched == ("conf/Kconfig",)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_a_declared_but_missing_root_is_not_silently_replaced_by_convention → discover_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_a_declared_but_missing_root_is_not_silently_replaced_by_convention → discover_kconfig → _declared_kconfig → within_repo
REQ-DDB-QUERY-006catalog
Source · 9 lines
def test_a_declared_but_missing_root_is_not_silently_replaced_by_convention(repo: Path) -> None:
    """A typo'd declaration must NOT fall through to the root file. Falling through
    would index a different configuration space than the one declared and report
    success — the quiet substitution the no-hardcoding mandate exists to prevent."""
    location = discover_kconfig(repo, {SECTION_KCONFIG: {KEY_ROOT: "conf/Kconfig"}})
    assert location.path is None
    assert location.searched == ("conf/Kconfig",)

Activity · 3 steps
lines 178–178location = discover_kconfig(repo, {SECTION_KCONFIG: {KEY_ROOT: "conf/Kconfig"}})lines 179–179assert location.path is Nonelines 180–180assert location.searched == ("conf/Kconfig",)

test_a_declared_root_beats_convention

None test_kconfig.test_a_declared_root_beats_convention(Path repo)

CLI flag &gt; declaration &gt; convention is the precedence every other discovery here follows. The declared file is deliberately NOT at the root, so a pass cannot be explained by the root fallback.

tests/test_kconfig.py:162

Checks

  • assert location.source == SOURCE_DECLARED
  • assert location.path == Path("conf/Kconfig")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_a_declared_root_beats_convention → discover_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_a_declared_root_beats_convention → discover_kconfig → _declared_kconfig → within_repo
REQ-DDB-QUERY-006catalog
Source · 12 lines
def test_a_declared_root_beats_convention(repo: Path) -> None:
    """CLI flag > declaration > convention is the precedence every other discovery
    here follows. The declared file is deliberately NOT at the root, so a pass cannot
    be explained by the root fallback."""
    (repo / "conf").mkdir()
    (repo / "conf" / KCONFIG_NAME).write_text("config DECLARED_ONLY\n\tbool\n", encoding="utf-8")

    location = discover_kconfig(repo, {SECTION_KCONFIG: {KEY_ROOT: "conf/Kconfig"}})
    assert location.source == SOURCE_DECLARED
    assert location.path == Path("conf/Kconfig")

Activity · 5 steps
lines 166–166(repo / "conf").mkdir()lines 167–167(repo / "conf" / KCONFIG_NAME).write_text("config DECLARED_ONLY\n\tbool\n", encoding="utf-8")lines 169–169location = discover_kconfig(repo, {SECTION_KCONFIG: {KEY_ROOT: "conf/Kconfig"}})lines 170–170assert location.source == SOURCE_DECLAREDlines 171–171assert location.path == Path("conf/Kconfig")

test_a_declared_root_outside_the_repository_is_refused

None test_kconfig.test_a_declared_root_outside_the_repository_is_refused(Path repo, Path tmp_path)

A declared Kconfig root outside the repository is refused.

tests/test_kconfig.py:1193

Checks

  • assert location.path is None, (f"{declared!r} escapes the repository and must not be parsed; got {location.path}" )
  • assert location.source != SOURCE_DECLARED, ("a refused declaration must not be recorded as the honoured source" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-005measuredtest_a_declared_root_outside_the_repository_is_refused → discover_kconfig
REQ-DDB-GUARD-012inferred
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_a_declared_root_outside_the_repository_is_refused → discover_kconfig → _declared_kconfig → within_repo
REQ-DDB-QUERY-006catalog
REQ-DDB-WIKI-054inferred
Source · 32 lines
def test_a_declared_root_outside_the_repository_is_refused(repo: Path, tmp_path: Path) -> None:
    """H4, 1.1.0 SECURITY AUDIT. `kconfig.root` is repo-relative by contract and nothing
    enforced it: `(root / declared).resolve()` honours an absolute entry and `../` walks out.
    Two consequences, both reachable by an MCP caller who STATES the section for a repository
    it merely names. First, arbitrary read — a Kconfig anywhere on the machine is parsed and
    its `help` text, prompts and defaults are served as this repository's configuration space.
    Second, it is a route around every other containment here: kconfiglib resolves `source`
    against `$srctree`, and the outside file chooses what gets sourced.

    Refused the way a missing path is — `path is None`, one warning, no configuration space —
    because the build must still produce an index, and a declaration that cannot be honoured
    must never be reported as honoured.

    @brief An escaping declared kconfig.root indexes nothing.
    @return None.
    @version 1
    """
    outside = tmp_path / "outside"
    outside.mkdir(exist_ok=True)
    (outside / KCONFIG_NAME).write_text("config LEAKED\n\tbool\n", encoding="utf-8")

    for declared in (str(outside / KCONFIG_NAME), "../outside/Kconfig"):
        location = discover_kconfig(repo, {SECTION_KCONFIG: {KEY_ROOT: declared}})

        assert location.path is None, (
            f"{declared!r} escapes the repository and must not be parsed; got {location.path}"
        )
        assert location.source != SOURCE_DECLARED, (
            "a refused declaration must not be recorded as the honoured source"
        )

Activity · 7 steps
lines 1210–1210outside = tmp_path / "outside"lines 1211–1211outside.mkdir(exist_ok=True)lines 1212–1212(outside / KCONFIG_NAME).write_text("config LEAKED\n\tbool\n", encoding="utf-8")lines 1214–1214◇ for declared in (str(outside / KCONFIG_NAME), "../outside/Kconfig")lines 1215–1215location = discover_kconfig(repo, {SECTION_KCONFIG: {KEY_ROOT: declared}})lines 1217–1219assert location.path is None, ( f"{declared!r} escapes the repository and must not be parsed; got {location.path}" )lines 1220–1222assert location.source != SOURCE_DECLARED, ( "a refused declaration must not be recorded as the honoured source" )

test_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity

None test_kconfig.test_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity(Path tmp_path)

A gate's recorded extent covers only the branch its own form describes.

tests/test_kconfig.py:859

Show on the map →

Called by none

Calls _no_kconfig_repo, gates_covering, import_kconfig_gates

Checks

  • assert import_kconfig_gates(db, root) > 0
  • assert fast_unknown == 0, "every gate in this file was harvested with an extent"
  • assert ("PROJ_FAST_PATH", KCONFIG_GATE_IFDEF) in fast_forms, (f"the true branch must report the symbol as REQUIRED: {sorted(fast_forms)}" )
  • assert ("PROJ_FAST_PATH", KCONFIG_GATE_IFNDEF) not in fast_forms, ("the true branch must NOT also report the inverted gate — that is the node-extent bug" )
  • assert ("PROJ_FAST_PATH", KCONFIG_GATE_IFNDEF) in slow_forms, (f"the else branch is present when the symbol is NOT set: {sorted(slow_forms)}" )
  • assert ("PROJ_FAST_PATH", KCONFIG_GATE_IFDEF) not in slow_forms, ("reporting the else branch as gated ON the symbol inverts the variant a reader concludes" )
  • assert not always, (f"an ungated function must report no gates, not the file's gates: {sorted(always)}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-003measuredtest_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → gates_covering → table_exists
REQ-DDB-QUERY-004inferredtest_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → gates_covering → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → gates_covering
REQ-DDB-QUERY-013inferredtest_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → gates_covering → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → import_kconfig_gates → ensure_kconfig_gates_table
Source · 53 lines
def test_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity(tmp_path: Path) -> None:
    """THE POLARITY TRAP, WHICH IS THE WHOLE REASON THE EXTENT IS NOT THE NODE'S EXTENT. Measured
    with `.claude/tmp/gate_extent_probe.py`: tree-sitter parses

        #ifdef PROJ_FAST_PATH / void widget_fast / #else / void widget_slow / #endif

    as ONE `preproc_ifdef` spanning the whole construct, with the `#else` as its `alternative`
    child. So a range join over the node's own extent reports `widget_slow` as present when
    `PROJ_FAST_PATH` is SET — the exact inverse of the truth, stated with full confidence. That is
    worse than no answer, and it is invisible to any test that only checks a gate was found.

    THE ASSERTIONS ARE A PAIR AND BOTH ARE LOAD-BEARING: `widget_fast` must be covered by `ifdef`
    and NOT by `ifndef`; `widget_slow` the other way round. A single-sided check passes against an
    implementation that reports both gates on both lines, which is the natural result of storing
    the node's extent and the thing this fixture exists to catch.

    @brief Extents stop at the else, and the else inverts.
    @version 1
    """
    root, db = _no_kconfig_repo(tmp_path)
    assert import_kconfig_gates(db, root) > 0

    conn = sqlite3.connect(str(db))
    try:
        fast, fast_unknown = gates_covering(conn, "src/widget.c", _FAST_LINE)
        slow, _ = gates_covering(conn, "src/widget.c", _SLOW_LINE)
        always, _ = gates_covering(conn, "src/widget.c", _ALWAYS_LINE)
    finally:
        conn.close()

    assert fast_unknown == 0, "every gate in this file was harvested with an extent"
    fast_forms = {(g.macro, g.form) for g in fast}
    slow_forms = {(g.macro, g.form) for g in slow}
    assert ("PROJ_FAST_PATH", KCONFIG_GATE_IFDEF) in fast_forms, (
        f"the true branch must report the symbol as REQUIRED: {sorted(fast_forms)}"
    )
    assert ("PROJ_FAST_PATH", KCONFIG_GATE_IFNDEF) not in fast_forms, (
        "the true branch must NOT also report the inverted gate — that is the node-extent bug"
    )
    assert ("PROJ_FAST_PATH", KCONFIG_GATE_IFNDEF) in slow_forms, (
        f"the else branch is present when the symbol is NOT set: {sorted(slow_forms)}"
    )
    assert ("PROJ_FAST_PATH", KCONFIG_GATE_IFDEF) not in slow_forms, (
        "reporting the else branch as gated ON the symbol inverts the variant a reader concludes"
    )
    ## THE NEGATIVE HALF. A function outside every conditional must come back with nothing;
    ## without this the feature could report every gate in the file for every line and still
    ## satisfy both assertions above.
    assert not always, (
        f"an ungated function must report no gates, not the file's gates: {sorted(always)}"
    )

Activity · 15 steps
lines 878–878root, db = _no_kconfig_repo(tmp_path)lines 879–879assert import_kconfig_gates(db, root) > 0lines 881–881conn = sqlite3.connect(str(db))lines 882–882trylines 883–883fast, fast_unknown = gates_covering(conn, "src/widget.c", _FAST_LINE)lines 884–884slow, _ = gates_covering(conn, "src/widget.c", _SLOW_LINE)lines 885–885always, _ = gates_covering(conn, "src/widget.c", _ALWAYS_LINE)lines 889–889assert fast_unknown == 0, "every gate in this file was harvested with an extent"lines 890–890fast_forms = {(g.macro, g.form) for g in fast}lines 891–891slow_forms = {(g.macro, g.form) for g in slow}lines 892–894assert ("PROJ_FAST_PATH", KCONFIG_GATE_IFDEF) in fast_forms, ( f"the true branch must report the symbol as REQUIRED: {sorted(fast_forms)}" )lines 895–897assert ("PROJ_FAST_PATH", KCONFIG_GATE_IFNDEF) not in fast_forms, ( "the true branch must NOT also report the inverted gate — that is the node-extent bug" )lines 898–900assert ("PROJ_FAST_PATH", KCONFIG_GATE_IFNDEF) in slow_forms, ( f"the else branch is present when the symbol is NOT set: {sorted(slow_forms)}" )lines 901–903assert ("PROJ_FAST_PATH", KCONFIG_GATE_IFDEF) not in slow_forms, ( "reporting the else branch as gated ON the symbol inverts the variant a reader concludes" )lines 907–909assert not always, ( f"an ungated function must report no gates, not the file's gates: {sorted(always)}" )

test_a_gate_on_an_undeclared_symbol_is_kept

None test_kconfig.test_a_gate_on_an_undeclared_symbol_is_kept(Path repo, Path tmp_path)

Dead code behind a symbol nobody can set is a defect in the target. Filtering the gate list to declared symbols would delete the evidence of it, and it is the kind of thing this tool exists to surface.

tests/test_kconfig.py:390

Checks

  • assert "WIDGET_UNDECLARED" not in {s.name for s in space.symbols}
  • assert "WIDGET_UNDECLARED" in {g.symbol for g in space.gates}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005measuredtest_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig
REQ-DDB-PIPE-003measuredtest_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014measuredtest_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig → load_kconfig → _served_parse_error
REQ-DDB-QUERY-001measuredtest_a_gate_on_an_undeclared_symbol_is_kept → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_a_gate_on_an_undeclared_symbol_is_kept → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_a_gate_on_an_undeclared_symbol_is_kept → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_a_gate_on_an_undeclared_symbol_is_kept → kconfig_space
REQ-DDB-QUERY-013inferredtest_a_gate_on_an_undeclared_symbol_is_kept → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig_gates → ensure_kconfig_gates_table
Source · 14 lines
def test_a_gate_on_an_undeclared_symbol_is_kept(repo: Path, tmp_path: Path) -> None:
    """Dead code behind a symbol nobody can set is a defect in the target. Filtering
    the gate list to declared symbols would delete the evidence of it, and it is the
    kind of thing this tool exists to surface."""
    db = tmp_path / "clew.db"
    _db_with_paths(db, ("src/motor.c",))
    import_kconfig(db, repo, None)
    import_kconfig_gates(db, repo)

    space = kconfig_space(db)
    assert "WIDGET_UNDECLARED" not in {s.name for s in space.symbols}
    assert "WIDGET_UNDECLARED" in {g.symbol for g in space.gates}

Activity · 7 steps
lines 394–394db = tmp_path / "clew.db"lines 395–395_db_with_paths(db, ("src/motor.c",))lines 396–396import_kconfig(db, repo, None)lines 397–397import_kconfig_gates(db, repo)lines 399–399space = kconfig_space(db)lines 400–400assert "WIDGET_UNDECLARED" not in {s.name for s in space.symbols}lines 401–401assert "WIDGET_UNDECLARED" in {g.symbol for g in space.gates}

test_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated

None test_kconfig.test_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated(Path tmp_path)

A gate with no recorded extent is counted, never guessed at.

tests/test_kconfig.py:915

Show on the map →

Called by none

Calls _no_kconfig_repo, gates_covering, import_kconfig_gates

Checks

  • assert import_kconfig_gates(db, root) > 0
  • assert gates == (), "with no extent recorded, no gate can honestly be placed on a line"
  • assert unknown > 0, ("an unplaceable gate must be COUNTED — an empty list with a zero count claims the " "function is ungated, which is a different and unearned answer" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-003measuredtest_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → gates_covering → table_exists
REQ-DDB-QUERY-004inferredtest_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → gates_covering → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → gates_covering
REQ-DDB-QUERY-013inferredtest_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → gates_covering → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → import_kconfig_gates → ensure_kconfig_gates_table
Source · 34 lines
def test_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated(tmp_path: Path) -> None:
    """THE THIRD STATE, which this project has been bitten by in five other places: an index built
    before the extent column stores `end_line = 0`, and both available guesses are wrong in a way
    that reads as an answer. Treating it as covering nothing reports a fully gated file as
    ungated; treating it as covering the rest of the file attributes ordinary code to the last
    conditional above it.

    So the count travels with the answer, and an empty `gates` beside a non-zero count means "this
    index cannot tell" — a different statement from "this function is ungated". Simulated by
    dropping the column, which is exactly what an older index looks like to the reader.

    @brief Unknown extent is disclosed, not resolved.
    @version 1
    """
    root, db = _no_kconfig_repo(tmp_path)
    assert import_kconfig_gates(db, root) > 0
    conn = sqlite3.connect(str(db))
    try:
        ## An index built before the column: same rows, no extent.
        conn.execute("ALTER TABLE kconfig_gates DROP COLUMN end_line")
        conn.commit()
        gates, unknown = gates_covering(conn, "src/widget.c", _FAST_LINE)
    finally:
        conn.close()
    assert gates == (), "with no extent recorded, no gate can honestly be placed on a line"
    assert unknown > 0, (
        "an unplaceable gate must be COUNTED — an empty list with a zero count claims the "
        "function is ungated, which is a different and unearned answer"
    )


# ─── part 6: `found` is about KCONFIG; the gate harvest speaks for itself (gh#404) ──

Activity · 9 steps
lines 929–929root, db = _no_kconfig_repo(tmp_path)lines 930–930assert import_kconfig_gates(db, root) > 0lines 931–931conn = sqlite3.connect(str(db))lines 932–932trylines 934–934conn.execute("ALTER TABLE kconfig_gates DROP COLUMN end_line")lines 935–935conn.commit()lines 936–936gates, unknown = gates_covering(conn, "src/widget.c", _FAST_LINE)lines 939–939assert gates == (), "with no extent recorded, no gate can honestly be placed on a line"lines 940–943assert unknown > 0, ( "an unplaceable gate must be COUNTED — an empty list with a zero count claims the " "function is ungated, which is a different and unearned answer" )

test_a_gated_on_symbol_is_a_dossier_subject

None test_kconfig.test_a_gated_on_symbol_is_a_dossier_subject(Path tmp_path)

THE OTHER HALF OF gh#390, and storing the rows without this fixes nothing a caller can see. `_is_config` used to probe declared symbols only, reasoning that a gate on an undeclared symbol "is not a subject, because there is nothing to describe". Once the harvest widened past the `CONFIG_` prefix there is a great deal to describe — where the symbol decides code exists, in how many files, in which form — and that IS the answer the benchmark questions wanted. Without this, `dossier` returned a confident negative for the exact symbols Q1 and Q2 are about while the rows sat in the table.

tests/test_kconfig.py:576

Show on the map →

Called by none

Calls _no_kconfig_repo, import_kconfig_gates, resolve_subject

Checks

  • assert "config" in resolve_subject(db, "PROJ_THREADING_PTHREAD")
  • assert subject is not None
  • assert subject.kind == "config"
  • assert subject.config is not None
  • assert {g.symbol for g in subject.config.gates} == {"PROJ_THREADING_PTHREAD"}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_a_gated_on_symbol_is_a_dossier_subject → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_a_gated_on_symbol_is_a_dossier_subject → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_a_gated_on_symbol_is_a_dossier_subject → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_a_gated_on_symbol_is_a_dossier_subject → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_gated_on_symbol_is_a_dossier_subject → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_a_gated_on_symbol_is_a_dossier_subject → resolve_subject → connect
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-013measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_a_gated_on_symbol_is_a_dossier_subject → import_kconfig_gates → ensure_kconfig_gates_table
Source · 20 lines
def test_a_gated_on_symbol_is_a_dossier_subject(tmp_path: Path) -> None:
    """THE OTHER HALF OF gh#390, and storing the rows without this fixes nothing a caller
    can see. `_is_config` used to probe declared symbols only, reasoning that a gate on an
    undeclared symbol "is not a subject, because there is nothing to describe". Once the
    harvest widened past the `CONFIG_` prefix there is a great deal to describe — where the
    symbol decides code exists, in how many files, in which form — and that IS the answer
    the benchmark questions wanted. Without this, `dossier` returned a confident negative
    for the exact symbols Q1 and Q2 are about while the rows sat in the table.
    """
    root, db = _no_kconfig_repo(tmp_path)
    import_kconfig_gates(db, root)

    assert "config" in resolve_subject(db, "PROJ_THREADING_PTHREAD")
    subject = dossier(db, "PROJ_THREADING_PTHREAD")
    assert subject is not None
    assert subject.kind == "config"
    assert subject.config is not None
    assert {g.symbol for g in subject.config.gates} == {"PROJ_THREADING_PTHREAD"}

Activity · 8 steps
lines 585–585root, db = _no_kconfig_repo(tmp_path)lines 586–586import_kconfig_gates(db, root)lines 588–588assert "config" in resolve_subject(db, "PROJ_THREADING_PTHREAD")lines 589–589subject = dossier(db, "PROJ_THREADING_PTHREAD")lines 590–590assert subject is not Nonelines 591–591assert subject.kind == "config"lines 592–592assert subject.config is not Nonelines 593–593assert {g.symbol for g in subject.config.gates} == {"PROJ_THREADING_PTHREAD"}

test_a_kconfig_parse_is_given_a_minimal_environment

None test_kconfig.test_a_kconfig_parse_is_given_a_minimal_environment(Path tmp_path, pytest.MonkeyPatch monkeypatch)

A hostile Kconfig can neither read the environment nor run a command.

tests/test_kconfig.py:1230

Checks

  • assert "SENTINEL-ENV-LEAK" not in served, (f"the indexing user's environment reached the served configuration space: {served}" )
  • assert not marker.exists(), "a Kconfig ran a shell command during the parse"
  • assert "RAN" not in served, "a shell command's output reached the served text"
  • assert model.shell_refused, "a refused shell expansion must be recorded, not swallowed"
  • assert model.as_meta()["shell_refused"] == str(len(model.shell_refused))

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_a_kconfig_parse_is_given_a_minimal_environment → discover_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_a_kconfig_parse_is_given_a_minimal_environment → load_kconfig → _served_parse_error
REQ-DDB-QUERY-006catalog
Source · 48 lines
def test_a_kconfig_parse_is_given_a_minimal_environment(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
    """H3, 1.1.0 SECURITY AUDIT — and the `$(shell,…)` half is not a read, it is EXECUTION.
    Measured against kconfiglib 14.1: `$(SENTINEL)` in a prompt expands from the process
    environment, which for the MCP plugin is the EDITOR's environment (`ANTHROPIC_API_KEY`,
    `GH_TOKEN`, `AWS_*`), and the expansion is then persisted and served as the repository's
    own configuration text. `$(shell,touch …)` ran the command. `KCONFIG_FUNCTIONS` imports a
    module by name, and `kconfigfunctions` is its default — a file a repository can ship.

    THE FIX IS ONE CONCEPT, not three: the parse gets a MINIMAL ENVIRONMENT instead of the
    process's. `srctree` is what it always was, `KCONFIG_FUNCTIONS` points at clew's own
    module (which supplies a refusing `shell`, since kconfiglib's `update` lets a named module
    REPLACE a built-in), and nothing else is inherited.

    @brief Neither an environment variable nor a shell command reaches the parse.
    @return None.
    @version 1
    """
    monkeypatch.setenv("SENTINEL_SECRET", "SENTINEL-ENV-LEAK")

    repo = tmp_path / "repo"
    repo.mkdir()
    marker = tmp_path / "pwned"
    (repo / KCONFIG_NAME).write_text(
        'config LEAKED\n\tbool "env says $(SENTINEL_SECRET)"\n'
        f'\tdefault "$(shell,touch {marker} && echo RAN)"\n',
        encoding="utf-8",
    )

    model = load_kconfig(discover_kconfig(repo, {}), repo)

    served = (
        " ".join(f"{s.name} {s.prompt} {s.help} {s.default}" for s in model.symbols) + model.error
    )
    assert "SENTINEL-ENV-LEAK" not in served, (
        f"the indexing user's environment reached the served configuration space: {served}"
    )
    assert not marker.exists(), "a Kconfig ran a shell command during the parse"
    assert "RAN" not in served, "a shell command's output reached the served text"

    ## THE REFUSAL IS RECORDED, because a silently empty expansion is the
    ## accepted-but-unread failure this project keeps finding: an owner whose Zephyr tree
    ## genuinely uses `$(shell,…)` must be able to see WHY their defaults came out empty.
    assert model.shell_refused, "a refused shell expansion must be recorded, not swallowed"
    assert model.as_meta()["shell_refused"] == str(len(model.shell_refused))

Activity · 12 steps
lines 1249–1249monkeypatch.setenv("SENTINEL_SECRET", "SENTINEL-ENV-LEAK")lines 1251–1251repo = tmp_path / "repo"lines 1252–1252repo.mkdir()lines 1253–1253marker = tmp_path / "pwned"lines 1254–1258(repo / KCONFIG_NAME).write_text( 'config LEAKED\n\tbool "env says $(SENTINEL_SECRET)"\n' f'\tdefault "$(shell,touch {marker} && echo RAN)"\n', encoding="utf-8", )lines 1260–1260model = load_kconfig(discover_kconfig(repo, {}), repo)lines 1262–1264served = ( " ".join(f"{s.name} {s.prompt} {s.help} {s.default}" for s in model.symbols) + model.error )lines 1265–1267assert "SENTINEL-ENV-LEAK" not in served, ( f"the indexing user's environment reached the served configuration space: {served}" )lines 1268–1268assert not marker.exists(), "a Kconfig ran a shell command during the parse"lines 1269–1269assert "RAN" not in served, "a shell command's output reached the served text"lines 1274–1274assert model.shell_refused, "a refused shell expansion must be recorded, not swallowed"lines 1275–1275assert model.as_meta()["shell_refused"] == str(len(model.shell_refused))

test_a_kconfig_sourcing_outside_the_repository_is_refused

None test_kconfig.test_a_kconfig_sourcing_outside_the_repository_is_refused(Path tmp_path)

A Kconfig that sources a file outside the repository indexes nothing from it.

tests/test_kconfig.py:1319

Checks

  • assert "SECRET-SOURCED-HELP" not in served, f"outside help text was served: {served}"
  • assert "SENTINEL_OUTSIDE" not in served, f"an outside symbol was served: {served}"
  • assert model.error, "the refusal must be recorded, not left as an empty configuration space"
  • assert not model.symbols

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_a_kconfig_sourcing_outside_the_repository_is_refused → discover_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_a_kconfig_sourcing_outside_the_repository_is_refused → load_kconfig → _served_parse_error
REQ-DDB-QUERY-006catalog
Source · 41 lines
def test_a_kconfig_sourcing_outside_the_repository_is_refused(tmp_path: Path) -> None:
    """M2, 1.1.0 SECURITY AUDIT — and wider than the finding as written. kconfiglib resolves
    `source` against `$srctree`, and NOTHING constrained it: `source "/abs/path"` parsed a
    file anywhere on the machine and served its symbols, prompts and help text as this
    repository's configuration space. Measured against kconfiglib 14.1.

    THE CHECK IS AFTER THE PARSE, deliberately: kconfiglib offers no hook on `source`
    resolution, and `kconf.kconfig_filenames` is its own record of every file it read. The
    read has happened by then; what the check prevents is DISCLOSURE, which is the harm — no
    row, no help text and no error line from an outside file reaches the index. A pre-parse
    scan of the text was the alternative and it is the fragile one: `source` takes globs and
    preprocessor-expanded variables, so a scanner would have to re-implement the parser.

    @brief An escaping `source` yields no symbols and a path-only refusal.
    @return None.
    @version 1
    """
    outside = tmp_path / "outside.Kconfig"
    outside.write_text(
        'config SENTINEL_OUTSIDE\n\tbool "leaked prompt"\n\thelp\n\t  SECRET-SOURCED-HELP\n',
        encoding="utf-8",
    )

    repo = tmp_path / "repo"
    repo.mkdir()
    (repo / KCONFIG_NAME).write_text(
        f'source "{outside}"\nconfig OWN\n\tbool "own"\n', encoding="utf-8"
    )

    model = load_kconfig(discover_kconfig(repo, {}), repo)

    served = " ".join(f"{s.name} {s.prompt} {s.help}" for s in model.symbols) + model.error
    assert "SECRET-SOURCED-HELP" not in served, f"outside help text was served: {served}"
    assert "SENTINEL_OUTSIDE" not in served, f"an outside symbol was served: {served}"
    assert model.error, "the refusal must be recorded, not left as an empty configuration space"
    ## THE WHOLE SPACE GOES, not just the outside rows. A tree whose `source` reaches out is
    ## not a configuration space clew can describe: the symbols that remain depend on the file
    ## that was refused, so serving them would be a partial model reading as a complete one.
    assert not model.symbols

Activity · 11 steps
lines 1336–1336outside = tmp_path / "outside.Kconfig"lines 1337–1340outside.write_text( 'config SENTINEL_OUTSIDE\n\tbool "leaked prompt"\n\thelp\n\t SECRET-SOURCED-HELP\n', encoding="utf-8", )lines 1342–1342repo = tmp_path / "repo"lines 1343–1343repo.mkdir()lines 1344–1346(repo / KCONFIG_NAME).write_text( f'source "{outside}"\nconfig OWN\n\tbool "own"\n', encoding="utf-8" )lines 1348–1348model = load_kconfig(discover_kconfig(repo, {}), repo)lines 1350–1350served = " ".join(f"{s.name} {s.prompt} {s.help}" for s in model.symbols) + model.errorlines 1351–1351assert "SECRET-SOURCED-HELP" not in served, f"outside help text was served: {served}"lines 1352–1352assert "SENTINEL_OUTSIDE" not in served, f"an outside symbol was served: {served}"lines 1353–1353assert model.error, "the refusal must be recorded, not left as an empty configuration space"lines 1357–1357assert not model.symbols

test_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent

None test_kconfig.test_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent(Path repo, Path tmp_path)

THE CASE A HARD DEPENDENCY DOES NOT COVER. A Zephyr application's top-level Kconfig `source`s the Zephyr tree's own, so indexing it outside a west workspace fails to parse — ordinarily, not exotically.

tests/test_kconfig.py:774

Checks

  • assert model.found is True, "discovery succeeded; only the parse failed"
  • assert model.error, "a failed parse must be recorded, not swallowed"
  • assert model.symbols == ()
  • assert space.found is True
  • assert space.error, "the query layer must report the parse failure, not a bare empty"
  • assert space.symbols == ()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → import_kconfig
REQ-DDB-CONFIG-006measuredtest_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → write_build_signature
REQ-DDB-CONFIG-007measuredtest_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → write_build_signature
REQ-DDB-PIPE-005measuredtest_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → write_build_signature
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → import_kconfig → load_kconfig → _served_parse_error
REQ-DDB-QUERY-001measuredtest_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → kconfig_space
REQ-DDB-QUERY-013inferredtest_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → import_kconfig → store_kconfig → ensure_kconfig_tables
Source · 27 lines
def test_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent(
    repo: Path, tmp_path: Path
) -> None:
    """THE CASE A HARD DEPENDENCY DOES NOT COVER. A Zephyr application's top-level
    Kconfig `source`s the Zephyr tree's own, so indexing it outside a west workspace
    fails to parse — ordinarily, not exotically.

    That must be distinguishable from a repo with no Kconfig. Both present as zero
    symbols, and this repo's standing lesson is that "no rows" is a claim about the
    detector until you have checked whether the detector could look."""
    (repo / "Kconfig.motor").unlink()
    db = tmp_path / "clew.db"
    _db_with_paths(db, ())

    model = import_kconfig(db, repo, None)
    write_build_signature(db, kconfig=model.as_meta())

    assert model.found is True, "discovery succeeded; only the parse failed"
    assert model.error, "a failed parse must be recorded, not swallowed"
    assert model.symbols == ()

    space = kconfig_space(db)
    assert space.found is True
    assert space.error, "the query layer must report the parse failure, not a bare empty"
    assert space.symbols == ()

Activity · 12 steps
lines 784–784(repo / "Kconfig.motor").unlink()lines 785–785db = tmp_path / "clew.db"lines 786–786_db_with_paths(db, ())lines 788–788model = import_kconfig(db, repo, None)lines 789–789write_build_signature(db, kconfig=model.as_meta())lines 791–791assert model.found is True, "discovery succeeded; only the parse failed"lines 792–792assert model.error, "a failed parse must be recorded, not swallowed"lines 793–793assert model.symbols == ()lines 795–795space = kconfig_space(db)lines 796–796assert space.found is Truelines 797–797assert space.error, "the query layer must report the parse failure, not a bare empty"lines 798–798assert space.symbols == ()

test_a_limitation_documented_only_in_help_is_searchable

None test_kconfig.test_a_limitation_documented_only_in_help_is_searchable(Path repo, Path tmp_path)

THE ISSUE'S OWN "DONE MEANS". A `help` block routinely carries the only statement of a known limitation in a repository, and until gh#18 not a word of it was indexed.

tests/test_kconfig.py:264

Checks

  • assert others == [], f"the phrase is not help-only any more — also in {others}"
  • assert search_prose(db, HELP_ONLY_PHRASE) == [], ("the markdown ingest alone must NOT find it — otherwise this test would pass " "without the Kconfig ingest doing anything" )
  • assert hits, "a limitation documented only in a help block is still unreachable"
  • assert any("MOTOR_BETA" in hit.heading for hit in hits), ("the hit must name the symbol the limitation belongs to" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_a_limitation_documented_only_in_help_is_searchable → import_kconfig
REQ-DDB-INDEX-002inferredtest_a_limitation_documented_only_in_help_is_searchable → ingest_supplementary_docs → _ingest_one_doc_file → memoized
REQ-DDB-PIPE-001measuredtest_a_limitation_documented_only_in_help_is_searchable → ingest_supplementary_docs
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_a_limitation_documented_only_in_help_is_searchable → ingest_supplementary_docs → within_repo
REQ-DDB-QUERY-001measuredtest_a_limitation_documented_only_in_help_is_searchable → search_prose
REQ-DDB-QUERY-003measuredtest_a_limitation_documented_only_in_help_is_searchable → search_prose → search_prose_graded → table_exists
REQ-DDB-QUERY-006catalog
REQ-DDB-QUERY-007measuredtest_a_limitation_documented_only_in_help_is_searchable → search_prose → search_prose_graded → member_doc_rows
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_a_limitation_documented_only_in_help_is_searchable → import_kconfig → store_kconfig → ensure_kconfig_tables
Source · 33 lines
def test_a_limitation_documented_only_in_help_is_searchable(repo: Path, tmp_path: Path) -> None:
    """THE ISSUE'S OWN "DONE MEANS". A `help` block routinely carries the only
    statement of a known limitation in a repository, and until gh#18 not a word of it
    was indexed.

    The control is the second assertion, and it is what makes the first one mean
    anything: the phrase appears in NO other file of the fixture, so a hit cannot be
    coming from a markdown chunk."""
    others = [
        path
        for path in repo.rglob("*")
        if path.is_file()
        and path.name != "Kconfig.motor"
        and HELP_ONLY_PHRASE in path.read_text(encoding="utf-8", errors="replace")
    ]
    assert others == [], f"the phrase is not help-only any more — also in {others}"

    db = tmp_path / "clew.db"
    _db_with_paths(db, ())
    ingest_supplementary_docs(db, repo)
    assert search_prose(db, HELP_ONLY_PHRASE) == [], (
        "the markdown ingest alone must NOT find it — otherwise this test would pass "
        "without the Kconfig ingest doing anything"
    )

    import_kconfig(db, repo, None)
    hits = search_prose(db, HELP_ONLY_PHRASE)
    assert hits, "a limitation documented only in a help block is still unreachable"
    assert any("MOTOR_BETA" in hit.heading for hit in hits), (
        "the hit must name the symbol the limitation belongs to"
    )

Activity · 10 steps
lines 272–278others = [ path for path in repo.rglob("*") if path.is_file() and path.name != "Kconfig.motor" and HELP_ONLY_PHRASE in path.read_text(encoding="utf-8", errors="replace") ]lines 279–279assert others == [], f"the phrase is not help-only any more — also in {others}"lines 281–281db = tmp_path / "clew.db"lines 282–282_db_with_paths(db, ())lines 283–283ingest_supplementary_docs(db, repo)lines 284–287assert search_prose(db, HELP_ONLY_PHRASE) == [], ( "the markdown ingest alone must NOT find it — otherwise this test would pass " "without the Kconfig ingest doing anything" )lines 289–289import_kconfig(db, repo, None)lines 290–290hits = search_prose(db, HELP_ONLY_PHRASE)lines 291–291assert hits, "a limitation documented only in a help block is still unreachable"lines 292–294assert any("MOTOR_BETA" in hit.heading for hit in hits), ( "the hit must name the symbol the limitation belongs to" )

test_a_measured_zero_survives_the_build_signature

None test_kconfig.test_a_measured_zero_survives_the_build_signature(Path tmp_path)

`write_build_signature` DROPS falsy values, so every count is passed as a STRING: `"0"` is truthy where `0` is not. gh#6 and gh#17 both had to work around this, and forgetting it here would erase exactly the finding that matters — "we found a Kconfig and it declares nothing".

tests/test_kconfig.py:801

Show on the map →

Called by none

Calls _db_with_paths, import_kconfig, write_build_signature

Checks

  • assert model.found is True
  • assert model.symbols == ()
  • assert meta["kconfig.symbol_count"] == "0", "the measured zero was dropped as falsy"
  • assert meta["kconfig.source"] == SOURCE_ROOT

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_a_measured_zero_survives_the_build_signature → import_kconfig
REQ-DDB-CONFIG-006measuredtest_a_measured_zero_survives_the_build_signature → write_build_signature
REQ-DDB-CONFIG-007measuredtest_a_measured_zero_survives_the_build_signature → write_build_signature
REQ-DDB-PIPE-005measuredtest_a_measured_zero_survives_the_build_signature → write_build_signature
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_a_measured_zero_survives_the_build_signature → import_kconfig → load_kconfig → _served_parse_error
REQ-DDB-QUERY-006catalog
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_a_measured_zero_survives_the_build_signature → import_kconfig → store_kconfig → ensure_kconfig_tables
Source · 23 lines
def test_a_measured_zero_survives_the_build_signature(tmp_path: Path) -> None:
    """`write_build_signature` DROPS falsy values, so every count is passed as a
    STRING: `"0"` is truthy where `0` is not. gh#6 and gh#17 both had to work around
    this, and forgetting it here would erase exactly the finding that matters —
    "we found a Kconfig and it declares nothing"."""
    root = tmp_path / "empty_space"
    root.mkdir()
    (root / KCONFIG_NAME).write_text("# a comment and nothing else\n", encoding="utf-8")
    db = tmp_path / "clew.db"
    _db_with_paths(db, ())

    model = import_kconfig(db, root, None)
    write_build_signature(db, kconfig=model.as_meta())

    assert model.found is True
    assert model.symbols == ()
    conn = sqlite3.connect(str(db))
    meta = dict(conn.execute("SELECT key, value FROM build_meta"))
    conn.close()
    assert meta["kconfig.symbol_count"] == "0", "the measured zero was dropped as falsy"
    assert meta["kconfig.source"] == SOURCE_ROOT

Activity · 14 steps
lines 806–806root = tmp_path / "empty_space"lines 807–807root.mkdir()lines 808–808(root / KCONFIG_NAME).write_text("# a comment and nothing else\n", encoding="utf-8")lines 809–809db = tmp_path / "clew.db"lines 810–810_db_with_paths(db, ())lines 812–812model = import_kconfig(db, root, None)lines 813–813write_build_signature(db, kconfig=model.as_meta())lines 815–815assert model.found is Truelines 816–816assert model.symbols == ()lines 817–817conn = sqlite3.connect(str(db))lines 818–818meta = dict(conn.execute("SELECT key, value FROM build_meta"))lines 819–819conn.close()lines 820–820assert meta["kconfig.symbol_count"] == "0", "the measured zero was dropped as falsy"lines 821–821assert meta["kconfig.source"] == SOURCE_ROOT

test_a_name_that_is_neither_declared_nor_gated_is_still_not_a_config_subject

None test_kconfig.test_a_name_that_is_neither_declared_nor_gated_is_still_not_a_config_subject(Path tmp_path)

THE NEGATIVE HALF. Widening `_is_config` to accept gated-on names must not widen it to accept ANY name — a probe that answers yes for everything classifies every string as a config symbol and makes the kind meaningless. Without this assertion the widened probe could be `return True` and the test above would still pass.

tests/test_kconfig.py:596

Show on the map →

Called by none

Calls _no_kconfig_repo, import_kconfig_gates, resolve_subject

Checks

  • assert "config" not in resolve_subject(db, "PROJ_NEVER_MENTIONED_ANYWHERE")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_a_name_that_is_neither_declared_nor_gated_is_still_not_a_config_subject → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_a_name_that_is_neither_declared_nor_gated_is_still_not_a_config_subject → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_a_name_that_is_neither_declared_nor_gated_is_still_not_a_config_subject → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_a_name_that_is_neither_declared_nor_gated_is_still_not_a_config_subject → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_name_that_is_neither_declared_nor_gated_is_still_not_a_config_subject → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_a_name_that_is_neither_declared_nor_gated_is_still_not_a_config_subject → resolve_subject → connect
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-006catalog
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_a_name_that_is_neither_declared_nor_gated_is_still_not_a_config_subject → import_kconfig_gates → ensure_kconfig_gates_table
Source · 13 lines
def test_a_name_that_is_neither_declared_nor_gated_is_still_not_a_config_subject(
    tmp_path: Path,
) -> None:
    """THE NEGATIVE HALF. Widening `_is_config` to accept gated-on names must not widen it
    to accept ANY name — a probe that answers yes for everything classifies every string as
    a config symbol and makes the kind meaningless. Without this assertion the widened
    probe could be `return True` and the test above would still pass.
    """
    root, db = _no_kconfig_repo(tmp_path)
    import_kconfig_gates(db, root)
    assert "config" not in resolve_subject(db, "PROJ_NEVER_MENTIONED_ANYWHERE")

Activity · 3 steps
lines 604–604root, db = _no_kconfig_repo(tmp_path)lines 605–605import_kconfig_gates(db, root)lines 606–606assert "config" not in resolve_subject(db, "PROJ_NEVER_MENTIONED_ANYWHERE")

test_a_parse_failure_records_the_location_and_not_the_line

None test_kconfig.test_a_parse_failure_records_the_location_and_not_the_line(Path tmp_path)

A parse failure reports where, not the offending line's content.

tests/test_kconfig.py:1364

Checks

  • assert model.error, "a failed parse must still be recorded"
  • assert "SENTINEL-UNPARSEABLE-CONTENT" not in model.error, (f"the served error carries the content of the file it failed on: {model.error!r}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_a_parse_failure_records_the_location_and_not_the_line → discover_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_a_parse_failure_records_the_location_and_not_the_line → load_kconfig → _served_parse_error
REQ-DDB-QUERY-006catalog
Source · 25 lines
def test_a_parse_failure_records_the_location_and_not_the_line(tmp_path: Path) -> None:
    """THE EXFILTRATION HALF OF M2. kconfiglib's exception messages QUOTE THE OFFENDING LINE,
    and `kconfig.error` is a served `build_meta` value — so a repository that `source`s a file
    it should not reach gets that file's content back out through the error text even when the
    parse fails. Reporting the type and the `file:line` location keeps the value diagnostic
    while making it carry no content; the full message still goes to the build log, which is
    the operator's to read and is not served.

    @brief The served error names a location, never a quoted source line.
    @return None.
    @version 1
    """
    secret = tmp_path / "secret.Kconfig"
    secret.write_text("SENTINEL-UNPARSEABLE-CONTENT not a kconfig line\n", encoding="utf-8")

    repo = tmp_path / "repo"
    repo.mkdir()
    (repo / KCONFIG_NAME).write_text(f'source "{secret}"\n', encoding="utf-8")

    model = load_kconfig(discover_kconfig(repo, {}), repo)

    assert model.error, "a failed parse must still be recorded"
    assert "SENTINEL-UNPARSEABLE-CONTENT" not in model.error, (
        f"the served error carries the content of the file it failed on: {model.error!r}"
    )

1 more lines, not shown

Activity · 8 steps
lines 1376–1376secret = tmp_path / "secret.Kconfig"lines 1377–1377secret.write_text("SENTINEL-UNPARSEABLE-CONTENT not a kconfig line\n", encoding="utf-8")lines 1379–1379repo = tmp_path / "repo"lines 1380–1380repo.mkdir()lines 1381–1381(repo / KCONFIG_NAME).write_text(f'source "{secret}"\n', encoding="utf-8")lines 1383–1383model = load_kconfig(discover_kconfig(repo, {}), repo)lines 1385–1385assert model.error, "a failed parse must still be recorded"lines 1386–1388assert "SENTINEL-UNPARSEABLE-CONTENT" not in model.error, ( f"the served error carries the content of the file it failed on: {model.error!r}" )

test_a_plain_ifndef_gate_survives_the_include_guard_exclusion

None test_kconfig.test_a_plain_ifndef_gate_survives_the_include_guard_exclusion(Path tmp_path)

THE LOAD-BEARING NEGATIVE. Excluding guards must not exclude every `#ifndef`, and the case that proves it is not hypothetical: Q2's whole answer rests on `#ifndef MBEDTLS_ALLOW_PRIVATE_ACCESS` at `private_access.h:14`, which is an ifndef that does NOT define its own symbol and is therefore a real gate. A rule keyed on the directive rather than on the self-define would have deleted it, and the deletion would have looked like a tidier gate layer.

tests/test_kconfig.py:628

Show on the map →

Called by none

Calls _no_kconfig_repo, import_kconfig_gates, kconfig_space

Checks

  • assert ("PROJ_OMIT_TELEMETRY", KCONFIG_GATE_IFNDEF) in gates

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_a_plain_ifndef_gate_survives_the_include_guard_exclusion → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_a_plain_ifndef_gate_survives_the_include_guard_exclusion → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_a_plain_ifndef_gate_survives_the_include_guard_exclusion → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_a_plain_ifndef_gate_survives_the_include_guard_exclusion → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_plain_ifndef_gate_survives_the_include_guard_exclusion → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_a_plain_ifndef_gate_survives_the_include_guard_exclusion → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_a_plain_ifndef_gate_survives_the_include_guard_exclusion → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_a_plain_ifndef_gate_survives_the_include_guard_exclusion → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_a_plain_ifndef_gate_survives_the_include_guard_exclusion → kconfig_space
REQ-DDB-QUERY-013inferredtest_a_plain_ifndef_gate_survives_the_include_guard_exclusion → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_a_plain_ifndef_gate_survives_the_include_guard_exclusion → import_kconfig_gates → ensure_kconfig_gates_table
Source · 15 lines
def test_a_plain_ifndef_gate_survives_the_include_guard_exclusion(tmp_path: Path) -> None:
    """THE LOAD-BEARING NEGATIVE. Excluding guards must not exclude every `#ifndef`, and
    the case that proves it is not hypothetical: Q2's whole answer rests on
    `#ifndef MBEDTLS_ALLOW_PRIVATE_ACCESS` at `private_access.h:14`, which is an ifndef
    that does NOT define its own symbol and is therefore a real gate. A rule keyed on the
    directive rather than on the self-define would have deleted it, and the deletion would
    have looked like a tidier gate layer.
    """
    root, db = _no_kconfig_repo(tmp_path)
    import_kconfig_gates(db, root)

    gates = {(g.symbol, g.form) for g in kconfig_space(db).gates}
    assert ("PROJ_OMIT_TELEMETRY", KCONFIG_GATE_IFNDEF) in gates

Activity · 4 steps
lines 636–636root, db = _no_kconfig_repo(tmp_path)lines 637–637import_kconfig_gates(db, root)lines 639–639gates = {(g.symbol, g.form) for g in kconfig_space(db).gates}lines 640–640assert ("PROJ_OMIT_TELEMETRY", KCONFIG_GATE_IFNDEF) in gates

test_a_repo_supplied_kconfig_functions_module_is_not_imported

None test_kconfig.test_a_repo_supplied_kconfig_functions_module_is_not_imported(Path tmp_path, pytest.MonkeyPatch monkeypatch)

A repository cannot supply the Python module kconfiglib imports.

tests/test_kconfig.py:1283

Checks

  • assert not marker.exists(), "a module named by KCONFIG_FUNCTIONS was imported and ran"
  • assert [s.name for s in model.symbols] == ["PLAIN"], ("the ordinary parse must still work with the environment replaced" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_a_repo_supplied_kconfig_functions_module_is_not_imported → discover_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_a_repo_supplied_kconfig_functions_module_is_not_imported → load_kconfig → _served_parse_error
REQ-DDB-QUERY-006catalog
Source · 32 lines
def test_a_repo_supplied_kconfig_functions_module_is_not_imported(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
    """The third vector, which is plain code execution: kconfiglib imports
    `os.getenv("KCONFIG_FUNCTIONS", "kconfigfunctions")` and runs its module body. An
    operator with that variable set — a Zephyr workspace sets it — pointed at a tree clew
    then indexed is the reachable case, and `sys.path` carrying the cwd is the other.

    @brief An operator-set or repo-dropped functions module never runs.
    @return None.
    @version 1
    """
    monkeypatch.setenv("KCONFIG_FUNCTIONS", "clew_test_hostile_kconfig_functions")
    monkeypatch.syspath_prepend(str(tmp_path))
    marker = tmp_path / "functions_ran"
    (tmp_path / "clew_test_hostile_kconfig_functions.py").write_text(
        f"from pathlib import Path\nPath({str(marker)!r}).write_text('ran')\nfunctions = {{}}\n",
        encoding="utf-8",
    )

    repo = tmp_path / "repo"
    repo.mkdir()
    (repo / KCONFIG_NAME).write_text('config PLAIN\n\tbool "plain"\n', encoding="utf-8")

    model = load_kconfig(discover_kconfig(repo, {}), repo)

    assert not marker.exists(), "a module named by KCONFIG_FUNCTIONS was imported and ran"
    assert [s.name for s in model.symbols] == ["PLAIN"], (
        "the ordinary parse must still work with the environment replaced"
    )

Activity · 10 steps
lines 1295–1295monkeypatch.setenv("KCONFIG_FUNCTIONS", "clew_test_hostile_kconfig_functions")lines 1296–1296monkeypatch.syspath_prepend(str(tmp_path))lines 1297–1297marker = tmp_path / "functions_ran"lines 1298–1301(tmp_path / "clew_test_hostile_kconfig_functions.py").write_text( f"from pathlib import Path\nPath({str(marker)!r}).write_text('ran')\nfunctions = {{}}\n", encoding="utf-8", )lines 1303–1303repo = tmp_path / "repo"lines 1304–1304repo.mkdir()lines 1305–1305(repo / KCONFIG_NAME).write_text('config PLAIN\n\tbool "plain"\n', encoding="utf-8")lines 1307–1307model = load_kconfig(discover_kconfig(repo, {}), repo)lines 1309–1309assert not marker.exists(), "a module named by KCONFIG_FUNCTIONS was imported and ran"lines 1310–1312assert [s.name for s in model.symbols] == ["PLAIN"], ( "the ordinary parse must still work with the environment replaced" )

test_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer

None test_kconfig.test_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer(Path tmp_path)

THE MEASURED DEFECT (gh#390). The harvest matched one hardcoded prefix, `CONFIG_`, justified as reading Kconfig's own universal convention. True for a Kconfig repo, and it made the layer INERT on the dominant C convention: on mbedtls — 500 files whose entire question is "what is compiled in" — `kconfig_gates` existed with exactly the right columns and held ZERO rows, so `search("MBEDTLS_THREADING_PTHREAD")` returned a confident empty result nine times across one benchmark run.

tests/test_kconfig.py:513

Show on the map →

Called by none

Calls _no_kconfig_repo, import_kconfig_gates, kconfig_space

Checks

  • assert import_kconfig_gates(db, root) > 0
  • assert ("PROJ_THREADING_C", KCONFIG_GATE_IF_EXPR) in gates
  • assert ("PROJ_THREADING_PTHREAD", KCONFIG_GATE_IF_EXPR) in gates
  • assert ("PROJ_LEGACY", KCONFIG_GATE_IFDEF) in gates

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → kconfig_space
REQ-DDB-QUERY-013inferredtest_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → import_kconfig_gates → ensure_kconfig_gates_table
Source · 21 lines
def test_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer(tmp_path: Path) -> None:
    """THE MEASURED DEFECT (gh#390). The harvest matched one hardcoded prefix, `CONFIG_`,
    justified as reading Kconfig's own universal convention. True for a Kconfig repo, and
    it made the layer INERT on the dominant C convention: on mbedtls — 500 files whose
    entire question is "what is compiled in" — `kconfig_gates` existed with exactly the
    right columns and held ZERO rows, so `search("MBEDTLS_THREADING_PTHREAD")` returned a
    confident empty result nine times across one benchmark run.

    A prefix that decides what is HARVESTED is a hardcoded assumption about a target's
    shape, which this project forbids. A prefix that decides how a row is LABELLED is a
    reading of a declaration, which it requires.
    """
    root, db = _no_kconfig_repo(tmp_path)
    assert import_kconfig_gates(db, root) > 0

    gates = {(g.symbol, g.form) for g in kconfig_space(db).gates}
    assert ("PROJ_THREADING_C", KCONFIG_GATE_IF_EXPR) in gates
    assert ("PROJ_THREADING_PTHREAD", KCONFIG_GATE_IF_EXPR) in gates
    assert ("PROJ_LEGACY", KCONFIG_GATE_IFDEF) in gates

Activity · 6 steps
lines 525–525root, db = _no_kconfig_repo(tmp_path)lines 526–526assert import_kconfig_gates(db, root) > 0lines 528–528gates = {(g.symbol, g.form) for g in kconfig_space(db).gates}lines 529–529assert ("PROJ_THREADING_C", KCONFIG_GATE_IF_EXPR) in gateslines 530–530assert ("PROJ_THREADING_PTHREAD", KCONFIG_GATE_IF_EXPR) in gateslines 531–531assert ("PROJ_LEGACY", KCONFIG_GATE_IFDEF) in gates

test_a_repo_with_no_kconfig_is_completely_unaffected

None test_kconfig.test_a_repo_with_no_kconfig_is_completely_unaffected(Path tmp_path)

The whole change must be inert for every existing target: no table created, no prose chunk, no `kconfig.*` row, and an honest `found: false` from the query layer.

tests/test_kconfig.py:722

Checks

  • assert model.as_meta() == {}, "a repo with no Kconfig must stamp no kconfig.* row"
  • assert "kconfig_symbols" not in tables
  • assert "kconfig_choices" not in tables
  • assert not any(key.startswith("kconfig.") for key in metas)
  • assert space.found is False
  • assert space.symbols == ()
  • assert space.error == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_a_repo_with_no_kconfig_is_completely_unaffected → import_kconfig
REQ-DDB-CONFIG-006measuredtest_a_repo_with_no_kconfig_is_completely_unaffected → write_build_signature
REQ-DDB-CONFIG-007measuredtest_a_repo_with_no_kconfig_is_completely_unaffected → write_build_signature
REQ-DDB-PIPE-005measuredtest_a_repo_with_no_kconfig_is_completely_unaffected → write_build_signature
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014catalogtest_a_repo_with_no_kconfig_is_completely_unaffected → import_kconfig → load_kconfig → _served_parse_error
REQ-DDB-QUERY-001measuredtest_a_repo_with_no_kconfig_is_completely_unaffected → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_a_repo_with_no_kconfig_is_completely_unaffected → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_a_repo_with_no_kconfig_is_completely_unaffected → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_a_repo_with_no_kconfig_is_completely_unaffected → kconfig_space
REQ-DDB-QUERY-013inferredtest_a_repo_with_no_kconfig_is_completely_unaffected → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-013inferredtest_a_repo_with_no_kconfig_is_completely_unaffected → import_kconfig → store_kconfig → ensure_kconfig_tables
Source · 28 lines
def test_a_repo_with_no_kconfig_is_completely_unaffected(tmp_path: Path) -> None:
    """The whole change must be inert for every existing target: no table created, no
    prose chunk, no `kconfig.*` row, and an honest `found: false` from the query
    layer."""
    root = tmp_path / "plain"
    (root / "src").mkdir(parents=True)
    (root / "src" / "main.c").write_text("int main(void) { return 0; }\n", encoding="utf-8")
    db = tmp_path / "clew.db"
    _db_with_paths(db, ("src/main.c",))

    model = import_kconfig(db, root, None)
    write_build_signature(db, kconfig=model.as_meta())

    assert model.as_meta() == {}, "a repo with no Kconfig must stamp no kconfig.* row"
    conn = sqlite3.connect(str(db))
    tables = {row[0] for row in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")}
    metas = {row[0] for row in conn.execute("SELECT key FROM build_meta")}
    conn.close()
    assert "kconfig_symbols" not in tables
    assert "kconfig_choices" not in tables
    assert not any(key.startswith("kconfig.") for key in metas)

    space = kconfig_space(db)
    assert space.found is False
    assert space.symbols == ()
    assert space.error == ""

Activity · 19 steps
lines 726–726root = tmp_path / "plain"lines 727–727(root / "src").mkdir(parents=True)lines 728–728(root / "src" / "main.c").write_text("int main(void) { return 0; }\n", encoding="utf-8")lines 729–729db = tmp_path / "clew.db"lines 730–730_db_with_paths(db, ("src/main.c",))lines 732–732model = import_kconfig(db, root, None)lines 733–733write_build_signature(db, kconfig=model.as_meta())lines 735–735assert model.as_meta() == {}, "a repo with no Kconfig must stamp no kconfig.* row"lines 736–736conn = sqlite3.connect(str(db))lines 737–737tables = {row[0] for row in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")}lines 738–738metas = {row[0] for row in conn.execute("SELECT key FROM build_meta")}lines 739–739conn.close()lines 740–740assert "kconfig_symbols" not in tableslines 741–741assert "kconfig_choices" not in tableslines 742–742assert not any(key.startswith("kconfig.") for key in metas)lines 744–744space = kconfig_space(db)lines 745–745assert space.found is Falselines 746–746assert space.symbols == ()lines 747–747assert space.error == ""

test_a_runtime_is_enabled_branch_is_not_a_gate

None test_kconfig.test_a_runtime_is_enabled_branch_is_not_a_gate(Path repo, Path tmp_path)

`if (IS_ENABLED(CONFIG_X))` in ordinary C is compiled either way. Recording it as gating would tell a reader that removing the symbol removes the function.

tests/test_kconfig.py:371

Show on the map →

Called by none

Calls _db_with_paths, all, import_kconfig_gates, kconfig_space

Checks

  • assert all(g.line != runtime_line for g in kconfig_space(db).gates)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_a_runtime_is_enabled_branch_is_not_a_gate → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_a_runtime_is_enabled_branch_is_not_a_gate → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_a_runtime_is_enabled_branch_is_not_a_gate → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_a_runtime_is_enabled_branch_is_not_a_gate → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_runtime_is_enabled_branch_is_not_a_gate → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_a_runtime_is_enabled_branch_is_not_a_gate → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_a_runtime_is_enabled_branch_is_not_a_gate → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_a_runtime_is_enabled_branch_is_not_a_gate → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_a_runtime_is_enabled_branch_is_not_a_gate → kconfig_space
REQ-DDB-QUERY-013inferredtest_a_runtime_is_enabled_branch_is_not_a_gate → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_a_runtime_is_enabled_branch_is_not_a_gate → import_kconfig_gates → ensure_kconfig_gates_table
REQ-DDB-WIKI-054inferredtest_a_runtime_is_enabled_branch_is_not_a_gate → all
Source · 19 lines
def test_a_runtime_is_enabled_branch_is_not_a_gate(repo: Path, tmp_path: Path) -> None:
    """`if (IS_ENABLED(CONFIG_X))` in ordinary C is compiled either way. Recording it
    as gating would tell a reader that removing the symbol removes the function.

    Asserted by LINE, because `CONFIG_WIDGET_RADIO` legitimately has a gate elsewhere
    in the same file — a symbol-level assertion would pass while the bug was present."""
    db = tmp_path / "clew.db"
    _db_with_paths(db, ("src/motor.c",))
    import_kconfig_gates(db, repo)

    lines = (repo / "src" / "motor.c").read_text(encoding="utf-8").splitlines()
    runtime_line = next(
        i + 1
        for i, text in enumerate(lines)
        if "IS_ENABLED" in text and text.lstrip().startswith("if (")
    )
    assert all(g.line != runtime_line for g in kconfig_space(db).gates)

Activity · 6 steps
lines 377–377db = tmp_path / "clew.db"lines 378–378_db_with_paths(db, ("src/motor.c",))lines 379–379import_kconfig_gates(db, repo)lines 381–381lines = (repo / "src" / "motor.c").read_text(encoding="utf-8").splitlines()lines 382–386runtime_line = next( i + 1 for i, text in enumerate(lines) if "IS_ENABLED" in text and text.lstrip().startswith("if (") )lines 387–387assert all(g.line != runtime_line for g in kconfig_space(db).gates)

test_a_single_conventional_candidate_is_accepted

None test_kconfig.test_a_single_conventional_candidate_is_accepted(Path tmp_path)

The refusal above must not be a refusal to look. One candidate is not ambiguous, and a fixture that only ever tests the refusal would pass with discovery hard-wired to None.

tests/test_kconfig.py:151

Checks

  • assert discover_kconfig(root).path == Path("app/Kconfig")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_a_single_conventional_candidate_is_accepted → discover_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014catalogtest_a_single_conventional_candidate_is_accepted → discover_kconfig → _declared_kconfig → within_repo
REQ-DDB-QUERY-006catalog
Source · 11 lines
def test_a_single_conventional_candidate_is_accepted(tmp_path: Path) -> None:
    """The refusal above must not be a refusal to look. One candidate is not
    ambiguous, and a fixture that only ever tests the refusal would pass with
    discovery hard-wired to None."""
    root = tmp_path / "app_only"
    (root / "app").mkdir(parents=True)
    (root / "app" / KCONFIG_NAME).write_text("config A\n\tbool\n", encoding="utf-8")

    assert discover_kconfig(root).path == Path("app/Kconfig")

Activity · 4 steps
lines 155–155root = tmp_path / "app_only"lines 156–156(root / "app").mkdir(parents=True)lines 157–157(root / "app" / KCONFIG_NAME).write_text("config A\n\tbool\n", encoding="utf-8")lines 159–159assert discover_kconfig(root).path == Path("app/Kconfig")

test_a_sourced_file_is_parsed_and_choices_group_their_members

None test_kconfig.test_a_sourced_file_is_parsed_and_choices_group_their_members(Path repo)

`source "Kconfig.motor"` is where a single-file fixture would have passed while the real path was broken, so the two grouped variants live there.

tests/test_kconfig.py:196

Checks

  • assert model.error == "", model.error
  • assert {"WIDGET_MOTOR_ALPHA", "WIDGET_MOTOR_BETA", "WIDGET_LOG_LEVEL"} <= set(by_name)
  • assert alpha.choice_key is not None
  • assert alpha.choice_key == beta.choice_key
  • assert by_name["WIDGET_LOG_LEVEL"].choice_key is None, "an ungrouped symbol has no group"
  • assert len(model.choices) == 1
  • assert model.choices[0].prompt == "Motor variant"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_a_sourced_file_is_parsed_and_choices_group_their_members → discover_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_a_sourced_file_is_parsed_and_choices_group_their_members → load_kconfig → _served_parse_error
REQ-DDB-QUERY-006catalog
Source · 20 lines
def test_a_sourced_file_is_parsed_and_choices_group_their_members(repo: Path) -> None:
    """`source "Kconfig.motor"` is where a single-file fixture would have passed while
    the real path was broken, so the two grouped variants live there.

    Both members must share ONE choice key. `choice` semantics are the point: exactly
    one member is selected, so a consumer that reads them as independent features will
    describe two mutually exclusive variants as both present."""
    model = load_kconfig(discover_kconfig(repo), repo)
    assert model.error == "", model.error
    by_name = {sym.name: sym for sym in model.symbols}

    assert {"WIDGET_MOTOR_ALPHA", "WIDGET_MOTOR_BETA", "WIDGET_LOG_LEVEL"} <= set(by_name)
    alpha, beta = by_name["WIDGET_MOTOR_ALPHA"], by_name["WIDGET_MOTOR_BETA"]
    assert alpha.choice_key is not None
    assert alpha.choice_key == beta.choice_key
    assert by_name["WIDGET_LOG_LEVEL"].choice_key is None, "an ungrouped symbol has no group"
    assert len(model.choices) == 1
    assert model.choices[0].prompt == "Motor variant"

Activity · 10 steps
lines 203–203model = load_kconfig(discover_kconfig(repo), repo)lines 204–204assert model.error == "", model.errorlines 205–205by_name = {sym.name: sym for sym in model.symbols}lines 207–207assert {"WIDGET_MOTOR_ALPHA", "WIDGET_MOTOR_BETA", "WIDGET_LOG_LEVEL"} <= set(by_name)lines 208–208alpha, beta = by_name["WIDGET_MOTOR_ALPHA"], by_name["WIDGET_MOTOR_BETA"]lines 209–209assert alpha.choice_key is not Nonelines 210–210assert alpha.choice_key == beta.choice_keylines 211–211assert by_name["WIDGET_LOG_LEVEL"].choice_key is None, "an ungrouped symbol has no group"lines 212–212assert len(model.choices) == 1lines 213–213assert model.choices[0].prompt == "Motor variant"

test_an_include_guard_is_not_a_configuration_gate

None test_kconfig.test_an_include_guard_is_not_a_configuration_gate(Path tmp_path)

DETECTED BY STRUCTURE, NOT BY A `_H` SUFFIX. `#ifndef FOO_H` / `#define FOO_H` tests a symbol the very next line defines, which no configuration gate ever does — a config gate reads a symbol somebody else set. Widening the harvest past `CONFIG_` (gh#390) admitted these, and once they reached `search` (gh#394) they ranked EXACT on their own names: 10 of 10 gating symbols in this repo's C fixture were guards.

tests/test_kconfig.py:609

Show on the map →

Called by none

Calls _no_kconfig_repo, import_kconfig_gates, kconfig_space

Checks

  • assert "PROJ_WIDGET_H" not in symbols
  • assert "PROJ_GUARD_WITHOUT_H_SUFFIX" not in symbols, "the suffix is not the rule"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_an_include_guard_is_not_a_configuration_gate → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_an_include_guard_is_not_a_configuration_gate → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_an_include_guard_is_not_a_configuration_gate → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_an_include_guard_is_not_a_configuration_gate → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_an_include_guard_is_not_a_configuration_gate → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_an_include_guard_is_not_a_configuration_gate → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_an_include_guard_is_not_a_configuration_gate → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_an_include_guard_is_not_a_configuration_gate → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_an_include_guard_is_not_a_configuration_gate → kconfig_space
REQ-DDB-QUERY-013inferredtest_an_include_guard_is_not_a_configuration_gate → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_an_include_guard_is_not_a_configuration_gate → import_kconfig_gates → ensure_kconfig_gates_table
Source · 19 lines
def test_an_include_guard_is_not_a_configuration_gate(tmp_path: Path) -> None:
    """DETECTED BY STRUCTURE, NOT BY A `_H` SUFFIX. `#ifndef FOO_H` / `#define FOO_H` tests
    a symbol the very next line defines, which no configuration gate ever does — a config
    gate reads a symbol somebody else set. Widening the harvest past `CONFIG_` (gh#390)
    admitted these, and once they reached `search` (gh#394) they ranked EXACT on their own
    names: 10 of 10 gating symbols in this repo's C fixture were guards.

    THE SUFFIX RULE WOULD HAVE BEEN WRONG, measured on mbedtls: the structural rule removed
    220 symbols where a `_H`-suffix count found only 201, so 19 real guards do not end in
    `_H`. `PROJ_GUARD_WITHOUT_H_SUFFIX` is that case in fixture form.
    """
    root, db = _no_kconfig_repo(tmp_path)
    import_kconfig_gates(db, root)

    symbols = {g.symbol for g in kconfig_space(db).gates}
    assert "PROJ_WIDGET_H" not in symbols
    assert "PROJ_GUARD_WITHOUT_H_SUFFIX" not in symbols, "the suffix is not the rule"

Activity · 5 steps
lines 620–620root, db = _no_kconfig_repo(tmp_path)lines 621–621import_kconfig_gates(db, root)lines 623–623symbols = {g.symbol for g in kconfig_space(db).gates}lines 624–624assert "PROJ_WIDGET_H" not in symbolslines 625–625assert "PROJ_GUARD_WITHOUT_H_SUFFIX" not in symbols, "the suffix is not the rule"

test_an_unambiguous_root_kconfig_is_found_and_stored_repo_relative

None test_kconfig.test_an_unambiguous_root_kconfig_is_found_and_stored_repo_relative(Path repo)

Root first, because an unambiguous root `Kconfig` is the convention every Kconfig build system shares. The path must come back REPO-RELATIVE: `build_meta` is published over MCP, and an absolute path here is the machine-layout disclosure that forced the build-version-9 bump.

tests/test_kconfig.py:124

Checks

  • assert location.source == SOURCE_ROOT
  • assert location.path == Path(KCONFIG_NAME)
  • assert not location.path.is_absolute()
  • assert location.searched, "a discovery that names no locations cannot be audited"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_an_unambiguous_root_kconfig_is_found_and_stored_repo_relative → discover_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014catalogtest_an_unambiguous_root_kconfig_is_found_and_stored_repo_relative → discover_kconfig → _declared_kconfig → within_repo
REQ-DDB-QUERY-006catalog
Source · 12 lines
def test_an_unambiguous_root_kconfig_is_found_and_stored_repo_relative(repo: Path) -> None:
    """Root first, because an unambiguous root `Kconfig` is the convention every
    Kconfig build system shares. The path must come back REPO-RELATIVE: `build_meta`
    is published over MCP, and an absolute path here is the machine-layout disclosure
    that forced the build-version-9 bump."""
    location = discover_kconfig(repo)
    assert location.source == SOURCE_ROOT
    assert location.path == Path(KCONFIG_NAME)
    assert not location.path.is_absolute()
    assert location.searched, "a discovery that names no locations cannot be audited"

Activity · 5 steps
lines 129–129location = discover_kconfig(repo)lines 130–130assert location.source == SOURCE_ROOTlines 131–131assert location.path == Path(KCONFIG_NAME)lines 132–132assert not location.path.is_absolute()lines 133–133assert location.searched, "a discovery that names no locations cannot be audited"

test_configured_macros_carry_their_provenance_and_a_route

None test_kconfig.test_configured_macros_carry_their_provenance_and_a_route()

The configured-macro list must say what it is evidence OF, and route to the default.

tests/test_kconfig.py:1007

Checks

  • assert "STATED BY THE OPERATOR" in stated
  • assert "may well be OFF, or commented out" in stated
  • assert header in stated, "the ROUTE is the point — a disclaimer alone leaves the agent hunting"
  • assert "COMBINES" in mixed
  • assert "STATED BY THE OPERATOR" not in mixed, ("on mbedtls this list is 142/144 read from the repository — claiming the operator stated " "it inverts the disclosure the other way" )
  • assert header in mixed
  • assert "does describe what the repository builds by default" in from_repo
  • assert "not a statement about what the repository" not in from_repo, ("the lead must not contradict the sentence after it" )
  • assert "No config header is recorded" in unknown
  • assert "treat the default as unknown" in unknown
  • assert macros_meaning("", "", "") == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-006measuredtest_configured_macros_carry_their_provenance_and_a_route → macros_meaning
Source · 54 lines
def test_configured_macros_carry_their_provenance_and_a_route() -> None:
    """THE PAYLOAD ARGUED FOR A FALSE ANSWER, which is worse than withholding a true one.

    Measured on Mbed-TLS/mbedtls 2026-08-14. The acceptance build states
    `MBEDTLS_THREADING_C` and `MBEDTLS_THREADING_PTHREAD` as PREDEFINED so doxygen can reach the
    guarded bodies. Every reply then carried
    `configured_macros: "MBEDTLS_THREADING_C" "MBEDTLS_THREADING_PTHREAD"` and labelled all 154
    matching gate rows `origin: "declared"` — while the repository ships both COMMENTED OUT at
    `include/mbedtls/mbedtls_config.h:3787` and `:2196`. Two graded marks ask for exactly that
    shipped state, and both `search(corpus='config')` and `dossier` pointed the other way,
    because they share this payload.

    FOUR STATES, and the MIXED one is the trap that caught my own first version. It said "these
    were STATED BY THE OPERATOR" whenever any statement was involved, which on mbedtls describes
    2 macros out of 144 — the other 142 come from the repository's own header. That inverts the
    disclosure in the opposite direction, inviting a reader to discount the whole list as a build
    artifact. A correction that is wrong the other way is not a correction.

    AND THE LEAD SENTENCE IS CONDITIONAL, because "never a statement about the default" is FALSE
    when the list WAS read from the repository's header, and a note contradicting its own next
    sentence teaches a reader to skip it.
    """
    from clew.query.kconfig import macros_meaning

    header = "include/mbedtls/mbedtls_config.h"

    stated = macros_meaning('"MBEDTLS_THREADING_C"', "declared", header)
    assert "STATED BY THE OPERATOR" in stated
    assert "may well be OFF, or commented out" in stated
    assert header in stated, "the ROUTE is the point — a disclaimer alone leaves the agent hunting"

    mixed = macros_meaning('"A" "B"', "declared+config_header", header)
    assert "COMBINES" in mixed
    assert "STATED BY THE OPERATOR" not in mixed, (
        "on mbedtls this list is 142/144 read from the repository — claiming the operator stated "
        "it inverts the disclosure the other way"
    )
    assert header in mixed

    from_repo = macros_meaning('"A"', "config_header", header)
    assert "does describe what the repository builds by default" in from_repo
    assert "not a statement about what the repository" not in from_repo, (
        "the lead must not contradict the sentence after it"
    )

    ## NO HEADER DECLARED: the default is UNKNOWN, said so, and never implied to be this list.
    unknown = macros_meaning('"A"', "declared", "")
    assert "No config header is recorded" in unknown
    assert "treat the default as unknown" in unknown

    ## NOTHING RECORDED AT ALL stays silent rather than emitting a note about an absent value.
    assert macros_meaning("", "", "") == ""

Activity · 17 steps
lines 1029–1029from clew.query.kconfig import macros_meaninglines 1031–1031header = "include/mbedtls/mbedtls_config.h"lines 1033–1033stated = macros_meaning('"MBEDTLS_THREADING_C"', "declared", header)lines 1034–1034assert "STATED BY THE OPERATOR" in statedlines 1035–1035assert "may well be OFF, or commented out" in statedlines 1036–1036assert header in stated, "the ROUTE is the point — a disclaimer alone leaves the agent hunting"lines 1038–1038mixed = macros_meaning('"A" "B"', "declared+config_header", header)lines 1039–1039assert "COMBINES" in mixedlines 1040–1043assert "STATED BY THE OPERATOR" not in mixed, ( "on mbedtls this list is 142/144 read from the repository — claiming the operator stated " "it inverts the disclosure the other way" )lines 1044–1044assert header in mixedlines 1046–1046from_repo = macros_meaning('"A"', "config_header", header)lines 1047–1047assert "does describe what the repository builds by default" in from_repolines 1048–1050assert "not a statement about what the repository" not in from_repo, ( "the lead must not contradict the sentence after it" )lines 1053–1053unknown = macros_meaning('"A"', "declared", "")lines 1054–1054assert "No config header is recorded" in unknownlines 1055–1055assert "treat the default as unknown" in unknownlines 1058–1058assert macros_meaning("", "", "") == ""

test_convention_refuses_among_several_candidates

None test_kconfig.test_convention_refuses_among_several_candidates(Path tmp_path)

`discover_doxyfile` was once caught selecting a TEST FIXTURE's Doxyfile to index a whole project by resolving strays alphabetically. Here the wrong choice describes a configuration space the repo does not ship, and every count taken from it looks legitimate — so ambiguity refuses.

tests/test_kconfig.py:136

Checks

  • assert location.path is None, "two conventional candidates must not be resolved by order"
  • assert len(location.searched) > 1

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_convention_refuses_among_several_candidates → discover_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014catalogtest_convention_refuses_among_several_candidates → discover_kconfig → _declared_kconfig → within_repo
REQ-DDB-QUERY-006catalog
Source · 15 lines
def test_convention_refuses_among_several_candidates(tmp_path: Path) -> None:
    """`discover_doxyfile` was once caught selecting a TEST FIXTURE's Doxyfile to index
    a whole project by resolving strays alphabetically. Here the wrong choice describes
    a configuration space the repo does not ship, and every count taken from it looks
    legitimate — so ambiguity refuses."""
    root = tmp_path / "ambiguous"
    for directory in ("app", "src"):
        (root / directory).mkdir(parents=True)
        (root / directory / KCONFIG_NAME).write_text("config A\n\tbool\n", encoding="utf-8")

    location = discover_kconfig(root)
    assert location.path is None, "two conventional candidates must not be resolved by order"
    assert len(location.searched) > 1

Activity · 7 steps
lines 141–141root = tmp_path / "ambiguous"lines 142–142◇ for directory in ("app", "src")lines 143–143(root / directory).mkdir(parents=True)lines 144–144(root / directory / KCONFIG_NAME).write_text("config A\n\tbool\n", encoding="utf-8")lines 146–146location = discover_kconfig(root)lines 147–147assert location.path is None, "two conventional candidates must not be resolved by order"lines 148–148assert len(location.searched) > 1

test_declared_macro_names_drops_the_value_half

None test_kconfig.test_declared_macro_names_drops_the_value_half(Path tmp_path)

PREDEFINED entries carry an optional `=value`, and comparing raw strings would classify every valued macro as undeclared — silently, on the exact repos that bother to declare one.

tests/test_kconfig.py:691

Show on the map →

Called by none

Calls declared_macro_names

Checks

  • assert declared_macro_names(["A", "B=1", " C = 2 ", ""]) == frozenset({"A", "B", "C"})
  • assert declared_macro_names(['"PROBE_DECLARED"', '"WITH_VALUE=1"']) == frozenset({"PROBE_DECLARED", "WITH_VALUE"} ), "the RENDERED doxygen shape is what the pipeline passes; the bare shape never reaches it"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_declared_macro_names_drops_the_value_half → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-006catalog
Source · 31 lines
def test_declared_macro_names_drops_the_value_half(tmp_path: Path) -> None:
    """PREDEFINED entries carry an optional `=value`, and comparing raw strings would
    classify every valued macro as undeclared — silently, on the exact repos that bother
    to declare one.

    THE QUOTED SHAPE IS THE ONE THAT MATTERED, AND THIS TEST USED TO OMIT IT. `macros` holds
    ALREADY-RENDERED doxygen tokens — `'"NAME"'`, quotes included, because rendering the Doxyfile
    is what they were built for — and this function stripped the value while leaving the quotes.
    So `'"PROBE_DECLARED"'` matched no bare symbol and EVERY macro a build actually declared was
    labelled `undeclared`: `kconfig_gates.origin` reported an entire configuration as absent from
    the build that declared it.

    It survived because the case above is the only one this test asserted — unquoted inputs that
    the pipeline never produces. That is the recorded shape "the fixture matched the detector
    rather than the world", and no mutation control could have caught it either, because a
    mutation control tests the code against its fixtures while only a real build tests the
    fixtures. What found it was an integration control asking ONE build to distinguish a
    satisfied gate from an unsatisfied one.

    The function now delegates to `preprocessor.bare_macro_names`, so both assertions below
    exercise the single shared spelling.
    """
    assert declared_macro_names(["A", "B=1", " C = 2 ", ""]) == frozenset({"A", "B", "C"})
    assert declared_macro_names(['"PROBE_DECLARED"', '"WITH_VALUE=1"']) == frozenset(
        {"PROBE_DECLARED", "WITH_VALUE"}
    ), "the RENDERED doxygen shape is what the pipeline passes; the bare shape never reaches it"


# ─── part 5: provenance, and the three ways to be empty ─────────────────────

Activity · 2 steps
lines 713–713assert declared_macro_names(["A", "B=1", " C = 2 ", ""]) == frozenset({"A", "B", "C"})lines 714–716assert declared_macro_names(['"PROBE_DECLARED"', '"WITH_VALUE=1"']) == frozenset( {"PROBE_DECLARED", "WITH_VALUE"} ), "the RENDERED doxygen shape is what the pipeline passes; the bare shape never reaches it"

test_defined_is_an_operator_and_never_a_gating_symbol

None test_kconfig.test_defined_is_an_operator_and_never_a_gating_symbol(Path tmp_path)

`defined` appears in nearly every `#if` a C repository writes, so harvesting it would put one meaningless symbol at the top of every gate query by sheer frequency — and it is an operator, not a name anybody can set.

tests/test_kconfig.py:534

Show on the map →

Called by none

Calls _no_kconfig_repo, import_kconfig_gates, kconfig_space

Checks

  • assert "defined" not in {g.symbol for g in kconfig_space(db).gates}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_defined_is_an_operator_and_never_a_gating_symbol → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_defined_is_an_operator_and_never_a_gating_symbol → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_defined_is_an_operator_and_never_a_gating_symbol → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_defined_is_an_operator_and_never_a_gating_symbol → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_defined_is_an_operator_and_never_a_gating_symbol → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_defined_is_an_operator_and_never_a_gating_symbol → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_defined_is_an_operator_and_never_a_gating_symbol → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_defined_is_an_operator_and_never_a_gating_symbol → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_defined_is_an_operator_and_never_a_gating_symbol → kconfig_space
REQ-DDB-QUERY-013inferredtest_defined_is_an_operator_and_never_a_gating_symbol → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_defined_is_an_operator_and_never_a_gating_symbol → import_kconfig_gates → ensure_kconfig_gates_table
Source · 10 lines
def test_defined_is_an_operator_and_never_a_gating_symbol(tmp_path: Path) -> None:
    """`defined` appears in nearly every `#if` a C repository writes, so harvesting it
    would put one meaningless symbol at the top of every gate query by sheer frequency —
    and it is an operator, not a name anybody can set.
    """
    root, db = _no_kconfig_repo(tmp_path)
    import_kconfig_gates(db, root)
    assert "defined" not in {g.symbol for g in kconfig_space(db).gates}

Activity · 3 steps
lines 539–539root, db = _no_kconfig_repo(tmp_path)lines 540–540import_kconfig_gates(db, root)lines 541–541assert "defined" not in {g.symbol for g in kconfig_space(db).gates}

test_gate_counts_reach_the_symbol_rows

None test_kconfig.test_gate_counts_reach_the_symbol_rows(Path repo, Path tmp_path)

A symbol that gates nothing must arrive as 0 rather than as an absence a caller has to interpret.

tests/test_kconfig.py:404

Checks

  • assert by_name["WIDGET_MOTOR_BETA"].gate_count == 1
  • assert by_name["WIDGET_MOTOR_NAME"].gate_count == 0

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_gate_counts_reach_the_symbol_rows → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005measuredtest_gate_counts_reach_the_symbol_rows → import_kconfig
REQ-DDB-CONFIG-006measuredtest_gate_counts_reach_the_symbol_rows → write_build_signature
REQ-DDB-CONFIG-007measuredtest_gate_counts_reach_the_symbol_rows → write_build_signature
REQ-DDB-PIPE-003measuredtest_gate_counts_reach_the_symbol_rows → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-005measuredtest_gate_counts_reach_the_symbol_rows → write_build_signature
REQ-DDB-PIPE-007measuredtest_gate_counts_reach_the_symbol_rows → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_gate_counts_reach_the_symbol_rows → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_gate_counts_reach_the_symbol_rows → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014measuredtest_gate_counts_reach_the_symbol_rows → import_kconfig → load_kconfig → _served_parse_error
REQ-DDB-QUERY-001measuredtest_gate_counts_reach_the_symbol_rows → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_gate_counts_reach_the_symbol_rows → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_gate_counts_reach_the_symbol_rows → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_gate_counts_reach_the_symbol_rows → kconfig_space
REQ-DDB-QUERY-013inferredtest_gate_counts_reach_the_symbol_rows → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_gate_counts_reach_the_symbol_rows → import_kconfig_gates → ensure_kconfig_gates_table
Source · 16 lines
def test_gate_counts_reach_the_symbol_rows(repo: Path, tmp_path: Path) -> None:
    """A symbol that gates nothing must arrive as 0 rather than as an absence a caller
    has to interpret."""
    db = tmp_path / "clew.db"
    _db_with_paths(db, ("src/motor.c",))
    model = import_kconfig(db, repo, None)
    import_kconfig_gates(db, repo)
    write_build_signature(db, kconfig=model.as_meta())

    by_name = {s.name: s for s in kconfig_space(db).symbols}
    assert by_name["WIDGET_MOTOR_BETA"].gate_count == 1
    assert by_name["WIDGET_MOTOR_NAME"].gate_count == 0


# ─── part 4: the gate harvest is not Kconfig-only (gh#390) ──────────────────
Activity · 8 steps
lines 407–407db = tmp_path / "clew.db"lines 408–408_db_with_paths(db, ("src/motor.c",))lines 409–409model = import_kconfig(db, repo, None)lines 410–410import_kconfig_gates(db, repo)lines 411–411write_build_signature(db, kconfig=model.as_meta())lines 413–413by_name = {s.name: s for s in kconfig_space(db).symbols}lines 414–414assert by_name["WIDGET_MOTOR_BETA"].gate_count == 1lines 415–415assert by_name["WIDGET_MOTOR_NAME"].gate_count == 0

test_gating_sites_record_the_form_and_the_line

None test_kconfig.test_gating_sites_record_the_form_and_the_line(Path repo, Path tmp_path)

`ifndef` must NOT be filed as `ifdef`. The C and C++ grammars use ONE node type for both directives, so the sense lives only in the leading token — and a consumer told the wrong one describes the variant exactly backwards.

tests/test_kconfig.py:337

Show on the map →

Called by none

Calls _db_with_paths, import_kconfig_gates, kconfig_space

Checks

  • assert import_kconfig_gates(db, repo) > 0
  • assert ("WIDGET_MOTOR_BETA", KCONFIG_GATE_IFDEF) in gates
  • assert ("WIDGET_RADIO", KCONFIG_GATE_IFNDEF) in gates
  • assert ("WIDGET_MOTOR_ALPHA", KCONFIG_GATE_IF_EXPR) in gates
  • assert ("WIDGET_RADIO", KCONFIG_GATE_IFDEF) not in gates, ("the #ifndef site was recorded with the opposite sense" )
  • assert beta.file_path == "src/motor.c"
  • assert beta.macro == "CONFIG_WIDGET_MOTOR_BETA"
  • assert "CONFIG_WIDGET_MOTOR_BETA" in text[beta.line - 1], "the recorded line is wrong"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_gating_sites_record_the_form_and_the_line → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_gating_sites_record_the_form_and_the_line → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_gating_sites_record_the_form_and_the_line → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_gating_sites_record_the_form_and_the_line → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_gating_sites_record_the_form_and_the_line → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_gating_sites_record_the_form_and_the_line → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_gating_sites_record_the_form_and_the_line → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_gating_sites_record_the_form_and_the_line → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_gating_sites_record_the_form_and_the_line → kconfig_space
REQ-DDB-QUERY-013inferredtest_gating_sites_record_the_form_and_the_line → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_gating_sites_record_the_form_and_the_line → import_kconfig_gates → ensure_kconfig_gates_table
Source · 23 lines
def test_gating_sites_record_the_form_and_the_line(repo: Path, tmp_path: Path) -> None:
    """`ifndef` must NOT be filed as `ifdef`. The C and C++ grammars use ONE node type
    for both directives, so the sense lives only in the leading token — and a consumer
    told the wrong one describes the variant exactly backwards."""
    db = tmp_path / "clew.db"
    _db_with_paths(db, ("src/motor.c",))
    assert import_kconfig_gates(db, repo) > 0

    gates = {(g.symbol, g.form) for g in kconfig_space(db).gates}
    assert ("WIDGET_MOTOR_BETA", KCONFIG_GATE_IFDEF) in gates
    assert ("WIDGET_RADIO", KCONFIG_GATE_IFNDEF) in gates
    assert ("WIDGET_MOTOR_ALPHA", KCONFIG_GATE_IF_EXPR) in gates
    assert ("WIDGET_RADIO", KCONFIG_GATE_IFDEF) not in gates, (
        "the #ifndef site was recorded with the opposite sense"
    )

    beta = next(g for g in kconfig_space(db).gates if g.symbol == "WIDGET_MOTOR_BETA")
    assert beta.file_path == "src/motor.c"
    assert beta.macro == "CONFIG_WIDGET_MOTOR_BETA"
    text = (repo / "src" / "motor.c").read_text(encoding="utf-8").splitlines()
    assert "CONFIG_WIDGET_MOTOR_BETA" in text[beta.line - 1], "the recorded line is wrong"

Activity · 13 steps
lines 341–341db = tmp_path / "clew.db"lines 342–342_db_with_paths(db, ("src/motor.c",))lines 343–343assert import_kconfig_gates(db, repo) > 0lines 345–345gates = {(g.symbol, g.form) for g in kconfig_space(db).gates}lines 346–346assert ("WIDGET_MOTOR_BETA", KCONFIG_GATE_IFDEF) in gateslines 347–347assert ("WIDGET_RADIO", KCONFIG_GATE_IFNDEF) in gateslines 348–348assert ("WIDGET_MOTOR_ALPHA", KCONFIG_GATE_IF_EXPR) in gateslines 349–351assert ("WIDGET_RADIO", KCONFIG_GATE_IFDEF) not in gates, ( "the #ifndef site was recorded with the opposite sense" )lines 353–353beta = next(g for g in kconfig_space(db).gates if g.symbol == "WIDGET_MOTOR_BETA")lines 354–354assert beta.file_path == "src/motor.c"lines 355–355assert beta.macro == "CONFIG_WIDGET_MOTOR_BETA"lines 356–356text = (repo / "src" / "motor.c").read_text(encoding="utf-8").splitlines()lines 357–357assert "CONFIG_WIDGET_MOTOR_BETA" in text[beta.line - 1], "the recorded line is wrong"

test_kconfig_prose_must_be_ingested_after_the_markdown_ingest

None test_kconfig.test_kconfig_prose_must_be_ingested_after_the_markdown_ingest(Path repo, Path tmp_path)

`ingest_supplementary_docs` DROPs and recreates `supplementary_docs` on every build. This pins the ORDER the pipeline depends on by demonstrating the failure: run the Kconfig ingest first and its rows are deleted, with no error anywhere.

tests/test_kconfig.py:309

Checks

  • assert ingest_kconfig_prose(wrong, model) > 0
  • assert search_prose(wrong, HELP_ONLY_PHRASE) == [], ("if this finds the phrase the ordering hazard has gone and this test is stale" )
  • assert search_prose(right, HELP_ONLY_PHRASE), "the pipeline's own order must work"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_kconfig_prose_must_be_ingested_after_the_markdown_ingest → discover_kconfig
REQ-DDB-INDEX-002inferredtest_kconfig_prose_must_be_ingested_after_the_markdown_ingest → ingest_supplementary_docs → _ingest_one_doc_file → memoized
REQ-DDB-PIPE-001measuredtest_kconfig_prose_must_be_ingested_after_the_markdown_ingest → ingest_supplementary_docs
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_kconfig_prose_must_be_ingested_after_the_markdown_ingest → load_kconfig → _served_parse_error
REQ-DDB-QUERY-001measuredtest_kconfig_prose_must_be_ingested_after_the_markdown_ingest → search_prose
REQ-DDB-QUERY-003measuredtest_kconfig_prose_must_be_ingested_after_the_markdown_ingest → search_prose → search_prose_graded → table_exists
REQ-DDB-QUERY-006catalog
REQ-DDB-QUERY-007measuredtest_kconfig_prose_must_be_ingested_after_the_markdown_ingest → search_prose → search_prose_graded → member_doc_rows
Source · 28 lines
def test_kconfig_prose_must_be_ingested_after_the_markdown_ingest(
    repo: Path, tmp_path: Path
) -> None:
    """`ingest_supplementary_docs` DROPs and recreates `supplementary_docs` on every
    build. This pins the ORDER the pipeline depends on by demonstrating the failure:
    run the Kconfig ingest first and its rows are deleted, with no error anywhere.

    That is the quietest possible failure mode, so it is asserted rather than left to
    a comment in `cli.py`."""
    wrong = tmp_path / "wrong.db"
    _db_with_paths(wrong, ())
    model = load_kconfig(discover_kconfig(repo), repo)
    assert ingest_kconfig_prose(wrong, model) > 0
    ingest_supplementary_docs(wrong, repo)
    assert search_prose(wrong, HELP_ONLY_PHRASE) == [], (
        "if this finds the phrase the ordering hazard has gone and this test is stale"
    )

    right = tmp_path / "right.db"
    _db_with_paths(right, ())
    ingest_supplementary_docs(right, repo)
    ingest_kconfig_prose(right, model)
    assert search_prose(right, HELP_ONLY_PHRASE), "the pipeline's own order must work"


# ─── part 3: symbol → file:line ──────────────────────────────────────────────

Activity · 11 steps
lines 318–318wrong = tmp_path / "wrong.db"lines 319–319_db_with_paths(wrong, ())lines 320–320model = load_kconfig(discover_kconfig(repo), repo)lines 321–321assert ingest_kconfig_prose(wrong, model) > 0lines 322–322ingest_supplementary_docs(wrong, repo)lines 323–325assert search_prose(wrong, HELP_ONLY_PHRASE) == [], ( "if this finds the phrase the ordering hazard has gone and this test is stale" )lines 327–327right = tmp_path / "right.db"lines 328–328_db_with_paths(right, ())lines 329–329ingest_supplementary_docs(right, repo)lines 330–330ingest_kconfig_prose(right, model)lines 331–331assert search_prose(right, HELP_ONLY_PHRASE), "the pipeline's own order must work"

test_locations_are_repo_relative_and_point_at_the_declaring_file

None test_kconfig.test_locations_are_repo_relative_and_point_at_the_declaring_file(Path repo)

A symbol declared in a `source`d file must report THAT file, not the top-level one — otherwise `file:line` cannot be opened. And repo-relative, always.

tests/test_kconfig.py:232

Checks

  • assert beta.file_path == "Kconfig.motor"
  • assert not Path(beta.file_path).is_absolute()
  • assert beta.line > 0

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_locations_are_repo_relative_and_point_at_the_declaring_file → discover_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_locations_are_repo_relative_and_point_at_the_declaring_file → load_kconfig → _served_parse_error
REQ-DDB-QUERY-006catalog
Source · 11 lines
def test_locations_are_repo_relative_and_point_at_the_declaring_file(repo: Path) -> None:
    """A symbol declared in a `source`d file must report THAT file, not the top-level
    one — otherwise `file:line` cannot be opened. And repo-relative, always."""
    model = load_kconfig(discover_kconfig(repo), repo)
    beta = next(s for s in model.symbols if s.name == "WIDGET_MOTOR_BETA")

    assert beta.file_path == "Kconfig.motor"
    assert not Path(beta.file_path).is_absolute()
    assert beta.line > 0

Activity · 5 steps
lines 235–235model = load_kconfig(discover_kconfig(repo), repo)lines 236–236beta = next(s for s in model.symbols if s.name == "WIDGET_MOTOR_BETA")lines 238–238assert beta.file_path == "Kconfig.motor"lines 239–239assert not Path(beta.file_path).is_absolute()lines 240–240assert beta.line > 0

test_one_conditional_naming_two_symbols_yields_two_rows

None test_kconfig.test_one_conditional_naming_two_symbols_yields_two_rows(Path repo, Path tmp_path)

Both symbols in `#if defined(A) || B &gt; 2` genuinely participate in deciding whether the line exists, so both are recorded.

tests/test_kconfig.py:360

Show on the map →

Called by none

Calls _db_with_paths, import_kconfig_gates, kconfig_space

Checks

  • assert {"WIDGET_MOTOR_ALPHA", "WIDGET_LOG_LEVEL"} <= expr

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_one_conditional_naming_two_symbols_yields_two_rows → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_one_conditional_naming_two_symbols_yields_two_rows → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_one_conditional_naming_two_symbols_yields_two_rows → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_one_conditional_naming_two_symbols_yields_two_rows → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_one_conditional_naming_two_symbols_yields_two_rows → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_one_conditional_naming_two_symbols_yields_two_rows → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_one_conditional_naming_two_symbols_yields_two_rows → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_one_conditional_naming_two_symbols_yields_two_rows → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_one_conditional_naming_two_symbols_yields_two_rows → kconfig_space
REQ-DDB-QUERY-013inferredtest_one_conditional_naming_two_symbols_yields_two_rows → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_one_conditional_naming_two_symbols_yields_two_rows → import_kconfig_gates → ensure_kconfig_gates_table
Source · 11 lines
def test_one_conditional_naming_two_symbols_yields_two_rows(repo: Path, tmp_path: Path) -> None:
    """Both symbols in `#if defined(A) || B > 2` genuinely participate in deciding
    whether the line exists, so both are recorded."""
    db = tmp_path / "clew.db"
    _db_with_paths(db, ("src/motor.c",))
    import_kconfig_gates(db, repo)

    expr = {g.symbol for g in kconfig_space(db).gates if g.form == KCONFIG_GATE_IF_EXPR}
    assert {"WIDGET_MOTOR_ALPHA", "WIDGET_LOG_LEVEL"} <= expr

Activity · 5 steps
lines 363–363db = tmp_path / "clew.db"lines 364–364_db_with_paths(db, ("src/motor.c",))lines 365–365import_kconfig_gates(db, repo)lines 367–367expr = {g.symbol for g in kconfig_space(db).gates if g.form == KCONFIG_GATE_IF_EXPR}lines 368–368assert {"WIDGET_MOTOR_ALPHA", "WIDGET_LOG_LEVEL"} <= expr

test_origin_labels_the_declared_variant_without_filtering_the_rest

None test_kconfig.test_origin_labels_the_declared_variant_without_filtering_the_rest(Path tmp_path)

CLASSIFY, NEVER FILTER. The declaration says which variant the index REPRESENTS; it must not decide which gates exist, or a target that has declared nothing — the third-party case the whole declaration model exists to serve — would get an empty layer again, for a new reason.

tests/test_kconfig.py:544

Show on the map →

Called by none

Calls _no_kconfig_repo, import_kconfig_gates, kconfig_space

Checks

  • assert origin["PROJ_THREADING_C"] == GATE_ORIGIN_DECLARED
  • assert origin["PROJ_THREADING_PTHREAD"] == GATE_ORIGIN_UNDECLARED
  • assert origin["PROJ_LEGACY"] == GATE_ORIGIN_UNDECLARED

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_origin_labels_the_declared_variant_without_filtering_the_rest → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_origin_labels_the_declared_variant_without_filtering_the_rest → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_origin_labels_the_declared_variant_without_filtering_the_rest → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_origin_labels_the_declared_variant_without_filtering_the_rest → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_origin_labels_the_declared_variant_without_filtering_the_rest → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_origin_labels_the_declared_variant_without_filtering_the_rest → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_origin_labels_the_declared_variant_without_filtering_the_rest → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_origin_labels_the_declared_variant_without_filtering_the_rest → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_origin_labels_the_declared_variant_without_filtering_the_rest → kconfig_space
REQ-DDB-QUERY-013inferredtest_origin_labels_the_declared_variant_without_filtering_the_rest → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_origin_labels_the_declared_variant_without_filtering_the_rest → import_kconfig_gates → ensure_kconfig_gates_table
Source · 17 lines
def test_origin_labels_the_declared_variant_without_filtering_the_rest(tmp_path: Path) -> None:
    """CLASSIFY, NEVER FILTER. The declaration says which variant the index REPRESENTS;
    it must not decide which gates exist, or a target that has declared nothing — the
    third-party case the whole declaration model exists to serve — would get an empty
    layer again, for a new reason.
    """
    root, db = _no_kconfig_repo(tmp_path)
    import_kconfig_gates(db, root, declared=["PROJ_THREADING_C=1"])

    origin = {g.symbol: g.origin for g in kconfig_space(db).gates}
    ## Declared WITH a value: the value is not part of the identity a gate matches on.
    assert origin["PROJ_THREADING_C"] == GATE_ORIGIN_DECLARED
    ## Gated on, declared by nothing: kept, and marked as the finding it is.
    assert origin["PROJ_THREADING_PTHREAD"] == GATE_ORIGIN_UNDECLARED
    assert origin["PROJ_LEGACY"] == GATE_ORIGIN_UNDECLARED

Activity · 6 steps
lines 550–550root, db = _no_kconfig_repo(tmp_path)lines 551–551import_kconfig_gates(db, root, declared=["PROJ_THREADING_C=1"])lines 553–553origin = {g.symbol: g.origin for g in kconfig_space(db).gates}lines 555–555assert origin["PROJ_THREADING_C"] == GATE_ORIGIN_DECLAREDlines 557–557assert origin["PROJ_THREADING_PTHREAD"] == GATE_ORIGIN_UNDECLAREDlines 558–558assert origin["PROJ_LEGACY"] == GATE_ORIGIN_UNDECLARED

test_prompt_and_symbol_name_both_reach_the_prose_corpus

None test_kconfig.test_prompt_and_symbol_name_both_reach_the_prose_corpus(Path repo, Path tmp_path)

Two different readers search two different ways: an engineer hunting a limitation types words from the help text, one auditing a symbol types its name. Both have to hit, which is why the name is in the heading AND the content.

tests/test_kconfig.py:297

Show on the map →

Called by none

Calls _db_with_paths, import_kconfig, search_prose

Checks

  • assert search_prose(db, "CONFIG_WIDGET_MOTOR_BETA"), "the symbol name is unreachable"
  • assert search_prose(db, "Motor"), "a prompt word is unreachable"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_prompt_and_symbol_name_both_reach_the_prose_corpus → import_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_prompt_and_symbol_name_both_reach_the_prose_corpus → import_kconfig → load_kconfig → _served_parse_error
REQ-DDB-QUERY-001measuredtest_prompt_and_symbol_name_both_reach_the_prose_corpus → search_prose
REQ-DDB-QUERY-003measuredtest_prompt_and_symbol_name_both_reach_the_prose_corpus → search_prose → search_prose_graded → table_exists
REQ-DDB-QUERY-006catalog
REQ-DDB-QUERY-007measuredtest_prompt_and_symbol_name_both_reach_the_prose_corpus → search_prose → search_prose_graded → member_doc_rows
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_prompt_and_symbol_name_both_reach_the_prose_corpus → import_kconfig → store_kconfig → ensure_kconfig_tables
Source · 12 lines
def test_prompt_and_symbol_name_both_reach_the_prose_corpus(repo: Path, tmp_path: Path) -> None:
    """Two different readers search two different ways: an engineer hunting a
    limitation types words from the help text, one auditing a symbol types its name.
    Both have to hit, which is why the name is in the heading AND the content."""
    db = tmp_path / "clew.db"
    _db_with_paths(db, ())
    import_kconfig(db, repo, None)

    assert search_prose(db, "CONFIG_WIDGET_MOTOR_BETA"), "the symbol name is unreachable"
    assert search_prose(db, "Motor"), "a prompt word is unreachable"

Activity · 5 steps
lines 301–301db = tmp_path / "clew.db"lines 302–302_db_with_paths(db, ())lines 303–303import_kconfig(db, repo, None)lines 305–305assert search_prose(db, "CONFIG_WIDGET_MOTOR_BETA"), "the symbol name is unreachable"lines 306–306assert search_prose(db, "Motor"), "a prompt word is unreachable"

test_search_finds_a_gating_symbol_by_name

None test_kconfig.test_search_finds_a_gating_symbol_by_name(Path tmp_path)

gh#394, THE DISCOVERY HALF. After gh#390 stored the rows, `dossier` answered for a config symbol and `search` still returned NOTHING — so a caller who did not already know the name could not find it, which is the common case for "what turns this on". The graded agent searched for these symbols BY NAME nine times in one run and was refused every time.

tests/test_kconfig.py:643

Show on the map →

Called by none

Calls _no_kconfig_repo, import_kconfig_gates

Checks

  • assert hits, "a stored gating symbol must be discoverable"
  • assert hits[0].name == "PROJ_THREADING_PTHREAD"
  • assert hits[0].kind == CONFIG_SYMBOL_KIND
  • assert len([h for h in hits if h.kind == CONFIG_SYMBOL_KIND]) == 1

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_search_finds_a_gating_symbol_by_name → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_search_finds_a_gating_symbol_by_name → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_search_finds_a_gating_symbol_by_name → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_search_finds_a_gating_symbol_by_name → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_search_finds_a_gating_symbol_by_name → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-006catalog
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-012measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_search_finds_a_gating_symbol_by_name → import_kconfig_gates → ensure_kconfig_gates_table
Source · 22 lines
def test_search_finds_a_gating_symbol_by_name(tmp_path: Path) -> None:
    """gh#394, THE DISCOVERY HALF. After gh#390 stored the rows, `dossier` answered for a
    config symbol and `search` still returned NOTHING — so a caller who did not already
    know the name could not find it, which is the common case for "what turns this on".
    The graded agent searched for these symbols BY NAME nine times in one run and was
    refused every time.

    Asserts the RANK, not just presence: a hit buried below a capped reply is a hit the
    caller never sees.
    """
    root, db = _no_kconfig_repo(tmp_path)
    import_kconfig_gates(db, root)

    hits = search(db, "PROJ_THREADING_PTHREAD")
    assert hits, "a stored gating symbol must be discoverable"
    assert hits[0].name == "PROJ_THREADING_PTHREAD"
    assert hits[0].kind == CONFIG_SYMBOL_KIND
    ## ONE ROW PER SYMBOL, never one per site: MBEDTLS_THREADING_C gates 151 lines and 151
    ## identical-looking hits would bury every other corpus for a query that means one thing.
    assert len([h for h in hits if h.kind == CONFIG_SYMBOL_KIND]) == 1

Activity · 7 steps
lines 653–653root, db = _no_kconfig_repo(tmp_path)lines 654–654import_kconfig_gates(db, root)lines 656–656hits = search(db, "PROJ_THREADING_PTHREAD")lines 657–657assert hits, "a stored gating symbol must be discoverable"lines 658–658assert hits[0].name == "PROJ_THREADING_PTHREAD"lines 659–659assert hits[0].kind == CONFIG_SYMBOL_KINDlines 662–662assert len([h for h in hits if h.kind == CONFIG_SYMBOL_KIND]) == 1

test_store_kconfig_refuses_an_unfound_model_on_its_own

None test_kconfig.test_store_kconfig_refuses_an_unfound_model_on_its_own(Path tmp_path)

FOUND BY A CONTROL, and the control is the only reason this exists.

tests/test_kconfig.py:750

Show on the map →

Called by none

Calls _db_with_paths, store_kconfig

Checks

  • assert store_kconfig(db, KconfigModel(location=KconfigLocation(path=None))) == 0
  • assert "kconfig_symbols" not in tables
  • assert "kconfig_choices" not in tables

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_store_kconfig_refuses_an_unfound_model_on_its_own → store_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-006catalog
REQ-DDB-SCHEMA-013inferredtest_store_kconfig_refuses_an_unfound_model_on_its_own → store_kconfig → ensure_kconfig_tables
Source · 24 lines
def test_store_kconfig_refuses_an_unfound_model_on_its_own(tmp_path: Path) -> None:
    """FOUND BY A CONTROL, and the control is the only reason this exists.

    `test_a_repo_with_no_kconfig_is_completely_unaffected` passed with
    `store_kconfig`'s own `found` guard removed, because `import_kconfig` short-circuits
    before reaching it — so the guard was untested and the test above was proving the
    short-circuit, not the guard. Both paths lead to "create no tables", and a defence
    that only one of them exercises is a defence that will be deleted as dead code.

    This drives `store_kconfig` directly, which is what makes the guard load-bearing.
    """
    from clew.kconfig import KconfigLocation, KconfigModel, store_kconfig

    db = tmp_path / "clew.db"
    _db_with_paths(db, ())
    assert store_kconfig(db, KconfigModel(location=KconfigLocation(path=None))) == 0

    conn = sqlite3.connect(str(db))
    tables = {row[0] for row in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")}
    conn.close()
    assert "kconfig_symbols" not in tables
    assert "kconfig_choices" not in tables

Activity · 9 steps
lines 761–761from clew.kconfig import KconfigLocation, KconfigModel, store_kconfiglines 763–763db = tmp_path / "clew.db"lines 764–764_db_with_paths(db, ())lines 765–765assert store_kconfig(db, KconfigModel(location=KconfigLocation(path=None))) == 0lines 767–767conn = sqlite3.connect(str(db))lines 768–768tables = {row[0] for row in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")}lines 769–769conn.close()lines 770–770assert "kconfig_symbols" not in tableslines 771–771assert "kconfig_choices" not in tables

test_the_config_inventory_lists_symbols_and_honours_text

None test_kconfig.test_the_config_inventory_lists_symbols_and_honours_text(Path tmp_path)

The config corpus lists SYMBOLS and filters on text, instead of dumping every site.

tests/test_kconfig.py:1064

Checks

  • assert inventory.gate_symbol_names == ("MBEDTLS_SSL_PROTO_TLS1_3", "MBEDTLS_THREADING_C")
  • assert inventory.gates == (), "the inventory form must NOT carry the per-site rows"
  • assert "omitted" in inventory.gates_meaning and "dossier" in inventory.gates_meaning, ("an empty gates list must say it was omitted and where the sites are" )
  • assert filtered.gate_symbol_names == ("MBEDTLS_THREADING_C",)
  • assert kconfig_space(db, "CONFIG_MBEDTLS_THREADING_C", include_gates=False).gate_symbol_names
  • assert len(sites.gates) == 2, "naming a symbol must still return ITS sites"
  • assert sites.gates_meaning == "", "the site form has nothing omitted to explain"
  • assert f"{_NAME_CAP}" in gates_meaning(_NAME_CAP, _NAME_CAP + 7, False)
  • assert "7 are not shown" in gates_meaning(_NAME_CAP, _NAME_CAP + 7, False)
  • assert gates_meaning(3, 3, False) and "not shown" not in gates_meaning(3, 3, False)
  • assert gates_meaning(0, 0, False) == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_the_config_inventory_lists_symbols_and_honours_text → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_the_config_inventory_lists_symbols_and_honours_text → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_the_config_inventory_lists_symbols_and_honours_text → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_the_config_inventory_lists_symbols_and_honours_text → kconfig_space
REQ-DDB-QUERY-013inferredtest_the_config_inventory_lists_symbols_and_honours_text → kconfig_space → _gates → _with_defaults → decided_default
Source · 64 lines
def test_the_config_inventory_lists_symbols_and_honours_text(tmp_path: Path) -> None:
    """A 2.1 MB REPLY ON THE AXIS UNDER TEST. `search(corpus='config', text='MBEDTLS_THREADING_C')`
    returned 2,149,463 characters on mbedtls 2026-08-14 — all 12,096 gate SITES, because inventory
    corpora ignored `text` — while reporting `found: false` for a symbol whose name sits in
    `configured_macros` in the same reply. In a graded cell that is a budget-destroying reply or a
    bail-out.

    The corpus's own contract is "the question `dossier` cannot answer: which symbols EXIST", and
    the sites are not that. `dossier` already returned one symbol's sites correctly filtered, so
    this is the corpus returning its own inventory rather than a new capability. Re-measured after
    the change: 5,423 characters filtered, 17,057 unfiltered.

    THE EMPTY `gates` LIST MUST NOT READ AS "NOTHING GATES CODE HERE" — the exact ambiguity
    `found`/`source`/`error` exist to prevent — so `gates_meaning` says the sites were omitted
    deliberately and names the call that returns them.
    """
    import sqlite3

    from clew.query.kconfig import _NAME_CAP, gates_meaning, kconfig_space

    db = tmp_path / "clew.db"
    conn = sqlite3.connect(str(db))
    conn.executescript(
        """
        CREATE TABLE kconfig_gates (
            symbol TEXT, macro TEXT, form TEXT, file_path TEXT, line INTEGER,
            origin TEXT, end_line INTEGER
        );
        INSERT INTO kconfig_gates VALUES ('MBEDTLS_THREADING_C','MBEDTLS_THREADING_C','if_expr','a.c',1,'declared',3);
        INSERT INTO kconfig_gates VALUES ('MBEDTLS_THREADING_C','MBEDTLS_THREADING_C','if_expr','b.c',9,'declared',11);
        INSERT INTO kconfig_gates VALUES ('MBEDTLS_SSL_PROTO_TLS1_3','MBEDTLS_SSL_PROTO_TLS1_3','ifdef','c.c',4,'undeclared',6);
        """
    )
    conn.commit()
    conn.close()

    ## INVENTORY FORM: names, no sites.
    inventory = kconfig_space(db, None, include_gates=False)
    assert inventory.gate_symbol_names == ("MBEDTLS_SSL_PROTO_TLS1_3", "MBEDTLS_THREADING_C")
    assert inventory.gates == (), "the inventory form must NOT carry the per-site rows"
    assert "omitted" in inventory.gates_meaning and "dossier" in inventory.gates_meaning, (
        "an empty gates list must say it was omitted and where the sites are"
    )

    ## `text` FILTERS, which is the whole difference between a usable reply and a 2 MB one.
    filtered = kconfig_space(db, "MBEDTLS_THREADING_C", include_gates=False)
    assert filtered.gate_symbol_names == ("MBEDTLS_THREADING_C",)
    ## The CONFIG_ prefix is accepted too — a caller reading a gate out of source has it in hand.
    assert kconfig_space(db, "CONFIG_MBEDTLS_THREADING_C", include_gates=False).gate_symbol_names

    ## THE SITE FORM IS UNCHANGED, or this fix would have removed the answer instead of bounding
    ## it. `dossier` uses this path and must still get every row for its symbol.
    sites = kconfig_space(db, "MBEDTLS_THREADING_C")
    assert len(sites.gates) == 2, "naming a symbol must still return ITS sites"
    assert sites.gates_meaning == "", "the site form has nothing omitted to explain"

    ## THE CAP SAYS SO. A truncated inventory that stays silent reads as the whole space.
    assert f"{_NAME_CAP}" in gates_meaning(_NAME_CAP, _NAME_CAP + 7, False)
    assert "7 are not shown" in gates_meaning(_NAME_CAP, _NAME_CAP + 7, False)
    assert gates_meaning(3, 3, False) and "not shown" not in gates_meaning(3, 3, False)
    ## Nothing measured stays silent rather than describing an absent layer.
    assert gates_meaning(0, 0, False) == ""

Activity · 21 steps
lines 1080–1080import sqlite3lines 1082–1082from clew.query.kconfig import _NAME_CAP, gates_meaning, kconfig_spacelines 1084–1084db = tmp_path / "clew.db"lines 1085–1085conn = sqlite3.connect(str(db))lines 1086–1096conn.executescript( """ CREATE TABLE kconfig_gates ( symbol TEXT, macro TEXT, form TEXT, file_path TEXT, line INTEGER, origin TEXT, end_line INTEGER ); INSERT INTO kconfig_gates VALUES ('MBEDTLS_THREADING_C','MBEDTLS_THREADING_C','if_expr','a.c',1,'declared',3); INSERT INTO kconfig_gates VALUES ('MBEDTLS_THREADING_C','MBEDTLS_THREADING_C','if_expr','b.c',9,'declared',11); INSERT INTO kconfig_gates VALUES ('MBEDTLS_SSL_PROTO_TLS1_3','MBEDTLS_SSL_PROTO_TLS1_3','ifdef','c.c',4,'undeclared',6); """ )lines 1097–1097conn.commit()lines 1098–1098conn.close()lines 1101–1101inventory = kconfig_space(db, None, include_gates=False)lines 1102–1102assert inventory.gate_symbol_names == ("MBEDTLS_SSL_PROTO_TLS1_3", "MBEDTLS_THREADING_C")lines 1103–1103assert inventory.gates == (), "the inventory form must NOT carry the per-site rows"lines 1104–1106assert "omitted" in inventory.gates_meaning and "dossier" in inventory.gates_meaning, ( "an empty gates list must say it was omitted and where the sites are" )lines 1109–1109filtered = kconfig_space(db, "MBEDTLS_THREADING_C", include_gates=False)lines 1110–1110assert filtered.gate_symbol_names == ("MBEDTLS_THREADING_C",)lines 1112–1112assert kconfig_space(db, "CONFIG_MBEDTLS_THREADING_C", include_gates=False).gate_symbol_nameslines 1116–1116sites = kconfig_space(db, "MBEDTLS_THREADING_C")lines 1117–1117assert len(sites.gates) == 2, "naming a symbol must still return ITS sites"lines 1118–1118assert sites.gates_meaning == "", "the site form has nothing omitted to explain"lines 1121–1121assert f"{_NAME_CAP}" in gates_meaning(_NAME_CAP, _NAME_CAP + 7, False)lines 1122–1122assert "7 are not shown" in gates_meaning(_NAME_CAP, _NAME_CAP + 7, False)lines 1123–1123assert gates_meaning(3, 3, False) and "not shown" not in gates_meaning(3, 3, False)lines 1125–1125assert gates_meaning(0, 0, False) == ""

test_the_configured_variant_travels_beside_the_space

None test_kconfig.test_the_configured_variant_travels_beside_the_space(Path repo, Path tmp_path)

Structure and instance must arrive TOGETHER and stay LABELLED. An agent reading a `default` without knowing which variant the index was built in will describe the default as what the firmware does — which is the confusion gh#18 part 5 names.

tests/test_kconfig.py:824

Checks

  • assert "CONFIG_WIDGET_MOTOR_BETA" in space.configured_macros
  • assert space.symbols, "the space must still be reported alongside the instance"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_the_configured_variant_travels_beside_the_space → import_kconfig
REQ-DDB-CONFIG-006measuredtest_the_configured_variant_travels_beside_the_space → write_build_signature
REQ-DDB-CONFIG-007measuredtest_the_configured_variant_travels_beside_the_space → write_build_signature
REQ-DDB-PIPE-005measuredtest_the_configured_variant_travels_beside_the_space → write_build_signature
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_the_configured_variant_travels_beside_the_space → import_kconfig → load_kconfig → _served_parse_error
REQ-DDB-QUERY-001measuredtest_the_configured_variant_travels_beside_the_space → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_the_configured_variant_travels_beside_the_space → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_the_configured_variant_travels_beside_the_space → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_the_configured_variant_travels_beside_the_space → kconfig_space
REQ-DDB-QUERY-013inferredtest_the_configured_variant_travels_beside_the_space → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_the_configured_variant_travels_beside_the_space → import_kconfig → store_kconfig → ensure_kconfig_tables
Source · 18 lines
def test_the_configured_variant_travels_beside_the_space(repo: Path, tmp_path: Path) -> None:
    """Structure and instance must arrive TOGETHER and stay LABELLED. An agent reading
    a `default` without knowing which variant the index was built in will describe the
    default as what the firmware does — which is the confusion gh#18 part 5 names."""
    db = tmp_path / "clew.db"
    _db_with_paths(db, ())
    model = import_kconfig(db, repo, None)
    write_build_signature(
        db,
        kconfig=model.as_meta(),
        preprocessor={"predefined": '"CONFIG_WIDGET_MOTOR_BETA"', "source": "declared"},
    )

    space = kconfig_space(db)
    assert "CONFIG_WIDGET_MOTOR_BETA" in space.configured_macros
    assert space.symbols, "the space must still be reported alongside the instance"

Activity · 7 steps
lines 828–828db = tmp_path / "clew.db"lines 829–829_db_with_paths(db, ())lines 830–830model = import_kconfig(db, repo, None)lines 831–835write_build_signature( db, kconfig=model.as_meta(), preprocessor={"predefined": '"CONFIG_WIDGET_MOTOR_BETA"', "source": "declared"}, )lines 837–837space = kconfig_space(db)lines 838–838assert "CONFIG_WIDGET_MOTOR_BETA" in space.configured_macroslines 839–839assert space.symbols, "the space must still be reported alongside the instance"

test_the_declaration_section_spelling_is_pinned

None test_kconfig.test_the_declaration_section_spelling_is_pinned()

`kconfig.py` does not import `declaration.py` and is not imported by it, so the section name is spelled twice. This pins them together, exactly as `test_declaration.py` does for `index_scope` and `preprocessor`. A drift here means a repo's declaration parses into a mapping nothing reads while the build reports it was honoured.

tests/test_kconfig.py:183

Show on the map →

Called by none

Calls none

Checks

  • assert SECTION_KCONFIG in decl_mod.KNOWN_SECTIONS
  • assert decl_mod.SECTION_KCONFIG == SECTION_KCONFIG

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-006catalog
Source · 13 lines
def test_the_declaration_section_spelling_is_pinned() -> None:
    """`kconfig.py` does not import `declaration.py` and is not imported by it, so the
    section name is spelled twice. This pins them together, exactly as
    `test_declaration.py` does for `index_scope` and `preprocessor`. A drift here means
    a repo's declaration parses into a mapping nothing reads while the build reports it
    was honoured."""
    assert SECTION_KCONFIG in decl_mod.KNOWN_SECTIONS
    assert decl_mod.SECTION_KCONFIG == SECTION_KCONFIG


# ─── part 2: the space, its choices and its defaults ─────────────────────────

Activity · 2 steps
lines 189–189assert SECTION_KCONFIG in decl_mod.KNOWN_SECTIONSlines 190–190assert decl_mod.SECTION_KCONFIG == SECTION_KCONFIG

test_the_gate_layer_reports_its_own_state_independently_of_kconfig

None test_kconfig.test_the_gate_layer_reports_its_own_state_independently_of_kconfig(Path tmp_path)

The three states of the gate layer, each on its own database.

tests/test_kconfig.py:952

Checks

  • assert import_kconfig_gates(_db, gated) > 0
  • assert space.found is False, "this fixture has no Kconfig — `found` must stay honest about that"
  • assert space.gate_state == LAYER_STATE_POPULATED
  • assert space.gate_symbols > 0, "the harvest saw gating symbols and must say how many"
  • assert space.found or space.gate_state == LAYER_STATE_POPULATED
  • assert empty_space.gate_state == LAYER_STATE_EMPTY, ("a table that exists and holds nothing is a MEASUREMENT, not an absent detector" )
  • assert empty_space.gate_symbols == 0
  • assert bare_space.gate_state == LAYER_STATE_ABSENT, ("an absent layer must NOT read as an empty one — that is the substitution this whole " "class was written to prevent" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_the_gate_layer_reports_its_own_state_independently_of_kconfig → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_the_gate_layer_reports_its_own_state_independently_of_kconfig → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_the_gate_layer_reports_its_own_state_independently_of_kconfig → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_the_gate_layer_reports_its_own_state_independently_of_kconfig → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_the_gate_layer_reports_its_own_state_independently_of_kconfig → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_the_gate_layer_reports_its_own_state_independently_of_kconfig → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_the_gate_layer_reports_its_own_state_independently_of_kconfig → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_the_gate_layer_reports_its_own_state_independently_of_kconfig → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_the_gate_layer_reports_its_own_state_independently_of_kconfig → kconfig_space
REQ-DDB-QUERY-013inferredtest_the_gate_layer_reports_its_own_state_independently_of_kconfig → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_the_gate_layer_reports_its_own_state_independently_of_kconfig → ensure_kconfig_gates_table
Source · 52 lines
def test_the_gate_layer_reports_its_own_state_independently_of_kconfig(tmp_path: Path) -> None:
    """gh#404 — `found` ANSWERS A DIFFERENT QUESTION THAN THE ONE CALLERS ASK. It is true when a
    Kconfig was discovered and parsed, which is all it ever claimed. But a caller reads
    `found: false` as "this repository has no configuration space", and mbedtls — which has no
    Kconfig — measured 12,096 gating sites over 1,107 distinct symbols. Kconfig is a Zephyr/Linux
    convention; a header of `#define`s is the dominant C one, and reporting the dominant case as
    absence is the misreport `KconfigSpace` exists to prevent, one level up.

    ALL THREE STATES, because the two that look alike are the ones this project keeps confusing. A
    table that EXISTS and holds nothing is a measurement — the harvest ran over this repo and found
    no gating site. An ABSENT table is a detector that never looked. Only the first is evidence
    about the repository, and a test asserting just `populated` would leave them interchangeable.

    @brief populated / empty / absent are distinguishable.
    @version 1
    """
    ## POPULATED: no Kconfig anywhere, but the gate harvest saw two symbols.
    gated, _db = _no_kconfig_repo(tmp_path / "gated")
    assert import_kconfig_gates(_db, gated) > 0
    space = kconfig_space(_db, None)
    assert space.found is False, "this fixture has no Kconfig — `found` must stay honest about that"
    assert space.gate_state == LAYER_STATE_POPULATED
    assert space.gate_symbols > 0, "the harvest saw gating symbols and must say how many"
    ## The question a caller actually has, answerable at last.
    assert space.found or space.gate_state == LAYER_STATE_POPULATED

    ## EMPTY: the table exists because the harvest ran; it found nothing to record.
    empty_db = tmp_path / "empty.db"
    conn = sqlite3.connect(str(empty_db))
    conn.execute("CREATE TABLE path (name TEXT, type INT)")
    ensure_kconfig_gates_table(conn)
    conn.commit()
    conn.close()
    empty_space = kconfig_space(empty_db, None)
    assert empty_space.gate_state == LAYER_STATE_EMPTY, (
        "a table that exists and holds nothing is a MEASUREMENT, not an absent detector"
    )
    assert empty_space.gate_symbols == 0

    ## ABSENT: no gate table at all — an older index, or a build where the layer never ran.
    bare_db = tmp_path / "bare.db"
    conn = sqlite3.connect(str(bare_db))
    conn.execute("CREATE TABLE path (name TEXT, type INT)")
    conn.commit()
    conn.close()
    bare_space = kconfig_space(bare_db, None)
    assert bare_space.gate_state == LAYER_STATE_ABSENT, (
        "an absent layer must NOT read as an empty one — that is the substitution this whole "
        "class was written to prevent"
    )

Activity · 23 steps
lines 969–969gated, _db = _no_kconfig_repo(tmp_path / "gated")lines 970–970assert import_kconfig_gates(_db, gated) > 0lines 971–971space = kconfig_space(_db, None)lines 972–972assert space.found is False, "this fixture has no Kconfig — `found` must stay honest about that"lines 973–973assert space.gate_state == LAYER_STATE_POPULATEDlines 974–974assert space.gate_symbols > 0, "the harvest saw gating symbols and must say how many"lines 976–976assert space.found or space.gate_state == LAYER_STATE_POPULATEDlines 979–979empty_db = tmp_path / "empty.db"lines 980–980conn = sqlite3.connect(str(empty_db))lines 981–981conn.execute("CREATE TABLE path (name TEXT, type INT)")lines 982–982ensure_kconfig_gates_table(conn)lines 983–983conn.commit()lines 984–984conn.close()lines 985–985empty_space = kconfig_space(empty_db, None)lines 986–988assert empty_space.gate_state == LAYER_STATE_EMPTY, ( "a table that exists and holds nothing is a MEASUREMENT, not an absent detector" )lines 989–989assert empty_space.gate_symbols == 0lines 992–992bare_db = tmp_path / "bare.db"lines 993–993conn = sqlite3.connect(str(bare_db))lines 994–994conn.execute("CREATE TABLE path (name TEXT, type INT)")lines 995–995conn.commit()lines 996–996conn.close()lines 997–997bare_space = kconfig_space(bare_db, None)lines 998–1001assert bare_space.gate_state == LAYER_STATE_ABSENT, ( "an absent layer must NOT read as an empty one — that is the substitution this whole " "class was written to prevent" )

test_the_gate_list_can_be_narrowed_to_one_symbol

None test_kconfig.test_the_gate_list_can_be_narrowed_to_one_symbol(Path repo, Path tmp_path)

Accepts the name bare or `CONFIG_`-prefixed, because a caller reading a gate out of source has the prefixed form in front of them and requiring them to strip it produces a confident empty result — the failure gh#31 records for `search`.

tests/test_kconfig.py:842

Show on the map →

Called by none

Calls _db_with_paths, import_kconfig_gates, kconfig_space

Checks

  • assert bare == prefixed
  • assert bare and {g.symbol for g in bare} == {"WIDGET_MOTOR_BETA"}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004measuredtest_the_gate_list_can_be_narrowed_to_one_symbol → import_kconfig_gates → declared_macro_names → bare_macro_names
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-003measuredtest_the_gate_list_can_be_narrowed_to_one_symbol → import_kconfig_gates → run_harvest
REQ-DDB-PIPE-007measuredtest_the_gate_list_can_be_narrowed_to_one_symbol → import_kconfig_gates
REQ-DDB-PIPE-011measuredtest_the_gate_list_can_be_narrowed_to_one_symbol → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_the_gate_list_can_be_narrowed_to_one_symbol → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_the_gate_list_can_be_narrowed_to_one_symbol → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_the_gate_list_can_be_narrowed_to_one_symbol → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_the_gate_list_can_be_narrowed_to_one_symbol → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_the_gate_list_can_be_narrowed_to_one_symbol → kconfig_space
REQ-DDB-QUERY-013inferredtest_the_gate_list_can_be_narrowed_to_one_symbol → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_the_gate_list_can_be_narrowed_to_one_symbol → import_kconfig_gates → ensure_kconfig_gates_table
Source · 14 lines
def test_the_gate_list_can_be_narrowed_to_one_symbol(repo: Path, tmp_path: Path) -> None:
    """Accepts the name bare or `CONFIG_`-prefixed, because a caller reading a gate out
    of source has the prefixed form in front of them and requiring them to strip it
    produces a confident empty result — the failure gh#31 records for `search`."""
    db = tmp_path / "clew.db"
    _db_with_paths(db, ("src/motor.c",))
    import_kconfig_gates(db, repo)

    bare = kconfig_space(db, "WIDGET_MOTOR_BETA").gates
    prefixed = kconfig_space(db, "CONFIG_WIDGET_MOTOR_BETA").gates
    assert bare == prefixed
    assert bare and {g.symbol for g in bare} == {"WIDGET_MOTOR_BETA"}

Activity · 7 steps
lines 846–846db = tmp_path / "clew.db"lines 847–847_db_with_paths(db, ("src/motor.c",))lines 848–848import_kconfig_gates(db, repo)lines 850–850bare = kconfig_space(db, "WIDGET_MOTOR_BETA").gateslines 851–851prefixed = kconfig_space(db, "CONFIG_WIDGET_MOTOR_BETA").gateslines 852–852assert bare == prefixedlines 853–853assert bare and {g.symbol for g in bare} == {"WIDGET_MOTOR_BETA"}

test_the_stated_macro_split_reaches_the_served_reply

None test_kconfig.test_the_stated_macro_split_reaches_the_served_reply(Path tmp_path)

The stated/default split must reach the SERVED reply, not just macros_meaning .

tests/test_kconfig.py:1132

Checks

  • assert "A_MACRO, B_MACRO" in served, (f"the served reply does not name the macros that ship OFF, so the split never reached a " f"consumer. Check that _PREPROCESSOR_STATED_ONLY is in _meta's fetch tuple. Got: {served}" )
  • assert "OFF" in served, "the reply must say those macros ship OFF, not merely that they differ"
  • assert "A, _, M" not in served and "A, _" not in served, (f"the names are being re-joined character by character — `stated_only` arrives already " f"comma-joined from `as_meta`. Got: {served}" )
  • assert "did not record which came from which" not in served, ("the reply fell through to the unrecorded-split wording while the split was present" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005catalog
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014catalog
REQ-DDB-QUERY-001measuredtest_the_stated_macro_split_reaches_the_served_reply → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_the_stated_macro_split_reaches_the_served_reply → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_the_stated_macro_split_reaches_the_served_reply → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_the_stated_macro_split_reaches_the_served_reply → kconfig_space
REQ-DDB-QUERY-013inferredtest_the_stated_macro_split_reaches_the_served_reply → kconfig_space → _gates → _with_defaults → decided_default
Source · 56 lines
def test_the_stated_macro_split_reaches_the_served_reply(tmp_path: Path) -> None:
    """THREE DEFECTS IN ONE SENTENCE, AND THE SUITE COULD NOT SEE ANY OF THEM, because every
    existing test calls `macros_meaning` DIRECTLY. This one goes through `kconfig_space`, which is
    what a consumer reaches, and that is the whole point of it.

      D1 — `_PREPROCESSOR_STATED_ONLY` was defined, documented with a five-line rationale, and
           passed at the call site, but never added to `_meta`'s fetch tuple. It therefore
           resolved to "" on every index ever built and the branch reading it was DEAD CODE. The
           reply fell through to "this build did not record which came from which" while the split
           sat in `build_meta`.
      D2 — `', '.join(stated_only)` over a value `as_meta` had already joined, so the answer
           rendered per character: "M, B, E, D, T, L, S, _, T, H, R, E, A, D, I, N, G, _, C, ...".
      D3 — `resolve_preprocessor` returned early on `if explicit:` and discarded the
           `config_header` declared in the same section, so the acceptance build — which promotes
           a declared `predefined:` to that argument — threw away its own header every run.

    The stamped shape is the one D3 now produces: `source: flag` WITH a known header and a split.

    ASSERTS THE NAMES AND THE WORD OFF, not the whole sentence. Pinning the prose would fail on
    every rewording; pinning the two load-bearing facts fails only when the answer is lost.

    @brief The served reply names the OFF macros and does not garble them.
    @return None.
    @version 1
    """
    db = tmp_path / "split.db"
    conn = sqlite3.connect(str(db))
    conn.execute("CREATE TABLE build_meta (key TEXT PRIMARY KEY, value TEXT)")
    conn.executemany(
        "INSERT INTO build_meta(key, value) VALUES(?, ?)",
        [
            ("preprocessor.source", "flag"),
            ("preprocessor.predefined", '"A_MACRO" "B_MACRO"'),
            ("preprocessor.config_header", "include/proj/config.h"),
            ("preprocessor.stated_only", "A_MACRO, B_MACRO"),
        ],
    )
    conn.commit()
    conn.close()

    served = kconfig_space(db, include_gates=False).macros_meaning

    assert "A_MACRO, B_MACRO" in served, (
        f"the served reply does not name the macros that ship OFF, so the split never reached a "
        f"consumer. Check that _PREPROCESSOR_STATED_ONLY is in _meta's fetch tuple. Got: {served}"
    )
    assert "OFF" in served, "the reply must say those macros ship OFF, not merely that they differ"
    assert "A, _, M" not in served and "A, _" not in served, (
        f"the names are being re-joined character by character — `stated_only` arrives already "
        f"comma-joined from `as_meta`. Got: {served}"
    )
    assert "did not record which came from which" not in served, (
        "the reply fell through to the unrecorded-split wording while the split was present"
    )

Activity · 11 steps
lines 1157–1157db = tmp_path / "split.db"lines 1158–1158conn = sqlite3.connect(str(db))lines 1159–1159conn.execute("CREATE TABLE build_meta (key TEXT PRIMARY KEY, value TEXT)")lines 1160–1168conn.executemany( "INSERT INTO build_meta(key, value) VALUES(?, ?)", [ ("preprocessor.source", "flag"), ("preprocessor.predefined", '"A_MACRO" "B_MACRO"'), ("preprocessor.config_header", "include/proj/config.h"), ("preprocessor.stated_only", "A_MACRO, B_MACRO"), ], )lines 1169–1169conn.commit()lines 1170–1170conn.close()lines 1172–1172served = kconfig_space(db, include_gates=False).macros_meaninglines 1174–1177assert "A_MACRO, B_MACRO" in served, ( f"the served reply does not name the macros that ship OFF, so the split never reached a " f"consumer. Check that _PREPROCESSOR_STATED_ONLY is in _meta's fetch tuple. Got: {served}" )lines 1178–1178assert "OFF" in served, "the reply must say those macros ship OFF, not merely that they differ"lines 1179–1182assert "A, _, M" not in served and "A, _" not in served, ( f"the names are being re-joined character by character — `stated_only` arrives already " f"comma-joined from `as_meta`. Got: {served}" )lines 1183–1185assert "did not record which came from which" not in served, ( "the reply fell through to the unrecorded-split wording while the split was present" )

test_the_stored_tables_round_trip_through_the_query_layer

None test_kconfig.test_the_stored_tables_round_trip_through_the_query_layer(Path repo, Path tmp_path)

Drives the real pipeline entry point and reads back through R2, so the DDL, the inserts and the JOIN are all the shipped ones rather than copies.

tests/test_kconfig.py:243

Checks

  • assert space.found is True
  • assert space.error == ""
  • assert by_name["WIDGET_MOTOR_BETA"].choice == "Motor variant", ("the query layer must surface the group's HUMAN identity, not the synthetic key" )
  • assert by_name["WIDGET_LOG_LEVEL"].choice is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_the_stored_tables_round_trip_through_the_query_layer → import_kconfig
REQ-DDB-CONFIG-006measuredtest_the_stored_tables_round_trip_through_the_query_layer → write_build_signature
REQ-DDB-CONFIG-007measuredtest_the_stored_tables_round_trip_through_the_query_layer → write_build_signature
REQ-DDB-PIPE-005measuredtest_the_stored_tables_round_trip_through_the_query_layer → write_build_signature
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_the_stored_tables_round_trip_through_the_query_layer → import_kconfig → load_kconfig → _served_parse_error
REQ-DDB-QUERY-001measuredtest_the_stored_tables_round_trip_through_the_query_layer → kconfig_space → connect
REQ-DDB-QUERY-003measuredtest_the_stored_tables_round_trip_through_the_query_layer → kconfig_space → table_exists
REQ-DDB-QUERY-004inferredtest_the_stored_tables_round_trip_through_the_query_layer → kconfig_space → _gates → _with_defaults → _in_default_build
REQ-DDB-QUERY-006measuredtest_the_stored_tables_round_trip_through_the_query_layer → kconfig_space
REQ-DDB-QUERY-013inferredtest_the_stored_tables_round_trip_through_the_query_layer → kconfig_space → _gates → _with_defaults → decided_default
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measuredtest_the_stored_tables_round_trip_through_the_query_layer → import_kconfig → store_kconfig → ensure_kconfig_tables
Source · 21 lines
def test_the_stored_tables_round_trip_through_the_query_layer(repo: Path, tmp_path: Path) -> None:
    """Drives the real pipeline entry point and reads back through R2, so the DDL, the
    inserts and the JOIN are all the shipped ones rather than copies."""
    db = tmp_path / "clew.db"
    _db_with_paths(db, ("src/motor.c",))
    model = import_kconfig(db, repo, None)
    write_build_signature(db, kconfig=model.as_meta())

    space = kconfig_space(db)
    assert space.found is True
    assert space.error == ""
    by_name = {sym.name: sym for sym in space.symbols}
    assert by_name["WIDGET_MOTOR_BETA"].choice == "Motor variant", (
        "the query layer must surface the group's HUMAN identity, not the synthetic key"
    )
    assert by_name["WIDGET_LOG_LEVEL"].choice is None


# ─── part 4: the help text, which is the reason for all of it ────────────────

Activity · 10 steps
lines 246–246db = tmp_path / "clew.db"lines 247–247_db_with_paths(db, ("src/motor.c",))lines 248–248model = import_kconfig(db, repo, None)lines 249–249write_build_signature(db, kconfig=model.as_meta())lines 251–251space = kconfig_space(db)lines 252–252assert space.found is Truelines 253–253assert space.error == ""lines 254–254by_name = {sym.name: sym for sym in space.symbols}lines 255–257assert by_name["WIDGET_MOTOR_BETA"].choice == "Motor variant", ( "the query layer must surface the group's HUMAN identity, not the synthetic key" )lines 258–258assert by_name["WIDGET_LOG_LEVEL"].choice is None

test_types_defaults_and_conditions_survive_verbatim

None test_kconfig.test_types_defaults_and_conditions_survive_verbatim(Path repo)

`default FOO if BAR` and `default FOO` say different things about which variant is the unstated one, so the condition is kept. Dropping the `if` would turn a conditional default into an unconditional claim.

tests/test_kconfig.py:216

Checks

  • assert by_name["WIDGET_LOG_LEVEL"].type == "int"
  • assert by_name["WIDGET_MOTOR_NAME"].type == "string"
  • assert by_name["WIDGET_MOTOR_ALPHA"].type == "bool"
  • assert "if" in by_name["WIDGET_MOTOR_NAME"].default, ("the conditional default lost its condition, which reads as unconditional" )
  • assert model.choices[0].default, "a choice's default names the unstated variant"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-005measuredtest_types_defaults_and_conditions_survive_verbatim → discover_kconfig
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measuredtest_types_defaults_and_conditions_survive_verbatim → load_kconfig → _served_parse_error
REQ-DDB-QUERY-006catalog
Source · 16 lines
def test_types_defaults_and_conditions_survive_verbatim(repo: Path) -> None:
    """`default FOO if BAR` and `default FOO` say different things about which variant
    is the unstated one, so the condition is kept. Dropping the `if` would turn a
    conditional default into an unconditional claim."""
    model = load_kconfig(discover_kconfig(repo), repo)
    by_name = {sym.name: sym for sym in model.symbols}

    assert by_name["WIDGET_LOG_LEVEL"].type == "int"
    assert by_name["WIDGET_MOTOR_NAME"].type == "string"
    assert by_name["WIDGET_MOTOR_ALPHA"].type == "bool"
    assert "if" in by_name["WIDGET_MOTOR_NAME"].default, (
        "the conditional default lost its condition, which reads as unconditional"
    )
    assert model.choices[0].default, "a choice's default names the unstated variant"

Activity · 7 steps
lines 220–220model = load_kconfig(discover_kconfig(repo), repo)lines 221–221by_name = {sym.name: sym for sym in model.symbols}lines 223–223assert by_name["WIDGET_LOG_LEVEL"].type == "int"lines 224–224assert by_name["WIDGET_MOTOR_NAME"].type == "string"lines 225–225assert by_name["WIDGET_MOTOR_ALPHA"].type == "bool"lines 226–228assert "if" in by_name["WIDGET_MOTOR_NAME"].default, ( "the conditional default lost its condition, which reads as unconditional" )lines 229–229assert model.choices[0].default, "a choice's default names the unstated variant"