Skip to content

test(subscription): bring src/api/subscription to 100% offline line coverage - #71

Merged
joeblau merged 1 commit into
mainfrom
test/subscription-coverage
Jul 27, 2026
Merged

test(subscription): bring src/api/subscription to 100% offline line coverage#71
joeblau merged 1 commit into
mainfrom
test/subscription-coverage

Conversation

@joeblau

@joeblau joeblau commented Jul 27, 2026

Copy link
Copy Markdown

What

The 28 method wrappers in src/api/subscription/_methods/*.ts and client.ts were only exercised by live tests (skipped under HL_OFFLINE=1), so their parse(...) + config.transport.subscribe(...) bodies were uncovered offline. This PR adds offline tests only — no src changes.

  • tests/api/subscription/_mockTransport.ts — a recording ISubscriptionTransport: captures every subscribe(channel, payload, listener, options) call, resolves with a stub ISubscription, and replays synthetic { detail } events through the captured listener.
  • tests/api/subscription/client.test.ts — drives every one of the 28 SubscriptionClient methods (plus the exported free-function overloads) against the mock:
    • valid params (every overload shape) → exactly one subscribe call; asserts the full payload including normalized fields, the channel, and options identity passthrough;
    • invalid params (bad address, wrong enum, out-of-range, wrong type) → ValidationError thrown synchronously, zero transport calls;
    • event delivery → synthetic event reaches the listener; for filtering methods a non-matching event is dropped (both paths asserted);
    • quirks: activeSpotAssetCtx/userEvents channel literals vs payload type, allMids || vs assetCtxs ?? dex normalization, l2Book null defaults, userFills aggregateByTime default, trades[0]?.coin filtering (empty array dropped), Address lowercasing, and fastAssetCtxs deflate 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)

File Before After
_methods/activeAssetCtx.ts 8/24 (33.3%) 24/24 (100%)
_methods/activeAssetData.ts 10/26 (38.5%) 26/26 (100%)
_methods/activeSpotAssetCtx.ts 8/24 (33.3%) 24/24 (100%)
_methods/allDexsAssetCtxs.ts 7/22 (31.8%) 22/22 (100%)
_methods/allDexsClearinghouseState.ts 9/28 (32.1%) 28/28 (100%)
_methods/allMids.ts 8/33 (24.2%) 32/32 (100%)
_methods/assetCtxs.ts 8/33 (24.2%) 32/32 (100%)
_methods/bbo.ts 8/24 (33.3%) 24/24 (100%)
_methods/candle.ts 9/25 (36.0%) 25/25 (100%)
_methods/clearinghouseState.ts 10/30 (33.3%) 30/30 (100%)
_methods/fastAssetCtxs.ts 46/46 (100%) 46/46 (100%)
_methods/l2Book.ts 11/32 (34.4%) 32/32 (100%)
_methods/notification.ts 9/23 (39.1%) 23/23 (100%)
_methods/openOrders.ts 10/30 (33.3%) 30/30 (100%)
_methods/orderUpdates.ts 9/23 (39.1%) 23/23 (100%)
_methods/outcomeMetaUpdates.ts 7/20 (35.0%) 20/20 (100%)
_methods/spotAssetCtxs.ts 7/20 (35.0%) 20/20 (100%)
_methods/spotState.ts 10/26 (38.5%) 26/26 (100%)
_methods/trades.ts 8/24 (33.3%) 24/24 (100%)
_methods/twapStates.ts 10/30 (33.3%) 30/30 (100%)
_methods/userEvents.ts 9/23 (39.1%) 23/23 (100%)
_methods/userFills.ts 10/30 (33.3%) 30/30 (100%)
_methods/userFundings.ts 9/25 (36.0%) 25/25 (100%)
_methods/userHistoricalOrders.ts 9/25 (36.0%) 25/25 (100%)
_methods/userNonFundingLedgerUpdates.ts 9/25 (36.0%) 25/25 (100%)
_methods/userTwapHistory.ts 9/25 (36.0%) 25/25 (100%)
_methods/userTwapSliceFills.ts 9/25 (36.0%) 25/25 (100%)
_methods/webData3.ts 9/25 (36.0%) 25/25 (100%)
client.ts 61/198 (30.8%) 198/198 (100%)
mod.ts 28/28 (100%) 28/28 (100%)
Total 390/972 (40.1%) 970/970 (100%)

The 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)

…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).
@joeblau
joeblau merged commit cf3de2c into main Jul 27, 2026
2 of 3 checks passed
@joeblau
joeblau deleted the test/subscription-coverage branch July 27, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant