8000 Tests: serialization round trips for the wire types · Issue #48 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

Tests: serialization round trips for the wire types #48

Closed

Description

@Lillecarl

Scope

Encode and decode every message in common.proto that carries a Nix concept.
Include the recursive DerivationOutputs tree.

rpc/_status_details.py trims a deep trace to a byte budget and marks what it
dropped. That trimming deserves a test with a trace of 1000 frames.

Section 5, item 3.3 of CODE_IMPROVEMENT_PLAN.md.

Activity

  1. Lillecarl commented on Aug 2, 2026

    @Lillecarl
    ContributorAuthor

    Done. The 1000-frame trace found a quadratic trimmer.

    The trimmer was quadratic, and the test the issue asked for is what showed it

    _trim_to_budget dropped the deepest trace frame one at a time and
    re-encoded the whole google.rpc.Status after each drop. With 1000 frames and
    only a few dozen fitting, that is ~950 full re-encodes of a large message.

    trace frames before after
    200 0.44s 0.02s
    1000 8.29s 0.08s

    A trace of 1000 frames is what an infinite recursion produces, so this is the
    realistic worst case rather than an invented one -- and it is the error most
    likely to be slow to report.

    The fix is a binary search over one cap. The old loop's result is always
    min(len(traces), cap) for a single shared cap, because each pass removes
    one frame from whichever payload is currently longest. So the answer is
    identical and the cost goes from O(n) re-encodes to O(log n). The existing
    tests -- head kept, tail dropped, truncated set, identity survives -- all
    pass unchanged, which is the evidence that the semantics did not move.

    The new test also pins that the cap is maximal, not merely sufficient: one
    more frame must not fit. Verified red-before-green by making the search stop a
    frame early.

    Round trips

    tests/nanopynix/rpc/test_wire_round_trips.py, 27 tests, every one through
    real bytes (bytes(msg) then Msg().parse(...)). An object-to-object
    comparison would pass while a field never reached the wire.

    Six messages had no mention anywhere in the suite: BuildResultList,
    CallArg, CallArgAttrs, CallArgList, RemoteCallArg, ErrorTrace. The
    CallArg tree is the argument encoding for a Nix function call and had no test
    of any kind, so it is now decoded by _worker_eval.py's own
    _call_arg_to_python rather than by a copy of it.

    The falsy scalars are the point of half the file. "", 0, False, 0.0 are
    all falsy, and every converter here asks if field is not None. A converter
    rewritten with if field: would turn each of them into None, and only after
    a serialize-and-parse cycle, because that is when proto3 presence is decided.
    Measured: all survive, with their types -- True does not come back as 1.

    The recursive DerivationOutputs tree is covered three levels deep.

    One thing found and deliberately not fixed

    A deeply nested DeepValue raises a bare RecursionError. Max depth per
    stage, one {"k": [...]} per level:

    stage under pytest plain
    python_to_deep_value 239 over 400
    bytes(...) 79 82
    DeepValue().parse(...) 63 65

    Two columns because the first measurement was wrong: beartype instruments
    nanopynix's callables under the suite and not under a plain interpreter, so it
    costs the encoder about 40% of its depth and the betterproto stages three
    levels. The conclusion holds either way and the gap makes it sharper --
    betterproto2's serializer and parser are the limit, by a factor of three,
    not nanopynix's converter.

    Pinned rather than corrected. Deciding what a caller should see instead of a
    third-party RecursionError is hostile-input work, so it belongs to #49.

  2. added
    source: nanopynix
    on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source: nanopynix

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0