test_overrides.py¶
tests/test_overrides.py
gh#8 — doxygen's `reimplements` relation, made reachable.
test_a_call_to_an_overridden_endpoint_is_annotated_with_its_implementors
None test_overrides.test_a_call_to_an_overridden_endpoint_is_annotated_with_its_implementors(Path overriding_db)
The `callees` half of gh#8 — and the two things it must NOT do.
Checks
assert set(edge.implementors) == {"telemetry_report", "handle_cloud_command"}assert {(e.name, e.confidence) for e in annotated} == plainassert all(e.implementors == () for e in annotated if e.name != "sensor_poll")
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_a_call_to_an_overridden_endpoint_is_annotated_with_its_implementors → callees |
| REQ-DDB-QUERY-003 | measured | test_a_call_to_an_overridden_endpoint_is_annotated_with_its_implementors → callees → _call_edges → _dataflow_edges → resolve_rowid |
| REQ-DDB-QUERY-009 | measured | test_a_call_to_an_overridden_endpoint_is_annotated_with_its_implementors → callees → _call_edges → _direct_call_edges → _implementors_by_identity |
| REQ-DDB-QUERY-010 | measured | test_a_call_to_an_overridden_endpoint_is_annotated_with_its_implementors → callees |
| REQ-DDB-WIKI-054 | inferred | test_a_call_to_an_overridden_endpoint_is_annotated_with_its_implementors → all |
Source · 21 lines
def test_a_call_to_an_overridden_endpoint_is_annotated_with_its_implementors(
overriding_db: Path,
) -> None:
"""The `callees` half of gh#8 — and the two things it must NOT do.
`app_run` calls `sensor_poll`, which the fixture makes virtual, so that edge names
the bodies the dispatch can reach. What it must not do is UPGRADE the edge or ADD
one: `confidence` still grades the call itself, and the neighbour count is
unchanged, because this repo's rule is that a synthetic edge inherits the weakest
link and the honest way to respect that is to annotate rather than to mint.
"""
plain = {(e.name, e.confidence) for e in q.callees(rich_db_of(overriding_db), "app_run")}
annotated = q.callees(overriding_db, "app_run")
edge = next(e for e in annotated if e.name == "sensor_poll")
assert set(edge.implementors) == {"telemetry_report", "handle_cloud_command"}
# Every OTHER neighbour is untouched, and no neighbour was gained or lost.
assert {(e.name, e.confidence) for e in annotated} == plain
assert all(e.implementors == () for e in annotated if e.name != "sensor_poll")
Activity · 6 steps
test_a_dossier_on_an_overridden_function_names_its_implementors
None test_overrides.test_a_dossier_on_an_overridden_function_names_its_implementors(Path overriding_db)
gh#8's "done means", asserted: a consumer can answer "what runs here?".
Checks
assert doss is not Noneassert doss.rowid == SENSOR_POLL_DEF, "the dossier describes the definition row"assert named == {"telemetry_report", "handle_cloud_command"}assert ref.rowid > 0assert ref.file, "an implementor must be locatable without a second lookup"assert ref.signature, "the signature is what distinguishes same-named overrides"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | inferred | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_a_dossier_on_an_overridden_function_names_its_implementors → function_dossier → _dossier_conn → locks_held_for_rowids |
Source · 20 lines
def test_a_dossier_on_an_overridden_function_names_its_implementors(overriding_db: Path) -> None:
"""gh#8's "done means", asserted: a consumer can answer "what runs here?".
Both implementors are named, with the location and signature that let the consumer
go and read one — the point of returning a ref rather than a bare name. And the
relation is found despite being recorded against the declaration while the dossier
describes the definition, which is the identity resolution doing its job.
"""
doss = q.function_dossier(overriding_db, "sensor_poll")
assert doss is not None
assert doss.rowid == SENSOR_POLL_DEF, "the dossier describes the definition row"
named = {o.name for o in doss.overridden_by}
assert named == {"telemetry_report", "handle_cloud_command"}
for ref in doss.overridden_by:
assert ref.rowid > 0
assert ref.file, "an implementor must be locatable without a second lookup"
assert ref.signature, "the signature is what distinguishes same-named overrides"
Activity · 9 steps
test_a_non_virtual_function_gets_no_override_fields
None test_overrides.test_a_non_virtual_function_gets_no_override_fields(Path rich_db)
No spurious polymorphism on the ordinary case, which is almost every function.
Checks
assert doss is not Noneassert doss.overrides == []assert doss.overridden_by == []assert all(edge.implementors == () for edge in doss.callers + doss.callees)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_non_virtual_function_gets_no_override_fields → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_a_non_virtual_function_gets_no_override_fields → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | inferred | test_a_non_virtual_function_gets_no_override_fields → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_a_non_virtual_function_gets_no_override_fields → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_a_non_virtual_function_gets_no_override_fields → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_a_non_virtual_function_gets_no_override_fields → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_a_non_virtual_function_gets_no_override_fields → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_a_non_virtual_function_gets_no_override_fields → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_a_non_virtual_function_gets_no_override_fields → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_a_non_virtual_function_gets_no_override_fields → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_a_non_virtual_function_gets_no_override_fields → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_a_non_virtual_function_gets_no_override_fields → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_a_non_virtual_function_gets_no_override_fields → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_a_non_virtual_function_gets_no_override_fields → function_dossier → _dossier_conn → locks_held_for_rowids |
| REQ-DDB-WIKI-054 | inferred | test_a_non_virtual_function_gets_no_override_fields → all |
Source · 15 lines
def test_a_non_virtual_function_gets_no_override_fields(rich_db: Path) -> None:
"""No spurious polymorphism on the ordinary case, which is almost every function.
Asserted on the UNMODIFIED fixture, whose `reimplements` table exists and is empty
— the state a C or Python target is permanently in. Both fields are `[]`, which is
the measurement "doxygen recorded no override relation", and no call edge claims an
implementor.
"""
doss = q.function_dossier(rich_db, "sensor_poll")
assert doss is not None
assert doss.overrides == []
assert doss.overridden_by == []
assert all(edge.implementors == () for edge in doss.callers + doss.callees)
Activity · 5 steps
test_an_index_without_the_relation_degrades_to_empty
None test_overrides.test_an_index_without_the_relation_degrades_to_empty(Path overriding_db)
`reimplements` is DOXYGEN'S table, not ours — we copy the file doxygen wrote.
Checks
assert doss is not Noneassert doss.overrides == []assert doss.overridden_by == []assert all(e.implementors == () for e in q.callees(overriding_db, "app_run"))
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_an_index_without_the_relation_degrades_to_empty → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_an_index_without_the_relation_degrades_to_empty → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | inferred | test_an_index_without_the_relation_degrades_to_empty → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_an_index_without_the_relation_degrades_to_empty → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_an_index_without_the_relation_degrades_to_empty → callees |
| REQ-DDB-QUERY-002 | measured | test_an_index_without_the_relation_degrades_to_empty → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_an_index_without_the_relation_degrades_to_empty → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_an_index_without_the_relation_degrades_to_empty → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_an_index_without_the_relation_degrades_to_empty → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_an_index_without_the_relation_degrades_to_empty → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_an_index_without_the_relation_degrades_to_empty → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_an_index_without_the_relation_degrades_to_empty → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_an_index_without_the_relation_degrades_to_empty → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_an_index_without_the_relation_degrades_to_empty → function_dossier → _dossier_conn → locks_held_for_rowids |
| REQ-DDB-WIKI-054 | inferred | test_an_index_without_the_relation_degrades_to_empty → all |
Source · 21 lines
def test_an_index_without_the_relation_degrades_to_empty(overriding_db: Path) -> None:
"""`reimplements` is DOXYGEN'S table, not ours — we copy the file doxygen wrote.
So its absence means the index predates that output, and the surface must return
empty rather than raising: an override query is exactly the kind a consumer runs
against an old index while investigating why an answer looks thin.
"""
conn = sqlite3.connect(overriding_db)
try:
conn.execute("DROP TABLE reimplements")
conn.commit()
finally:
conn.close()
doss = q.function_dossier(overriding_db, "sensor_poll")
assert doss is not None
assert doss.overrides == []
assert doss.overridden_by == []
assert all(e.implementors == () for e in q.callees(overriding_db, "app_run"))
Activity · 9 steps
test_the_override_fields_reach_the_mcp_wire
None test_overrides.test_the_override_fields_reach_the_mcp_wire(Path overriding_db, Path repo_root)
gh#8 END TO END, because the query layer is not the surface a model sees.
Checks
assert doss["overrides"] == [], "an envelope key survives at empty"assert {o["name"] for o in doss["overridden_by"]} == {assert set(edge["implementors"]) == {"telemetry_report", "handle_cloud_command"}assert others, "the control needs at least one unannotated neighbour"assert all("implementors" not in e for e in others), ("an empty implementors list is a ROW field and must be elided, not shipped" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-MCP-003 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | 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 | |
| REQ-DDB-WIKI-054 | inferred | test_the_override_fields_reach_the_mcp_wire → all |
Source · 42 lines
def test_the_override_fields_reach_the_mcp_wire(overriding_db: Path, repo_root: Path) -> None:
"""gh#8 END TO END, because the query layer is not the surface a model sees.
Two elision rules meet here and they pull opposite ways. `overrides` /
`overridden_by` are ENVELOPE keys, so they survive at `[]` and a consumer can read
"no override recorded" without guessing. `implementors` is a field of a ROW, so it
is elided when empty — which is correct and is why the assertion checks the
ANNOTATED row rather than merely that the key exists somewhere.
An empty `implementors` shipping as `[]` on every one of a hub symbol's neighbours
would be pure noise; an absent `overrides` on a dossier would be a question the
caller has to ask again.
"""
pytest.importorskip(
"mcp",
reason="the MCP SDK is a REQUIRED dependency, so this skipping means a BROKEN install, not an unselected extra",
)
from clew.mcp_server.tools_query import QueryTools
tools = QueryTools(lambda: overriding_db, lambda: repo_root)
doss = tools.dossier("sensor_poll")
assert doss["overrides"] == [], "an envelope key survives at empty"
assert {o["name"] for o in doss["overridden_by"]} == {
"telemetry_report",
"handle_cloud_command",
}
## Read off `dossier`'s own `callees` since gh#372 folded the neighbour tools into it.
## The rows are the same rows, which is exactly the claim that fold rests on — and
## `implementors` is the field most able to be lost in a re-serialization, because it
## is a ROW field that is elided when empty.
callees = tools.dossier("app_run")["callees"]
edge = next(e for e in callees if e["name"] == "sensor_poll")
assert set(edge["implementors"]) == {"telemetry_report", "handle_cloud_command"}
others = [e for e in callees if e["name"] != "sensor_poll"]
assert others, "the control needs at least one unannotated neighbour"
assert all("implementors" not in e for e in others), (
"an empty implementors list is a ROW field and must be elided, not shipped"
)
Activity · 12 steps
test_the_override_surface_is_reachable_from_the_package
None test_overrides.test_the_override_surface_is_reachable_from_the_package(Path overriding_db)
Exported, because "populated and unreachable" was the whole defect.
Checks
assert "overrides_of" in q.__all__assert "overridden_by" in q.__all__assert "OverrideRef" in q.__all__assert {o.name for o in q.overridden_by(conn, "sensor_poll")} == {assert q.overrides_of(conn, "sensor_poll") == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_the_override_surface_is_reachable_from_the_package → overridden_by |
| REQ-DDB-QUERY-003 | measured | test_the_override_surface_is_reachable_from_the_package → overridden_by → _override_refs → table_exists |
| REQ-DDB-QUERY-009 | measured | test_the_override_surface_is_reachable_from_the_package → overridden_by |
| REQ-DDB-QUERY-010 | measured | test_the_override_surface_is_reachable_from_the_package → overridden_by |
Source · 20 lines
def test_the_override_surface_is_reachable_from_the_package(overriding_db: Path) -> None:
"""Exported, because "populated and unreachable" was the whole defect.
The accessors are also usable directly, not only through `dossier`: a consumer that
already has a name and wants only the dispatch answer should not have to compose a
whole dossier for it.
"""
assert "overrides_of" in q.__all__
assert "overridden_by" in q.__all__
assert "OverrideRef" in q.__all__
conn = sqlite3.connect(overriding_db)
try:
assert {o.name for o in q.overridden_by(conn, "sensor_poll")} == {
"telemetry_report",
"handle_cloud_command",
}
assert q.overrides_of(conn, "sensor_poll") == []
finally:
conn.close()1 more lines, not shown
Activity · 7 steps
test_the_two_directions_are_not_the_same_question
None test_overrides.test_the_two_directions_are_not_the_same_question(Path overriding_db)
`overrides` and `overridden_by` must not be each other.
Checks
assert base is not Noneassert impl is not Noneassert base.overrides == [], "the base method reimplements nothing"assert len(base.overridden_by) == 2assert {o.name for o in impl.overrides} == {"sensor_poll"}assert impl.overridden_by == [], "nothing reimplements the leaf implementor"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_the_two_directions_are_not_the_same_question → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_the_two_directions_are_not_the_same_question → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | inferred | test_the_two_directions_are_not_the_same_question → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_the_two_directions_are_not_the_same_question → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_the_two_directions_are_not_the_same_question → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_the_two_directions_are_not_the_same_question → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_the_two_directions_are_not_the_same_question → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_the_two_directions_are_not_the_same_question → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_the_two_directions_are_not_the_same_question → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_the_two_directions_are_not_the_same_question → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_the_two_directions_are_not_the_same_question → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_the_two_directions_are_not_the_same_question → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_the_two_directions_are_not_the_same_question → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_the_two_directions_are_not_the_same_question → function_dossier → _dossier_conn → locks_held_for_rowids |
Source · 20 lines
def test_the_two_directions_are_not_the_same_question(overriding_db: Path) -> None:
"""`overrides` and `overridden_by` must not be each other.
A single relation table read in one direction only is the easy mistake here, and it
would present a base method as overriding its own implementors. The base's
`overrides` is EMPTY (it reimplements nothing) while an implementor's names it —
asserted on the same database so a symmetric bug cannot satisfy both halves.
"""
base = q.function_dossier(overriding_db, "sensor_poll")
impl = q.function_dossier(overriding_db, "telemetry_report")
assert base is not None
assert impl is not None
assert base.overrides == [], "the base method reimplements nothing"
assert len(base.overridden_by) == 2
assert {o.name for o in impl.overrides} == {"sensor_poll"}
assert impl.overridden_by == [], "nothing reimplements the leaf implementor"