test_dossier_batch.py¶
tests/test_dossier_batch.py
Tests for the BATCHED dossier — several symbols, one call, one shared byte budget.
test_a_batch_returns_the_same_payload_per_symbol_as_the_single_calls
None test_dossier_batch.test_a_batch_returns_the_same_payload_per_symbol_as_the_single_calls(Path rich_db)
Each batch entry matches its single-call dossier.
tests/test_dossier_batch.py:69
Checks
assert batch["kind"] == "dossiers"assert batch["count"] == len(INDEXED)assert batch["found"] == len(INDEXED)assert [e["name"] for e in batch["results"]] == list(INDEXED)assert entry.get(panel) == single.get(panel), panelassert entry.get(ident) == single.get(ident), ident
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 · 28 lines
def test_a_batch_returns_the_same_payload_per_symbol_as_the_single_calls(rich_db: Path) -> None:
"""THE WHOLE PREMISE. A batch is only a saving if it is the same answer in fewer
turns; if the batched entry differs from the single-call payload the saving is
bought with data the caller then has to go back for, which is a net loss of a turn
rather than a gain of four.
Compared field by field over the panels that carry rows, because comparing whole
dicts would fail on the envelope keys a single reply carries and a batch entry
deliberately does not (`target`, stamped once for the batch).
@brief Each batch entry matches its single-call dossier.
@version 1
"""
tools = _tools(rich_db)
singles = [tools.dossier(n) for n in INDEXED]
batch = tools.dossier(list(INDEXED))
assert batch["kind"] == "dossiers"
assert batch["count"] == len(INDEXED)
assert batch["found"] == len(INDEXED)
assert [e["name"] for e in batch["results"]] == list(INDEXED)
for single, entry in zip(singles, batch["results"], strict=True):
for panel in ("callers", "callees", "writes", "reads", "requirements"):
assert entry.get(panel) == single.get(panel), panel
for ident in ("name", "signature", "file", "brief", "liveness"):
assert entry.get(ident) == single.get(ident), ident
Activity · 12 steps
test_a_qualified_argument_beside_a_list_is_refused_not_ignored
None test_dossier_batch.test_a_qualified_argument_beside_a_list_is_refused_not_ignored(Path rich_db)
A list plus `qualified` raises.
tests/test_dossier_batch.py:123
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-003 | measured | |
| REQ-DDB-QUERY-010 | measured |
Source · 13 lines
def test_a_qualified_argument_beside_a_list_is_refused_not_ignored(rich_db: Path) -> None:
"""`qualified` names ONE identity among namesakes. Applied to a list it would scope
four dossiers by a key belonging to the fifth; ignored, the caller who asked for a
specific identity would receive an arbitrary one and no indication of it. Both silent
options produce a confidently mislabelled answer, so the call is refused.
@brief A list plus `qualified` raises.
@version 1
"""
with pytest.raises(ValueError, match="cannot be combined with a list"):
_tools(rich_db).dossier(list(INDEXED), qualified="some::identity")
Activity · 2 steps
test_a_repeated_name_is_answered_once
None test_dossier_batch.test_a_repeated_name_is_answered_once(Path rich_db)
Duplicates collapse to one entry.
tests/test_dossier_batch.py:170
Checks
assert [e["name"] for e in batch["results"]] == [INDEXED[0], INDEXED[1]]
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 · 11 lines
def test_a_repeated_name_is_answered_once(rich_db: Path) -> None:
"""A duplicate costs a whole dossier of the shared budget to say the same thing
twice, and the entry it occupies is better spent on a symbol that was asked about.
@brief Duplicates collapse to one entry.
@version 1
"""
batch = _tools(rich_db).dossier([INDEXED[0], INDEXED[0], INDEXED[1]])
assert [e["name"] for e in batch["results"]] == [INDEXED[0], INDEXED[1]]
Activity · 2 steps
test_a_single_string_argument_is_unchanged_by_the_batch_path
None test_dossier_batch.test_a_single_string_argument_is_unchanged_by_the_batch_path(Path rich_db)
The single-symbol form still returns a bare dossier.
tests/test_dossier_batch.py:181
Checks
assert single["name"] == INDEXED[0]assert single["kind"] != "dossiers"assert "results" not in single
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 · 13 lines
def test_a_single_string_argument_is_unchanged_by_the_batch_path(rich_db: Path) -> None:
"""The common case and every existing caller. A polymorphic first argument is only
safe if the string branch is byte-identical to what it always returned.
@brief The single-symbol form still returns a bare dossier.
@version 1
"""
single = _tools(rich_db).dossier(INDEXED[0])
assert single["name"] == INDEXED[0]
assert single["kind"] != "dossiers"
assert "results" not in single
Activity · 4 steps
test_an_empty_list_is_refused_rather_than_answered_with_zero_results
None test_dossier_batch.test_an_empty_list_is_refused_rather_than_answered_with_zero_results(Path rich_db)
An empty list raises.
tests/test_dossier_batch.py:157
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-003 | measured | |
| REQ-DDB-QUERY-010 | measured |
Source · 13 lines
def test_an_empty_list_is_refused_rather_than_answered_with_zero_results(
rich_db: Path,
) -> None:
"""`count: 0` to a request that asked for nothing reads as "none of your symbols is
indexed", which is a measurement the database never made.
@brief An empty list raises.
@version 1
"""
with pytest.raises(ValueError, match="at least one"):
_tools(rich_db).dossier([])
Activity · 2 steps
test_one_unresolvable_name_misses_in_its_own_slot_and_the_rest_still_answer
None test_dossier_batch.test_one_unresolvable_name_misses_in_its_own_slot_and_the_rest_still_answer(Path rich_db)
A miss occupies its own slot and does not fail the batch.
tests/test_dossier_batch.py:97
Checks
assert [e["name"] for e in batch["results"]] == namesassert batch["count"] == 3assert batch["found"] == 2assert batch["results"][1]["found"] is Falseassert "not an error" in batch["results"][1]["note"]assert batch["results"][0].get("found") is Noneassert batch["results"][2]["signature"]
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-013 | measured | |
| REQ-DDB-QUERY-014 | measured | |
| REQ-DDB-SCHEMA-011 | measured |
Source · 26 lines
def test_one_unresolvable_name_misses_in_its_own_slot_and_the_rest_still_answer(
rich_db: Path,
) -> None:
"""POSITIONAL, INCLUDING THE MISSES. Dropping the miss would silently re-align every
entry after it, so a reader pairing names with answers by position would attribute
the third symbol's dossier to the second name — a wrong answer delivered with full
confidence, which is worse than the miss it hides.
The miss is placed in the MIDDLE deliberately: a miss at the end is caught by a
length check alone, and a length check is what a dropped-and-shifted list passes.
@brief A miss occupies its own slot and does not fail the batch.
@version 1
"""
names = [INDEXED[0], MISSING, INDEXED[1]]
batch = _tools(rich_db).dossier(names)
assert [e["name"] for e in batch["results"]] == names
assert batch["count"] == 3
assert batch["found"] == 2
assert batch["results"][1]["found"] is False
assert "not an error" in batch["results"][1]["note"]
assert batch["results"][0].get("found") is None
assert batch["results"][2]["signature"]
Activity · 9 steps
test_over_the_batch_cap_answers_the_first_n_and_names_the_rest
None test_dossier_batch.test_over_the_batch_cap_answers_the_first_n_and_names_the_rest(Path rich_db)
Over the cap answers the first N and names the rest; at the cap names nothing.
tests/test_dossier_batch.py:136
Checks
assert reply["count"] == q.MAX_BATCH_SYMBOLSassert reply["subject"] == over[: q.MAX_BATCH_SYMBOLS]assert reply["not_answered"] == over[q.MAX_BATCH_SYMBOLS :]assert "re-ask" in reply["not_answered_means"]assert at_cap["count"] == q.MAX_BATCH_SYMBOLS and "not_answered" not in at_cap
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-003 | measured | |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-004 | measured | |
| REQ-DDB-QUERY-010 | measured | |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-QUERY-013 | measured | |
| REQ-DDB-QUERY-014 | measured |
Source · 21 lines
def test_over_the_batch_cap_answers_the_first_n_and_names_the_rest(rich_db: Path) -> None:
"""THE RULE CHANGED BY OWNER RULING (2026-11-13, 1.3.10): an over-cap batch used to be
REFUSED, which cost the agent a second call every time (2 of 188 mbedtls calls in the 1.3.0
grid). It now answers the first `MAX_BATCH_SYMBOLS` and names every subject it did not answer
in `not_answered` — the disclosure that kept the old rule's purpose: a truncated request must
never read as a complete one. At the cap nothing is named.
@brief Over the cap answers the first N and names the rest; at the cap names nothing.
@version 2
"""
tools = _tools(rich_db)
over = [f"{INDEXED[0]}_{i}" for i in range(q.MAX_BATCH_SYMBOLS + 2)]
reply = tools.dossier(over)
assert reply["count"] == q.MAX_BATCH_SYMBOLS
assert reply["subject"] == over[: q.MAX_BATCH_SYMBOLS]
assert reply["not_answered"] == over[q.MAX_BATCH_SYMBOLS :]
assert "re-ask" in reply["not_answered_means"]
at_cap = tools.dossier(over[: q.MAX_BATCH_SYMBOLS])
assert at_cap["count"] == q.MAX_BATCH_SYMBOLS and "not_answered" not in at_cap
Activity · 9 steps
test_r2_dossiers_is_positional_and_matches_the_single_symbol_function
None test_dossier_batch.test_r2_dossiers_is_positional_and_matches_the_single_symbol_function(Path rich_db)
R2 `dossiers` is positional and agrees with `dossier`.
tests/test_dossier_batch.py:273
Checks
assert len(built) == len(names)assert built[1] is Noneassert doss == q.function_dossier(rich_db, name)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier → _dossier_conn → symbol_provenance |
| REQ-DDB-PIPE-003 | inferred | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_harvest_calls → is_python_tree |
| REQ-DDB-PIPE-011 | inferred | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier → _dossier_conn → _body_and_external → external_callees → _harvest_file → _ast_parse_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | inferred | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier → _dossier_conn → _body_and_external → external_callees → _ts_language_for → _grammar_available → has_language |
| REQ-DDB-QUERY-001 | measured | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier → connect |
| REQ-DDB-QUERY-002 | measured | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier → _dossier_conn → unresolved_inbound_for_rowids |
| REQ-DDB-QUERY-003 | measured | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier → _dossier_conn → function_candidates |
| REQ-DDB-QUERY-004 | measured | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier |
| REQ-DDB-QUERY-006 | measured | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier → _dossier_conn → gates_covering |
| REQ-DDB-QUERY-009 | measured | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier |
| REQ-DDB-QUERY-010 | measured | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier |
| REQ-DDB-QUERY-012 | measured | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier → _dossier_conn → _macro_dossier |
| REQ-DDB-QUERY-013 | inferred | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier → _dossier_conn → config_defaults_conn |
| REQ-DDB-SCHEMA-011 | measured | test_r2_dossiers_is_positional_and_matches_the_single_symbol_function → function_dossier → _dossier_conn → locks_held_for_rowids |
Source · 23 lines
def test_r2_dossiers_is_positional_and_matches_the_single_symbol_function(
rich_db: Path,
) -> None:
"""The library contract underneath the tool: one entry per requested name, in
request order, `None` where a name resolves to nothing — and each one equal to what
the single-symbol `dossier` would have built for it.
Guards the split that makes the batch cheap. `_dossier_conn` was extracted so five
symbols share one connection; if that extraction changed an answer, the saving would
have been bought with correctness.
@brief R2 `dossiers` is positional and agrees with `dossier`.
@version 1
"""
names = [INDEXED[0], MISSING, INDEXED[1]]
built = q.function_dossiers(rich_db, names)
assert len(built) == len(names)
assert built[1] is None
for name, doss in zip(names, built, strict=True):
assert doss == q.function_dossier(rich_db, name)
Activity · 6 steps
test_the_chain_loses_its_outermost_ring_before_a_neighbour_list_is_trimmed
None test_dossier_batch.test_the_chain_loses_its_outermost_ring_before_a_neighbour_list_is_trimmed()
Depth is spent before rows, and hops leave with their nodes.
tests/test_dossier_batch.py:296
Checks
assert len(payload["callers"]) == 8, ("the immediate neighbours are the DEAREST rows and must survive a chain that " "could have been dropped instead" )assert cut.get("chain_depth") == 3, "the dropped depth must be reported as a depth"assert all(n["depth"] < 3 for n in payload["chain"]["nodes"])assert payload["chain"]["hops"] == []assert _size(payload) <= RESPONSE_BUDGET_BYTES
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-054 | inferred | test_the_chain_loses_its_outermost_ring_before_a_neighbour_list_is_trimmed → all |
Source · 45 lines
def test_the_chain_loses_its_outermost_ring_before_a_neighbour_list_is_trimmed() -> None:
"""gh#383, and the defect is sharper than "step depth before halving". `_DOSSIER_LISTS`
holds TOP-LEVEL keys and `payload["chain"]` is a NESTED dict of nodes/hops, so
`_shrink_to_budget` could not see the chain at all: an oversized traversal was carried in
full while `callers` and `callees` — the highest-value rows in the reply — were halved to
pay for it. Exactly backwards. Depth 1 is adjacency, which the populated section already
carries; depth 2+ is traversal, and fan-out is roughly geometric, so the outermost ring is
both the cheapest thing to lose and usually the largest.
THE ORDERING IS THE CLAIM, so it is what is asserted: with a chain big enough to blow the
budget on its own, the neighbour list must come through UNTOUCHED. A test that only
checked "the payload fits" would pass on the old behaviour too.
HOPS ARE PRUNED WITH THEIR NODES. A hop whose endpoint left would assert an edge into
nothing, which is a worse answer than a smaller chain.
@brief Depth is spent before rows, and hops leave with their nodes.
@version 1
"""
payload: dict = {
"subject": "seed",
"callers": [{"name": f"caller_{i}"} for i in range(8)],
"chain": {
"seed": "seed",
"nodes": [{"name": "seed", "depth": 1}]
+ [{"name": f"far_{i}" * 30, "depth": 3} for i in range(400)],
"hops": [
{"edge_class": "call", "from_name": "seed", "to_name": f"far_{i}" * 30}
for i in range(400)
],
},
}
cut = _shrink_to_budget(payload, ("callers",))
assert len(payload["callers"]) == 8, (
"the immediate neighbours are the DEAREST rows and must survive a chain that "
"could have been dropped instead"
)
assert cut.get("chain_depth") == 3, "the dropped depth must be reported as a depth"
assert all(n["depth"] < 3 for n in payload["chain"]["nodes"])
## Every hop pointed at a depth-3 node, so all of them must go with it.
assert payload["chain"]["hops"] == []
assert _size(payload) <= RESPONSE_BUDGET_BYTES