test_config_subject_defaults.py¶
tests/test_config_subject_defaults.py
THE SAME FACT, REACHABLE FROM ONE DIRECTION AND NOT THE OTHER (C3 of the 1.1.0 review).
test_a_config_symbols_own_gates_carry_the_resolved_default
None test_config_subject_defaults.test_a_config_symbols_own_gates_carry_the_resolved_default(Path gated)
The config subject's gates carry the resolved default state.
tests/test_config_subject_defaults.py:98
Checks
assert len(space.gates) == 2, "both preprocessor arms must survive"assert states == {"off"}, (f"the shipped config says off; the config subject reports {states} — a reader asking " f"about the symbol cannot tell which arm the default build takes" )assert all("mbedtls_config.h" in gate.default_site for gate in space.gates), ("the site must name the file that was believed, so a reader can disagree with the choice" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_a_config_symbols_own_gates_carry_the_resolved_default → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_a_config_symbols_own_gates_carry_the_resolved_default → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | measured | test_a_config_symbols_own_gates_carry_the_resolved_default → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_a_config_symbols_own_gates_carry_the_resolved_default → kconfig_space |
| REQ-DDB-QUERY-013 | measured | test_a_config_symbols_own_gates_carry_the_resolved_default → kconfig_space → _gates → _with_defaults → decided_default |
| REQ-DDB-WIKI-054 | inferred | test_a_config_symbols_own_gates_carry_the_resolved_default → all |
Source · 18 lines
def test_a_config_symbols_own_gates_carry_the_resolved_default(gated: Path) -> None:
"""RED BEFORE THE FIX: `_gates` returns `KconfigGate` rows straight from SQL, so
`default_state` holds its dataclass default and every site reads as "no default known"
against an index that knows it.
"""
space = q.kconfig_space(gated, MACRO)
assert len(space.gates) == 2, "both preprocessor arms must survive"
states = {gate.default_state for gate in space.gates}
assert states == {"off"}, (
f"the shipped config says off; the config subject reports {states} — a reader asking "
f"about the symbol cannot tell which arm the default build takes"
)
assert all("mbedtls_config.h" in gate.default_site for gate in space.gates), (
"the site must name the file that was believed, so a reader can disagree with the choice"
)
Activity · 5 steps
test_a_gate_layer_without_defaults_reports_no_state_rather_than_raising
None test_config_subject_defaults.test_a_gate_layer_without_defaults_reports_no_state_rather_than_raising(Path tmp_path)
An index with no config_defaults table still answers, thinly.
tests/test_config_subject_defaults.py:145
Checks
assert len(space.gates) == 1assert space.gates[0].default_state == "", ("no defaults corpus means the state is UNKNOWN, which must not read as a measured state" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_a_gate_layer_without_defaults_reports_no_state_rather_than_raising → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_a_gate_layer_without_defaults_reports_no_state_rather_than_raising → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_a_gate_layer_without_defaults_reports_no_state_rather_than_raising → kconfig_space → _gates → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_a_gate_layer_without_defaults_reports_no_state_rather_than_raising → kconfig_space |
| REQ-DDB-QUERY-013 | inferred | test_a_gate_layer_without_defaults_reports_no_state_rather_than_raising → kconfig_space → _gates → _with_defaults → decided_default |
Source · 34 lines
def test_a_gate_layer_without_defaults_reports_no_state_rather_than_raising(tmp_path: Path) -> None:
"""The graceful-degradation contract, on the path C3 adds. `_with_defaults` already returns
the gates untouched when the table is absent; this pins that the new call site inherits that
rather than being a second place to get it wrong.
An ABSENT default is the honest answer for an index that holds no such measurement, and is
distinct from `off` — which is why the field defaults to empty rather than to a state.
"""
db = tmp_path / "clew.db"
conn = sqlite3.connect(str(db))
conn.executescript(
"""
CREATE TABLE build_meta (key TEXT, value TEXT);
CREATE TABLE kconfig_gates (
symbol TEXT, macro TEXT, form TEXT, file_path TEXT, line INTEGER,
origin TEXT, end_line INTEGER
);
"""
)
conn.execute("INSERT INTO build_meta VALUES ('kconfig.source', 'config_header')")
conn.execute(
"INSERT INTO kconfig_gates VALUES (?, ?, 'if_expr', 'src/x.c', 10, 'undeclared', 20)",
(MACRO, MACRO),
)
conn.commit()
conn.close()
space = q.kconfig_space(db, MACRO)
assert len(space.gates) == 1
assert space.gates[0].default_state == "", (
"no defaults corpus means the state is UNKNOWN, which must not read as a measured state"
)
Activity · 10 steps
test_more_macros_than_one_in_clause_still_all_resolve
None test_config_subject_defaults.test_more_macros_than_one_in_clause_still_all_resolve(Path tmp_path)
More gating macros than one IN clause holds still resolve, all of them.
tests/test_config_subject_defaults.py:181
Checks
assert not unresolved, (f"{len(unresolved)} of {total} macros lost their default across the chunk boundary, " f"first few: {unresolved[:5]}" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-003 | measured | test_more_macros_than_one_in_clause_still_all_resolve → _with_defaults → table_exists |
| REQ-DDB-QUERY-004 | measured | test_more_macros_than_one_in_clause_still_all_resolve → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-013 | measured | test_more_macros_than_one_in_clause_still_all_resolve → _with_defaults → decided_default |
Source · 51 lines
def test_more_macros_than_one_in_clause_still_all_resolve(tmp_path: Path) -> None:
"""C3 MADE THE WHOLE-REPO GATE LIST A CALLER OF THIS JOIN, and that changed the input size
by three orders of magnitude: `gates_covering` resolves the handful of gates over one line,
while `_gates(conn, None)` resolves every gating macro in the repository. Counted: RIOT's
gate layer holds **2,029 distinct gating macros**, sassafras-class 503.
`SQLITE_MAX_VARIABLE_NUMBER` is compile-time and defaulted to **999 before SQLite 3.32**, so
one parameter per macro is over a documented default by a factor of two on a real target.
NOT A CRASH REPRODUCED HERE — this interpreter links a build that accepts 32,766 — which is
exactly why it needs a test rather than a trusted comment: on this machine the unchunked
version passes.
So the assertion is on COMPLETENESS ACROSS THE BOUNDARY, not on an exception: every macro
must come back resolved, including the ones in the second and third chunk. A chunking bug
that silently dropped the tail would be invisible to any test that only counted rows.
@brief Every macro resolves regardless of how many chunks it takes.
@return None.
@version 1
"""
from clew.query.kconfig import _MACRO_CHUNK, _with_defaults
from clew.query.models import KconfigGate
total = _MACRO_CHUNK * 2 + 7
names = [f"CONFIG_THING_{i:05d}" for i in range(total)]
db = tmp_path / "many.db"
conn = sqlite3.connect(str(db))
conn.execute(
"CREATE TABLE config_defaults (macro TEXT, state TEXT, value TEXT, file_path TEXT, "
"line INTEGER, doc TEXT, origin TEXT)"
)
conn.executemany(
"INSERT INTO config_defaults (macro, state, value, file_path, line, doc, origin) "
"VALUES (?, 'on', '', 'include/project_config.h', 1, '', 'declared')",
[(n,) for n in names],
)
conn.commit()
gates = tuple(
KconfigGate(symbol=n, macro=n, form="if_expr", file_path="src/x.c", line=i)
for i, n in enumerate(names)
)
resolved = _with_defaults(conn, gates)
conn.close()
unresolved = [g.macro for g in resolved if g.default_state != "on"]
assert not unresolved, (
f"{len(unresolved)} of {total} macros lost their default across the chunk boundary, "
f"first few: {unresolved[:5]}"
)1 more lines, not shown
Activity · 14 steps
test_the_function_route_and_the_symbol_route_report_the_same_default
None test_config_subject_defaults.test_the_function_route_and_the_symbol_route_report_the_same_default(Path gated)
The two surfaces agree about the same macro.
tests/test_config_subject_defaults.py:118
Checks
assert by_function == by_symbol, (f"the two routes disagree about one macro: function route {by_function}, symbol route " f"{by_symbol}. One join, two callers — a second implementation is how they drift." )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_the_function_route_and_the_symbol_route_report_the_same_default → kconfig_space → connect |
| REQ-DDB-QUERY-003 | measured | test_the_function_route_and_the_symbol_route_report_the_same_default → kconfig_space → table_exists |
| REQ-DDB-QUERY-004 | measured | test_the_function_route_and_the_symbol_route_report_the_same_default → gates_covering → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_the_function_route_and_the_symbol_route_report_the_same_default → kconfig_space |
| REQ-DDB-QUERY-013 | measured | test_the_function_route_and_the_symbol_route_report_the_same_default → gates_covering → _with_defaults → decided_default |
Source · 25 lines
def test_the_function_route_and_the_symbol_route_report_the_same_default(gated: Path) -> None:
"""THE PROPERTY, NOT THE VALUE. Whatever the resolution rule decides, the function subject's
`gated_by` and the config subject's `gates` must decide it identically, because they are the
same join over the same rows. Asserting the shared answer rather than a literal is what makes
this test fail if a second implementation is ever introduced for one of them — which is the
outcome it exists to prevent, not the current `off`.
"""
from clew.query.kconfig import gates_covering
conn = sqlite3.connect(str(gated))
try:
covering, _unknown = gates_covering(conn, "include/mbedtls/platform.h", 150)
by_function = {(g.line, g.default_state, g.default_site) for g in covering}
finally:
conn.close()
space = q.kconfig_space(gated, MACRO)
by_symbol = {(g.line, g.default_state, g.default_site) for g in space.gates if g.line == 144}
assert by_function == by_symbol, (
f"the two routes disagree about one macro: function route {by_function}, symbol route "
f"{by_symbol}. One join, two callers — a second implementation is how they drift."
)