Test/ws backpressure drain#547
Merged
Baskarayelu merged 9 commits intoJun 25, 2026
Merged
Conversation
Adds all 11 routes that were in the hardcoded drift-check list but absent from docs/openapi.yaml, so the openapiDrift CI test passes.
Adds two exact-arithmetic primitives needed by the wallet debit fix: - compareDecimals(a, b) — BigInt-scaled integer comparison that never touches Number(); returns -1 | 0 | 1. - isValidPositiveDecimal(value) — validates that a decimal string is strictly greater than zero (rejects zero, negatives, and garbage).
The FOR UPDATE row lock made the write atomic but the funds check used
Number(), which loses precision on large/high-scale balances and could
permit an overdraft (e.g. Number("9007199254740992") ===
Number("9007199254740993") is true, so a debit of the larger value
against the smaller balance was silently allowed).
Comparison now uses compareDecimals() from decimalMath.ts, which uses
BigInt-scaled integer arithmetic and is always exact. Also adds
isValidPositiveDecimal() guards in both debit() and credit() to reject
zero, negative, or malformed amounts before the row lock is acquired.
- Overdraft-by-precision regression: confirms Number() collapses 9007199254740992 and 9007199254740993 to the same float, then asserts compareDecimals() correctly rejects the overdraft. - Exact-balance debit succeeds (boundary condition). - Sub-unit precision (9-decimal-place amounts accepted / rejected). - 30+ digit balances: debit succeeds and overdraft is caught. - Upfront validation for debit() and credit(): zero, negative, garbage. - InsufficientBalanceError field contents verified. - Wallet-not-found and no-pool error paths. - Extends vitest.config.ts include patterns to cover tests/repositories/.
Adds the wallets table to docs/schema.md with column definitions, constraints, and a note explaining why compareDecimals() is used instead of Number() for the sufficiency check in WalletsRepository.
… premature resolve drainWsConnections compared closed against wss.clients.size inside the close listener, but the ws library removes each client from the Set before the listener fires — so for N > 0 connections the equality check could never reach the initial total and the drain always fell back to the hard terminate timeout. Fix: snapshot const total = wss.clients.size before attaching listeners and gate on closed >= total instead.
Forces a slow-consumer buffer overflow and asserts the message is silently dropped; verifies drainWsConnections closes all sockets within the grace window (not falling back to the hard timeout); confirms one noisy connection is rate-throttled without affecting an independent connection; and tests auth rejection (missing/invalid key, missing identity segment, Authorization header) plus identity lowercasing. Adds shared helpers createTestServer, connectAndSubscribe, and collectMessages used across all new suites.
aed932c to
01de1d3
Compare
|
@444notdotun Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
4 tasks
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.
Bug fix (src/routes/ws.ts): drainWsConnections compared closed against wss.clients.size inside the close listener, but the ws library removes each client from the Set before that listener fires – so for N > 0 connections the equality check never reached the initial total and the drain always fell back to the hard-terminate timeout. Fixed by snapshotting const total = wss.clients.size before attaching listeners and gating on closed >= total.
New tests (src/tests/wsScoreStream.test.ts): 14 new integration tests across 5 suites covering the previously untested paths in ws.ts:
closes #515