Testing: Add structured validation for resource JSON files (#100)#135
Conversation
|
@rhoggs-bot-test-account is attempting to deploy a commit to the Rishi Bhardwaj's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThis PR adds a Node.js CLI that validates JSON files under ChangesResource JSON validation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@project/scripts/validate-resources.mjs`:
- Around line 124-130: The difficulty validation currently only checks invalid
string values (uses VALID_DIFFICULTIES) so non-string values slip through;
update the validation around res.difficulty to first reject non-string types by
pushing an error using resLabel (e.g., "Invalid difficulty type: must be a
string"), then keep the existing branch that checks string values against
VALID_DIFFICULTIES; reference res.difficulty, VALID_DIFFICULTIES, errors, and
resLabel when making the change.
- Around line 67-72: Before iterating REQUIRED_TOP_LEVEL, verify that data is a
plain object (e.g., typeof data === 'object' && data !== null &&
!Array.isArray(data')); if that guard fails, push a single readable error to
errors (use fileName) saying the JSON is not an object and skip the field-check
loop; update the block that currently references data[field] (involving
REQUIRED_TOP_LEVEL, data, errors, fileName) so you never access properties on
non-object values.
- Around line 87-112: The code dereferences category and resource items without
ensuring they are plain objects; update the validation in the
data.categories.forEach handler to first verify each cat is an object (e.g., cat
!== null && typeof cat === "object") and if not push an error like `${catLabel}:
Category must be an object` and skip further checks for that item, and similarly
before iterating cat.resources or checking REQUIRED_RESOURCE fields verify each
res is an object (res !== null && typeof res === "object"), otherwise push an
error like `${resLabel}: Resource must be an object` and skip its field checks;
keep the existing REQUIRED_CATEGORY / REQUIRED_RESOURCE checks but only run them
after these object-type guards.
🪄 Autofix (Beta)
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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6b359c0f-a59c-4bf4-b529-40d565969561
📒 Files selected for processing (2)
project/package.jsonproject/scripts/validate-resources.mjs
|
@coolss21 sorry but there is a branch conflict in it so fix it please |
|
Could you send a screenshot of the conflict? |
|
@coolss21 it's fixed now |
Resolves #100.
Overview
This PR adds a standalone validation script for all resource JSON files under
project/src/data/resources/.Changes Made:
project/scripts/validate-resources.mjs— a zero-dependency Node.js validation script.validate:resourcesnpm script toproject/package.json.What the script validates:
id,title,description,categories)categoryId,name,resources)id,name,url,type,difficulty)difficultyvalues (must be one of: Beginner, Intermediate, Advanced, or compound ranges)Usage: