Skip to content

fix : added max length guards to session creation validator fields (issue #1402) - #1407

Closed
tmdeveloper007 wants to merge 2 commits into
Canopus-Labs:mainfrom
tmdeveloper007:fix/1402-session-validator-max-length
Closed

fix : added max length guards to session creation validator fields (issue #1402)#1407
tmdeveloper007 wants to merge 2 commits into
Canopus-Labs:mainfrom
tmdeveloper007:fix/1402-session-validator-max-length

Conversation

@tmdeveloper007

@tmdeveloper007 tmdeveloper007 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary of What Has Been Done

Added .max() guards to all string fields in createSessionSchema in backend/Input_validators/ValidateSession.js:

  • role: max 200 characters
  • experience: max 50 characters
  • description: max 2000 characters
  • topicsToFocus[]: max 100 characters per topic
  • question[].question: max 5000 characters
  • question[].answer: max 10000 characters

Changes Made

  • Modified backend/Input_validators/ValidateSession.js: Added .max() Zod validators
  • Added backend/tests/sessionValidator.maxLength.unit.test.js: 8 unit tests covering max-length boundary cases

Impact it Made

  • Prevents storage bloat from arbitrarily long session content
  • Reduces network bandwidth waste from large request payloads
  • Aligns backend validation with sensible UI input limits

Closes #1402

Note: Please assign this PR to the tmdeveloper007 account.

Looks good to me. Ready to merge.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds maximum-length guards to flashcard and session creation validators. It adds Vitest coverage for valid boundaries, rejected oversized fields, empty values, validation responses, and the default flashcard category.

Changes

Input validation limits

Layer / File(s) Summary
Schema length guards
backend/Input_validators/ValidateFlashcard.js, backend/Input_validators/ValidateSession.js
Flashcard fields and session fields now enforce maximum string lengths while retaining required fields and the "General" category default.
Validator boundary tests
backend/tests/*Validator.maxLength.unit.test.js
Tests cover valid boundaries, oversized values, empty fields, HTTP 400 responses, and flashcard category defaulting.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The flashcard validator changes and related tests are unrelated to the session validator requirements in issue [#1402]. Remove the flashcard validator changes and tests, or link them to a separate issue.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: maximum-length guards for session creation validator fields, and references issue #1402.
Linked Issues check ✅ Passed The PR implements the requested maximum-length guards for role, experience, description, question, and answer fields in issue [#1402].
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

🧹 Nitpick comments (2)
backend/tests/flashcardValidator.maxLength.unit.test.js (1)

70-78: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test the exact category boundary.

This boundary test omits category. It does not verify that a 100-character category is accepted. Set category to "C".repeat(100) in this request.

🤖 Prompt for 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.

In `@backend/tests/flashcardValidator.maxLength.unit.test.js` around lines 70 -
78, Update the request in the exact-boundary test for validateCreateFlashcard to
include category set to a 100-character value using the existing repeat pattern.
Keep the question and answer boundary values and assertions unchanged.
backend/tests/sessionValidator.maxLength.unit.test.js (1)

91-100: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for the topicsToFocus item limit.

The suite does not exercise the new .max(100) constraint for a topic. Add a passing case with "T".repeat(100) and a rejected case with "T".repeat(101).

🤖 Prompt for 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.

In `@backend/tests/sessionValidator.maxLength.unit.test.js` around lines 91 - 100,
Add tests in the “accepts role and experience at exact boundaries” area for the
topicsToFocus item length: verify a topic of 100 characters passes validation
and a topic of 101 characters is rejected, using the existing request/response
helpers and assertions.
🤖 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.

Nitpick comments:
In `@backend/tests/flashcardValidator.maxLength.unit.test.js`:
- Around line 70-78: Update the request in the exact-boundary test for
validateCreateFlashcard to include category set to a 100-character value using
the existing repeat pattern. Keep the question and answer boundary values and
assertions unchanged.

In `@backend/tests/sessionValidator.maxLength.unit.test.js`:
- Around line 91-100: Add tests in the “accepts role and experience at exact
boundaries” area for the topicsToFocus item length: verify a topic of 100
characters passes validation and a topic of 101 characters is rejected, using
the existing request/response helpers and assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 48e9dd82-a434-45d7-8aae-8879cf293765

📥 Commits

Reviewing files that changed from the base of the PR and between 8acb5b8 and f38b88f.

📒 Files selected for processing (4)
  • backend/Input_validators/ValidateFlashcard.js
  • backend/Input_validators/ValidateSession.js
  • backend/tests/flashcardValidator.maxLength.unit.test.js
  • backend/tests/sessionValidator.maxLength.unit.test.js

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.

fix : add max length guards to session creation validator fields

1 participant