fix(unread): prevent negative totals, fix edge cases, and add test coverage#78
Open
DSBaibhav wants to merge 4 commits into
Open
fix(unread): prevent negative totals, fix edge cases, and add test coverage#78DSBaibhav wants to merge 4 commits into
DSBaibhav wants to merge 4 commits into
Conversation
- unreadService.js: clamp server totals to >= 0 on write and read; reset Redis client promise on error/failure so reconnects work; add isUsingRedis() diagnostic helper and resetForTesting() for tests; document Redis vs in-memory fallback behavior in JSDoc - notifications.js: validate required body params (400 on missing friend_id / server_id / channel_id); add GET /unread_storage_mode diagnostic route to inspect active storage backend - unreadSlice.js: clamp server total with Math.max(0, ...) in clear_channel_unread so double-clearing never produces a negative total; remove server entry only when total reaches exactly 0 - NotificationListener.jsx: add socket 'connect' handler to re-fetch unread summary on reconnect (covers device sleep/wake, server restart, Redis loss); wrap fetchUnreadSummary in try/catch with non-OK HTTP status handling; add .catch() to fire-and-forget mark-read fetches; call socket.connect() explicitly since socket now uses autoConnect:false - test-unread-edge-cases.mjs: new 20-assertion automated test script covering DM and server channel edge cases (double-clear, multi-user isolation, cross-server isolation, memory reset / reconnect sim) Closes #<issue-number> Test: npm run test:unread (20/20 passing)
- Socket.jsx: switch from socketIO.connect() to socketIO() with autoConnect:false to prevent crash-on-import when backend is unreachable; add polling transport fallback and reconnection config; add DEV console logs for connect/disconnect/error events - supabaseClient.js: guard createClient() with URL validation and try/catch so an invalid/missing SUPABASE_URL never crashes the app at module-load time (was causing blank white/black screen) - App.jsx: wrap root with ErrorBoundary so any render crash shows a visible error message instead of a completely blank page - ErrorBoundary.jsx: new class component that catches React tree errors and displays a styled fallback with the error message and a reload button - Register.jsx: fix date-of-birth validation — month dropdown now stores the full month name instead of a numeric index; validation uses ISO YYYY-MM-DD format so new Date() parses reliably across all browsers (fixes 'Please enter a valid date' on every valid date) - dev-server.mjs: new development startup script that auto-spins up mongodb-memory-server when no real MONGO_URI is set, so the server can run locally without any database configuration; also injects a dev-only ACCESS_TOKEN when none is provided
👷 Deploy request for piperchat01 pending review.Visit the deploys page to approve it
|
3ce1809 to
23d9212
Compare
Contributor
|
@DSBaibhav is attempting to deploy a commit to the Sunil Kumar's projects Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
Hey @0rigin-c0de,just following up on this PR whenever you get time to review it. Please let me know if any changes or improvements are needed from my side. Thanks! |
Resolve conflicts across all conflicting files: - frontend/src/App.jsx: keep ErrorBoundary + add Vercel Analytics - frontend/src/components/notifications/NotificationListener.jsx: adopt upstream API_BASE_URL from config; keep reconnect handler, notification prefs re-sync, full error handling and JSDoc comments - frontend/src/components/socket/Socket.jsx: adopt SOCKET_URL from config with VITE env var fallback chain; keep autoConnect:false, transport fallbacks, withCredentials, debug helpers - server/package.json: adopt src/ entry point and new deps (logtail, compression, helmet, rate-limit, winston); keep dev:local, watch:local, test:unread, gmail:oauth-setup scripts - server/src/routes/notifications.js: adopt logger; keep input validation and /unread_storage_mode diagnostic endpoint - server/src/services/unreadService.js: adopt config/logger pattern; keep Redis promise-reset-on-error, clamping to >=0, clearServerChannelUnread algorithm, isUsingRedis(), resetForTesting()
Author
|
Hey @0rigin-c0de,I have resolved all the conflicts,just following up please review this PR whenever you get the time under GSSoC'26 |
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.
Summary
Resolved the unread count edge cases described in the issue.
Changes
server/services/unreadService.jsisUsingRedis()diagnostic helper andresetForTesting()for unit testsserver/routes/notifications.jsfriend_id,server_id, orchannel_idare missingGET /unread_storage_moderoute to inspect which backend is activefrontend/src/store/unreadSlice.jsMath.max(0, ...)inclear_channel_unreadfrontend/src/components/notifications/NotificationListener.jsxfetchUnreadSummaryin try/catch with non-OK HTTP status handlingsocket.connect()since socket now usesautoConnect: falseserver/scripts/test-unread-edge-cases.mjs(new)npm run test:unreadTest Results
Results: 20 passed, 0 failed ✅
Acceptance Criteria