test_richness.py¶
tests/integration/test_richness.py
The readiness gate: can a real index actually ANSWER the acceptance matrix?
test_declared_causal_chains_connect
None test_richness.test_declared_causal_chains_connect(Path self_index_db)
The causal traversal connects the pairs a question depends on.
tests/integration/test_richness.py:120
Checks
assert target in reached, (f"chain_trace({seed!r}) does not reach {target!r} — a matrix question " f"depends on that path existing" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | inferred | test_declared_causal_chains_connect → chain_trace → candidate_rows → symbol_provenance |
| REQ-DDB-QUERY-001 | measured | test_declared_causal_chains_connect → chain_trace → connect |
| REQ-DDB-QUERY-002 | measured | test_declared_causal_chains_connect → chain_trace |
| REQ-DDB-QUERY-003 | measured | test_declared_causal_chains_connect → chain_trace → function_candidates |
| REQ-DDB-QUERY-005 | measured | test_declared_causal_chains_connect → chain_trace → _make_node |
| REQ-DDB-QUERY-010 | measured | test_declared_causal_chains_connect → chain_trace → function_candidates |
Source · 21 lines
def test_declared_causal_chains_connect(self_index_db: Path) -> None:
"""A separate claim from symbol presence, and a stronger one: Q1 asks how a
build reaches its stages, which needs an actual PATH, not two resolvable names.
Uses the shipped `chain_trace` rather than its own SQL, so this measures what a
consumer would get.
@brief Each declared (seed, target) pair is reachable.
@version 1
"""
from clew import query as q
for seed, target in Q_CHAINS:
chain = q.chain_trace(self_index_db, seed, max_depth=6)
reached = {node.name for node in chain.nodes}
assert target in reached, (
f"chain_trace({seed!r}) does not reach {target!r} — a matrix question "
f"depends on that path existing"
)
Activity · 5 steps
test_query_surface_invariants_hold_on_real_data
None test_richness.test_query_surface_invariants_hold_on_real_data(Path self_index_db)
The #46 edge_class tag and #38 collapse hold on real data.
tests/integration/test_richness.py:145
Checks
assert callees, f"precondition: {subject} must have neighbours for this to mean anything"assert all(e.edge_class for e in callees), "#46: every neighbour row must carry edge_class"assert len(names) == len(set(names)), (f"#38: {subject} returned duplicate neighbours — the per-layer rows are not " f"being collapsed, so every count and depth cap downstream is inflated" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_query_surface_invariants_hold_on_real_data → callees |
| REQ-DDB-QUERY-003 | measured | test_query_surface_invariants_hold_on_real_data → callees → _call_edges → _dataflow_edges → resolve_rowid |
| REQ-DDB-QUERY-009 | measured | test_query_surface_invariants_hold_on_real_data → callees → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_query_surface_invariants_hold_on_real_data → callees |
| REQ-DDB-WIKI-054 | inferred | test_query_surface_invariants_hold_on_real_data → all |
Source · 29 lines
def test_query_surface_invariants_hold_on_real_data(self_index_db: Path) -> None:
"""Reads the DATA rather than checking that a helper's name exists, which is why
it replaced an earlier name-probe that reported a false gap whenever the index
lagged the source.
Two invariants a matrix answer can rest on:
* #46 — every neighbour row is TAGGED with its `edge_class`, so a consumer can
tell a call from a dataflow hand-off.
* #38 — neighbours are COLLAPSED to one row each, so counts mean something.
The raw table stores one row per extraction layer by design.
@brief The public neighbour surface is tagged and collapsed.
@version 1
"""
from clew import query as q
subject = "_run_pipeline"
callees = q.callees(self_index_db, subject)
assert callees, f"precondition: {subject} must have neighbours for this to mean anything"
assert all(e.edge_class for e in callees), "#46: every neighbour row must carry edge_class"
names = [e.name for e in callees]
assert len(names) == len(set(names)), (
f"#38: {subject} returned duplicate neighbours — the per-layer rows are not "
f"being collapsed, so every count and depth cap downstream is inflated"
)
Activity · 7 steps
test_requirement_traceability_state_is_known
None test_richness.test_requirement_traceability_state_is_known(Path self_index_db)
Q6's requirement traceability: implementers work, tests are still the gap.
tests/integration/test_richness.py:178
Checks
assert trace.implementers, ("REQ-DDB-CONFIG-001 resolves to no implementers. The package tags itself, so " "this is a req_edges regression, not the old task #62 gap — check that the " "declared id pattern in .clew.yaml's guard: section still matches the tags." )assert all(imp.name and imp.liveness for imp in trace.implementers), ("an implementer with no name or no liveness verdict is an unusable row" )assert trace.title, ("the catalog metadata did not come through — req_edges populate from TAGS and " "the catalog is read separately, so titles can be NULL while coverage looks fine" )assert covered.tests, ("REQ-DDB-MCP-003 reports no covering tests — req_test_edges regressed. Two " "test functions in tests/test_mcp_server.py tag it; if the tags are still " "there, the edge builder stopped reading them." )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_requirement_traceability_state_is_known → req_trace |
| REQ-DDB-QUERY-003 | measured | test_requirement_traceability_state_is_known → req_trace → table_exists |
| REQ-DDB-QUERY-010 | measured | test_requirement_traceability_state_is_known → req_trace → _req_implementers → resolve_rowid |
| REQ-DDB-SCHEMA-006 | measured | test_requirement_traceability_state_is_known → req_trace → _req_failure_modes |
| REQ-DDB-SCHEMA-015 | measured | test_requirement_traceability_state_is_known → req_trace → _req_links |
| REQ-DDB-WIKI-054 | inferred | test_requirement_traceability_state_is_known → all |
Source · 53 lines
def test_requirement_traceability_state_is_known(self_index_db: Path) -> None:
"""THE HALF THIS TEST USED TO PIN IS RETIRED, and it retired itself exactly as
designed. It asserted `implementers == []` because the package carried ZERO `@req`
tags (task #62), with an escape hatch saying that if implementers ever appeared
the limitation should be removed rather than the assertion loosened. They
appeared: the package now tags itself, and `REQ-DDB-CONFIG-001` alone resolves to
~80 live implementers on a fresh self-index. The CHANGELOG had already been
updated to say implementation traceability works; only this test lagged, which is
why it failed (gh#362) — a STALE EXPECTATION, not a regression.
THE TEST HALF HAS RETIRED TOO, and that was found here rather than believed: the
CHANGELOG still claimed "no TEST function carries a `@req` tag, so `req_test_edges`
is empty", while a real self-index emits SIX `req_test_edges` rows and
`req_trace('REQ-DDB-MCP-003').tests` names two covering tests. Both halves of Q6
are therefore asserted POSITIVELY, on two different requirement ids, because they
populate from different tables through different code paths and one working says
nothing about the other.
NO EXACT COUNT IS ASSERTED, deliberately. Both counts move with every tag anyone
adds — neither is a property of the tool — and a number that has to be re-derived
on each commit is a number that gets loosened rather than fixed. What is asserted
is the SHAPE: rows exist, each names a function, and the catalog metadata that
makes the answer useful came through with them.
@brief Both halves of requirement traceability resolve on a real self-index.
@version 2
"""
from clew import query as q
trace = q.req_trace(self_index_db, "REQ-DDB-CONFIG-001")
assert trace.implementers, (
"REQ-DDB-CONFIG-001 resolves to no implementers. The package tags itself, so "
"this is a req_edges regression, not the old task #62 gap — check that the "
"declared id pattern in .clew.yaml's guard: section still matches the tags."
)
assert all(imp.name and imp.liveness for imp in trace.implementers), (
"an implementer with no name or no liveness verdict is an unusable row"
)
assert trace.title, (
"the catalog metadata did not come through — req_edges populate from TAGS and "
"the catalog is read separately, so titles can be NULL while coverage looks fine"
)
## A DIFFERENT id on purpose: `REQ-DDB-MCP-003` is one of the few this repo tags
## from a test as well as from the implementation, so it is the only id that can
## demonstrate the `req_test_edges` path at all. Asserting `tests` on
## `REQ-DDB-CONFIG-001` would assert emptiness and pass for the wrong reason.
covered = q.req_trace(self_index_db, "REQ-DDB-MCP-003")
assert covered.tests, (
"REQ-DDB-MCP-003 reports no covering tests — req_test_edges regressed. Two "
"test functions in tests/test_mcp_server.py tag it; if the tags are still "
"there, the edge builder stopped reading them."
)1 more lines, not shown