Skip to content

Testing: Add structured validation for resource JSON files (#100)#135

Merged
RishiByte merged 3 commits into
Demon-Die:mainfrom
coolss21:testing/validate-resource-data
Jun 9, 2026
Merged

Testing: Add structured validation for resource JSON files (#100)#135
RishiByte merged 3 commits into
Demon-Die:mainfrom
coolss21:testing/validate-resource-data

Conversation

@coolss21

@coolss21 coolss21 commented Jun 9, 2026

Copy link
Copy Markdown

Resolves #100.

Overview
This PR adds a standalone validation script for all resource JSON files under project/src/data/resources/.

Changes Made:

  • Added project/scripts/validate-resources.mjs — a zero-dependency Node.js validation script.
  • Added validate:resources npm script to project/package.json.

What the script validates:

  • Valid JSON syntax
  • Required top-level fields (id, title, description, categories)
  • Required category fields (categoryId, name, resources)
  • Required resource fields (id, name, url, type, difficulty)
  • Duplicate resource IDs within a file
  • Duplicate resource URLs within a file
  • Empty or whitespace-only titles/names/URLs
  • Invalid difficulty values (must be one of: Beginner, Intermediate, Advanced, or compound ranges)

Usage:

npm run validate:resources --workspace project

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **Chores**
  * Added a new resource validation tool accessible via project scripts.
  * Validates resource JSON files for required top-level fields, non-empty names/URLs, allowed difficulty values, and duplicate IDs/URLs.
  * Produces per-file pass/fail reports with error counts/messages and returns a non-zero exit code on validation failures.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

@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.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f31fc153-2808-4743-8c5e-b1f6841f445b

📥 Commits

Reviewing files that changed from the base of the PR and between 0b0bd98 and 4f7b69c.

📒 Files selected for processing (1)
  • project/package.json
✅ Files skipped from review due to trivial changes (1)
  • project/package.json

📝 Walkthrough

Walkthrough

This PR adds a Node.js CLI that validates JSON files under project/src/data/resources/ for required fields, empty values, allowed difficulty values, and duplicate resource IDs/URLs, prints per-file results, aggregates errors, and exposes it as the validate:resources npm script.

Changes

Resource JSON validation

Layer / File(s) Summary
Validation schema and setup
project/scripts/validate-resources.mjs
Constants define allowed difficulty values (beginner, intermediate, advanced, expert) and required field names for resources, categories, and top-level JSON structure; resources directory path is resolved.
Resource file validation logic
project/scripts/validate-resources.mjs
validateResourceFile() reads and parses each JSON file, validates presence of required fields (id, title, description, categories at top level; categoryId, name, resources in categories; id, name, url, type, difficulty in resources), detects empty or whitespace-only title, category.name, and resource.name/resource.url, enforces difficulty against allowed values, and identifies duplicate resource IDs and URLs within each file.
Orchestration and npm integration
project/scripts/validate-resources.mjs, project/package.json
main() discovers all .json files in the resources directory, validates each sequentially, prints per-file results with error counts and messages, aggregates total errors, and exits with code 1 on validation failures or directory read errors (code 0 otherwise); validate:resources npm script is added to run the validation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A little script hops through the tree,
Checking JSON leaves for what should be,
No empty names, no duplicate tracks,
Valid resources, no hiccups, no cracks.
npm run validate — the rabbit smiles with glee.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a validation script for resource JSON files. It is concise, directly related to the changeset, and indicates both the action (Add) and the subject (structured validation for resource JSON files).
Linked Issues check ✅ Passed All acceptance criteria from issue #100 are met: validation script exists, catches duplicate URLs, detects missing titles/URLs, provides readable error messages, and npm script (validate:resources) is added.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #100 requirements: the validation script and npm script addition align with the linked issue objectives and no unrelated modifications are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between e6bfac7 and c6050f1.

📒 Files selected for processing (2)
  • project/package.json
  • project/scripts/validate-resources.mjs

Comment thread project/scripts/validate-resources.mjs
Comment thread project/scripts/validate-resources.mjs
Comment thread project/scripts/validate-resources.mjs
@RishiByte

Copy link
Copy Markdown
Member

@coolss21 sorry but there is a branch conflict in it so fix it please

@coolss21

coolss21 commented Jun 9, 2026

Copy link
Copy Markdown
Author

Could you send a screenshot of the conflict?

@RishiByte

Copy link
Copy Markdown
Member

@coolss21 it's fixed now

@RishiByte RishiByte merged commit cb4c939 into Demon-Die:main Jun 9, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add structured validation for resource JSON files

2 participants