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

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054inferredtest_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
lines 125–125from clew.mcp_server.server import _OUTPUT_CAP, _bounded_outputlines 127–127text = "\n".join(f"INFO unique line {i} with padding {'x' * 60}" for i in range(4000))lines 128–128out = _bounded_output(text)lines 130–130assert len(out) <= _OUTPUT_CAP * 2, f"{len(out)} characters is not a bound"lines 131–131assert "buildlog" in out, "say where the full stream is"lines 132–132assert "INFO unique line 0" in out, "the head carries the scope explanation"lines 133–136assert "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" )

test_a_lone_warning_is_never_collapsed

None test_reply_bounds.test_a_lone_warning_is_never_collapsed()

A single occurrence passes through verbatim.

tests/test_reply_bounds.py:62

Checks

  • assert _bounded_output(text) == text

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054inferredtest_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
lines 71–71from clew.mcp_server.server import _bounded_outputlines 73–73text = "WARNING file_docs: could not read only.h, skipping\nINFO done"lines 74–74assert _bounded_output(text) == text

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

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054inferredtest_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
lines 110–110from clew.mcp_server.server import _bounded_outputlines 112–112text = "INFO resolve: 96 ms\nINFO doxygen: 3695 ms\nINFO coverage: 812/913 files\n"lines 113–113assert _bounded_output(text) == text

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.

tests/test_reply_bounds.py:77

Checks

  • assert "roots: is required" in out
  • assert "could not read a.h" in out
  • assert "INPUT names a path" in out

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054inferredtest_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
lines 86–86from clew.mcp_server.server import _bounded_outputlines 88–96out = _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", ] ) )lines 97–97assert "roots: is required" in outlines 98–98assert "could not read a.h" in outlines 99–99assert "INPUT names a path" in out

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.

tests/test_reply_bounds.py:40

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

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054inferredtest_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
lines 49–49from clew.mcp_server.server import _bounded_outputlines 51–51lines = [f"WARNING file_docs: could not read sys{i}.h, skipping" for i in range(95)]lines 52–52out = _bounded_output("\n".join(["INFO stage resolve: 96 ms", *lines, "INFO build complete"]))lines 54–54assert "INFO stage resolve: 96 ms" in out, "the stage costs are what a reader acts on"lines 55–55assert "INFO build complete" in out, "the tail must survive collapsing the middle"lines 56–56assert "sys0.h" in out, "the first of a collapsed group stays verbatim"lines 57–57assert "sys50.h" not in out, "the ninety-fifth namesake is buildlog material"lines 58–58assert "94" in out, "the count of collapsed lines must be disclosed"lines 59–59assert out.count("could not read") == 1, f"one line for the group, got:\n{out}"

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

Show on the map →

Called by none

Calls none

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

requirementlinkedpath to the implementer
REQ-DDB-MCP-003measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-014measured
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

Activity · 4 steps
lines 192–192from clew.mcp_server.tools_query import QueryToolslines 196–196tools = QueryTools(lambda: rich_db, lambda: rich_db.parent)lines 197–197reply = tools._search_prose("the", limit=3, target=None)lines 199–201assert "data to reason about" in reply.get("provenance", ""), ( f"the prose reply does not say whose words it carries: {sorted(reply)}" )