Repository navigation
feat(openapi-sync): preserve user-configured request values on sync - #8204
bijin-bruno merged 1 commit into
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds a preserveValues toggle in the SyncReviewPage UI and threads that choice into ExpandableEndpointRow, useSyncFlow, and Electron IPC handlers; implements preserve-aware masking and merge helpers in main-process code, exports helpers for tests, and adds extensive Jest coverage. ExpandableEndpointRow also suppresses stale diff responses with a requestIdRef. ChangesOpenAPI Preserve Values Synchronization
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 (1)
packages/bruno-app/src/components/OpenAPISyncTab/SyncReviewPage/index.js (1)
243-251: ⚡ Quick winAdd
data-testidfor Playwright testing.The toggle button is a key user interaction point but lacks a test identifier.
🧪 Suggested fix
<button className={`bulk-btn ${preserveValues ? 'active' : ''}`} onClick={() => setPreserveValues((v) => !v)} aria-pressed={preserveValues} title="When on, your edited values (body, params, headers, auth, {{vars}}) are kept; only fields the spec adds or removes change. When off, spec values overwrite yours." + data-testid="preserve-values-toggle" >As per coding guidelines: "Add
data-testidto testable elements for Playwright".🤖 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 `@packages/bruno-app/src/components/OpenAPISyncTab/SyncReviewPage/index.js` around lines 243 - 251, The toggle button in SyncReviewPage lacks a Playwright test id; add a data-testid attribute to the button element that contains the preserveValues state and setPreserveValues handler (the button rendering the IconCheck/IconInfoCircle) — e.g., data-testid="preserve-values-toggle" — so tests can reliably select it; ensure the attribute is added on the same button that uses preserveValues, setPreserveValues, IconCheck and IconInfoCircle.Source: Coding guidelines
🤖 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 `@packages/bruno-app/src/components/OpenAPISyncTab/SyncReviewPage/index.js`:
- Around line 243-251: The toggle button in SyncReviewPage lacks a Playwright
test id; add a data-testid attribute to the button element that contains the
preserveValues state and setPreserveValues handler (the button rendering the
IconCheck/IconInfoCircle) — e.g., data-testid="preserve-values-toggle" — so
tests can reliably select it; ensure the attribute is added on the same button
that uses preserveValues, setPreserveValues, IconCheck and IconInfoCircle.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1ddce66d-4c18-4b24-8452-a9b0a7f89b0f
📒 Files selected for processing (5)
packages/bruno-app/src/components/OpenAPISyncTab/EndpointChangeSection/ExpandableEndpointRow.jspackages/bruno-app/src/components/OpenAPISyncTab/SyncReviewPage/index.jspackages/bruno-app/src/components/OpenAPISyncTab/hooks/useSyncFlow.jspackages/bruno-electron/src/ipc/openapi-sync.jspackages/bruno-electron/tests/ipc/openapi-sync-merge.spec.js
cce8319 to
1a377ee
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/bruno-app/src/components/OpenAPISyncTab/StyledWrapper.js (1)
1848-1853: ⚡ Quick winUse theme tokens for knob/shadow colors in this styled-component block.
Line 1848 and Line 1853 hardcode visual colors (
#fff,rgba(0, 0, 0, 0.2)) instead of theme-driven values.As per coding guidelines: "Use styled component's theme prop to manage CSS colors and not CSS variables when in the context of a styled component".Suggested fix
.preserve-toggle-knob { @@ - background: `#fff`; + background: ${(props) => props.theme.background.base}; @@ - box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); + box-shadow: 0 1px 2px ${(props) => rgba(props.theme.text, 0.2)}; }🤖 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 `@packages/bruno-app/src/components/OpenAPISyncTab/StyledWrapper.js` around lines 1848 - 1853, Replace the hardcoded colors in the StyledWrapper styled-component (the knob element’s background: `#fff` and box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2)) with theme tokens by using the theme prop—e.g. background: ${({ theme }) => theme.colors.background || theme.palette.background.paper} and box-shadow: ${({ theme }) => theme.shadows?.small || `0 1px 2px ${theme.colors.shadow || 'rgba(0,0,0,0.2)'}`}; update the CSS lines in StyledWrapper.js accordingly so all color and shadow values come from theme instead of hardcoded literals.Source: Coding guidelines
🤖 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.
Inline comments:
In `@packages/bruno-app/src/components/OpenAPISyncTab/StyledWrapper.js`:
- Around line 1827-1839: The .preserve-toggle button lacks a keyboard
focus-visible style making it hard for keyboard users to see focus; update the
StyledWrapper CSS to add a :focus-visible rule for .preserve-toggle (and the
other toggle at 1840-1858) that applies a visible outline or box-shadow and
ensures sufficient contrast (e.g., theme primary color), preserves border-radius
and does not alter layout, and include -webkit-focus-ring-color fallback for
cross-browser consistency so keyboard focus is clearly visible.
---
Nitpick comments:
In `@packages/bruno-app/src/components/OpenAPISyncTab/StyledWrapper.js`:
- Around line 1848-1853: Replace the hardcoded colors in the StyledWrapper
styled-component (the knob element’s background: `#fff` and box-shadow: 0 1px 2px
rgba(0, 0, 0, 0.2)) with theme tokens by using the theme prop—e.g. background:
${({ theme }) => theme.colors.background || theme.palette.background.paper} and
box-shadow: ${({ theme }) => theme.shadows?.small || `0 1px 2px
${theme.colors.shadow || 'rgba(0,0,0,0.2)'}`}; update the CSS lines in
StyledWrapper.js accordingly so all color and shadow values come from theme
instead of hardcoded literals.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ba319f6b-ad3d-4dc3-b272-22123bfe8092
📒 Files selected for processing (6)
packages/bruno-app/src/components/OpenAPISyncTab/EndpointChangeSection/ExpandableEndpointRow.jspackages/bruno-app/src/components/OpenAPISyncTab/StyledWrapper.jspackages/bruno-app/src/components/OpenAPISyncTab/SyncReviewPage/index.jspackages/bruno-app/src/components/OpenAPISyncTab/hooks/useSyncFlow.jspackages/bruno-electron/src/ipc/openapi-sync.jspackages/bruno-electron/tests/ipc/openapi-sync-merge.spec.js
🚧 Files skipped from review as they are similar to previous changes (4)
- packages/bruno-app/src/components/OpenAPISyncTab/hooks/useSyncFlow.js
- packages/bruno-app/src/components/OpenAPISyncTab/EndpointChangeSection/ExpandableEndpointRow.js
- packages/bruno-app/src/components/OpenAPISyncTab/SyncReviewPage/index.js
- packages/bruno-electron/tests/ipc/openapi-sync-merge.spec.js
9f91a67 to
c07e58d
Compare
Reconcile request structure against the spec on sync while preserving the
user's values (JSON body, params, headers, auth) and {{var}} references for
fields that still exist. A "Preserve values" toggle (default on) on the Spec
Updates review controls it; turning it off lets spec values overwrite. The diff
preview's EXPECTED column shows the post-merge result so unchanged values do not
render as changes.
- field-level merge for JSON body (by key path), form fields and params/headers
(by name, duplicate names paired positionally), preserving value + enabled
- {{var}} masking so interpolated bodies parse, merge and restore safely,
using a private-use sentinel that never collides with body text
- auth merged by mode: same mode keeps the user's values and adds spec-introduced
fields; a mode change takes the spec. compareRequestFields compares auth by
mode only, so preserved auth values no longer mark the collection out of sync
- preserveValues threaded through apply and diff-preview IPC handlers
- reset path left unchanged; scripts/tests/assertions preserved in sync and reset
- 67 unit tests covering the merge helpers and masking edge cases
c07e58d to
f06c9a3
Compare
…sebruno#8204) Reconcile request structure against the spec on sync while preserving the user's values (JSON body, params, headers, auth) and {{var}} references for fields that still exist. A "Preserve values" toggle (default on) on the Spec Updates review controls it; turning it off lets spec values overwrite. The diff preview's EXPECTED column shows the post-merge result so unchanged values do not render as changes. - field-level merge for JSON body (by key path), form fields and params/headers (by name, duplicate names paired positionally), preserving value + enabled - {{var}} masking so interpolated bodies parse, merge and restore safely, using a private-use sentinel that never collides with body text - auth merged by mode: same mode keeps the user's values and adds spec-introduced fields; a mode change takes the spec. compareRequestFields compares auth by mode only, so preserved auth values no longer mark the collection out of sync - preserveValues threaded through apply and diff-preview IPC handlers - reset path left unchanged; scripts/tests/assertions preserved in sync and reset - 67 unit tests covering the merge helpers and masking edge cases
Description
Discussion: #7401
On the Spec Updates sync, Bruno currently overwrites a request's body, params, headers and auth wholesale, destroying user-entered values and
{{envVar}}references whenever the spec changes shape. This PR makes sync reconcile the request structure against the spec while preserving the user's values for fields that still exist.JIRA : https://usebruno.atlassian.net/browse/BRU-3205
A "Preserve values" toggle (default ON) on the Spec Updates review toolbar controls this. With it on, your edits are kept and only the spec's structural additions/removals are applied; with it off, spec values overwrite (the seam for an explicit "take the spec's version"). The diff preview's EXPECTED column shows the post-merge result, so unchanged values no longer render as changes.
What changed
Backend —
packages/bruno-electron/src/ipc/openapi-sync.jsvalue+enabled.{{var}}masking so an interpolated body can be parsed, merged and restored safely — using a private-use sentinel that never collides with body text and never reaches disk.compareRequestFieldsnow compares auth by mode only, so preserved auth values no longer keep the collection permanently "out of sync".preserveValues(defaulttrue) threaded throughrenderer:apply-openapi-syncandrenderer:get-endpoint-diff-data. Reset path left unchanged; scripts/tests/assertions preserved in both sync and reset.Frontend —
OpenAPISyncTabNote for reviewers — one intended behavior change:
compareRequestFieldsno longer flags auth config differences (e.g. apikey placement, oauth2 url/scope) when the auth mode is unchanged; only a mode change is drift. This is required so preserved auth values don't perpetually re-flag the endpoint.Tests: 67 unit tests in
packages/bruno-electron/tests/ipc/openapi-sync-merge.spec.jscovering the merge helpers and{{var}}masking edge cases (string boundaries, object keys, nested/array bodies, many vars, dual-side). Fullbruno-electronandbruno-appsuites pass.Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge.
Summary by CodeRabbit