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.
Checks
assert origin["WIDGET_MOTOR_BETA"] == GATE_ORIGIN_KCONFIG
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_a_config_prefixed_symbol_is_labelled_kconfig_whatever_else_is_declared → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_a_config_symbol_does_not_outrank_a_function_it_gates → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-PIPE-003 | measured | test_a_config_symbol_does_not_outrank_a_function_it_gates → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_a_config_symbol_does_not_outrank_a_function_it_gates → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_a_config_symbol_does_not_outrank_a_function_it_gates → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-006 | catalog | |
| REQ-DDB-QUERY-007 | measured | |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert location.path is Noneassert location.searched == ("conf/Kconfig",)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_a_declared_but_missing_root_is_not_silently_replaced_by_convention → discover_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_a_declared_but_missing_root_is_not_silently_replaced_by_convention → discover_kconfig → _declared_kconfig → within_repo |
| REQ-DDB-QUERY-006 | catalog |
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
test_a_declared_root_beats_convention
None test_kconfig.test_a_declared_root_beats_convention(Path repo)
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.
Checks
assert location.source == SOURCE_DECLAREDassert location.path == Path("conf/Kconfig")
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_a_declared_root_beats_convention → discover_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_a_declared_root_beats_convention → discover_kconfig → _declared_kconfig → within_repo |
| REQ-DDB-QUERY-006 | catalog |
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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | |
| REQ-DDB-CONFIG-005 | measured | test_a_declared_root_outside_the_repository_is_refused → discover_kconfig |
| REQ-DDB-GUARD-012 | inferred | |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_a_declared_root_outside_the_repository_is_refused → discover_kconfig → _declared_kconfig → within_repo |
| REQ-DDB-QUERY-006 | catalog | |
| REQ-DDB-WIKI-054 | inferred |
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
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.
Checks
assert import_kconfig_gates(db, root) > 0assert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_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-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → gates_covering → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → gates_covering → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → gates_covering |
| REQ-DDB-QUERY-013 | inferred | test_a_gate_covers_its_own_branch_and_the_else_gets_inverted_polarity → gates_covering → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Called by none
Calls _db_with_paths, import_kconfig, import_kconfig_gates, kconfig_space
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | measured | test_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig |
| REQ-DDB-PIPE-003 | measured | test_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | measured | test_a_gate_on_an_undeclared_symbol_is_kept → import_kconfig → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-001 | measured | test_a_gate_on_an_undeclared_symbol_is_kept → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_a_gate_on_an_undeclared_symbol_is_kept → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_a_gate_on_an_undeclared_symbol_is_kept → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_a_gate_on_an_undeclared_symbol_is_kept → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_a_gate_on_an_undeclared_symbol_is_kept → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert import_kconfig_gates(db, root) > 0assert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_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-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → gates_covering → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → gates_covering → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → gates_covering |
| REQ-DDB-QUERY-013 | inferred | test_a_gate_without_an_extent_is_reported_as_unknown_not_as_ungated → gates_covering → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert "config" in resolve_subject(db, "PROJ_THREADING_PTHREAD")assert subject is not Noneassert subject.kind == "config"assert subject.config is not Noneassert {g.symbol for g in subject.config.gates} == {"PROJ_THREADING_PTHREAD"}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_a_gated_on_symbol_is_a_dossier_subject → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_a_gated_on_symbol_is_a_dossier_subject → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_a_gated_on_symbol_is_a_dossier_subject → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_a_gated_on_symbol_is_a_dossier_subject → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_a_gated_on_symbol_is_a_dossier_subject → resolve_subject → connect |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-004 | measured | |
| REQ-DDB-QUERY-006 | measured | |
| REQ-DDB-QUERY-010 | measured | |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-QUERY-013 | measured | |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_a_kconfig_parse_is_given_a_minimal_environment → discover_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_a_kconfig_parse_is_given_a_minimal_environment → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-006 | catalog |
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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_a_kconfig_sourcing_outside_the_repository_is_refused → discover_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_a_kconfig_sourcing_outside_the_repository_is_refused → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-006 | catalog |
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
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.
Called by none
Calls _db_with_paths, import_kconfig, kconfig_space, write_build_signature
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 Trueassert space.error, "the query layer must report the parse failure, not a bare empty"assert space.symbols == ()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → import_kconfig |
| REQ-DDB-CONFIG-006 | measured | test_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → write_build_signature |
| REQ-DDB-CONFIG-007 | measured | test_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → write_build_signature |
| REQ-DDB-PIPE-005 | measured | test_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → write_build_signature |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → import_kconfig → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-001 | measured | test_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_a_kconfig_that_cannot_be_parsed_is_recorded_rather_than_silent → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Called by none
Calls _db_with_paths, import_kconfig, ingest_supplementary_docs, search_prose
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_a_limitation_documented_only_in_help_is_searchable → import_kconfig |
| REQ-DDB-INDEX-002 | inferred | test_a_limitation_documented_only_in_help_is_searchable → ingest_supplementary_docs → _ingest_one_doc_file → memoized |
| REQ-DDB-PIPE-001 | measured | test_a_limitation_documented_only_in_help_is_searchable → ingest_supplementary_docs |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_a_limitation_documented_only_in_help_is_searchable → ingest_supplementary_docs → within_repo |
| REQ-DDB-QUERY-001 | measured | test_a_limitation_documented_only_in_help_is_searchable → search_prose |
| REQ-DDB-QUERY-003 | measured | test_a_limitation_documented_only_in_help_is_searchable → search_prose → search_prose_graded → table_exists |
| REQ-DDB-QUERY-006 | catalog | |
| REQ-DDB-QUERY-007 | measured | test_a_limitation_documented_only_in_help_is_searchable → search_prose → search_prose_graded → member_doc_rows |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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".
Checks
assert model.found is Trueassert model.symbols == ()assert meta["kconfig.symbol_count"] == "0", "the measured zero was dropped as falsy"assert meta["kconfig.source"] == SOURCE_ROOT
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_a_measured_zero_survives_the_build_signature → import_kconfig |
| REQ-DDB-CONFIG-006 | measured | test_a_measured_zero_survives_the_build_signature → write_build_signature |
| REQ-DDB-CONFIG-007 | measured | test_a_measured_zero_survives_the_build_signature → write_build_signature |
| REQ-DDB-PIPE-005 | measured | test_a_measured_zero_survives_the_build_signature → write_build_signature |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_a_measured_zero_survives_the_build_signature → import_kconfig → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-006 | catalog | |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert "config" not in resolve_subject(db, "PROJ_NEVER_MENTIONED_ANYWHERE")
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_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-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_a_name_that_is_neither_declared_nor_gated_is_still_not_a_config_subject → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_a_name_that_is_neither_declared_nor_gated_is_still_not_a_config_subject → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_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-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_a_name_that_is_neither_declared_nor_gated_is_still_not_a_config_subject → resolve_subject → connect |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-004 | measured | |
| REQ-DDB-QUERY-006 | catalog | |
| REQ-DDB-QUERY-010 | measured | |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_a_parse_failure_records_the_location_and_not_the_line → discover_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_a_parse_failure_records_the_location_and_not_the_line → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-006 | catalog |
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
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.
Checks
assert ("PROJ_OMIT_TELEMETRY", KCONFIG_GATE_IFNDEF) in gates
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_a_plain_ifndef_gate_survives_the_include_guard_exclusion → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_a_plain_ifndef_gate_survives_the_include_guard_exclusion → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_a_plain_ifndef_gate_survives_the_include_guard_exclusion → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_a_plain_ifndef_gate_survives_the_include_guard_exclusion → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_a_plain_ifndef_gate_survives_the_include_guard_exclusion → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_a_plain_ifndef_gate_survives_the_include_guard_exclusion → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_a_plain_ifndef_gate_survives_the_include_guard_exclusion → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_a_plain_ifndef_gate_survives_the_include_guard_exclusion → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_a_plain_ifndef_gate_survives_the_include_guard_exclusion → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_a_repo_supplied_kconfig_functions_module_is_not_imported → discover_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_a_repo_supplied_kconfig_functions_module_is_not_imported → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-006 | catalog |
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
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.
Checks
assert import_kconfig_gates(db, root) > 0assert ("PROJ_THREADING_C", KCONFIG_GATE_IF_EXPR) in gatesassert ("PROJ_THREADING_PTHREAD", KCONFIG_GATE_IF_EXPR) in gatesassert ("PROJ_LEGACY", KCONFIG_GATE_IFDEF) in gates
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_a_repo_that_uses_no_kconfig_still_gets_a_gate_layer → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Called by none
Calls _db_with_paths, import_kconfig, kconfig_space, write_build_signature
Checks
assert model.as_meta() == {}, "a repo with no Kconfig must stamp no kconfig.* row"assert "kconfig_symbols" not in tablesassert "kconfig_choices" not in tablesassert not any(key.startswith("kconfig.") for key in metas)assert space.found is Falseassert space.symbols == ()assert space.error == ""
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_a_repo_with_no_kconfig_is_completely_unaffected → import_kconfig |
| REQ-DDB-CONFIG-006 | measured | test_a_repo_with_no_kconfig_is_completely_unaffected → write_build_signature |
| REQ-DDB-CONFIG-007 | measured | test_a_repo_with_no_kconfig_is_completely_unaffected → write_build_signature |
| REQ-DDB-PIPE-005 | measured | test_a_repo_with_no_kconfig_is_completely_unaffected → write_build_signature |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | catalog | test_a_repo_with_no_kconfig_is_completely_unaffected → import_kconfig → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-001 | measured | test_a_repo_with_no_kconfig_is_completely_unaffected → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_a_repo_with_no_kconfig_is_completely_unaffected → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_a_repo_with_no_kconfig_is_completely_unaffected → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_a_repo_with_no_kconfig_is_completely_unaffected → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_a_repo_with_no_kconfig_is_completely_unaffected → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-013 | inferred | test_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
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.
Checks
assert all(g.line != runtime_line for g in kconfig_space(db).gates)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_a_runtime_is_enabled_branch_is_not_a_gate → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_a_runtime_is_enabled_branch_is_not_a_gate → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_a_runtime_is_enabled_branch_is_not_a_gate → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_a_runtime_is_enabled_branch_is_not_a_gate → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_a_runtime_is_enabled_branch_is_not_a_gate → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_a_runtime_is_enabled_branch_is_not_a_gate → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_a_runtime_is_enabled_branch_is_not_a_gate → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_a_runtime_is_enabled_branch_is_not_a_gate → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_a_runtime_is_enabled_branch_is_not_a_gate → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_a_runtime_is_enabled_branch_is_not_a_gate → import_kconfig_gates → ensure_kconfig_gates_table |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert discover_kconfig(root).path == Path("app/Kconfig")
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_a_single_conventional_candidate_is_accepted → discover_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | catalog | test_a_single_conventional_candidate_is_accepted → discover_kconfig → _declared_kconfig → within_repo |
| REQ-DDB-QUERY-006 | catalog |
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
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.
Checks
assert model.error == "", model.errorassert {"WIDGET_MOTOR_ALPHA", "WIDGET_MOTOR_BETA", "WIDGET_LOG_LEVEL"} <= set(by_name)assert alpha.choice_key is not Noneassert alpha.choice_key == beta.choice_keyassert by_name["WIDGET_LOG_LEVEL"].choice_key is None, "an ungrouped symbol has no group"assert len(model.choices) == 1assert model.choices[0].prompt == "Motor variant"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_a_sourced_file_is_parsed_and_choices_group_their_members → discover_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_a_sourced_file_is_parsed_and_choices_group_their_members → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-006 | catalog |
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
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.
Checks
assert "PROJ_WIDGET_H" not in symbolsassert "PROJ_GUARD_WITHOUT_H_SUFFIX" not in symbols, "the suffix is not the rule"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_an_include_guard_is_not_a_configuration_gate → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_an_include_guard_is_not_a_configuration_gate → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_an_include_guard_is_not_a_configuration_gate → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_an_include_guard_is_not_a_configuration_gate → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_an_include_guard_is_not_a_configuration_gate → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_an_include_guard_is_not_a_configuration_gate → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_an_include_guard_is_not_a_configuration_gate → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_an_include_guard_is_not_a_configuration_gate → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_an_include_guard_is_not_a_configuration_gate → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert location.source == SOURCE_ROOTassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_an_unambiguous_root_kconfig_is_found_and_stored_repo_relative → discover_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | catalog | test_an_unambiguous_root_kconfig_is_found_and_stored_repo_relative → discover_kconfig → _declared_kconfig → within_repo |
| REQ-DDB-QUERY-006 | catalog |
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
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.
Checks
assert "STATED BY THE OPERATOR" in statedassert "may well be OFF, or commented out" in statedassert header in stated, "the ROUTE is the point — a disclaimer alone leaves the agent hunting"assert "COMBINES" in mixedassert "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 mixedassert "does describe what the repository builds by default" in from_repoassert "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 unknownassert "treat the default as unknown" in unknownassert macros_meaning("", "", "") == ""
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | catalog | |
| REQ-DDB-QUERY-006 | measured | test_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
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.
Checks
assert location.path is None, "two conventional candidates must not be resolved by order"assert len(location.searched) > 1
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_convention_refuses_among_several_candidates → discover_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | catalog | test_convention_refuses_among_several_candidates → discover_kconfig → _declared_kconfig → within_repo |
| REQ-DDB-QUERY-006 | catalog |
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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_declared_macro_names_drops_the_value_half → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | catalog | |
| REQ-DDB-QUERY-006 | catalog |
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
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.
Checks
assert "defined" not in {g.symbol for g in kconfig_space(db).gates}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_defined_is_an_operator_and_never_a_gating_symbol → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_defined_is_an_operator_and_never_a_gating_symbol → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_defined_is_an_operator_and_never_a_gating_symbol → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_defined_is_an_operator_and_never_a_gating_symbol → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_defined_is_an_operator_and_never_a_gating_symbol → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_defined_is_an_operator_and_never_a_gating_symbol → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_defined_is_an_operator_and_never_a_gating_symbol → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_defined_is_an_operator_and_never_a_gating_symbol → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_defined_is_an_operator_and_never_a_gating_symbol → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Called by none
Calls _db_with_paths, import_kconfig, import_kconfig_gates, kconfig_space, write_build_signature
Checks
assert by_name["WIDGET_MOTOR_BETA"].gate_count == 1assert by_name["WIDGET_MOTOR_NAME"].gate_count == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_gate_counts_reach_the_symbol_rows → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | measured | test_gate_counts_reach_the_symbol_rows → import_kconfig |
| REQ-DDB-CONFIG-006 | measured | test_gate_counts_reach_the_symbol_rows → write_build_signature |
| REQ-DDB-CONFIG-007 | measured | test_gate_counts_reach_the_symbol_rows → write_build_signature |
| REQ-DDB-PIPE-003 | measured | test_gate_counts_reach_the_symbol_rows → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-005 | measured | test_gate_counts_reach_the_symbol_rows → write_build_signature |
| REQ-DDB-PIPE-007 | measured | test_gate_counts_reach_the_symbol_rows → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_gate_counts_reach_the_symbol_rows → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_gate_counts_reach_the_symbol_rows → import_kconfig_gates → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-PIPE-014 | measured | test_gate_counts_reach_the_symbol_rows → import_kconfig → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-001 | measured | test_gate_counts_reach_the_symbol_rows → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_gate_counts_reach_the_symbol_rows → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_gate_counts_reach_the_symbol_rows → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_gate_counts_reach_the_symbol_rows → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_gate_counts_reach_the_symbol_rows → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert import_kconfig_gates(db, repo) > 0assert ("WIDGET_MOTOR_BETA", KCONFIG_GATE_IFDEF) in gatesassert ("WIDGET_RADIO", KCONFIG_GATE_IFNDEF) in gatesassert ("WIDGET_MOTOR_ALPHA", KCONFIG_GATE_IF_EXPR) in gatesassert ("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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_gating_sites_record_the_form_and_the_line → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_gating_sites_record_the_form_and_the_line → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_gating_sites_record_the_form_and_the_line → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_gating_sites_record_the_form_and_the_line → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_gating_sites_record_the_form_and_the_line → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_gating_sites_record_the_form_and_the_line → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_gating_sites_record_the_form_and_the_line → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_gating_sites_record_the_form_and_the_line → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_gating_sites_record_the_form_and_the_line → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Called by none
Calls _db_with_paths, discover_kconfig, ingest_kconfig_prose, ingest_supplementary_docs, load_kconfig, search_prose
Checks
assert ingest_kconfig_prose(wrong, model) > 0assert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_kconfig_prose_must_be_ingested_after_the_markdown_ingest → discover_kconfig |
| REQ-DDB-INDEX-002 | inferred | test_kconfig_prose_must_be_ingested_after_the_markdown_ingest → ingest_supplementary_docs → _ingest_one_doc_file → memoized |
| REQ-DDB-PIPE-001 | measured | test_kconfig_prose_must_be_ingested_after_the_markdown_ingest → ingest_supplementary_docs |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_kconfig_prose_must_be_ingested_after_the_markdown_ingest → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-001 | measured | test_kconfig_prose_must_be_ingested_after_the_markdown_ingest → search_prose |
| REQ-DDB-QUERY-003 | measured | test_kconfig_prose_must_be_ingested_after_the_markdown_ingest → search_prose → search_prose_graded → table_exists |
| REQ-DDB-QUERY-006 | catalog | |
| REQ-DDB-QUERY-007 | measured | test_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
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.
Checks
assert beta.file_path == "Kconfig.motor"assert not Path(beta.file_path).is_absolute()assert beta.line > 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_locations_are_repo_relative_and_point_at_the_declaring_file → discover_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_locations_are_repo_relative_and_point_at_the_declaring_file → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-006 | catalog |
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
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 > 2` genuinely participate in deciding whether the line exists, so both are recorded.
Checks
assert {"WIDGET_MOTOR_ALPHA", "WIDGET_LOG_LEVEL"} <= expr
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_one_conditional_naming_two_symbols_yields_two_rows → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_one_conditional_naming_two_symbols_yields_two_rows → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_one_conditional_naming_two_symbols_yields_two_rows → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_one_conditional_naming_two_symbols_yields_two_rows → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_one_conditional_naming_two_symbols_yields_two_rows → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_one_conditional_naming_two_symbols_yields_two_rows → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_one_conditional_naming_two_symbols_yields_two_rows → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_one_conditional_naming_two_symbols_yields_two_rows → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_one_conditional_naming_two_symbols_yields_two_rows → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert origin["PROJ_THREADING_C"] == GATE_ORIGIN_DECLAREDassert origin["PROJ_THREADING_PTHREAD"] == GATE_ORIGIN_UNDECLAREDassert origin["PROJ_LEGACY"] == GATE_ORIGIN_UNDECLARED
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_origin_labels_the_declared_variant_without_filtering_the_rest → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_origin_labels_the_declared_variant_without_filtering_the_rest → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_origin_labels_the_declared_variant_without_filtering_the_rest → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_origin_labels_the_declared_variant_without_filtering_the_rest → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_origin_labels_the_declared_variant_without_filtering_the_rest → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_origin_labels_the_declared_variant_without_filtering_the_rest → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_origin_labels_the_declared_variant_without_filtering_the_rest → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_origin_labels_the_declared_variant_without_filtering_the_rest → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_origin_labels_the_declared_variant_without_filtering_the_rest → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_prompt_and_symbol_name_both_reach_the_prose_corpus → import_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_prompt_and_symbol_name_both_reach_the_prose_corpus → import_kconfig → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-001 | measured | test_prompt_and_symbol_name_both_reach_the_prose_corpus → search_prose |
| REQ-DDB-QUERY-003 | measured | test_prompt_and_symbol_name_both_reach_the_prose_corpus → search_prose → search_prose_graded → table_exists |
| REQ-DDB-QUERY-006 | catalog | |
| REQ-DDB-QUERY-007 | measured | test_prompt_and_symbol_name_both_reach_the_prose_corpus → search_prose → search_prose_graded → member_doc_rows |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert hits, "a stored gating symbol must be discoverable"assert hits[0].name == "PROJ_THREADING_PTHREAD"assert hits[0].kind == CONFIG_SYMBOL_KINDassert len([h for h in hits if h.kind == CONFIG_SYMBOL_KIND]) == 1
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_search_finds_a_gating_symbol_by_name → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_search_finds_a_gating_symbol_by_name → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_search_finds_a_gating_symbol_by_name → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_search_finds_a_gating_symbol_by_name → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-006 | catalog | |
| REQ-DDB-QUERY-007 | measured | |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert store_kconfig(db, KconfigModel(location=KconfigLocation(path=None))) == 0assert "kconfig_symbols" not in tablesassert "kconfig_choices" not in tables
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_store_kconfig_refuses_an_unfound_model_on_its_own → store_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | catalog | |
| REQ-DDB-QUERY-006 | catalog | |
| REQ-DDB-SCHEMA-013 | inferred | test_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
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.
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_namesassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_the_config_inventory_lists_symbols_and_honours_text → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_the_config_inventory_lists_symbols_and_honours_text → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_the_config_inventory_lists_symbols_and_honours_text → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_the_config_inventory_lists_symbols_and_honours_text → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_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
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.
Called by none
Calls _db_with_paths, import_kconfig, kconfig_space, write_build_signature
Checks
assert "CONFIG_WIDGET_MOTOR_BETA" in space.configured_macrosassert space.symbols, "the space must still be reported alongside the instance"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_the_configured_variant_travels_beside_the_space → import_kconfig |
| REQ-DDB-CONFIG-006 | measured | test_the_configured_variant_travels_beside_the_space → write_build_signature |
| REQ-DDB-CONFIG-007 | measured | test_the_configured_variant_travels_beside_the_space → write_build_signature |
| REQ-DDB-PIPE-005 | measured | test_the_configured_variant_travels_beside_the_space → write_build_signature |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_the_configured_variant_travels_beside_the_space → import_kconfig → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-001 | measured | test_the_configured_variant_travels_beside_the_space → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_the_configured_variant_travels_beside_the_space → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_the_configured_variant_travels_beside_the_space → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_the_configured_variant_travels_beside_the_space → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_the_configured_variant_travels_beside_the_space → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
Checks
assert SECTION_KCONFIG in decl_mod.KNOWN_SECTIONSassert decl_mod.SECTION_KCONFIG == SECTION_KCONFIG
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | catalog | |
| REQ-DDB-QUERY-006 | catalog |
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
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.
Called by none
Calls _no_kconfig_repo, ensure_kconfig_gates_table, import_kconfig_gates, kconfig_space
Checks
assert import_kconfig_gates(_db, gated) > 0assert space.found is False, "this fixture has no Kconfig — `found` must stay honest about that"assert space.gate_state == LAYER_STATE_POPULATEDassert space.gate_symbols > 0, "the harvest saw gating symbols and must say how many"assert space.found or space.gate_state == LAYER_STATE_POPULATEDassert 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 == 0assert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_the_gate_layer_reports_its_own_state_independently_of_kconfig → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_the_gate_layer_reports_its_own_state_independently_of_kconfig → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_the_gate_layer_reports_its_own_state_independently_of_kconfig → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_the_gate_layer_reports_its_own_state_independently_of_kconfig → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_the_gate_layer_reports_its_own_state_independently_of_kconfig → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_the_gate_layer_reports_its_own_state_independently_of_kconfig → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_the_gate_layer_reports_its_own_state_independently_of_kconfig → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_the_gate_layer_reports_its_own_state_independently_of_kconfig → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_the_gate_layer_reports_its_own_state_independently_of_kconfig → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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`.
Checks
assert bare == prefixedassert bare and {g.symbol for g in bare} == {"WIDGET_MOTOR_BETA"}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_the_gate_list_can_be_narrowed_to_one_symbol → import_kconfig_gates → declared_macro_names → bare_macro_names |
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-003 | measured | test_the_gate_list_can_be_narrowed_to_one_symbol → import_kconfig_gates → run_harvest |
| REQ-DDB-PIPE-007 | measured | test_the_gate_list_can_be_narrowed_to_one_symbol → import_kconfig_gates |
| REQ-DDB-PIPE-011 | measured | test_the_gate_list_can_be_narrowed_to_one_symbol → import_kconfig_gates → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_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-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_the_gate_list_can_be_narrowed_to_one_symbol → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_the_gate_list_can_be_narrowed_to_one_symbol → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_the_gate_list_can_be_narrowed_to_one_symbol → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_the_gate_list_can_be_narrowed_to_one_symbol → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_the_gate_list_can_be_narrowed_to_one_symbol → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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 .
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | catalog | |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | catalog | |
| REQ-DDB-QUERY-001 | measured | test_the_stated_macro_split_reaches_the_served_reply → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_the_stated_macro_split_reaches_the_served_reply → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_the_stated_macro_split_reaches_the_served_reply → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_the_stated_macro_split_reaches_the_served_reply → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_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
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.
Called by none
Calls _db_with_paths, import_kconfig, kconfig_space, write_build_signature
Checks
assert space.found is Trueassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_the_stored_tables_round_trip_through_the_query_layer → import_kconfig |
| REQ-DDB-CONFIG-006 | measured | test_the_stored_tables_round_trip_through_the_query_layer → write_build_signature |
| REQ-DDB-CONFIG-007 | measured | test_the_stored_tables_round_trip_through_the_query_layer → write_build_signature |
| REQ-DDB-PIPE-005 | measured | test_the_stored_tables_round_trip_through_the_query_layer → write_build_signature |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_the_stored_tables_round_trip_through_the_query_layer → import_kconfig → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-001 | measured | test_the_stored_tables_round_trip_through_the_query_layer → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_the_stored_tables_round_trip_through_the_query_layer → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_the_stored_tables_round_trip_through_the_query_layer → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_the_stored_tables_round_trip_through_the_query_layer → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_the_stored_tables_round_trip_through_the_query_layer → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured | |
| REQ-DDB-SCHEMA-013 | measured | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-005 | measured | test_types_defaults_and_conditions_survive_verbatim → discover_kconfig |
| REQ-DDB-PIPE-007 | catalog | |
| REQ-DDB-PIPE-014 | measured | test_types_defaults_and_conditions_survive_verbatim → load_kconfig → _served_parse_error |
| REQ-DDB-QUERY-006 | catalog |
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"