test_config_defaults.py¶
tests/test_config_defaults.py
What a build leaves OFF, which an index of what exists cannot otherwise hold.
test_a_commented_define_in_ordinary_source_is_not_a_config_option
None test_config_defaults.test_a_commented_define_in_ordinary_source_is_not_a_config_option(Path tmp_path)
Ordinary source is not mined for commented-out code.
tests/test_config_defaults.py:148
Checks
assert "DEBUG_ONLY_LEFTOVER" not in names, "a commented define in .c is not an option"assert not any(r[3].endswith(".c") for r in rows), "no row may come from ordinary source"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_a_commented_define_in_ordinary_source_is_not_a_config_option → _build → import_config_defaults → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_a_commented_define_in_ordinary_source_is_not_a_config_option → _build → import_config_defaults → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_a_commented_define_in_ordinary_source_is_not_a_config_option → _build → import_config_defaults → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-PIPE-015 | measured | test_a_commented_define_in_ordinary_source_is_not_a_config_option → _build → import_config_defaults |
| REQ-DDB-SCHEMA-012 | measured |
Source · 19 lines
def test_a_commented_define_in_ordinary_source_is_not_a_config_option(tmp_path: Path) -> None:
"""A COMMENTED DEFINE IN A .c FILE IS DEAD CODE, not a configuration decision. That is a
different finding, and letting it into this layer would make every answer here less
trustworthy — a reader could not tell an option the project offers from a line somebody
abandoned.
Also guards the inverse: a prose comment MENTIONING a define must not become a row, which
is why the scan reads comment nodes and requires the define to be the whole comment.
@brief Dead code stays out.
@return None.
@version 1
"""
_, rows = _build(tmp_path)
names = {r[0] for r in rows}
assert "DEBUG_ONLY_LEFTOVER" not in names, "a commented define in .c is not an option"
assert not any(r[3].endswith(".c") for r in rows), "no row may come from ordinary source"
Activity · 4 steps
test_a_commented_out_define_is_recorded_as_off_by_default
None test_config_defaults.test_a_commented_out_define_is_recorded_as_off_by_default(Path tmp_path)
A commented-out define is recorded as off, not omitted.
tests/test_config_defaults.py:91
Checks
assert by[("FEATURE_PLATFORM_MEMORY", shipped)][1] == "off"assert by[("FEATURE_SPACED_FORM", shipped)][1] == "off"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_a_commented_out_define_is_recorded_as_off_by_default → _build → import_config_defaults → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_a_commented_out_define_is_recorded_as_off_by_default → _build → import_config_defaults → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_a_commented_out_define_is_recorded_as_off_by_default → _build → import_config_defaults → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-PIPE-015 | measured | test_a_commented_out_define_is_recorded_as_off_by_default → _build → import_config_defaults |
| REQ-DDB-SCHEMA-012 | measured |
Source · 21 lines
def test_a_commented_out_define_is_recorded_as_off_by_default(tmp_path: Path) -> None:
"""THE WHOLE POINT. Without this row the only trace of the option in the index is the
alternative profile that enables it, so an agent reads "defined" and answers the opposite
of the truth for a default build.
@brief Commented defines are off.
@return None.
@version 1
"""
_, rows = _build(tmp_path)
## KEYED ON (macro, file), NOT macro ALONE. One macro legitimately has a row per header
## that decides it — that is the whole mbedtls shape — so a macro-keyed lookup silently
## returns whichever row sorted last and this assertion would then describe the wrong file.
by = {(r[0], r[3]): r for r in rows}
shipped = "include/proj_config.h"
assert by[("FEATURE_PLATFORM_MEMORY", shipped)][1] == "off"
## BOTH COMMENT SPELLINGS. `//#define` with no space is mbedtls's; `/* #define X */` is the
## other common form, and recognising only one would silently halve the layer.
assert by[("FEATURE_SPACED_FORM", shipped)][1] == "off"
Activity · 5 steps
test_a_gate_carries_its_macros_shipped_default
None test_config_defaults.test_a_gate_carries_its_macros_shipped_default(Path tmp_path)
A covering gate carries the shipped default of the macro it names.
tests/test_config_defaults.py:307
Checks
assert len(gates) == 1assert gates[0].default_state == "off"assert gates[0].default_site == "include/proj_config.h:208"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-015 | measured | test_a_gate_carries_its_macros_shipped_default → _gate_db → ensure_config_defaults_table |
| REQ-DDB-QUERY-003 | measured | test_a_gate_carries_its_macros_shipped_default → gates_covering → table_exists |
| REQ-DDB-QUERY-004 | measured | test_a_gate_carries_its_macros_shipped_default → gates_covering → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_a_gate_carries_its_macros_shipped_default → gates_covering |
| REQ-DDB-QUERY-013 | measured | test_a_gate_carries_its_macros_shipped_default → gates_covering → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured |
Source · 24 lines
def test_a_gate_carries_its_macros_shipped_default(tmp_path: Path) -> None:
"""THE JOIN THAT ANSWERS THE QUESTION, and the reason the harvest layer alone is worth
nothing. `form` says "present when this symbol is set"; the default says whether it IS set.
Only the two together answer "is this code compiled in", which is what the mbedtls marks
asked and the index-only arm scored 0/3 on.
@brief Gates carry defaults.
@return None.
@version 1
"""
from clew.query.kconfig import gates_covering
conn = _gate_db(
tmp_path,
"g.db",
[("FEATURE_X", "off", "", "include/proj_config.h", 208, "", "declared")],
)
gates, _ = gates_covering(conn, "src/platform.h", 20)
conn.close()
assert len(gates) == 1
assert gates[0].default_state == "off"
assert gates[0].default_site == "include/proj_config.h:208"
Activity · 7 steps
test_an_active_define_is_recorded_as_on
None test_config_defaults.test_an_active_define_is_recorded_as_on(Path tmp_path)
An active define in the same header is recorded as on.
tests/test_config_defaults.py:115
Checks
assert by[("FEATURE_ON_BY_DEFAULT", "include/proj_config.h")][1] == "on"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_an_active_define_is_recorded_as_on → _build → import_config_defaults → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_an_active_define_is_recorded_as_on → _build → import_config_defaults → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_an_active_define_is_recorded_as_on → _build → import_config_defaults → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-PIPE-015 | measured | test_an_active_define_is_recorded_as_on → _build → import_config_defaults |
| REQ-DDB-SCHEMA-012 | measured |
Source · 14 lines
def test_an_active_define_is_recorded_as_on(tmp_path: Path) -> None:
"""ONE SCAN FOR BOTH STATES, so "on" and "off" cannot disagree about which options a header
decides. A layer that recorded only the off ones would leave a reader unable to tell an
enabled option from an option this header never mentions.
@brief Active defines are on.
@return None.
@version 1
"""
_, rows = _build(tmp_path)
by = {(r[0], r[3]): r for r in rows}
assert by[("FEATURE_ON_BY_DEFAULT", "include/proj_config.h")][1] == "on"
Activity · 3 steps
test_an_include_guard_is_not_an_option
None test_config_defaults.test_an_include_guard_is_not_an_option(Path tmp_path)
An include guard is not a configuration option.
tests/test_config_defaults.py:229
Checks
assert "PROJ_CONFIG_H" not in names, "an include guard is not a configuration option"assert "FEATURE_REAL_OPTION" in namesassert "FEATURE_OFF_OPTION" in names
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_an_include_guard_is_not_an_option → import_config_defaults → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_an_include_guard_is_not_an_option → import_config_defaults → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_an_include_guard_is_not_an_option → import_config_defaults → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-PIPE-015 | measured | test_an_include_guard_is_not_an_option → import_config_defaults |
| REQ-DDB-SCHEMA-012 | measured |
Source · 44 lines
def test_an_include_guard_is_not_an_option(tmp_path: Path) -> None:
"""`#ifndef FOO_H` / `#define FOO_H` IS "INCLUDE ME ONCE", NOT A FEATURE. Measured on the
real mbedtls tree before this exclusion: 39 of 1,206 "on" rows were guards, and nobody asks
whether MBEDTLS_CONFIG_H is enabled by default. Left in, they rank EXACT on their own names
in the discovery surface and become pure noise — the same reason `kconfig_gates` excludes
them from gating sites.
STRUCTURAL, NOT A `_H` SUFFIX RULE. The discriminator is that the guarded block defines the
SAME symbol it just tested, which no configuration option ever does. A suffix test misses
guards spelled otherwise and would catch feature macros that legitimately end in _H.
@brief Guards stay out.
@return None.
@version 1
"""
repo = tmp_path / "repo"
(repo / "include").mkdir(parents=True)
(repo / "include" / "guard_config.h").write_text(
"#ifndef PROJ_CONFIG_H\n"
"#define PROJ_CONFIG_H\n"
"#define FEATURE_REAL_OPTION\n"
"//#define FEATURE_OFF_OPTION\n"
"#endif\n",
encoding="utf-8",
)
db = tmp_path / "guard.db"
conn = sqlite3.connect(str(db))
conn.execute("CREATE TABLE path (rowid INTEGER PRIMARY KEY, name TEXT)")
conn.execute("INSERT INTO path (rowid, name) VALUES (1, 'include/guard_config.h')")
conn.commit()
conn.close()
import_config_defaults(db, repo)
conn = sqlite3.connect(str(db))
names = {r[0] for r in conn.execute("SELECT macro FROM config_defaults").fetchall()}
conn.close()
assert "PROJ_CONFIG_H" not in names, "an include guard is not a configuration option"
## The real options inside the guarded block must survive it — a guard excludes ITSELF,
## not everything it wraps, which is every option in a guarded config header.
assert "FEATURE_REAL_OPTION" in names
assert "FEATURE_OFF_OPTION" in names
Activity · 16 steps
test_an_index_without_the_table_still_serves_gates
None test_config_defaults.test_an_index_without_the_table_still_serves_gates(Path tmp_path)
An index built before this layer serves gates unchanged.
tests/test_config_defaults.py:391
Checks
assert len(gates) == 1 and gates[0].default_state == ""
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-015 | catalog | test_an_index_without_the_table_still_serves_gates → _gate_db → ensure_config_defaults_table |
| REQ-DDB-QUERY-003 | measured | test_an_index_without_the_table_still_serves_gates → gates_covering → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_an_index_without_the_table_still_serves_gates → gates_covering → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_an_index_without_the_table_still_serves_gates → gates_covering |
| REQ-DDB-QUERY-013 | inferred | test_an_index_without_the_table_still_serves_gates → gates_covering → _with_defaults → decided_default |
Source · 15 lines
def test_an_index_without_the_table_still_serves_gates(tmp_path: Path) -> None:
"""THE TABLE IS NEW, SO EVERY INDEX IN EXISTENCE LACKS IT. A reader of an older index must
get its gates with an empty default rather than an exception — the same tolerance every
other column-added layer here carries.
@brief Older indexes still work.
@return None.
@version 1
"""
from clew.query.kconfig import gates_covering
conn = _gate_db(tmp_path, "old.db", None)
gates, _ = gates_covering(conn, "src/platform.h", 20)
conn.close()
assert len(gates) == 1 and gates[0].default_state == ""1 more lines, not shown
Activity · 5 steps
test_disagreeing_profiles_leave_the_default_undecided
None test_config_defaults.test_disagreeing_profiles_leave_the_default_undecided(Path tmp_path)
Disagreeing guesses with no declared header decide nothing.
tests/test_config_defaults.py:364
Checks
assert gates[0].default_state == "", "two guesses that disagree must not pick a winner"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-015 | measured | test_disagreeing_profiles_leave_the_default_undecided → _gate_db → ensure_config_defaults_table |
| REQ-DDB-QUERY-003 | measured | test_disagreeing_profiles_leave_the_default_undecided → gates_covering → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_disagreeing_profiles_leave_the_default_undecided → gates_covering → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_disagreeing_profiles_leave_the_default_undecided → gates_covering |
| REQ-DDB-QUERY-013 | measured | test_disagreeing_profiles_leave_the_default_undecided → gates_covering → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured |
Source · 24 lines
def test_disagreeing_profiles_leave_the_default_undecided(tmp_path: Path) -> None:
"""EMPTY MEANS UNDECIDED, NEVER OFF. With two profiles disagreeing and no declared header to
settle it, naming either as "the default" is the confident wrong answer this whole layer
exists to remove — rebuilt one level up, which is exactly how it would come back.
@brief Ambiguity stays ambiguous.
@return None.
@version 1
"""
from clew.query.kconfig import gates_covering
conn = _gate_db(
tmp_path,
"a.db",
[
("FEATURE_X", "off", "", "configs/a_config.h", 1, "", "heuristic"),
("FEATURE_X", "on", "", "configs/b_config.h", 1, "", "heuristic"),
],
)
gates, _ = gates_covering(conn, "src/platform.h", 20)
conn.close()
assert gates[0].default_state == "", "two guesses that disagree must not pick a winner"
Activity · 5 steps
test_header_detection_is_named_and_narrow
None test_config_defaults.test_header_detection_is_named_and_narrow(Path tmp_path)
The config-header heuristic is narrow and is labelled as a heuristic.
tests/test_config_defaults.py:210
Checks
assert looks_like_config_header("include/mbedtls/mbedtls_config.h")assert looks_like_config_header("tests/configs/user-config-malloc-0-null.h")assert not looks_like_config_header("library/ssl_tls.c")assert not looks_like_config_header("include/mbedtls/platform.h")assert {r[5] for r in rows} == {"heuristic"}, "an unstated header is a guess, and says so"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_header_detection_is_named_and_narrow → _build → import_config_defaults → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_header_detection_is_named_and_narrow → _build → import_config_defaults → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_header_detection_is_named_and_narrow → _build → import_config_defaults → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-PIPE-015 | measured | test_header_detection_is_named_and_narrow → _build → import_config_defaults |
| REQ-DDB-SCHEMA-012 | measured |
Source · 16 lines
def test_header_detection_is_named_and_narrow(tmp_path: Path) -> None:
"""NAME-MATCHED, AND THE ROW SAYS SO. `origin` separates a header the operator declared
from one this guessed at, so a consumer is never handed a guess as a fact.
@brief Heuristic is labelled.
@return None.
@version 1
"""
assert looks_like_config_header("include/mbedtls/mbedtls_config.h")
assert looks_like_config_header("tests/configs/user-config-malloc-0-null.h")
assert not looks_like_config_header("library/ssl_tls.c")
assert not looks_like_config_header("include/mbedtls/platform.h")
_, rows = _build(tmp_path)
assert {r[5] for r in rows} == {"heuristic"}, "an unstated header is a guess, and says so"
Activity · 6 steps
test_the_commented_value_is_kept
None test_config_defaults.test_the_commented_value_is_kept(Path tmp_path)
The value a commented define carries is kept beside its state.
tests/test_config_defaults.py:132
Checks
assert by[("FEATURE_WITH_VALUE", "include/proj_config.h")][2] == "42"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_the_commented_value_is_kept → _build → import_config_defaults → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_the_commented_value_is_kept → _build → import_config_defaults → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_the_commented_value_is_kept → _build → import_config_defaults → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-PIPE-015 | measured | test_the_commented_value_is_kept → _build → import_config_defaults |
| REQ-DDB-SCHEMA-012 | measured |
Source · 13 lines
def test_the_commented_value_is_kept(tmp_path: Path) -> None:
""" "off" and "off, and it would be 42" are different answers, and the second is what a
reader asking about a default actually wants.
@brief Values survive.
@return None.
@version 1
"""
_, rows = _build(tmp_path)
by = {(r[0], r[3]): r for r in rows}
assert by[("FEATURE_WITH_VALUE", "include/proj_config.h")][2] == "42"
Activity · 3 steps
test_the_declared_header_wins_over_an_alternative_profile
None test_config_defaults.test_the_declared_header_wins_over_an_alternative_profile(Path tmp_path)
The declared header outvotes an alternative profile.
tests/test_config_defaults.py:334
Checks
assert gates[0].default_state == "off", "the shipped header decides the default build"assert gates[0].default_site == "include/proj_config.h:208"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-015 | measured | test_the_declared_header_wins_over_an_alternative_profile → _gate_db → ensure_config_defaults_table |
| REQ-DDB-QUERY-003 | measured | test_the_declared_header_wins_over_an_alternative_profile → gates_covering → table_exists |
| REQ-DDB-QUERY-004 | measured | test_the_declared_header_wins_over_an_alternative_profile → gates_covering → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_the_declared_header_wins_over_an_alternative_profile → gates_covering |
| REQ-DDB-QUERY-013 | measured | test_the_declared_header_wins_over_an_alternative_profile → gates_covering → _with_defaults → decided_default |
| REQ-DDB-SCHEMA-012 | measured |
Source · 27 lines
def test_the_declared_header_wins_over_an_alternative_profile(tmp_path: Path) -> None:
"""THE EXACT mbedtls SHAPE. `MBEDTLS_PLATFORM_MEMORY` is commented out in the declared
`mbedtls_config.h` and actively defined in two profiles under `configs/`. A default build
reads the declared header, so it answers; the profiles describe other builds and must not
outvote it. Letting them would reproduce the measured wrong answer with extra steps.
@brief Declared beats heuristic.
@return None.
@version 1
"""
from clew.query.kconfig import gates_covering
conn = _gate_db(
tmp_path,
"w.db",
[
("FEATURE_X", "off", "", "include/proj_config.h", 208, "", "declared"),
("FEATURE_X", "on", "", "configs/profile_a_config.h", 87, "", "heuristic"),
("FEATURE_X", "on", "", "configs/profile_b_config.h", 20, "", "heuristic"),
],
)
gates, _ = gates_covering(conn, "src/platform.h", 20)
conn.close()
assert gates[0].default_state == "off", "the shipped header decides the default build"
assert gates[0].default_site == "include/proj_config.h:208"
Activity · 6 steps
test_the_table_is_created_even_at_zero_rows
None test_config_defaults.test_the_table_is_created_even_at_zero_rows(Path tmp_path)
The table exists even when a repo decides nothing.
tests/test_config_defaults.py:188
Checks
assert found, "the table must exist at zero rows"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-015 | measured | test_the_table_is_created_even_at_zero_rows → ensure_config_defaults_table |
| REQ-DDB-SCHEMA-012 | measured |
Source · 19 lines
def test_the_table_is_created_even_at_zero_rows(tmp_path: Path) -> None:
"""An EMPTY table means "we looked and this repo decides nothing"; an ABSENT one means the
layer never ran. A consumer separating a correct negative from a detector failure needs
both, and writing down the wrong one is the mistake this repo has made three times.
@brief Empty is not absent.
@return None.
@version 1
"""
db = tmp_path / "empty.db"
conn = sqlite3.connect(str(db))
ensure_config_defaults_table(conn)
found = conn.execute(
"SELECT name FROM sqlite_master WHERE type='table' AND name='config_defaults'"
).fetchone()
conn.close()
assert found, "the table must exist at zero rows"
Activity · 6 steps
test_two_headers_disagreeing_both_get_rows
None test_config_defaults.test_two_headers_disagreeing_both_get_rows(Path tmp_path)
An alternative profile's active define is recorded separately, not merged.
tests/test_config_defaults.py:170
Checks
assert ("include/proj_config.h", "off") in statesassert ("profiles/tiny_config.h", "on") in states
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | test_two_headers_disagreeing_both_get_rows → _build → import_config_defaults → run_harvest |
| REQ-DDB-PIPE-011 | measured | test_two_headers_disagreeing_both_get_rows → _build → import_config_defaults → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_two_headers_disagreeing_both_get_rows → _build → import_config_defaults → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-PIPE-015 | measured | test_two_headers_disagreeing_both_get_rows → _build → import_config_defaults |
| REQ-DDB-SCHEMA-012 | measured |
Source · 15 lines
def test_two_headers_disagreeing_both_get_rows(tmp_path: Path) -> None:
"""THE EXACT mbedtls SHAPE: the shipped header says off, a profile says on, and BOTH are
true of their own file. Collapsing them to one answer is what produced the wrong one — a
consumer needs to see that the default is off and that something else turns it on.
@brief Disagreeing headers coexist.
@return None.
@version 1
"""
_, rows = _build(tmp_path)
states = {(r[3], r[1]) for r in rows if r[0] == "FEATURE_PLATFORM_MEMORY"}
assert ("include/proj_config.h", "off") in states
assert ("profiles/tiny_config.h", "on") in states