test_reply_bounds.py¶
tests/test_reply_bounds.py
gh#37 — refresh and status replies carried unbounded build detail and overflowed.
test_a_huge_output_is_capped_whatever_its_shape
None test_reply_bounds.test_a_huge_output_is_capped_whatever_its_shape()
Output beyond the cap is trimmed with the omission disclosed.
tests/test_reply_bounds.py:116
Checks
assert len(out) <= _OUTPUT_CAP * 2, f"{len(out)} characters is not a bound"assert "buildlog" in out, "say where the full stream is"assert "INFO unique line 0" in out, "the head carries the scope explanation"assert "INFO unique line 3999" in out, ("the TAIL carries the build summary — `test_the_build_runs_in_process_and_keeps_stdout_" "clean` asserts `memberdef` reaches the caller, and it is the last thing emitted" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-054 | inferred | test_a_huge_output_is_capped_whatever_its_shape → _bounded_output → all |
Source · 23 lines
def test_a_huge_output_is_capped_whatever_its_shape() -> None:
"""THE BACKSTOP, because collapsing is content-dependent and the overflow must not be.
253,867 characters reached a client that discards past its limit in silence; a bound that
only works on the shapes seen so far is not a bound.
@brief Output beyond the cap is trimmed with the omission disclosed.
@return None.
@version 1
"""
from clew.mcp_server.server import _OUTPUT_CAP, _bounded_output
text = "\n".join(f"INFO unique line {i} with padding {'x' * 60}" for i in range(4000))
out = _bounded_output(text)
assert len(out) <= _OUTPUT_CAP * 2, f"{len(out)} characters is not a bound"
assert "buildlog" in out, "say where the full stream is"
assert "INFO unique line 0" in out, "the head carries the scope explanation"
assert "INFO unique line 3999" in out, (
"the TAIL carries the build summary — `test_the_build_runs_in_process_and_keeps_stdout_"
"clean` asserts `memberdef` reaches the caller, and it is the last thing emitted"
)
Activity · 7 steps
test_a_lone_warning_is_never_collapsed
None test_reply_bounds.test_a_lone_warning_is_never_collapsed()
A single occurrence passes through verbatim.
Checks
assert _bounded_output(text) == text
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-054 | inferred | test_a_lone_warning_is_never_collapsed → _bounded_output → all |
Source · 15 lines
def test_a_lone_warning_is_never_collapsed() -> None:
"""A GROUP OF ONE IS NOT A GROUP. Collapsing a single warning would replace a specific,
actionable line with a count of one — strictly worse than leaving it, and the case where
the header name is most likely to matter.
@brief A single occurrence passes through verbatim.
@return None.
@version 1
"""
from clew.mcp_server.server import _bounded_output
text = "WARNING file_docs: could not read only.h, skipping\nINFO done"
assert _bounded_output(text) == text
Activity · 3 steps
test_an_output_with_no_repetition_is_returned_unchanged
None test_reply_bounds.test_an_output_with_no_repetition_is_returned_unchanged()
Varied short output is untouched.
tests/test_reply_bounds.py:102
Checks
assert _bounded_output(text) == text
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-054 | inferred | test_an_output_with_no_repetition_is_returned_unchanged → _bounded_output → all |
Source · 14 lines
def test_an_output_with_no_repetition_is_returned_unchanged() -> None:
"""THE CONTROL. Most builds emit a short, varied stream, and this must be a no-op for them
— a bound that rewrites every reply is a bound nobody can reason about.
@brief Varied short output is untouched.
@return None.
@version 1
"""
from clew.mcp_server.server import _bounded_output
text = "INFO resolve: 96 ms\nINFO doxygen: 3695 ms\nINFO coverage: 812/913 files\n"
assert _bounded_output(text) == text
Activity · 3 steps
test_distinct_warnings_are_not_merged_with_each_other
None test_reply_bounds.test_distinct_warnings_are_not_merged_with_each_other()
Warnings of different shapes each survive.
Checks
assert "roots: is required" in outassert "could not read a.h" in outassert "INPUT names a path" in out
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-054 | inferred | test_distinct_warnings_are_not_merged_with_each_other → _bounded_output → all |
Source · 25 lines
def test_distinct_warnings_are_not_merged_with_each_other() -> None:
"""THE RISK THIS RULE CARRIES, pinned. Grouping by shape must not fold two DIFFERENT
diagnostics into one — a reader told "3 similar lines" when one of them named a broken
declaration and another named an unreadable header has been actively misled.
@brief Warnings of different shapes each survive.
@return None.
@version 1
"""
from clew.mcp_server.server import _bounded_output
out = _bounded_output(
"\n".join(
[
"WARNING index_scope: roots: is required but absent",
"WARNING file_docs: could not read a.h, skipping",
"WARNING doxygen: INPUT names a path that does not exist",
]
)
)
assert "roots: is required" in out
assert "could not read a.h" in out
assert "INPUT names a path" in out
Activity · 5 steps
test_repeated_warnings_collapse_to_one_line_and_a_count
None test_reply_bounds.test_repeated_warnings_collapse_to_one_line_and_a_count()
Same-shape warning lines collapse, keeping the first verbatim.
Checks
assert "INFO stage resolve: 96 ms" in out, "the stage costs are what a reader acts on"assert "INFO build complete" in out, "the tail must survive collapsing the middle"assert "sys0.h" in out, "the first of a collapsed group stays verbatim"assert "sys50.h" not in out, "the ninety-fifth namesake is buildlog material"assert "94" in out, "the count of collapsed lines must be disclosed"assert out.count("could not read") == 1, f"one line for the group, got:\n{out}"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-054 | inferred | test_repeated_warnings_collapse_to_one_line_and_a_count → _bounded_output → all |
Source · 22 lines
def test_repeated_warnings_collapse_to_one_line_and_a_count() -> None:
"""THE REPORTED SHAPE. Ninety-five lines differing only in the header name are one fact,
and a reply that spends ninety-five lines on it has spent them instead of on the stage
costs and the coverage block a reader came for.
@brief Same-shape warning lines collapse, keeping the first verbatim.
@return None.
@version 1
"""
from clew.mcp_server.server import _bounded_output
lines = [f"WARNING file_docs: could not read sys{i}.h, skipping" for i in range(95)]
out = _bounded_output("\n".join(["INFO stage resolve: 96 ms", *lines, "INFO build complete"]))
assert "INFO stage resolve: 96 ms" in out, "the stage costs are what a reader acts on"
assert "INFO build complete" in out, "the tail must survive collapsing the middle"
assert "sys0.h" in out, "the first of a collapsed group stays verbatim"
assert "sys50.h" not in out, "the ninety-fifth namesake is buildlog material"
assert "94" in out, "the count of collapsed lines must be disclosed"
assert out.count("could not read") == 1, f"one line for the group, got:\n{out}"
Activity · 9 steps
test_the_prose_reply_labels_its_text_as_the_repositorys_own
None test_reply_bounds.test_the_prose_reply_labels_its_text_as_the_repositorys_own(Path rich_db)
The prose corpus says whose words it is serving.
tests/test_reply_bounds.py:178
Checks
assert "data to reason about" in reply.get("provenance", ""), (f"the prose reply does not say whose words it carries: {sorted(reply)}" )
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-007 | measured | |
| REQ-DDB-QUERY-014 | measured |
Source · 24 lines
def test_the_prose_reply_labels_its_text_as_the_repositorys_own(rich_db: Path) -> None:
"""M9, 1.1.0 SECURITY AUDIT. This corpus carries the longest verbatim spans of third-party
text in the product — a repository's README, arriving with the authority of a tool result.
The server's INSTRUCTIONS carry the framing too, but those are read once at session start
and this reply may arrive two hundred turns later.
FRAMING IS NOT A FILTER, and `docs/SECURITY.md` says so: carrying third-party prose into a
model's context is clew's thesis, not an accident. What this asserts is that the text
arrives LABELLED.
@brief Every prose reply carries a provenance clause.
@return None.
@version 1
"""
from clew.mcp_server.tools_query import QueryTools
## Built around the fixture index directly: this test is about the PAYLOAD the corpus
## assembles, not about target resolution, which `test_mcp_routing.py` owns.
tools = QueryTools(lambda: rich_db, lambda: rich_db.parent)
reply = tools._search_prose("the", limit=3, target=None)
assert "data to reason about" in reply.get("provenance", ""), (
f"the prose reply does not say whose words it carries: {sorted(reply)}"
)1 more lines, not shown