Skip to content

refactor(testing): fold api endpoint response logic into the test spec - #1155

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor-api-endpoint-fixture
Jun 18, 2026
Merged

refactor(testing): fold api endpoint response logic into the test spec#1155
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor-api-endpoint-fixture

Conversation

@tcoratger

Copy link
Copy Markdown
Collaborator

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 a dict[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:

  • All seven free functions and the _ENDPOINT_HANDLERS table are gone.
  • ApiEndpointTest._expected_response dispatches by structural pattern matching on (method, endpoint); each endpoint's contract is inline and visible in one place.
  • The single-use store builder is inlined into generate().

Incidental cleanups

  • Hoist the metrics-registry import to module top (no circular dependency justified the local import).
  • Lift the required metric names to a module-level constant that documents the cross-client surface.
  • Drop the unreachable validator_count else 0 guard; the head always has a stored state, so a missing one now fails loud instead of silently emitting 0.

Verification

Pure structural refactor — no change to emitted vectors. Filled tests/consensus/lstar/api before and after the change and confirmed the generated JSON is byte-identical (diff -rq), with the determinism check passing both ways. just check passes (ruff lint + format, ty, codespell, mdformat).

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>
@tcoratger
tcoratger merged commit f4b15b5 into leanEthereum:main Jun 18, 2026
14 checks passed
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.

1 participant