test_payload_completeness.py¶
tests/test_payload_completeness.py
A reply must close the loops it opens, because an open loop costs a whole turn.
test_a_files_miss_routes_rather_than_claiming_exhaustion
None test_payload_completeness.test_a_files_miss_routes_rather_than_claiming_exhaustion(QueryTools tools)
A files miss names its boundary and routes, instead of claiming the index is exhausted.
tests/test_payload_completeness.py:106
Checks
assert note, "an empty files reply must explain itself"assert "Do not retry this query" not in note, ("a miss in ONE corpus must not be phrased as the index being exhausted — that wording is " "what routed a measured cell to four shell calls while the answer sat in build_meta" )assert "INDEXED SOURCE FILES" in note, "the note must name what this corpus actually holds"assert "doc_scope" in note and "inventory" in note, ("route, do not disclaim: the note must name where the answer IS" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-003 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-002 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-007 | measured | |
| REQ-DDB-QUERY-014 | measured |
Source · 25 lines
def test_a_files_miss_routes_rather_than_claiming_exhaustion(tools: QueryTools) -> None:
"""THE DISTINCTION THIS PINS is between "this corpus does not hold that" and "the index does
not know that". The first is true and useful; the second is false and sends the caller to the
shell. The default `_many` wording asserted the second.
THE NEGATIVE ASSERTION IS THE ONE THAT MATTERS. A note can name the boundary AND still carry
the old "do not retry" sentence, and the caller would act on the stronger claim — so the test
requires the exhaustion wording to be ABSENT, not merely the routing to be present.
@brief An empty glob routes onward.
@version 1
"""
reply = tools.search("nosuchdirectory/*", corpus="files")
note = reply.get("note", "")
assert note, "an empty files reply must explain itself"
assert "Do not retry this query" not in note, (
"a miss in ONE corpus must not be phrased as the index being exhausted — that wording is "
"what routed a measured cell to four shell calls while the answer sat in build_meta"
)
assert "INDEXED SOURCE FILES" in note, "the note must name what this corpus actually holds"
assert "doc_scope" in note and "inventory" in note, (
"route, do not disclaim: the note must name where the answer IS"
)
Activity · 6 steps
test_a_named_gate_symbol_resolves_to_its_definition_sites
None test_payload_completeness.test_a_named_gate_symbol_resolves_to_its_definition_sites(Path rich_db)
A gate symbol named in a payload resolves to where it is defined.
tests/test_payload_completeness.py:157
Checks
assert "SOUND_FINDME" in resolved, ("a gate symbol the index can place must come back placed — leaving it unresolved is the " "open loop that cost four greps in a measured cell" )assert resolved["SOUND_FINDME"][0]["file"], "a resolved site without a file is not a route"assert _gate_definitions(rich_db, itself)[0] == {}, ("a subject listed among its own gates must not have its sites echoed back" )assert _gate_definitions(rich_db, {"name": "X", "gated_by": []})[0] == {}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_named_gate_symbol_resolves_to_its_definition_sites → _gate_definitions → macro_definitions → macro_definitions_conn → _macro_def → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_a_named_gate_symbol_resolves_to_its_definition_sites → _gate_definitions → macro_definitions → connect |
| REQ-DDB-QUERY-003 | measured | test_a_named_gate_symbol_resolves_to_its_definition_sites → _gate_definitions → macro_definitions → macro_definitions_conn → has_columns |
| REQ-DDB-QUERY-004 | inferred | test_a_named_gate_symbol_resolves_to_its_definition_sites → _gate_definitions → macro_definitions → macro_definitions_conn → _macro_def → gates_covering → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_a_named_gate_symbol_resolves_to_its_definition_sites → _gate_definitions → macro_definitions → macro_definitions_conn → _macro_def → gates_covering |
| REQ-DDB-QUERY-012 | measured | test_a_named_gate_symbol_resolves_to_its_definition_sites → _gate_definitions → macro_definitions |
| REQ-DDB-QUERY-013 | inferred | test_a_named_gate_symbol_resolves_to_its_definition_sites → _gate_definitions → macro_definitions → macro_definitions_conn → _macro_def → gates_covering → _with_defaults → decided_default |
Source · 32 lines
def test_a_named_gate_symbol_resolves_to_its_definition_sites(rich_db: Path) -> None:
"""ONE CALL, NOT TWO. Naming a symbol the caller now needs, without saying where it lives, is
an instruction to go looking — and the tool the caller reaches for is grep, because grep is in
its training distribution millions of times and our tool is not.
SELF-REFERENCE IS DROPPED, which is not a tidiness rule: a config symbol's own dossier lists
itself among its gates, and echoing its sites back under a second key would duplicate the
payload it is already inside while implying a second symbol exists.
@brief Gate symbols resolve; self-reference does not.
@version 1
"""
payload = {"name": "SOMETHING_ELSE", "gated_by": [{"symbol": "SOUND_FINDME"}]}
## Returns (resolved, disclosure) since the cap and the no-definition-site case had to
## become distinguishable; this test is about the RESOLVED half.
resolved, _gaps = _gate_definitions(rich_db, payload)
assert "SOUND_FINDME" in resolved, (
"a gate symbol the index can place must come back placed — leaving it unresolved is the "
"open loop that cost four greps in a measured cell"
)
assert resolved["SOUND_FINDME"][0]["file"], "a resolved site without a file is not a route"
## SELF-REFERENCE, and the payload is otherwise identical so nothing else can explain a change.
itself = {"name": "SOUND_FINDME", "gated_by": [{"symbol": "SOUND_FINDME"}]}
assert _gate_definitions(rich_db, itself)[0] == {}, (
"a subject listed among its own gates must not have its sites echoed back"
)
## AND AN UNGATED PAYLOAD GAINS NOTHING, so the block cannot appear as noise on every reply.
assert _gate_definitions(rich_db, {"name": "X", "gated_by": []})[0] == {}
Activity · 7 steps
test_doc_scope_is_empty_rather_than_invented_when_nothing_is_declared
None test_payload_completeness.test_doc_scope_is_empty_rather_than_invented_when_nothing_is_declared(Path rich_db)
Declared doc scope is returned, and its absence is reported as absence.
tests/test_payload_completeness.py:135
Checks
assert doc_scope(rich_db) == {}, ("a repository that declares nothing must return an empty mapping, not a fabricated one" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_doc_scope_is_empty_rather_than_invented_when_nothing_is_declared → doc_scope → connect |
| REQ-DDB-QUERY-003 | measured | test_doc_scope_is_empty_rather_than_invented_when_nothing_is_declared → doc_scope → _scope_provenance → table_exists |
| REQ-DDB-QUERY-007 | measured | test_doc_scope_is_empty_rather_than_invented_when_nothing_is_declared → doc_scope |
Source · 18 lines
def test_doc_scope_is_empty_rather_than_invented_when_nothing_is_declared(rich_db: Path) -> None:
"""FAIL CLOSED, AND SAY WHICH. The fixture declares no Doxyfile, so {} is the correct answer
and is a different fact from "this repository has no doc build" — the caller is told the
index holds no statement, not that no statement exists.
The populated direction is asserted against the real target in the acceptance run rather
than here, because a fixture that declares a Doxyfile would be a fixture built to match the
reader — the standing lesson that a detector agreeing with its own fixture is blind to the
world.
@brief An undeclared doc scope reads empty.
@version 1
"""
assert doc_scope(rich_db) == {}, (
"a repository that declares nothing must return an empty mapping, not a fabricated one"
)
Activity · 1 steps
test_gate_definitions_are_attached_to_the_payload_not_just_computable
None test_payload_completeness.test_gate_definitions_are_attached_to_the_payload_not_just_computable(QueryTools tools, pytest.MonkeyPatch monkeypatch)
The gate resolver is actually WIRED INTO the dossier payload, not merely importable.
tests/test_payload_completeness.py:195
Checks
assert reply.get("found") is not False, "the fixture must resolve this subject"assert reply.get("gate_definitions") == sentinel, ("the resolver's output must reach the payload — computing it and dropping it is the " "failure a unit test of the resolver cannot see" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-MCP-003 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-002 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-004 | measured | |
| REQ-DDB-QUERY-006 | measured | |
| REQ-DDB-QUERY-009 | measured | |
| REQ-DDB-QUERY-010 | measured | |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-QUERY-014 | measured | |
| REQ-DDB-SCHEMA-011 | measured |
Source · 42 lines
def test_gate_definitions_are_attached_to_the_payload_not_just_computable(
tools: QueryTools, monkeypatch: pytest.MonkeyPatch
) -> None:
"""THIS TEST EXISTS BECAUSE A MUTATION SURVIVED. Deleting the call site in `_flatten_subject`
— the two lines that put `gate_definitions` on the payload — left the whole suite green,
including the test directly above, because that one calls `_gate_definitions` itself. It
proved the function works and said nothing about whether anything invokes it.
That is the accepted-but-unread class this repo keeps rediscovering: a mechanism that is
correct, tested, and connected to nothing. The unit test cannot see it by construction, so
the integration assertion has to be separate.
PATCHED RATHER THAN FIXTURED, deliberately. `rich_db` records ZERO `kconfig_gates` rows —
its own docstring says the fixture gates nothing on configuration — so no real subject in it
can produce a `gated_by` list, and a fixture grown to carry one would be a fixture built to
satisfy this test. What broke was the WIRING, so the wiring is what is asserted: a sentinel
return must reach the payload.
@brief The dossier payload carries whatever the gate resolver returns.
@version 2
"""
## PATCHED WHERE `_flatten_subject` LOOKS IT UP. Since 1.3.1 both live in `clew.query.payload`
## (shared with the export API); patching the old name in `tools_query` would leave the
## flattener calling the real resolver and test nothing. The wiring asserted is unchanged.
import clew.query.payload as tq
sentinel = {"SENTINEL_GATE": [{"file": "x.h", "line": 1, "expansion": ""}]}
## Returns (resolved, disclosure) now — the cap and the no-definition-site case had to
## become distinguishable. The stub returns no disclosure, so this stays a test of the
## WIRING of the resolved half and nothing else.
monkeypatch.setattr(tq, "_gate_definitions", lambda _db, _payload: (sentinel, None))
reply = tools.dossier("main")
## A MISS ENVELOPE NEVER REACHES `_flatten_subject`, so an unresolvable subject would make
## this test pass for the wrong reason under the very mutation it exists to catch. The first
## draft named a symbol the fixture does not hold and failed for exactly that reason.
assert reply.get("found") is not False, "the fixture must resolve this subject"
assert reply.get("gate_definitions") == sentinel, (
"the resolver's output must reach the payload — computing it and dropping it is the "
"failure a unit test of the resolver cannot see"
)
Activity · 6 steps
test_operator_stated_macros_are_distinguished_from_the_repos_own_defaults
None test_payload_completeness.test_operator_stated_macros_are_distinguished_from_the_repos_own_defaults()
A build that turns a macro ON records that the repository ships it OFF.
tests/test_payload_completeness.py:240
Checks
assert _stated_only(declared, harvested) == ("MBEDTLS_THREADING_C",), ("only the macro the repository's own header does NOT define ships OFF; " "`WITH_VALUE` differs only in its VALUE and must not count as operator-only" )assert _stated_only(declared, ()) == (), ("with no header read there is no claim to make about the repository's defaults — " "asserting every stated macro ships OFF would invent a fact" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-004 | measured | test_operator_stated_macros_are_distinguished_from_the_repos_own_defaults → _stated_only |
Source · 38 lines
def test_operator_stated_macros_are_distinguished_from_the_repos_own_defaults() -> None:
"""THE ONLY DEFECT IN THIS FAMILY THAT PRODUCED A WRONG ANSWER RATHER THAN A MISSING ONE.
Measured on mbedtls: the acceptance build declares `MBEDTLS_THREADING_C` as PREDEFINED so
doxygen can reach the guarded bodies. The repository ships it COMMENTED OUT. An agent asked
whether threading is on by default, saw the name in `configured_macros`, and concluded the
opposite of the truth — on two graded marks.
`macros` is the UNION of what the operator stated and what the repo's own header defines, and
the union cannot answer "does the repository ship this ON". `stated_only` is the difference,
and membership is the whole signal: a name in it ships OFF, a name in `macros` but not in it
was read from the header and ships ON.
COMPARED BY BARE NAME, asserted here because both sides are rendered doxygen tokens (`"X"`,
`"X=1"`) and a token comparison would call those two different macros — the exact drift that
once labelled every declared macro `undeclared`.
EMPTY WITHOUT A HEADER is the fail-closed half: with nothing harvested there is no statement
about the repository's defaults to make, and claiming every stated macro ships OFF would be
inventing a fact.
@brief stated_only separates this build's variant from the repository's default.
@version 1
"""
from clew.preprocessor import _stated_only
declared = ('"MBEDTLS_THREADING_C"', '"MBEDTLS_HAVE_ASM"', '"WITH_VALUE=1"')
harvested = ('"MBEDTLS_HAVE_ASM"', '"WITH_VALUE=7"', '"MBEDTLS_CIPHER_C"')
assert _stated_only(declared, harvested) == ("MBEDTLS_THREADING_C",), (
"only the macro the repository's own header does NOT define ships OFF; "
"`WITH_VALUE` differs only in its VALUE and must not count as operator-only"
)
assert _stated_only(declared, ()) == (), (
"with no header read there is no claim to make about the repository's defaults — "
"asserting every stated macro ships OFF would invent a fact"
)
Activity · 5 steps
test_unresolved_gates_distinguish_no_definition_site_from_never_tried
None test_payload_completeness.test_unresolved_gates_distinguish_no_definition_site_from_never_tried(Path rich_db)
An unresolved gate must say WHICH kind of unresolved it is.
tests/test_payload_completeness.py:282
Checks
assert "SOUND_FINDME" in resolved, "precondition: the placeable gate must still resolve"assert gaps is not None, "an unplaceable gate must be disclosed, not silently dropped"assert gaps["no_definition_site"] == ["NOWHERE_DEFINED_XYZ"], (f"the unplaceable gate must be NAMED, not counted — a count leaves a reader unable to ask " f"for the one they care about; got {gaps}" )assert "not_attempted" not in gaps, "nothing was capped here, so nothing may claim it was"assert gaps2 is not None and len(gaps2["not_attempted"]) == 3, (f"the three gates beyond the cap must be named as not attempted; got {gaps2}" )assert gaps3 is None, ("when every gate resolves there is nothing to disclose — a block on every reply is one a " "reader learns to skip" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_unresolved_gates_distinguish_no_definition_site_from_never_tried → _gate_definitions → macro_definitions → macro_definitions_conn → _macro_def → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_unresolved_gates_distinguish_no_definition_site_from_never_tried → _gate_definitions → macro_definitions → connect |
| REQ-DDB-QUERY-003 | measured | test_unresolved_gates_distinguish_no_definition_site_from_never_tried → _gate_definitions → macro_definitions → macro_definitions_conn → has_columns |
| REQ-DDB-QUERY-004 | inferred | test_unresolved_gates_distinguish_no_definition_site_from_never_tried → _gate_definitions → macro_definitions → macro_definitions_conn → _macro_def → gates_covering → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-006 | measured | test_unresolved_gates_distinguish_no_definition_site_from_never_tried → _gate_definitions → macro_definitions → macro_definitions_conn → _macro_def → gates_covering |
| REQ-DDB-QUERY-012 | measured | test_unresolved_gates_distinguish_no_definition_site_from_never_tried → _gate_definitions → macro_definitions |
| REQ-DDB-QUERY-013 | inferred | test_unresolved_gates_distinguish_no_definition_site_from_never_tried → _gate_definitions → macro_definitions → macro_definitions_conn → _macro_def → gates_covering → _with_defaults → decided_default |
Source · 53 lines
def test_unresolved_gates_distinguish_no_definition_site_from_never_tried(rich_db: Path) -> None:
"""TWO GAPS THAT LOOKED IDENTICAL AND MEAN OPPOSITE THINGS. `if sites:` dropped the key for a
gate the index cannot place, so its absence was indistinguishable from having been capped out.
`no_definition_site` is usually the ANSWER: a `//#define MBEDTLS_THREADING_C` is not a
definition the preprocessor sees, so it produces no `memberdef` row. "Nowhere actively defined"
is what a reader asking about the shipped default needs.
`not_attempted` is a fact about the TOOL. It promises more exists and claims nothing about the
repository.
AND THE CAP WAS A LOTTERY. It sliced `sorted(names)`, so with mbedtls' twelve-macro conditional
the survivors were chosen ALPHABETICALLY and `MBEDTLS_THREADING_C` — tenth of twelve, and the
symbol two graded marks ask about — silently vanished. The previous comment called 6 "not a
budget the ordinary case approaches"; twelve is the ordinary case.
@brief The two unresolved kinds are named separately, and neither fires when all resolve.
@return None.
@version 1
"""
from clew.mcp_server.tools_query import _GATE_DEFINITION_CAP, _gate_definitions
## A gate the index genuinely cannot place, beside one it can.
payload = {
"name": "subject_fn",
"gated_by": [{"symbol": "SOUND_FINDME"}, {"symbol": "NOWHERE_DEFINED_XYZ"}],
}
resolved, gaps = _gate_definitions(rich_db, payload)
assert "SOUND_FINDME" in resolved, "precondition: the placeable gate must still resolve"
assert gaps is not None, "an unplaceable gate must be disclosed, not silently dropped"
assert gaps["no_definition_site"] == ["NOWHERE_DEFINED_XYZ"], (
f"the unplaceable gate must be NAMED, not counted — a count leaves a reader unable to ask "
f"for the one they care about; got {gaps}"
)
assert "not_attempted" not in gaps, "nothing was capped here, so nothing may claim it was"
## OVER THE CAP: the overflow is named as a TOOL limit, distinctly.
many = {
"name": "subject_fn",
"gated_by": [{"symbol": f"GATE_{i:03d}"} for i in range(_GATE_DEFINITION_CAP + 3)],
}
_resolved2, gaps2 = _gate_definitions(rich_db, many)
assert gaps2 is not None and len(gaps2["not_attempted"]) == 3, (
f"the three gates beyond the cap must be named as not attempted; got {gaps2}"
)
## THE SILENCE CONTROL: every gate placed means no disclosure at all.
_r3, gaps3 = _gate_definitions(rich_db, {"name": "f", "gated_by": [{"symbol": "SOUND_FINDME"}]})
assert gaps3 is None, (
"when every gate resolves there is nothing to disclose — a block on every reply is one a "
"reader learns to skip"
)1 more lines, not shown