fix: DSA sheet progress never persists — accept object completedTopics shape - #1729
fix: DSA sheet progress never persists — accept object completedTopics shape#1729vedant7007 wants to merge 2 commits into
Conversation
The controller required completedTopics to be an Array, but the frontend,
the Zod validator (z.record), the Mongoose schema ({ type: Object }), the
import util, and resetProgress all use an object/map — so every save hit
!Array.isArray({...}) and returned 400, and progress was silently lost
(kept only in localStorage). Validate it as a plain object instead.
Fixes Canopus-Labs#1727
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe progress controller now validates ChangesProgress validation
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/controllers/userSheetProgressController.js`:
- Around line 63-71: Strengthen the completedTopics validation in the user sheet
progress controller to require a plain object and boolean values for every
property, matching the contract enforced by ValidateUserSheetProgress. Reject
non-plain objects and any entry whose value is not boolean before persisting the
record, while preserving the existing 400 response.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f3981c68-c780-418a-ac3b-4a331ec7ad11
📒 Files selected for processing (1)
backend/controllers/userSheetProgressController.js
|
@vedant7007 address the coderabbit suggestions |
…ntract)
Per review: the object check accepted any non-null object, so { "0-0-0": "true" }
(string value) passed. Also require every value to be a boolean, matching the
Zod z.record(z.string(), z.boolean()) contract and the map/{key:bool} shape.
|
Good catch @coderabbitai — tightened the check to also require every value to be a boolean ( Contributing as part of Elite Coders Summer of Code (ECSoC 2026). |
|
Tip For best results, initiate chat on the files or code changes.
🐇 ✓ ✏️ Learnings added
You are interacting with an AI system. |
Closes #1727
Problem
saveProgressrejected the real payload with400:The frontend sends
completedTopicsas an object/map ({ "0-0-0": true }), and so do the Zod validator (z.record(z.string(), z.boolean())), the Mongoose schema ({ type: Object }),resetProgress({}), and the import util.!Array.isArray({...})istrue, so every save returned 400 and the frontend.catchswallowed it — progress lived only in localStorage and was lost across devices / on cache clear.Fix
Validate
completedTopicsas a plain object (reject arrays/null) to match the rest of the system.Testing
node --checkon the changed controller.Contributing as part of Elite Coders Summer of Code (ECSoC 2026).
Summary
saveProgressvalidation forcompletedTopics.{ "0-0-0": true }.null, and non-boolean values.node --check.