Skip to content

refactor(api): share route and schema derivation (#859) - #1059

Merged
athvin merged 2 commits into
mainfrom
issue/859-api-spec
Nov 9, 2026
Merged

athvin merged 2 commits into
mainfrom
issue/859-api-spec

Conversation

@athvin

@athvin athvin commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Closes #859

Claimed by Codex at 2026-11-09T20:06:09.157197+00:00, session 01a1be1b-0c92-7703-a4c2-25cb2c999baa on Mac-46.lan.
The open draft PR holds this claim; closing it releases the ticket.

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

Extract the existing route, request-body and response-envelope derivation into the pure er-api-spec library. The three contract gates consume that shared machinery.

Why

#859 removes three copies of the router scan and makes the already-gated derivation reusable by the next OpenAPI ticket, without changing the derived contract.

Proof

Six pure-library fixtures, strict crate Clippy and all nine real-source contract assertions pass. Both artifact-fidelity assertions were observed failing under deliberate byte drift, then passing after restoration. Both regeneration tests ran and their outputs match the baseline SHA-256 hashes byte-for-byte. Full make check passed locally. The original implementation commit passed every CI workflow; after rebasing onto the independent production IAM change at 3e95a13d, the Rust tree and reviewed patch are byte-identical to the tested version. Six independent house reviews (library/adapters, each covering instrumentation, execution placement and reuse) found no candidates. All 15 live required contexts and all four detect jobs passed on 25f98c4f; the final preflight verified its base still matched main before squash merge.

Risk & rollback

The risk is changing parser behavior while moving it. Preserve existing comments, thresholds and fixture coverage; compare the artifacts byte-for-byte. Revert the refactor to restore the old test-local helpers.

Post-merge ledger

Closed by: Codex · session Codex:01a1be1b-0c92-7703-a4c2-25cb2c999baa on Mac-46 · 2026-11-09T21:08:13Z

Specific to this change

Context — plan, discoveries, measurements, files

Plan

  1. Capture the current artifact bytes and audit the three parser implementations. Extract one balanced route-registration walk while retaining the existing method/handler interpretation at its consumers.
  2. Add er-api-spec with pure source-string inputs for route/docs/body/envelope derivation. Move the parser rationale and classifier fixtures with the functions; add focused route and injected-source cases for the shared seam.
  3. Replace the three test-local derivations with library calls. Preserve every parser floor and the committed-artifact comparisons; keep the mock-specific JavaScript adapter and actual server path normalizer in the mock contract gate.
  4. Add the local dependency through cargo add, update the API-contract reference and regenerate the crate inventory. Prove the two committed JSON artifacts are unchanged; observe a deliberate bad derivation fail the fidelity gate before restoring the implementation.
  5. Focused checks, full make check, six independent house reviews, refreshed exact-head CI, squash merge and the 30-minute main watch are complete. The ledger records the remaining guarded-access process-log verification gap explicitly.

Discoveries

The existing consumers intentionally differ after locating each registration: MCP detects method substrings, the mock gate enforces identifier boundaries and erases parameter names, and the envelope gate selects GET handlers. The extracted routes returns the original path/handler slices, so those consumer rules remain unchanged. er-api-spec is a dev-dependency of er-server in this PR; no request handler, endpoint, SQL statement or deployed task changes.

The pure library accepts source strings for documentation/body parsing and ledger generation. It preserves the existing fallback/unsupported-type behavior; broadening the supported source language belongs in a subsequent ticket with its own contract changes.

Commit audit

  • Claim: 38f68dbf75159b6bf2b548c8041b48b68c9357de.
  • Implementation: 25f98c4f9c6e1627d046610a42eca42806ed1261.
  • Squash merge: 8453c27debfd5b1b1a44ff86503662673d6de23a.

Measurements

Focused proof: 6 library tests and 9 existing real-server contract assertions pass. Both existing fidelity assertions failed on a deliberately appended newline, then passed after restoring the exact bytes. The two ignored regeneration tests were explicitly run and produced unchanged artifacts:

  • rust/crates/er-mcp/tools.json: SHA-256 52760cad4f7916ebce04f70fd8c494b607972dd3721a8556df6abdefd41cba63.
  • frontend/src/lib/api/envelopes.json: SHA-256 ba939b61cb4e737a0fb4e5f776450484aa99f9e94398f6c2cb14efdd434012c8.

Files

@athvin
athvin marked this pull request as ready for review November 9, 2026 20:31
@athvin
athvin force-pushed the issue/859-api-spec branch from bc15916 to 25f98c4 Compare November 9, 2026 20:31
@athvin
athvin merged commit 8453c27 into main Nov 9, 2026
39 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.

Extract the route/body/envelope derivation into an er-api-spec crate

2 participants