Multi-version µEd API support via versioned adapters - #34
Open
m-messer wants to merge 2 commits into
Open
Conversation
The standalone server wrapped the route mux with NormalizePath + the OpenAPI request/response validation middleware; the Lambda adapter wrapped it with NormalizePath only. That left Lambda requests unvalidated against the spec and, more importantly, Lambda responses unchecked — so a non-conforming response would 500 on standalone but ship as-is on Lambda. Extract the wrapped chain into server.NewMux (mux + NormalizePath + per-version OpenAPI validation) and a server.HandlerModule fx module. Both app/standalone and app/lambda now depend on it and serve the exact same *server.Mux, so the two deployments validate identically. The only remaining deployment difference is transport: standalone runs an http.Server + listener (and optional h2c); Lambda hands the same handler to httpadapter. NewHttpServer / NewLifecycleServer no longer build the chain or return an error. Added fx.ValidateApp coverage for the Lambda graph and a NewMux test asserting validation + path normalisation are applied. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YAusDUAMwEVN8hAV4N8qGk
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.
Context
shimmy previously had only single-version negotiation scaffolding for the µEd API: it could advertise and gate on an
X-Api-Versionstring, but there was exactly one version (0.1.0) and no code path behaved differently per requested version. This adds a generic, additive framework so a future version slots in as one adapter file + one spec file + one registration line, with0.1.0behaviour byte-for-byte unchanged.Design
Adapter-per-version behind one interface + an ordered registry.
runtime/mued_adapter.go—MuEdAdapterinterface (decode + encode for evaluate/preview/health/chat) andMuEdRegistry(Register/Resolve/Adapter/Default/Latest, oldest-first order).Default()is the first registered version, pinned separately fromLatest(), so registering a newer version never silently moves header-less clients onto new semantics.runtime/mued_v0_1_0.go—muEdV010delegates every method to the existingMuEdBuildLegacy*/MuEdTo*free functions;init()registers it.runtime/version.go—SupportedMuEdVersionsis now a function backed by the registry;MuEdIsVersionSupported/MuEdResolveVersiondelegate to it (behaviour and call signatures otherwise unchanged).checkMuEdVersionresolvesX-Api-Versionto an adapter andServeEvaluate/ServeHealth/ServeChat/ServeChatHealthdrive it.MuEdHandlergained an optional injected registry (nil → process default).//go:embed mued_v*.ymlinto a version-keyed map;OpenAPIMiddlewarebuilds one router per version and selects per request via the same resolver the handlers use. Unknown-route pass-through and 400/500 semantics unchanged.One shared handler chain on both deployments. The standalone server used to wrap the mux with
NormalizePath+ OpenAPI validation; the Lambda adapter wrapped it withNormalizePathonly, leaving Lambda requests unvalidated and Lambda responses unchecked (a non-conforming response would 500 on standalone but ship as-is on Lambda). The wrapped chain is nowserver.NewMuxbehindserver.HandlerModule, and bothapp/standaloneandapp/lambdaserve the exact same*server.Mux. The only remaining deployment difference is transport.Backward compatibility
Only
0.1.0is registered, soSupportedMuEdVersions()==["0.1.0"], version resolution behaves exactly as before, and all pre-existingruntime/*_test.goandhandler/*_test.goassertions pass unmodified.Tests
runtime/mued_adapter_test.go— registry order/resolution/dispatch, multi-version via a synthetic adapter.runtime/mued_v0_1_0_test.go— byte-for-byte equivalence of every adapter method vs the free functions.handler/mued_version_test.go— dispatch to a synthetic version adapter;""vs0.1.0parity.internal/server/openapi_test.go+testdata/mued_v0.2.0.yml— same body accepted under v0.1.0, rejected under a synthetic v0.2.0 requiring an extra field.internal/server/mux_test.go— the shared chain applies validation + path normalisation.app/standalone/module_test.go,app/lambda/module_test.go—fx.ValidateAppover both graphs.go build ./...,go vet ./..., andgo test ./...all pass.Follow-up (not in this PR)
Semver ordering of embedded specs is currently lexical — fine while version components stay single-digit.
🤖 Generated with Claude Code