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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-014measuredtest_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
lines 221–221from clew.query.payload import compact_docslines 223–229payload = { "detail": _DOC, "body": { "lines": ["def fetch(id):", f' """{_DOC}"""', " return cache[id]"], "truncated": True, }, }lines 230–230assert compact_docs(copy.deepcopy(payload)) == payload

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)) == elsewhere
  • assert compact_docs(copy.deepcopy(bodiless)) == bodiless

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-014measuredtest_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
lines 204–204from clew.query.payload import compact_docslines 206–206elsewhere = {"detail": _DOC, "body": {"lines": ["int fetch(int id) {", " return 0;", "}"]}}lines 207–207assert compact_docs(copy.deepcopy(elsewhere)) == elsewherelines 208–208bodiless = {"detail": _DOC}lines 209–209assert compact_docs(copy.deepcopy(bodiless)) == bodiless

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-014measuredtest_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 True

1 more lines, not shown

Activity · 8 steps
lines 244–244from clew.query.payload import compact_docslines 246–246extra = "Answering the routed repository, or None when the derived one answered."lines 247–247detail = f"{_DOC} {extra}"lines 248–253body = [ "def fetch(id, answering):", f' """{_DOC}"""', " # the routed repository answering, or the derived one when None answered", " return cache[id]", ]lines 254–254payload = {"detail": detail, "body": {"lines": body}}lines 255–255out = compact_docs(copy.deepcopy(payload))lines 259–259assert out["detail"].rstrip(".") == extra.rstrip(".")lines 260–260assert out["detail_in_body"] is True

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 True
  • assert out["brief"] == payload["brief"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-014measuredtest_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
lines 187–187from clew.query.payload import compact_docslines 189–193payload = { "brief": "Fetch the widget.", "detail": _DOC, "body": {"lines": ["def fetch(id):", f' """{_DOC}"""', " return cache[id]"]}, }lines 194–194out = compact_docs(copy.deepcopy(payload))lines 195–195assert "detail" not in out and out["detail_in_body"] is Truelines 196–196assert out["brief"] == payload["brief"]

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

requirementlinkedpath to the implementer
REQ-DDB-QUERY-014measuredtest_a_payload_without_neighbours_is_untouched → compact_neighbours
REQ-DDB-WIKI-054inferredtest_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
lines 131–131payload = {"subject": "v", "sites": [{"file": "a.c", "line": 1}]}lines 132–132assert compact_neighbours(copy.deepcopy(payload)) == payload

test_rows_are_grouped_by_file_and_shared_values_stated_once

None test_compact_wire.test_rows_are_grouped_by_file_and_shared_values_stated_once()

Groups by file in first-seen order; the modal values move to edge_defaults.

tests/test_compact_wire.py:109

Checks

  • assert [g["file"] for g in compact["callers"]] == ["x.ts", "y.ts"]
  • assert compact["edge_defaults"] == {
  • assert first == {"name": "a"}, first
  • assert {"name": "c", "source": "doxygen_sqlite"} in compact["callers"][0]["rows"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-014measuredtest_rows_are_grouped_by_file_and_shared_values_stated_once → compact_neighbours
REQ-DDB-WIKI-054inferredtest_rows_are_grouped_by_file_and_shared_values_stated_once → compact_neighbours → _edge_defaults → all
Source · 17 lines
def test_rows_are_grouped_by_file_and_shared_values_stated_once() -> None:
    """@brief Groups by file in first-seen order; the modal values move to edge_defaults.
    @return None.
    @version 1
    """
    compact = compact_neighbours(copy.deepcopy(_FLAT))
    assert [g["file"] for g in compact["callers"]] == ["x.ts", "y.ts"]
    assert compact["edge_defaults"] == {
        "source": "ast",
        "confidence": "resolved",
        "edge_class": "call",
    }
    first = compact["callers"][0]["rows"][0]
    assert first == {"name": "a"}, first
    assert {"name": "c", "source": "doxygen_sqlite"} in compact["callers"][0]["rows"]

Activity · 6 steps
lines 114–114compact = compact_neighbours(copy.deepcopy(_FLAT))lines 115–115assert [g["file"] for g in compact["callers"]] == ["x.ts", "y.ts"]lines 116–120assert compact["edge_defaults"] == { "source": "ast", "confidence": "resolved", "edge_class": "call", }lines 121–121first = compact["callers"][0]["rows"][0]lines 122–122assert first == {"name": "a"}, firstlines 123–123assert {"name": "c", "source": "doxygen_sqlite"} in compact["callers"][0]["rows"]

test_the_compact_shape_is_lossless

None test_compact_wire.test_the_compact_shape_is_lossless()

Expanding a compact reply reproduces the flat rows.

tests/test_compact_wire.py:98

Show on the map →

Called by none

Calls _canon, _expand, compact_neighbours

Checks

  • assert _canon(expanded[key]) == _canon(_FLAT[key])

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-014measuredtest_the_compact_shape_is_lossless → compact_neighbours
REQ-DDB-WIKI-054inferredtest_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
lines 103–103compact = compact_neighbours(copy.deepcopy(_FLAT))lines 104–104expanded = _expand(compact)lines 105–105◇ for key in ("callers", "callees")lines 106–106assert _canon(expanded[key]) == _canon(_FLAT[key])

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

Show on the map →

Called by none

Calls _canon, _expand

Checks

  • assert flat.get("callers") and "file" in flat["callers"][0]
  • assert "rows" in compact["callers"][0] and "edge_defaults" in compact
  • assert _canon(_expand(compact)["callers"]) == _canon(flat["callers"])

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measured
REQ-DDB-MCP-003measured
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-011measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-002measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-009measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-014measured
REQ-DDB-SCHEMA-011measured
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"])

Activity · 9 steps
lines 144–144from clew.mcp_server.tools_query import QueryToolslines 146–146tools = QueryTools(lambda: rich_db, lambda: repo_root)lines 147–147monkeypatch.delenv("CLEW_WIRE", raising=False)lines 148–148flat = tools.dossier("sensor_poll")lines 149–149assert flat.get("callers") and "file" in flat["callers"][0]lines 150–150monkeypatch.setenv("CLEW_WIRE", "compact")lines 151–151compact = tools.dossier("sensor_poll")lines 152–152assert "rows" in compact["callers"][0] and "edge_defaults" in compactlines 153–153assert _canon(_expand(compact)["callers"]) == _canon(flat["callers"])