Skip to content

fix: isJson assertion should accept arrays as valid JSON#7620

Merged
bijin-bruno merged 2 commits intousebruno:mainfrom
abhishek-bruno:fix/isJson-assertion-accept-arrays
Apr 2, 2026
Merged

fix: isJson assertion should accept arrays as valid JSON#7620
bijin-bruno merged 2 commits intousebruno:mainfrom
abhishek-bruno:fix/isJson-assertion-accept-arrays

Conversation

@abhishek-bruno
Copy link
Copy Markdown
Member

@abhishek-bruno abhishek-bruno commented Mar 30, 2026

Description

JIRA

  • Fixes the isJson assertion to accept JSON arrays (e.g. ["A55001213ZX0A"]), which were incorrectly rejected
  • Updates existing test and adds new test cases for array variants

Context

The isJson chai property explicitly excluded arrays with !Array.isArray(obj). This caused res.body: isJson assertions to fail for API responses returning JSON arrays — a valid and common response format.

Fixes #7556

Test plan

  • Existing isJson tests updated and passing
  • New tests for: array of strings, empty array, array of objects
  • Plain object assertions still pass
  • Cross-realm object assertions still pass
  • String and null still correctly fail

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • Bug Fixes

    • The isJson assertion now treats arrays (including empty arrays, arrays of primitives, and arrays of objects) as valid JSON; previously it accepted only plain objects. Assertion behavior and error reporting remain unchanged.
  • Tests

    • Test suite updated to mark array cases as passing JSON assertions while retaining failing cases for non-array negatives (e.g., strings, null).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 30, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c9dc41ea-4203-4fb2-9d22-b072ccfdaa0e

📥 Commits

Reviewing files that changed from the base of the PR and between 5301b71 and 6f88960.

📒 Files selected for processing (1)
  • packages/bruno-js/src/sandbox/quickjs/shims/test.js

Walkthrough

The isJson Chai assertion was relaxed to treat arrays as valid JSON (in addition to plain objects). The runtime and QuickJS shim assertion logic were updated accordingly, and tests were changed to expect arrays (including arrays of strings, empty arrays, and arrays of objects) to pass.

Changes

Cohort / File(s) Summary
Runtime assertion
packages/bruno-js/src/runtime/assert-runtime.js
Broadened isJson predicate to accept arrays by adding Array.isArray(obj) alongside the plain-object check. No other assertion behavior changed.
QuickJS shim
packages/bruno-js/src/sandbox/quickjs/shims/test.js
Applied the same isJson widening to the QuickJS shim so arrays are recognized as JSON there as well.
Tests
packages/bruno-js/tests/runtime.spec.js
Updated tests to expect array bodies (numbers, strings, empty arrays, arrays of objects) to pass isJson; retained failure expectations for strings and null.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

size/S

Suggested reviewers

  • helloanoop
  • naman-bruno
  • bijin-bruno

Poem

Arrays once stood outside the gate,
Now welcomed in — JSON feels great.
Tests adjusted, assertions cheer,
Small change, fewer developers in fear. 🎉

🚥 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 accurately summarizes the main change: refactoring isJson assertion to accept arrays as valid JSON, which directly addresses the linked issue #7556.
Linked Issues check ✅ Passed The PR successfully implements the core requirement from #7556: allowing isJson assertions to accept JSON arrays while maintaining existing behavior for plain objects, null, and strings.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the isJson assertion logic across runtime and test files—no unrelated modifications present.
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 unit tests (beta)
  • Create PR with unit tests

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.

@abhishek-bruno abhishek-bruno force-pushed the fix/isJson-assertion-accept-arrays branch 2 times, most recently from 483554a to 2eba837 Compare March 31, 2026 14:18
…ce test coverage

- Modified the JSON validation logic to accept arrays as valid JSON objects.
- Updated tests to ensure correct behavior for various array scenarios, including empty arrays and arrays of strings and objects.
@abhishek-bruno abhishek-bruno force-pushed the fix/isJson-assertion-accept-arrays branch from 2eba837 to 5301b71 Compare April 1, 2026 06:24
Comment thread packages/bruno-js/src/runtime/assert-runtime.js
… arrays

- Updated the JSON validation to allow arrays as valid JSON objects, ensuring compatibility with various data structures.
- Adjusted the test assertions to reflect the new validation criteria.
@bijin-bruno bijin-bruno merged commit 5c1dc11 into usebruno:main Apr 2, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assert Section Signals Invalid JSON For Array With String Values

2 participants