feat(tii): type-directed argument encoding to the TaggedArg wire form#20
Merged
Conversation
Mirror the Rust reference: marshal every arg through one recursive walk over (ParamType, value) in `tii/encode.py`, wired into `into_resolve_request`. A scalar leaf renders bare at the top level (the resolver coerces it via the flat type) and tagged when nested in an aggregate; aggregates (list/tuple/map/record/variant) render to the self-describing tagged form. No separate scalar/aggregate path. Records map the user's by-name dict to positional struct fields in declared (`required`-array) order; variants resolve the case index from the `oneOf` ordering; map keys are `string` leaves, pairs sorted. Ill- shaped values are rejected before sending. The record ParamType stays a `dict[str, ParamType]` but is now built in `required` order so iteration is positional; the public type is unchanged. Tests drive the shared cross-SDK oracle (accept + reject vectors). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Parity with the Rust SDK: encodes an argument of an aggregate type (record,
List,Map,Tuple, variant) into the TRPTaggedArgwire form. Newtii/encode.py, wired intointo_resolve_request.One walk, not two paths
encode(param, value)is a single recursive walk over(type, value)— scalars are the leaf cases. A scalar leaf renders bare at the top level (resolver coerces via the flat TIR type) and tagged when nested; aggregates always render to their tagged structural form. Bare top-level scalars keep their pre-existing wire shape.Encoding rules
structfields in declared order, from the schema'srequiredarray (tx3cemits source order;propertiesis alphabetized).constructor= theoneOfcase index.[key, value]pairs; keys arestringleaves (the.tiierases the key type), pairs sorted.Note (not breaking)
The record
ParamTypestays adict[str, ParamType]— now built inrequiredorder so iteration is positional. The public type is unchanged, so existing consumers are unaffected. The encoder is wired into the synced SDK release.Tests
Vector-driven over the shared cross-SDK oracle (
tests/fixtures/wire-vectors.json, mirrored fromsdk-spec): accept vectors encode equal, reject vectors raise; plus theMetafield-order regression, top-level-bare vs nested-tagged, and an end-to-endinto_resolve_requestcheck.pytest -m "not e2e"green (86);ruffclean.🤖 Generated with Claude Code