test_wire.py

tests/test_wire.py

Tests for the shared R2→JSON serializer.

test_envelope_keys_all_survive

None test_wire.test_envelope_keys_all_survive()

The envelope keeps every key, even the empty ones.

tests/test_wire.py:89

Show on the map →

Called by none

Calls one

Checks

  • assert out is not None
  • assert set(out) == {"subject", "brief", "threads", "callers"}
  • assert out["brief"] is None
  • assert out["threads"] == []
  • assert out["callers"] == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_envelope_keys_all_survive → one
Source · 12 lines
def test_envelope_keys_all_survive() -> None:
    """A consumer reads the envelope key by key, so `threads: []` must be PRESENT to
    be read as "none". This is the distinction that broke when elision was applied
    universally, and the viewer/MCP field-parity test caught it."""
    out = wire.one(_Envelope())
    assert out is not None
    assert set(out) == {"subject", "brief", "threads", "callers"}
    assert out["brief"] is None
    assert out["threads"] == []
    assert out["callers"] == []

Activity · 6 steps
lines 93–93out = wire.one(_Envelope())lines 94–94assert out is not Nonelines 95–95assert set(out) == {"subject", "brief", "threads", "callers"}lines 96–96assert out["brief"] is Nonelines 97–97assert out["threads"] == []lines 98–98assert out["callers"] == []

test_false_and_zero_are_measurements_not_absences

None test_wire.test_false_and_zero_are_measurements_not_absences()

A false or zero value is kept, not treated as absent.

tests/test_wire.py:114

Show on the map →

Called by none

Calls one

Checks

  • assert out is not None
  • assert row["crosses_thread"] is False
  • assert row["line_start"] == 0
  • assert "strength" not in row

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_false_and_zero_are_measurements_not_absences → one
Source · 12 lines
def test_false_and_zero_are_measurements_not_absences() -> None:
    """`crosses_thread: false` says "this edge stays on one thread", which is a
    different claim from the field being missing ("nobody looked"). Eliding falsy
    values instead of absent ones would silently turn the former into the latter."""
    out = wire.one(_Envelope(callers=[_Row(crosses_thread=False, line_start=0)]))
    assert out is not None
    row = out["callers"][0]
    assert row["crosses_thread"] is False
    assert row["line_start"] == 0
    assert "strength" not in row

Activity · 6 steps
lines 118–118out = wire.one(_Envelope(callers=[_Row(crosses_thread=False, line_start=0)]))lines 119–119assert out is not Nonelines 120–120row = out["callers"][0]lines 121–121assert row["crosses_thread"] is Falselines 122–122assert row["line_start"] == 0lines 123–123assert "strength" not in row

test_internal_row_ids_are_stripped_from_envelope_and_rows

None test_wire.test_internal_row_ids_are_stripped_from_envelope_and_rows()

Internal database row ids must never reach a served payload.

tests/test_wire.py:208

Show on the map →

Called by none

Calls one

Checks

  • assert out is not None
  • assert "rowid" not in out, "an internal row id must not be served on the envelope"
  • assert "rowid" not in out["callers"][0], "nor inside a neighbour row"
  • assert out["subject"] == "thing", "stripping must not remove real envelope fields"
  • assert out["callers"][0]["name"] == "callee", "nor real row fields"
  • assert out["callers"][0]["line_start"] == 7, "a genuine int field must survive"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_internal_row_ids_are_stripped_from_envelope_and_rows → one
Source · 48 lines
def test_internal_row_ids_are_stripped_from_envelope_and_rows() -> None:
    """A GRADED ANSWER PUBLISHED ONE AS A SOURCE LOCATION. An index-arm run wrote
    `programs/ssl/ssl_pthread_server.c:2244` as a citation; the file is 484 lines and 2244 was a
    `rowid`. The answer even hedged "per index rowid", so the model half-knew and wrote it anyway —
    which makes this a payload-shape defect rather than a model slip.

    THE SHAPE IS WHY. `rowid` sat beside `line_start` and `line_end`, which ARE locations, and
    repeated inside every `callers`/`callees` row — 15 occurrences in one measured reply, each an
    integer next to a symbol name with no line number of its own. That is precisely the slot a
    reader fills with "line". Nothing on the tool surface accepts a rowid as input, so it bought
    nothing in exchange.

    BOTH LEVELS, which is what distinguishes this from elision. Elision is row-scoped because an
    envelope key must be present to read as "none"; a `rowid` misleads equally in either place.

    @brief `rowid` is absent from both the envelope and its rows.
    @return None.
    @version 1
    """

    ## THE FIXTURE MUST ACTUALLY CARRY A rowid, and the first version of this test did not — the
    ## shared `_Row` had been renamed to `line_start`, so `"rowid" not in row` was trivially true
    ## and emptying `_INTERNAL_ONLY` left the test GREEN. The mutation control caught it. A fixture
    ## that matches the detector rather than the world is this repo's standing failure.
    @dataclass(frozen=True)
    class _IdBearing:
        """@brief A row and envelope that really do carry an internal id. @version 1"""

        rowid: int = 99
        name: str = "callee"
        line_start: int = 7

    @dataclass(frozen=True)
    class _IdEnvelope:
        """@brief Envelope carrying an id of its own plus id-bearing rows. @version 1"""

        rowid: int = 42
        subject: str = "thing"
        callers: tuple[_IdBearing, ...] = (_IdBearing(),)

    out = wire.one(_IdEnvelope())
    assert out is not None
    assert "rowid" not in out, "an internal row id must not be served on the envelope"
    assert "rowid" not in out["callers"][0], "nor inside a neighbour row"
    ## A strip that emptied everything would satisfy both assertions above.
    assert out["subject"] == "thing", "stripping must not remove real envelope fields"
    assert out["callers"][0]["name"] == "callee", "nor real row fields"
    assert out["callers"][0]["line_start"] == 7, "a genuine int field must survive"

1 more lines, not shown

Activity · 9 steps
lines 233–238class _IdBearing: """@brief A row and envelope that really do carry an internal id. @version 1""" rowid: int = 99 name: str = "callee" line_start: int = 7lines 241–246class _IdEnvelope: """@brief Envelope carrying an id of its own plus id-bearing rows. @version 1""" rowid: int = 42 subject: str = "thing" callers: tuple[_IdBearing, ...] = (_IdBearing(),)lines 248–248out = wire.one(_IdEnvelope())lines 249–249assert out is not Nonelines 250–250assert "rowid" not in out, "an internal row id must not be served on the envelope"lines 251–251assert "rowid" not in out["callers"][0], "nor inside a neighbour row"lines 253–253assert out["subject"] == "thing", "stripping must not remove real envelope fields"lines 254–254assert out["callers"][0]["name"] == "callee", "nor real row fields"lines 255–255assert out["callers"][0]["line_start"] == 7, "a genuine int field must survive"

test_none_serializes_to_none

None test_wire.test_none_serializes_to_none()

None in, None out.

tests/test_wire.py:199

Show on the map →

Called by none

Calls one

Checks

  • assert wire.one(None) is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_none_serializes_to_none → one
Source · 6 lines
def test_none_serializes_to_none() -> None:
    """Every MCP wrapper over an optional R2 result depends on this: a missing symbol
    is a null payload, not an exception and not an empty dict."""
    assert wire.one(None) is None

Activity · 1 steps
lines 202–202assert wire.one(None) is None

test_rows_helper_treats_its_items_as_rows

None test_wire.test_rows_helper_treats_its_items_as_rows()

rows prunes each element; one per element would not.

tests/test_wire.py:182

Show on the map →

Called by none

Calls one, rows

Checks

  • assert wire.rows([_Row()]) == [{"name": "callee", "line_start": 7}]
  • assert wire.one(_Row()) == {

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_rows_helper_treats_its_items_as_rows → rows
Source · 14 lines
def test_rows_helper_treats_its_items_as_rows() -> None:
    """The two entry points differ ONLY in whether the top level is a row, and calling
    the wrong one is a real mistake that the MCP parity test caught: `one` per element
    treats each as an envelope and prunes nothing."""
    assert wire.rows([_Row()]) == [{"name": "callee", "line_start": 7}]
    assert wire.one(_Row()) == {
        "name": "callee",
        "line_start": 7,
        "strength": None,
        "crosses_thread": None,
        "implementors": [],
    }

Activity · 2 steps
lines 186–186assert wire.rows([_Row()]) == [{"name": "callee", "line_start": 7}]lines 187–193assert wire.one(_Row()) == { "name": "callee", "line_start": 7, "strength": None, "crosses_thread": None, "implementors": [], }

test_rows_inside_an_envelope_are_pruned

None test_wire.test_rows_inside_an_envelope_are_pruned()

A row inside a list drops the fields carrying nothing.

tests/test_wire.py:104

Show on the map →

Called by none

Calls one

Checks

  • assert out is not None
  • assert out["callers"] == [{"name": "callee", "line_start": 7}]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_rows_inside_an_envelope_are_pruned → one
Source · 7 lines
def test_rows_inside_an_envelope_are_pruned() -> None:
    """The measured saving: 54% of a real call row's fields were null by kind."""
    out = wire.one(_Envelope(callers=[_Row()]))
    assert out is not None
    assert out["callers"] == [{"name": "callee", "line_start": 7}]

Activity · 3 steps
lines 106–106out = wire.one(_Envelope(callers=[_Row()]))lines 107–107assert out is not Nonelines 108–108assert out["callers"] == [{"name": "callee", "line_start": 7}]

test_tuples_become_lists

None test_wire.test_tuples_become_lists()

A tuple field becomes a JSON array so the round trip holds.

tests/test_wire.py:170

Show on the map →

Called by none

Calls one

Checks

  • assert out is not None
  • assert out["callers"][0]["implementors"] == ["Derived::run", "Other::run"]
  • assert json.loads(json.dumps(out)) == out

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_tuples_become_lists → one
Source · 9 lines
def test_tuples_become_lists() -> None:
    """R2's dataclasses are frozen, so a multi-valued field is a tuple; `json.loads`
    returns a list, so a tuple on the wire fails equality with its own round trip."""
    out = wire.one(_Envelope(callers=[_Row(implementors=("Derived::run", "Other::run"))]))
    assert out is not None
    assert out["callers"][0]["implementors"] == ["Derived::run", "Other::run"]
    assert json.loads(json.dumps(out)) == out

Activity · 4 steps
lines 173–173out = wire.one(_Envelope(callers=[_Row(implementors=("Derived::run", "Other::run"))]))lines 174–174assert out is not Nonelines 175–175assert out["callers"][0]["implementors"] == ["Derived::run", "Other::run"]lines 176–176assert json.loads(json.dumps(out)) == out

test_unknown_enums_are_elided_but_only_the_named_ones

None test_wire.test_unknown_enums_are_elided_but_only_the_named_ones()

An undetermined enum is absent, and a determined one is present.

tests/test_wire.py:129

Show on the map →

Called by none

Calls one, rows

Checks

  • assert out is not None # envelope path still intact
  • assert "dispatch_mode" not in pruned, "an undetermined dispatch_mode must not ship"
  • assert "edge_kind" not in pruned, "an undetermined edge_kind must not ship"
  • assert pruned["lock_kind"] == "unknown", ("lock_kind='unknown' is a measurement — a lock of undetermined type is not no lock" )
  • assert pruned["crosses_thread"] is False, "a measured non-crossing must still ship"
  • assert determined["dispatch_mode"] == "keyed"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-001measuredtest_unknown_enums_are_elided_but_only_the_named_ones → rows
Source · 38 lines
def test_unknown_enums_are_elided_but_only_the_named_ones() -> None:
    """A REGRESSION TEST for an inversion this module itself introduced.

    `dispatch_mode` and `edge_kind` are `TEXT NOT NULL DEFAULT 'unknown'`, so unlike a
    nullable column they cannot BE null — the pipeline records "undetermined" as a
    literal string. Row elision therefore kept those two while dropping
    `crosses_thread = NULL`, which is informative when known. The result was exactly
    backwards: the two fields that say nothing were presented as measurements, and the
    one that would matter was presented as not-applicable, which the shared `rows`
    description tells a model to read as "the question does not apply".

    `lock_kind` is the control. It also has an `'unknown'` member and there it IS
    informative — "a lock whose type was not determined" is a different claim from "no
    lock" — so the rule is keyed on FIELD NAME, and matching the string alone would
    erase that."""
    row = {
        "name": "publish",
        "dispatch_mode": "unknown",
        "edge_kind": "unknown",
        "lock_kind": "unknown",
        "crosses_thread": False,
    }
    out = wire.one(_Envelope(callers=[]))
    assert out is not None  # envelope path still intact

    pruned = wire.rows([_KeyRow(**row)])[0]
    assert "dispatch_mode" not in pruned, "an undetermined dispatch_mode must not ship"
    assert "edge_kind" not in pruned, "an undetermined edge_kind must not ship"
    assert pruned["lock_kind"] == "unknown", (
        "lock_kind='unknown' is a measurement — a lock of undetermined type is not no lock"
    )
    assert pruned["crosses_thread"] is False, "a measured non-crossing must still ship"

    ## And a DETERMINED value of the same field must survive.
    determined = wire.rows([_KeyRow(**{**row, "dispatch_mode": "keyed"})])[0]
    assert determined["dispatch_mode"] == "keyed"

Activity · 10 steps
lines 144–150row = { "name": "publish", "dispatch_mode": "unknown", "edge_kind": "unknown", "lock_kind": "unknown", "crosses_thread": False, }lines 151–151out = wire.one(_Envelope(callers=[]))lines 152–152assert out is not Nonelines 154–154pruned = wire.rows([_KeyRow(**row)])[0]lines 155–155assert "dispatch_mode" not in pruned, "an undetermined dispatch_mode must not ship"lines 156–156assert "edge_kind" not in pruned, "an undetermined edge_kind must not ship"lines 157–159assert pruned["lock_kind"] == "unknown", ( "lock_kind='unknown' is a measurement — a lock of undetermined type is not no lock" )lines 160–160assert pruned["crosses_thread"] is False, "a measured non-crossing must still ship"lines 163–163determined = wire.rows([_KeyRow(**{**row, "dispatch_mode": "keyed"})])[0]lines 164–164assert determined["dispatch_mode"] == "keyed"