fix(cloud-tests): render nested JSON in manual remediation steps correctly#2919
Merged
Conversation
…ectly
Customer Simon reported that an IAM bucket policy embedded in an
auto-generated manual step was rendering with parts inside the code
block and parts as plain prose. Verified the cause in
RemediationDialog's `TextWithInlineCode`: the previous splitter used
a regex that only handles ONE level of brace nesting
\{[^{}]*"(?:Version|Effect|Statement)"[^{}]*(?:\{[^{}]*\}[^{}]*)*\}
so a CloudTrail bucket policy — which has two-deep nesting via
`Statement[].Principal.{...}` AND `Statement[].Condition.StringEquals.
{...}` — matched only the first Statement object. The outer
`{"Version":...,"Statement":[` wrapper and the second Statement
escaped into prose around the code block.
Replaces the regex with a brace-balanced scan in a new helper
`extract-json-segments.ts`:
- Walks the string counting braces, respecting string literals and
escaped quotes so `"description":"} { inside"` doesn't confuse
the depth counter.
- Validates each candidate via `JSON.parse` before classifying it
as a code block — invalid candidates fall through to text so we
don't render garbage.
- Pure function, no React/DOM, easy to test in isolation.
18 unit tests cover: arbitrary nesting, arrays of objects, multiple
JSONs in one step, escaped quotes, unbalanced braces, the customer-
reported CloudTrail-policy round-trip, and the no-JSON pass-through.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
🎉 This PR is included in version 3.63.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Customer Simon reported a rendering bug: an IAM bucket policy embedded in an AI-generated manual remediation step rendered with parts inside the code block and parts spilling out as plain prose. Cause traced to
RemediationDialog.tsx:179— the JSON splitter used a regex that only handles one level of brace nesting:A CloudTrail bucket policy has TWO levels of nesting (
Statement[].Principal.{Service}ANDStatement[].Condition.StringEquals.{...}), so the regex matched only the firstStatementobject. The outer{"Version":...,"Statement":[wrapper and the secondStatementescaped around the code block.Fix
New pure helper
extract-json-segments.tsdoes a brace-balanced scan:"description":"} { inside"doesn't confuse the depth counter).JSON.parsebefore classifying as a code block — invalid candidates fall through to text.Segment[]taggedtextorjson.TextWithInlineCodenow delegates to this helper and removes the regex entirely.Tests
18 unit tests on
extract-json-segments.test.ts:Backward compat
"Version","Effect", or"Statement". The new scanner handles any JSON object/array. Steps that used to render correctly still do. Steps that used to misrender now render correctly.Manual test plan
🤖 Generated with Claude Code
Summary by cubic
Fixes nested JSON rendering in manual remediation steps by replacing the regex splitter with a brace-balanced parser. IAM/S3 bucket policies now render as a single formatted code block without prose spillover.
Bug Fixes
JSON.parse; invalid or unbalanced blocks stay as text.Refactors
extract-json-segmentsand updatedRemediationDialogto use it.TextWithInlineCode.Written for commit 014c4ab. Summary will update on new commits. Review in cubic