test_compact_wire.py¶
tests/test_compact_wire.py
The opt-in compact wire shape: neighbour rows grouped by file, shared values stated once.
test_a_detail_is_not_dropped_when_the_body_shown_is_truncated
None test_compact_wire.test_a_detail_is_not_dropped_when_the_body_shown_is_truncated()
A truncated body keeps `detail`.
tests/test_compact_wire.py:212
Checks
assert compact_docs(copy.deepcopy(payload)) == payload
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-014 | measured | test_a_detail_is_not_dropped_when_the_body_shown_is_truncated → compact_docs |
Source · 21 lines
def test_a_detail_is_not_dropped_when_the_body_shown_is_truncated() -> None:
"""1.4.0 GRID: `build_or_refresh` was served `detail_in_body: true` with its body cut at 60 of
137 lines, mid-docstring — the docstring's tail reached the agent nowhere. A detail is "in the
body" only if it is in the body THAT WAS SERVED.
@brief A truncated body keeps `detail`.
@return None.
@version 1
"""
from clew.query.payload import compact_docs
payload = {
"detail": _DOC,
"body": {
"lines": ["def fetch(id):", f' """{_DOC}"""', " return cache[id]"],
"truncated": True,
},
}
assert compact_docs(copy.deepcopy(payload)) == payload
Activity · 3 steps
test_a_detail_the_body_does_not_carry_is_kept
None test_compact_wire.test_a_detail_the_body_does_not_carry_is_kept()
Doc text outside the body (a C comment above it), or no body, keeps `detail`.
tests/test_compact_wire.py:199
Checks
assert compact_docs(copy.deepcopy(elsewhere)) == elsewhereassert compact_docs(copy.deepcopy(bodiless)) == bodiless
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-014 | measured | test_a_detail_the_body_does_not_carry_is_kept → compact_docs |
Source · 13 lines
def test_a_detail_the_body_does_not_carry_is_kept() -> None:
"""@brief Doc text outside the body (a C comment above it), or no body, keeps `detail`.
@return None.
@version 1
"""
from clew.query.payload import compact_docs
elsewhere = {"detail": _DOC, "body": {"lines": ["int fetch(int id) {", " return 0;", "}"]}}
assert compact_docs(copy.deepcopy(elsewhere)) == elsewhere
bodiless = {"detail": _DOC}
assert compact_docs(copy.deepcopy(bodiless)) == bodiless
Activity · 5 steps
test_a_detail_whose_words_merely_overlap_the_body_is_kept
None test_compact_wire.test_a_detail_whose_words_merely_overlap_the_body_is_kept()
A detail sentence absent from the body is still served.
tests/test_compact_wire.py:233
Checks
assert out["detail"].rstrip(".") == extra.rstrip(".")assert out["detail_in_body"] is True
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-014 | measured | test_a_detail_whose_words_merely_overlap_the_body_is_kept → compact_docs |
Source · 28 lines
def test_a_detail_whose_words_merely_overlap_the_body_is_kept() -> None:
"""1.4.0 GRID: `_staleness` lost its `@param` text ("answering The routed repository, or None
when the derived one answered") — text that is NOT in the body, admitted because 90% of the
detail's WORDS occurred somewhere in it. Overlap of a bag of words is not containment: a
sentence counts as carried only when it appears, in order, in the served body, and every
sentence that is not carried is still served.
@brief A detail sentence absent from the body is still served.
@return None.
@version 1
"""
from clew.query.payload import compact_docs
extra = "Answering the routed repository, or None when the derived one answered."
detail = f"{_DOC} {extra}"
body = [
"def fetch(id, answering):",
f' """{_DOC}"""',
" # the routed repository answering, or the derived one when None answered",
" return cache[id]",
]
payload = {"detail": detail, "body": {"lines": body}}
out = compact_docs(copy.deepcopy(payload))
## THE ABSENT SENTENCE REACHES THE AGENT; only what the body already shows is dropped. Measured
## on the 1.4.0 self index: most such sentences are `## @param` / `@return` text from the block
## above the `def`, which no body excerpt contains.
assert out["detail"].rstrip(".") == extra.rstrip(".")
assert out["detail_in_body"] is True1 more lines, not shown
Activity · 8 steps
test_a_docstring_already_in_the_body_is_served_once
None test_compact_wire.test_a_docstring_already_in_the_body_is_served_once()
compact_docs drops a detail the body repeats, and marks it.
tests/test_compact_wire.py:177
Checks
assert "detail" not in out and out["detail_in_body"] is Trueassert out["brief"] == payload["brief"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-014 | measured | test_a_docstring_already_in_the_body_is_served_once → compact_docs |
Source · 22 lines
def test_a_docstring_already_in_the_body_is_served_once() -> None:
"""1.3.9. A Python docstring sits INSIDE the body excerpt, and doxygen serves the same text
again as `detail` — measured at 14.7% of this repository's dossier bytes. In the compact shape
`detail` is dropped when the body already carries it, and `detail_in_body: true` says so, so
an absent `detail` is never read as "undocumented".
@brief compact_docs drops a detail the body repeats, and marks it.
@return None.
@version 1
"""
from clew.query.payload import compact_docs
payload = {
"brief": "Fetch the widget.",
"detail": _DOC,
"body": {"lines": ["def fetch(id):", f' """{_DOC}"""', " return cache[id]"]},
}
out = compact_docs(copy.deepcopy(payload))
assert "detail" not in out and out["detail_in_body"] is True
assert out["brief"] == payload["brief"]
Activity · 5 steps
test_a_payload_without_neighbours_is_untouched
None test_compact_wire.test_a_payload_without_neighbours_is_untouched()
No callers/callees: nothing added, nothing removed.
tests/test_compact_wire.py:126
Checks
assert compact_neighbours(copy.deepcopy(payload)) == payload
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-014 | measured | test_a_payload_without_neighbours_is_untouched → compact_neighbours |
| REQ-DDB-WIKI-054 | inferred | test_a_payload_without_neighbours_is_untouched → compact_neighbours → _edge_defaults → all |
Source · 9 lines
def test_a_payload_without_neighbours_is_untouched() -> None:
"""@brief No callers/callees: nothing added, nothing removed.
@return None.
@version 1
"""
payload = {"subject": "v", "sites": [{"file": "a.c", "line": 1}]}
assert compact_neighbours(copy.deepcopy(payload)) == payload
Activity · 2 steps
test_the_compact_shape_is_lossless
None test_compact_wire.test_the_compact_shape_is_lossless()
Expanding a compact reply reproduces the flat rows.
Checks
assert _canon(expanded[key]) == _canon(_FLAT[key])
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-014 | measured | test_the_compact_shape_is_lossless → compact_neighbours |
| REQ-DDB-WIKI-054 | inferred | test_the_compact_shape_is_lossless → compact_neighbours → _edge_defaults → all |
Source · 11 lines
def test_the_compact_shape_is_lossless() -> None:
"""@brief Expanding a compact reply reproduces the flat rows.
@return None.
@version 1
"""
compact = compact_neighbours(copy.deepcopy(_FLAT))
expanded = _expand(compact)
for key in ("callers", "callees"):
assert _canon(expanded[key]) == _canon(_FLAT[key])
Activity · 4 steps
test_the_server_serves_compact_only_when_asked
None test_compact_wire.test_the_server_serves_compact_only_when_asked(Path rich_db, Path repo_root, pytest.MonkeyPatch monkeypatch)
CLEW_WIRE=compact switches the dossier reply to the grouped shape.
tests/test_compact_wire.py:135
Checks
assert flat.get("callers") and "file" in flat["callers"][0]assert "rows" in compact["callers"][0] and "edge_defaults" in compactassert _canon(_expand(compact)["callers"]) == _canon(flat["callers"])
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | |
| REQ-DDB-MCP-003 | measured | |
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-PIPE-011 | 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 · 21 lines
def test_the_server_serves_compact_only_when_asked(
rich_db: Path, repo_root: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""THE DEFAULT IS UNCHANGED: without `CLEW_WIRE=compact` a dossier's rows are flat.
@brief CLEW_WIRE=compact switches the dossier reply to the grouped shape.
@return None.
@version 1
"""
from clew.mcp_server.tools_query import QueryTools
tools = QueryTools(lambda: rich_db, lambda: repo_root)
monkeypatch.delenv("CLEW_WIRE", raising=False)
flat = tools.dossier("sensor_poll")
assert flat.get("callers") and "file" in flat["callers"][0]
monkeypatch.setenv("CLEW_WIRE", "compact")
compact = tools.dossier("sensor_poll")
assert "rows" in compact["callers"][0] and "edge_defaults" in compact
assert _canon(_expand(compact)["callers"]) == _canon(flat["callers"])