Skip to content

Rpcv2 json codegen - #915

Merged
kingaly111 merged 3 commits into
developfrom
rpcv2-json-codegen
Nov 12, 2026
Merged

kingaly111 merged 3 commits into
developfrom
rpcv2-json-codegen

Conversation

@kingaly111

@kingaly111 kingaly111 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Add rpcv2Json codegen, protocol tests and duplex integration test

Summary

Generated clients can now target services that use smithy.protocols#rpcv2Json. The runtime protocol landed in #902; this PR adds the codegen that selects it, runs Smithy's rpcv2Json protocol test suite against a generated client, and adds an end-to-end event-streaming test over real HTTP/2.

Codegen

  • Rpcv2JsonProtocolGenerator and Rpcv2JsonIntegration: copies of the rpcv2Cbor versions.
    • The generator applies to services with @rpcv2Json.
    • It reads http and eventStreamHttp from the trait.
    • Generated clients default to AsyncRpcV2JsonClientProtocol and depend on smithy-http[json].
    • The sync client gets RpcV2JsonClientProtocol automatically through the existing async-to-sync mapping, so no extra runtime type was needed.
  • Registration: the integration is listed in META-INF/services/...PythonIntegration, and RuntimeTypes.RPC_V2_JSON_CLIENT_PROTOCOL is added.
  • SchemaTraitFilterIndex: the comments on the kept originalShapeId trait now say it's used for unit detection by both rpcv2 protocols. No behavior change.
  • bigDecimal test values: ValueNodeVisitor wrote bigDecimal values in generated tests as Python float literals, which lose precision past about 17 digits and are the wrong type. It now writes Decimal("...") using the exact text from the model. This fixed 8 rpcv2Json arbitrary-precision tests and changed no other snapshot.

Protocol tests

  • New projection: rpcv2-json in codegen/protocol-test/smithy-build.json, for smithy.protocoltests.rpcv2Json#RpcV2JsonProtocol from smithy-protocol-tests 1.74.1.
  • Snapshot: the generated client is committed as codegen-output/rpcv2-json.
  • Results: 70 passed, 4 xfailed. The 4 xfails are the explicit-default tests, which rpcv2Cbor and RestJson already skip. Generated models can't tell a member left unset from one set to its default value.

Duplex event-stream integration test (Simon Says)

  • New model: my-handwritten-json-model.smithy is an @rpcv2Json copy of the hand-written event-stream service. Its projection generates AsyncMyHandwrittenJsonModel. The shapes are local copies, so the CBOR service and its snapshot are untouched.
  • Shared game: the Simon Says game moved into tests/integration/_simon_says.py. Each protocol's test file supplies its client, models, codec, event content type and Smithy-Protocol value.
    • test_rpcv2cbor_event_stream.py keeps its test id and behavior.
    • test_rpcv2json_event_stream.py plays the same game using the client's own JSON codec.
    • It also checks that the client's codec has the rpcv2Json settings.
  • Stronger checks, for both protocols: the server must receive initial-request followed by exactly one move or pass per turn, in order, and every frame must carry the protocol's content type.
  • HTTP/2 test server:
    • H2BidiServer now takes the event content type and the Smithy-Protocol value, defaulting to rpcv2Cbor.
    • It records each frame's content type.
    • It keeps the connection open until the client ends its stream. Before, it closed as soon as the game ended, so the client's final close raised AWS_ERROR_HTTP_STREAM_HAS_COMPLETED. That's gone for both protocols.

Testing

  • make generate-protocol-tests: only the new rpcv2-json and my-handwritten-json-model directories differ; every existing snapshot is byte-identical. Generation was repeated and produced the same output.
  • make test-protocols: all projections pass, including rpcv2-json (70 passed, 4 xfailed) and rpcv2-cbor (69 passed, 4 xfailed).
  • make typecheck-protocols: 0 errors in every projection.
  • make test-functional: both test_simon_says_duplex tests and test_client_uses_rpcv2json_codec run (none skipped) and pass.
  • make static-analysis, uv run pyright packages and make check-java: pass.

Notes

  • No runtime package changed, so there are no changelog fragments. Codegen-only PRs in this repo don't add them.
  • Regenerating snapshots needs pandoc 3.8.2, the version CI pins.

@kingaly111
kingaly111 marked this pull request as ready for review November 10, 2026 20:30
@kingaly111
kingaly111 requested a review from a team as a code owner November 10, 2026 20:30
kuhe
kuhe previously approved these changes Nov 11, 2026
Add Rpcv2JsonProtocolGenerator and Rpcv2JsonIntegration, mirroring the
rpcv2Cbor versions. Generated clients use AsyncRpcV2JsonClientProtocol
and depend on smithy-http[json].

Add an rpcv2-json projection for
smithy.protocoltests.rpcv2Json#RpcV2JsonProtocol and commit the
generated codegen-output/rpcv2-json snapshot. The four explicit-default
vectors are marked xfail, matching rpcv2Cbor and RestJson.

Fix HttpProtocolTestGenerator writing bigDecimal params as float
literals, which lost precision and produced the wrong type; they are
now written as Decimal("...") from the exact model text.
Add an rpcv2Json counterpart of the handwritten event-stream model and a
my-handwritten-json-model projection, and play the Simon Says duplex
game against the generated rpcv2Json client as well as rpcv2Cbor.

The game moves into a shared _simon_says helper parametrized by client,
models, codec, event content type and Smithy-Protocol value. The HTTP/2
test server takes the content type and Smithy-Protocol value (defaulting
to rpcv2Cbor), records each frame's content type, and keeps the
connection open until the client ends its stream, which removes a
spurious "HTTP-stream has completed" error on close.
Develop raised the generated pytest requirement to >=9.0.3; regenerate
the rpcv2-json and my-handwritten-json-model snapshots to match.
@kingaly111
kingaly111 merged commit cfb06ee into develop Nov 12, 2026
26 checks passed
@kuhe
kuhe deleted the rpcv2-json-codegen branch November 12, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants