Skip to content

🧪 Add comprehensive tests for parseJSONFromAI#64

Merged
APPLEPIE6969 merged 1 commit intomainfrom
test-parse-json-from-ai-13080009789046424794
Mar 19, 2026
Merged

🧪 Add comprehensive tests for parseJSONFromAI#64
APPLEPIE6969 merged 1 commit intomainfrom
test-parse-json-from-ai-13080009789046424794

Conversation

@APPLEPIE6969
Copy link
Copy Markdown
Owner

@APPLEPIE6969 APPLEPIE6969 commented Mar 19, 2026

This PR adds a new test file lib/ai-utils.test.ts with comprehensive test coverage for the parseJSONFromAI utility function. It covers direct JSON parsing, Markdown code block extraction, regex-based structure detection, and aggressive cleaning fallback logic. The redundant lib/ai.test.ts has been replaced by this more focused and exhaustive test suite.


PR created automatically by Jules for task 13080009789046424794 started by @APPLEPIE6969

Summary by CodeRabbit

  • Tests
    • Reorganized and enhanced test coverage for JSON parsing utility. Tests now cover direct JSON parsing with whitespace handling, extraction from Markdown code blocks, multi-block selection logic, regex-based JSON extraction from conversational text, and error handling for malformed input.

Co-authored-by: APPLEPIE6969 <242827480+APPLEPIE6969@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studyflow Ready Ready Preview, Comment Mar 19, 2026 2:04pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 19, 2026

📝 Walkthrough

Walkthrough

The PR reorganizes test suites by moving the parseJSONFromAI test suite from lib/ai.test.ts to a new dedicated test file lib/ai-utils.test.ts, expanding coverage with additional edge cases including Markdown parsing, whitespace handling, and malformed input validation.

Changes

Cohort / File(s) Summary
Test Reorganization
lib/ai.test.ts, lib/ai-utils.test.ts
Removed parseJSONFromAI test suite from lib/ai.test.ts and relocated it to new lib/ai-utils.test.ts file with expanded test coverage including Markdown code fence extraction, regex-based JSON detection, whitespace handling, and comprehensive error scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Tests hoppy-hopped to their new warren,
From ai to ai-utils, no more sorrow!
Markdown fences and whitespace too,
More coverage makes the function more true! ✨🧪

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses an emoji (🧪) which adds noise rather than clarity, and the phrasing is somewhat generic. However, it accurately describes the main change: adding comprehensive tests for the parseJSONFromAI function. The core message is clear despite the stylistic issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test-parse-json-from-ai-13080009789046424794
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

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

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 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 SyntaxError explicitly 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

📥 Commits

Reviewing files that changed from the base of the PR and between e05aff9 and 0d2268c.

📒 Files selected for processing (2)
  • lib/ai-utils.test.ts
  • lib/ai.test.ts
💤 Files with no reviewable changes (1)
  • lib/ai.test.ts

@APPLEPIE6969 APPLEPIE6969 merged commit 6daa385 into main Mar 19, 2026
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.

1 participant