Add language-agnostic conformance suite for credit lease semantics#147
Draft
bpapillon wants to merge 1 commit into
Draft
Add language-agnostic conformance suite for credit lease semantics#147bpapillon wants to merge 1 commit into
bpapillon wants to merge 1 commit into
Conversation
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.
Precursor to SCH-6531 (lease support in other SDKs): extracts the credit lease/reservation semantics from this SDK — the reference implementation — into a language-agnostic conformance suite, so the upcoming Python/Go ports can prove "implements the same semantics" instead of approximating it.
conformance/SPEC.md— the semantics spec (state machine, store-op contracts, check/track flows, config knobs, bounded-leak contract table, and the invariants that can't be vectors), written for implementing from scratch without reading the Node source.conformance/vectors/*.json— 48 deterministic test vectors (plain JSON, snake_case, virtual clock): reservation lifecycle 7, lease lifecycle 9, expiry 4, crash windows 5, lease manager 10, check flow 10, track/settle 3.tests/conformance/runner.test.ts— runs every vector against both store backends (in-memory + the existing fake-redis Lua interpreter): 95 passing runs. The runner is the only language-specific piece a port reimplements.Behaviors worth calling out (vectors follow the code):
credits_reserved, but the Track event bills the unclamped actual quantity (server is source of truth).replacekeeps a live lease even under a different lease id; the losing acquire releases its redundant lease only when the server minted a different id.extendreconciles to the server's absolute total (lower/equal totals are no-ops) and expiry only moves forward; both extend and refund are pinned to the originating lease id and silently dropped if a successor holds the slot.Not capturable as vectors (documented as prose invariants in SPEC.md): single-flight/concurrent-race schedules, Redis server-clock TTL authority and single-key Lua atomicity, NaN guards (JSON can't encode NaN), Track idempotency-key dedupe, the background sweep timer, and offline/unconfigured wrapper degradation.