test_a_response_over_budget_is_trimmed_AND_says_so

Tests › tests/test_mcp_server.py

passed Passed in the packaged run.

What this test is for

Why it exists

A hub symbol must not blow a model's context, and must not lie about it.

Verifies REQ-DDB-MCP-001 REQ-DDB-MCP-003 REQ-DDB-QUERY-006 REQ-DDB-QUERY-008 REQ-DDB-QUERY-009

Given

  1. payload = { "kind": "callers", "count": 400, "results": [ {"name": f"caller_{i}", "source": "ast_member", "confidence": "resolved", "edge_class": "call", "implementors": [], "padding": "x" * 120} for i in range(400) ], }
→

When

  1. cut = tq._shrink_to_budget(payload, ("results",))
  2. block = tq._limited_block("callers", cut["results"], len(payload["results"]), "narrow it")
→

Then

  1. ✓ len(json.dumps(payload)) is greater than tq.RESPONSE_BUDGET_BYTES
  2. ✓ len(json.dumps(payload)) is at most tq.RESPONSE_BUDGET_BYTES
  3. ✓ cut equals {"results": 400}
  4. ✓ block["total_available"] equals 400
  5. ✓ block["adjusted"]["callers"].startswith("400 -> ") holds
  6. ✓ len(payload["results"]) is less than 400

What it exercises

The parts of the system's flows this test ran, measured by per-test coverage: lit steps ran in this test, dimmed ones did not, and ▶ marks where the test called in. Each title opens the whole flow with these steps lit.

Look up one name: everything the index holds about it · 1 of 226 steps

… 97 earlier steps

callercallercallercallerclew/mcp_server/tools_query.pyclew/mcp_server/tools_query.pyclew/mcp_server/tools_query.pyclew/mcp_server/tools_query.pyother filesother filesother filesother filesloop (line 973)looploop (line 578)looploop (line 1539)looploop (line 198)loopdossier98–99. _budget_batch → _fair_shares98_fair_shares +1 more100. _shrink_to_budget → _step_chain_depth100_step_chain_depth▶ test enters101. _batched_dossiers → prune_absent_keys101prune_absent_keys102. prune_absent_keys → _absent102_absent

… 124 later steps

tests/test_mcp_server.py:1104 · its file's page

What it checks (6)

  1. assert len(json.dumps(payload)) > tq.RESPONSE_BUDGET_BYTES, "premise: must start over budget" not attributed
  2. assert len(json.dumps(payload)) <= tq.RESPONSE_BUDGET_BYTES, ( "the trimmed payload must fit the cap — a cap that can be exceeded is not a cap" ) not attributed
  3. assert cut == {"results": 400}, f"the ORIGINAL length must be reported, got {cut}" observes _shrink_to_budget via cut
  4. assert block["total_available"] == 400, "a model must be told the true total" observes _limited_block via block
  5. assert block["adjusted"]["callers"].startswith("400 -> "), ( f"before/after must be explicit, got {block['adjusted']}" ) observes _limited_block via block
  6. assert len(payload["results"]) < 400, "something must actually have been dropped" not attributed

Where the product reaches it

  • dossier → _capped_neighbors → _limited_block (flow)
  • dossier → _budgeted_dossier → _shrink_to_budget (flow)

Call flow

test_a_response_over_budget_is_trimmed_AND_says_so→_shrink_to_budget→_limited_block

What it reaches

Each row runs from this test, through the calls it makes, to the code a requirement names. If that code breaks, the test's checks are what should catch it. Reaching is not proving: a check only proves what it observes. No mutation records were given, so these rows say what the test REACHES.

Requirements it verifies (5)

requirementlinked byimplementers exercised
REQ-DDB-MCP-001catalogunknown
REQ-DDB-MCP-003catalogunknown
REQ-DDB-QUERY-006catalogunknown
REQ-DDB-QUERY-008catalogunknown
REQ-DDB-QUERY-009catalogunknown