test(subscription): bring src/api/subscription to 100% offline line coverage - #71
Merged
Conversation
…overage Drive all 28 SubscriptionClient methods against a recording mock subscription transport (tests/api/subscription/_mockTransport.ts): - assert the exact channel, validated/normalized payload and options handed to transport.subscribe for every overload shape; - assert invalid params throw ValidationError synchronously with zero transport calls; - replay synthetic events through the captured listener, asserting delivery plus per-method filtering on both match and drop paths; - cover the quirks: activeSpotAssetCtx/userEvents channel literals, allMids `||` vs assetCtxs `??` dex normalization, l2Book null defaults, userFills aggregateByTime default, trades[0] filtering, Address lowercasing, and fastAssetCtxs deflate frame delivery (including a skipped bad frame that keeps the queue alive).
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.
What
The 28 method wrappers in
src/api/subscription/_methods/*.tsandclient.tswere only exercised by live tests (skipped underHL_OFFLINE=1), so theirparse(...)+config.transport.subscribe(...)bodies were uncovered offline. This PR adds offline tests only — no src changes.tests/api/subscription/_mockTransport.ts— a recordingISubscriptionTransport: captures everysubscribe(channel, payload, listener, options)call, resolves with a stubISubscription, and replays synthetic{ detail }events through the captured listener.tests/api/subscription/client.test.ts— drives every one of the 28SubscriptionClientmethods (plus the exported free-function overloads) against the mock:optionsidentity passthrough;ValidationErrorthrown synchronously, zero transport calls;activeSpotAssetCtx/userEventschannel literals vs payloadtype,allMids||vsassetCtxs??dex normalization,l2Booknull defaults,userFillsaggregateByTimedefault,trades[0]?.coinfiltering (empty array dropped), Address lowercasing, andfastAssetCtxsdeflate frame delivery incl. a skipped bad frame that keeps the queue alive.Coverage (lines, from
HL_OFFLINE=1 bun test tests/ --coverage --coverage-reporter=lcov)_methods/activeAssetCtx.ts_methods/activeAssetData.ts_methods/activeSpotAssetCtx.ts_methods/allDexsAssetCtxs.ts_methods/allDexsClearinghouseState.ts_methods/allMids.ts_methods/assetCtxs.ts_methods/bbo.ts_methods/candle.ts_methods/clearinghouseState.ts_methods/fastAssetCtxs.ts_methods/l2Book.ts_methods/notification.ts_methods/openOrders.ts_methods/orderUpdates.ts_methods/outcomeMetaUpdates.ts_methods/spotAssetCtxs.ts_methods/spotState.ts_methods/trades.ts_methods/twapStates.ts_methods/userEvents.ts_methods/userFills.ts_methods/userFundings.ts_methods/userHistoricalOrders.ts_methods/userNonFundingLedgerUpdates.ts_methods/userTwapHistory.ts_methods/userTwapSliceFills.ts_methods/webData3.tsclient.tsmod.tsThe lcov report carries no branch (BRDA) data for these files, so line coverage is the only metric available.
Verification
bun run check— all gates pass (format, lint, docs, tsc 5, tsc 7, jsdoc sync, export sync)HL_OFFLINE=1 bun test tests/— 1119 pass, 0 fail (99 new tests)