🧪 Add comprehensive tests for parseJSONFromAI#64
Conversation
Co-authored-by: APPLEPIE6969 <242827480+APPLEPIE6969@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe PR reorganizes test suites by moving the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
lib/ai-utils.test.ts (2)
52-57: Tighten the unclosed-markdown failure assertion.Line 56 currently passes on any thrown error. Assert the expected error type to avoid false positives.
Suggested diff
- assert.throws(() => parseJSONFromAI(input)); + assert.throws(() => parseJSONFromAI(input), { + name: 'SyntaxError' + });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/ai-utils.test.ts` around lines 52 - 57, The test "should handle unclosed markdown blocks" is currently asserting that any error is thrown; tighten it to assert the specific error type from JSON.parse by changing assert.throws(() => parseJSONFromAI(input)) to assert.throws(() => parseJSONFromAI(input), SyntaxError) (or the exact error constructor/message produced by parseJSONFromAI) so the test verifies the expected JSON parse failure from parseJSONFromAI rather than any thrown error.
80-83: Make the invalid-input test assert the expected error type.Line 82 should validate
SyntaxErrorexplicitly for stronger failure diagnostics.Suggested diff
test('should throw on completely invalid input', () => { const input = 'This is just some text with no JSON in it.'; - assert.throws(() => parseJSONFromAI(input)); + assert.throws(() => parseJSONFromAI(input), { + name: 'SyntaxError' + }); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/ai-utils.test.ts` around lines 80 - 83, The test "should throw on completely invalid input" currently only checks that parseJSONFromAI(input) throws; update it to assert the specific error type by asserting a SyntaxError is thrown (use assert.throws with SyntaxError as the expected error constructor for the call to parseJSONFromAI). This targets the parseJSONFromAI function and will make the test fail more informatively when a different error is raised.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@lib/ai-utils.test.ts`:
- Around line 52-57: The test "should handle unclosed markdown blocks" is
currently asserting that any error is thrown; tighten it to assert the specific
error type from JSON.parse by changing assert.throws(() =>
parseJSONFromAI(input)) to assert.throws(() => parseJSONFromAI(input),
SyntaxError) (or the exact error constructor/message produced by
parseJSONFromAI) so the test verifies the expected JSON parse failure from
parseJSONFromAI rather than any thrown error.
- Around line 80-83: The test "should throw on completely invalid input"
currently only checks that parseJSONFromAI(input) throws; update it to assert
the specific error type by asserting a SyntaxError is thrown (use assert.throws
with SyntaxError as the expected error constructor for the call to
parseJSONFromAI). This targets the parseJSONFromAI function and will make the
test fail more informatively when a different error is raised.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2fa051a0-368e-43d5-8d83-f418519d2741
📒 Files selected for processing (2)
lib/ai-utils.test.tslib/ai.test.ts
💤 Files with no reviewable changes (1)
- lib/ai.test.ts
This PR adds a new test file
lib/ai-utils.test.tswith comprehensive test coverage for theparseJSONFromAIutility function. It covers direct JSON parsing, Markdown code block extraction, regex-based structure detection, and aggressive cleaning fallback logic. The redundantlib/ai.test.tshas been replaced by this more focused and exhaustive test suite.PR created automatically by Jules for task 13080009789046424794 started by @APPLEPIE6969
Summary by CodeRabbit