refactor(testing): replace dict[str, Any] result bags with typed models - #910
Merged
tcoratger merged 1 commit intoJun 10, 2026
Merged
Conversation
Two spots returned untyped dict[str, Any] bags with magic string keys while every other fixture uses a typed model. The API endpoint handlers returned a dict keyed by expected_status_code, expected_content_type, and expected_body, read back positionally in the generator. Introduce EndpointResponseContract so the handler signature is typed and a handler that forgets a field is caught at construction. This is internal plumbing, so the emitted fixture fields are unchanged. The justifiability fixture stored its result as a hand-written camelCase dict. Introduce JustifiabilityOutput so the camelCase keys come from the model and the delta and verdict are validated. Both changes are byte-identical on every emitted vector: the endpoint contract feeds the same fixture fields, and the output model serializes isJustifiable through the camelCase alias exactly as before. 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.
Motivation
Two spots returned untyped
dict[str, Any]bags with magic string keys, while every other fixture in the package uses a typed model:dict[str, Any]keyed by"expected_status_code","expected_content_type","expected_body", read back positionally in the generator. A handler that forgot a key would only fail at the read site.{"delta": ..., "isJustifiable": ...}).What this does
EndpointResponseContract(status_code, content_type, body)— the endpoint handler signature is now typed, and a handler that omits a field is caught at construction. This is internal plumbing (the contract feeds the same threeApiEndpointFixturefields), so emitted fixtures are unchanged.JustifiabilityOutput(delta, is_justifiable)— the camelCaseisJustifiablekey now comes from the model alias, and the values are validated. Thebody/response payloads keep their own API-defined snake_case keys untouched.Byte-equivalence
Both suites were filled before and after and diffed:
The endpoint contract feeds the same fixture fields, and
JustifiabilityOutputserializesis_justifiablethrough the camelCase alias exactly as the hand-written dict did.Testing
just checkpasses (lint, format, ty, codespell, mdformat).tests/consensus/lstar/api+tests/consensus/lstar/state_transition(114 fixtures) is byte-identical to the pre-change output.🤖 Generated with Claude Code