feat: health check breakdown, per-user SSE cap, claimable invalidation test, api-types sync doc - #1136
Open
david87131 wants to merge 1 commit into
Open
Conversation
…nvalidation test, api-types sync doc - Health endpoint now returns a `checks` object breaking down database, indexer lag, redis, and soroban RPC status individually, while keeping the top-level `status` field for simple uptime monitors. Updated the Postman collection's example response to match. - SSE subscriptions now enforce a per-authenticated-user concurrent connection cap (independent of the existing per-IP cap), returning 429 when exceeded. Added tests covering the cap, its independence from IP, and release on disconnect. - Added a claimable.service test that primes the cache, simulates an indexed TokensWithdrawn event, and asserts the next read reflects the new claimable amount immediately rather than waiting for the TTL. - Added an opt-in `codegen:api-types` dev script (openapi-typescript against the backend's /api-docs.json) and a doc comment on api-types.ts pointing at backend/src/config/swagger.ts as the source of truth. Not wired into CI and does not replace existing hand-written types/call sites. Fixes LabsCrypt#1117 Fixes LabsCrypt#1116 Fixes LabsCrypt#1115 Fixes LabsCrypt#1114
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.
/healthnow returns achecksobject breaking down status per subsystem:database,indexer(enabled + lag),redis(only checked subsystems that actually exist in the codebase — no soroban RPC state client beyond a lightweightgetHealth()ping, which is now also included assorobanRpc). The top-levelstatusfield is unchanged for simple uptime monitors. Updateddocs/api/flowfi.postman_collection.json's example response to match the new shape. Did not touch the 60s lag threshold (tracked separately) or build a status-page integration.MAX_CONNECTIONS_PER_USER = 10), independent of and in addition to the existing per-IP cap. Tracked with the same counting-map pattern as the per-IP limit (userConnectionCounts), keyed by the authenticated user's public key, incremented/decremented alongside connection open/close. Returns 429 with a clear message when exceeded. Added tests covering: cap enforcement across different IPs, no cap for unauthenticated checks, and slot release on disconnect. Left the existing per-IP limit (MAX_CONNECTIONS_PER_IP) untouched.claimable.service.ts: primes the cache, simulates an indexedTokensWithdrawnevent (i.e.withdrawnAmount/lastUpdateTimeadvancing on the stream, exactly ashandleTokensWithdrawndoes), and asserts the very next read reflects the new claimable amount immediately — well within the cache TTL, not after it expires. No production code changes were needed: the cache key already folds inwithdrawnAmount/lastUpdateTimeviagetStateFingerprint(), so a state change naturally produces a different cache key once callers pass the freshly-reloaded stream (whichstream.controller.ts/withdraw.tsalready do). Added a comment in the test explaining this. Did not touch the cache-key/token-collision bug or the TTL-default inconsistency (both tracked separately).openapi-typescriptagainst the backend's existing/api-docs.json(built frombackend/src/config/swagger.tsvia swagger-jsdoc) — confirmed it's a small, safe addition. Added an opt-innpm run codegen:api-typesscript infrontend/that a developer can run manually against a locally running backend; it writes tosrc/lib/api-types.generated.ts(gitignored) and does not replaceapi-types.tsor any call sites, and is not wired into CI. Also added a doc comment block at the top offrontend/src/lib/api-types.tsnoting it must be manually kept in sync withbackend/src/config/swagger.tsand pointing to the codegen script for cross-checking.Test plan
backend:npx vitest run tests/claimable.service.test.ts tests/sse.service.test.ts tests/sse.controller.test.ts— all passbackend:npx vitest run(full suite, afternpx prisma generate) — same 4 integration test files fail as onmain(require a live local Postgres DB; unrelated to this change) and 2 pre-existing rate-limiter failures unrelated to this change; all other 41 test files passbackend:npx tsc --noEmit— same 15 pre-existing errors as onmainin untouched files; no new errors in changed filesfrontend:npx tsc --noEmit— same pre-existing parse errors in unrelated files as onmain; no errors inapi-types.tsfrontend:npx vitest run— 182/182 tests pass; same 2 pre-existing broken test files as onmain(unrelated.tsfiles containing JSX)Fixes #1117
Fixes #1116
Fixes #1115
Fixes #1114