refactor(testing): fold api endpoint response logic into the test spec - #1155
Merged
tcoratger merged 1 commit intoJun 18, 2026
Merged
Conversation
Replace the module-level response builders and the (method, path) dispatch dict with one cohesive object. Every endpoint's expected response now lives in a single match-based method on the test spec, and the response builders that only ever needed the spec's own fields are no longer free functions. - Delete the seven _*_response free functions and the _ENDPOINT_HANDLERS table. - Dispatch by structural pattern matching in ApiEndpointTest._expected_response. - Inline the single-use store builder into generate(). - Hoist the metrics-registry import to module top (no circular dependency). - Lift the required metric names to a module constant documenting the cross-client surface. - Drop the unreachable validator_count guard so a missing head state fails loud instead of silently emitting zero. Pure structural refactor: emitted vectors are byte-identical (verified by filling tests/consensus/lstar/api before and after). 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.
Summary
Restructures the API endpoint conformance fixture so all response logic lives on one object instead of a pile of module-level functions wired together by a dispatch dict.
Previously the file held seven
_*_response(store, fixture)free functions plus adict[tuple[str, str], EndpointHandler]table. Those builders only ever read the test spec's own fields, so they were never really standalone — they belong on the spec. The new shape:_ENDPOINT_HANDLERStable are gone.ApiEndpointTest._expected_responsedispatches by structural pattern matching on(method, endpoint); each endpoint's contract is inline and visible in one place.generate().Incidental cleanups
validator_countelse 0guard; the head always has a stored state, so a missing one now fails loud instead of silently emitting0.Verification
Pure structural refactor — no change to emitted vectors. Filled
tests/consensus/lstar/apibefore and after the change and confirmed the generated JSON is byte-identical (diff -rq), with the determinism check passing both ways.just checkpasses (ruff lint + format, ty, codespell, mdformat).