test_search_type_corpora.py¶
tests/test_search_type_corpora.py
gh#374 — the typedef/enumeration corpora, and an empty result that cannot overclaim.
test_a_conjunction_miss_still_names_its_dead_token
None test_search_type_corpora.test_a_conjunction_miss_still_names_its_dead_token(Path db)
A multi-token miss keeps its per-token diagnosis and gains the unread finding.
tests/test_search_type_corpora.py:275
Checks
assert search(db, "pump zzznosuchtoken") == []assert extra["token_hits"] == {"pump": 2, "zzznosuchtoken": 0}assert "'zzznosuchtoken'" in noteassert "RETRY WITHOUT THEM" in note
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | test_a_conjunction_miss_still_names_its_dead_token → search_emptiness → index_scope → connect |
| REQ-DDB-QUERY-003 | measured | test_a_conjunction_miss_still_names_its_dead_token → search_emptiness → unsearched_corpora → table_exists |
| REQ-DDB-QUERY-007 | measured | test_a_conjunction_miss_still_names_its_dead_token → search_emptiness |
| REQ-DDB-QUERY-012 | measured |
Source · 12 lines
def test_a_conjunction_miss_still_names_its_dead_token(db: Path) -> None:
"""gh#31's diagnosis is not displaced by gh#374's. The two answer different
questions — WHICH token emptied the conjunction, and whether the emptiness is a
claim about the repository — and a reply that dropped the first to make room for
the second would re-open the defect it was written for."""
assert search(db, "pump zzznosuchtoken") == []
note, extra = search_emptiness(db, "pump zzznosuchtoken")
assert extra["token_hits"] == {"pump": 2, "zzznosuchtoken": 0}
assert "'zzznosuchtoken'" in note
assert "RETRY WITHOUT THEM" in note
Activity · 5 steps
test_a_genuinely_absent_token_still_gets_the_definitive_note
None test_search_type_corpora.test_a_genuinely_absent_token_still_gets_the_definitive_note(Path db)
A genuinely absent single token still gets the full definitive note.
tests/test_search_type_corpora.py:181
Checks
assert search(db, "zzznosuchtoken") == []assert "definitive" in noteassert "Do not retry this query or fall back to guessing" in noteassert "unsearched_corpus_hits" not in extra
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | test_a_genuinely_absent_token_still_gets_the_definitive_note → search_emptiness → index_scope → connect |
| REQ-DDB-QUERY-003 | measured | test_a_genuinely_absent_token_still_gets_the_definitive_note → search_emptiness → unsearched_corpora → table_exists |
| REQ-DDB-QUERY-007 | measured | test_a_genuinely_absent_token_still_gets_the_definitive_note → search_emptiness |
| REQ-DDB-QUERY-012 | measured |
Source · 12 lines
def test_a_genuinely_absent_token_still_gets_the_definitive_note(db: Path) -> None:
"""THE CONTROL ON THE GRADING. Nothing in this database matches, in a read corpus
or an unread one, so the strong wording is earned and must survive. If this test
ever needs weakening, the change has become a blanket hedge — which is the other
way to be useless about an empty result."""
assert search(db, "zzznosuchtoken") == []
note, extra = search_emptiness(db, "zzznosuchtoken")
assert "definitive" in note
assert "Do not retry this query or fall back to guessing" in note
assert "unsearched_corpus_hits" not in extra
Activity · 5 steps
test_a_name_that_is_both_a_function_and_a_type_returns_both
None test_search_type_corpora.test_a_name_that_is_both_a_function_and_a_type_returns_both(Path db)
A name that is BOTH a function and a typedef returns both, function first.
tests/test_search_type_corpora.py:149
Checks
assert [(h.name, h.kind) for h in hits] == [
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-007 | measured | |
| REQ-DDB-QUERY-012 | measured |
Source · 13 lines
def test_a_name_that_is_both_a_function_and_a_type_returns_both(db: Path) -> None:
"""THE COLLISION CASE, and the one an obvious implementation gets wrong. Falling
back to the type corpus only when no function resolves would pass every other test
here and go dark on the shape C headers use most — a callback typedef named after
the function it fronts. Both rows must come back, and the FUNCTION must lead:
types sit in the lowest tie-break tier for exactly this."""
hits = search(db, "poll_state")
assert [(h.name, h.kind) for h in hits] == [
("poll_state", "function"),
("poll_state", TYPEDEF_KIND),
]
Activity · 2 steps
test_a_type_only_token_is_not_blamed_for_the_conjunction
None test_search_type_corpora.test_a_type_only_token_is_not_blamed_for_the_conjunction(Path db)
A token matching only a TYPE is never named as the token that emptied a query.
tests/test_search_type_corpora.py:291
Checks
assert search(db, "mbed_mode_t run_pump") == []assert extra["token_hits"] == {"mbed_mode_t": 1, "run_pump": 1}assert "RETRY WITH FEWER TOKENS" in _note
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | test_a_type_only_token_is_not_blamed_for_the_conjunction → search_emptiness → index_scope → connect |
| REQ-DDB-QUERY-003 | measured | test_a_type_only_token_is_not_blamed_for_the_conjunction → search_emptiness → unsearched_corpora → table_exists |
| REQ-DDB-QUERY-007 | measured | test_a_type_only_token_is_not_blamed_for_the_conjunction → search_emptiness |
| REQ-DDB-QUERY-012 | measured |
Source · 15 lines
def test_a_type_only_token_is_not_blamed_for_the_conjunction(db: Path) -> None:
"""gh#31's defect, reachable through gh#374's corpora. The per-token diagnosis
counts matches so it can tell the caller WHICH token to drop, and it counted only
the kinds it had listed for itself. Add a corpus to the searcher and not to the
counter and the counter names the working token as the guilty one — advice that is
not merely unhelpful but backwards.
`mbed_mode_t` matches the enumeration and nothing else; `run_pump` matches the
function and nothing else. Neither is to blame: both match alone, no unit carries
both, and the correct advice is fewer tokens. A counter blind to the type corpora
reports `mbed_mode_t=0` and tells the caller to delete it."""
assert search(db, "mbed_mode_t run_pump") == []
_note, extra = search_emptiness(db, "mbed_mode_t run_pump")
assert extra["token_hits"] == {"mbed_mode_t": 1, "run_pump": 1}
assert "RETRY WITH FEWER TOKENS" in _note1 more lines, not shown
Activity · 4 steps
test_a_typedef_is_findable
None test_search_type_corpora.test_a_typedef_is_findable(Path db)
A typedef that shares its name with nothing else is findable.
tests/test_search_type_corpora.py:125
Checks
assert [(h.name, h.kind) for h in hits] == [("ctx_state_t", TYPEDEF_KIND)]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-007 | measured | |
| REQ-DDB-QUERY-012 | measured |
Source · 7 lines
def test_a_typedef_is_findable(db: Path) -> None:
"""The measured case: on mbedtls, 239 typedef names existed under no other kind, so
`search` returned zero for names like `mbedtls_x509_buf` and said so definitively."""
hits = search(db, "ctx_state_t")
assert [(h.name, h.kind) for h in hits] == [("ctx_state_t", TYPEDEF_KIND)]
Activity · 2 steps
test_an_enumeration_is_findable_and_says_it_is_one
None test_search_type_corpora.test_an_enumeration_is_findable_and_says_it_is_one(Path db)
An enumeration is findable, and reports its own kind rather than a function's.
tests/test_search_type_corpora.py:136
Checks
assert [(h.name, h.kind) for h in hits] == [("mbed_mode_t", ENUM_KIND)]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-007 | measured | |
| REQ-DDB-QUERY-012 | measured |
Source · 9 lines
def test_an_enumeration_is_findable_and_says_it_is_one(db: Path) -> None:
"""`kind` is what a caller must read before treating a hit as callable: an
enumeration has no body, no callers and no callees, and every call, thread and
requirement layer filters `kind='function'`. A hit that came back labelled
`function` would be worse than the empty result it replaced."""
hits = search(db, "mbed_mode_t")
assert [(h.name, h.kind) for h in hits] == [("mbed_mode_t", ENUM_KIND)]
Activity · 2 steps
test_an_undocumented_file_is_not_assumed_searchable
None test_search_type_corpora.test_an_undocumented_file_is_not_assumed_searchable(Path db)
An UNDOCUMENTED indexed file is reported, not assumed covered.
tests/test_search_type_corpora.py:246
Checks
assert search(db, "legacy_shim") == []assert extra["unsearched_corpus_hits"] == {"file": 1}assert "NOT DEFINITIVE" in noteassert hits and hits[0] == "src/pump.c", f"the documented file is not the first hit: {hits}"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | test_an_undocumented_file_is_not_assumed_searchable → search_emptiness → index_scope → connect |
| REQ-DDB-QUERY-003 | measured | test_an_undocumented_file_is_not_assumed_searchable → search_emptiness → unsearched_corpora → table_exists |
| REQ-DDB-QUERY-007 | measured | test_an_undocumented_file_is_not_assumed_searchable → search_emptiness |
| REQ-DDB-QUERY-012 | measured |
Source · 25 lines
def test_an_undocumented_file_is_not_assumed_searchable(db: Path) -> None:
"""The near-miss in this change. `file` looks like a covered kind because file-level
documentation IS a search corpus — but that corpus is `file_docs`, one row per
DOCUMENTED file, so `legacy_shim.c` (indexed, no docstring) is reachable by no
route `search` has. Excluding `file` from the unread set would have asserted
coverage the searcher does not have, which is this defect one table over.
The documented control is `src/pump.c`: it has a `file_docs` row, so it is FOUND
and never reaches the grader at all.
THE CONTROL IS NOW "FOUND AND FIRST", NOT "FOUND AND ALONE". Symbol search gained the
containing file path as a match target, so a query naming a file also returns the symbols
defined in it — deliberately: a symbol whose file was named for the query used to be
reachable by no query at all (`search("loader")` returned 24 rows and none was
`_candidate_paths`, defined in `_loader.py`). The property this test guards is unchanged:
the documented file is found, the undocumented one is not. Only the incidental
exact-equality moved, and the file still ranks ahead of its own contents."""
assert search(db, "legacy_shim") == []
note, extra = search_emptiness(db, "legacy_shim")
assert extra["unsearched_corpus_hits"] == {"file": 1}
assert "NOT DEFINITIVE" in note
hits = [h.name for h in search(db, "pump.c")]
assert hits and hits[0] == "src/pump.c", f"the documented file is not the first hit: {hits}"
Activity · 6 steps
test_an_unread_corpus_downgrades_the_verdict
None test_search_type_corpora.test_an_unread_corpus_downgrades_the_verdict(Path db)
A match in a corpus search does not read strips the definitive claim.
tests/test_search_type_corpora.py:197
Checks
assert search(db, "asn1_module") == []assert "NOT DEFINITIVE" in noteassert "Do not retry this query or fall back to guessing" not in noteassert "1 group" in noteassert extra["unsearched_corpus_hits"] == {"group": 1}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | test_an_unread_corpus_downgrades_the_verdict → search_emptiness → index_scope → connect |
| REQ-DDB-QUERY-003 | measured | test_an_unread_corpus_downgrades_the_verdict → search_emptiness → unsearched_corpora → table_exists |
| REQ-DDB-QUERY-007 | measured | test_an_unread_corpus_downgrades_the_verdict → search_emptiness |
| REQ-DDB-QUERY-012 | measured |
Source · 16 lines
def test_an_unread_corpus_downgrades_the_verdict(db: Path) -> None:
"""THE CLASS FIX. `asn1_module` is a doxygen `group`, which `search` does not read
and is not being taught to read here — the point is that the reply KNOWS it did not
look. The old note asserted absence with maximum confidence in exactly this
situation, and did so four times over four different kinds.
The count is published as well as worded, so the claim is checkable by the caller
rather than merely asserted at them."""
assert search(db, "asn1_module") == []
note, extra = search_emptiness(db, "asn1_module")
assert "NOT DEFINITIVE" in note
assert "Do not retry this query or fall back to guessing" not in note
assert "1 group" in note
assert extra["unsearched_corpus_hits"] == {"group": 1}
Activity · 6 steps
test_the_unread_set_is_derived_from_the_database
None test_search_type_corpora.test_the_unread_set_is_derived_from_the_database(Path db)
The unread set is derived by subtraction, so a NEW unread kind is caught unaided.
tests/test_search_type_corpora.py:217
Checks
assert search(db, "quantum_widget") == []assert unsearched_corpora(db, ["quantum_widget"]) == {"concept": 1}assert unsearched_corpora(db, ["poll_state"]) == {}assert "NOT DEFINITIVE" in noteassert "1 concept" in note
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-QUERY-001 | measured | test_the_unread_set_is_derived_from_the_database → unsearched_corpora → connect |
| REQ-DDB-QUERY-003 | measured | test_the_unread_set_is_derived_from_the_database → unsearched_corpora → table_exists |
| REQ-DDB-QUERY-007 | measured | test_the_unread_set_is_derived_from_the_database → search_emptiness |
| REQ-DDB-QUERY-012 | measured |
Source · 25 lines
def test_the_unread_set_is_derived_from_the_database(db: Path) -> None:
"""The difference between a fix and a guard. A hardcoded list of unread kinds would
be exactly as stale as the hardcoded list of READ kinds turned out to be; this
inserts a kind no line of production code mentions and requires it to be reported.
A future doxygen kind, or a layer a later pipeline stage adds, is covered on the day
it first appears with no edit to the grader."""
conn = sqlite3.connect(db)
conn.execute(
"INSERT INTO memberdef (name, kind, briefdescription, initializer, file_id) "
"VALUES ('quantum_widget', 'concept', 'A kind that did not exist yesterday', NULL, 1)"
)
conn.commit()
conn.close()
assert search(db, "quantum_widget") == []
assert unsearched_corpora(db, ["quantum_widget"]) == {"concept": 1}
## THE OTHER DIRECTION, and it needs asserting HERE because no reply can show it:
## a searched kind that matched means `search` returned hits, so the grader is
## never called and a subtraction that had stopped subtracting would look exactly
## like one that works. `poll_state` is a function AND a typedef, both read.
assert unsearched_corpora(db, ["poll_state"]) == {}
note, _extra = search_emptiness(db, "quantum_widget")
assert "NOT DEFINITIVE" in note
assert "1 concept" in note