Repository navigation
feat: implement collection migration to YML format - #7669
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 BRU→YML collection migration feature with a dismissible toolbar pill that alerts users, a settings component providing conversion with backup export options, a Redux thunk orchestrating the Electron-side migration, and E2E test coverage for the pill behavior. The toolbar pill persists dismissal state in localStorage by collection pathname; clicking navigates to settings where users confirm conversion and trigger the thunk. ChangesBRU to YML Migration Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/bruno-app/src/components/CollectionSettings/Overview/Migration/index.js (1)
53-72: Add a stable test id to the new migration CTA.This button is now part of the e2e surface, so giving it a
data-testidwill make the spec less brittle to copy or layout changes.♻️ Suggested change
<Button + data-testid="migrate-collection-to-yml-button" size="sm" color="primary" className="mt-2"As per coding guidelines, 'Add
data-testidto testable elements for Playwright.'🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-app/src/components/CollectionSettings/Overview/Migration/index.js` around lines 53 - 72, The new migration CTA lacks a stable test id; add a data-testid attribute to the Button that opens the confirm modal (the Button with onClick={() => setShowConfirmModal(true)} and props disabled={isMigrating} loading={isMigrating}) such as data-testid="migrate-to-yml-cta" and also add a matching data-testid to the confirm button inside the Modal (the Modal using title="Migrate to YML format" and handleConfirm={handleMigrate}) so Playwright tests can reliably target both the CTA and the confirm action.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 3236-3249: The current flow removes the old collection
(dispatch(_removeCollection) and dispatch(closeAllCollectionTabs)) before
attempting to open/mount the replacement, which can leave the UI without the
collection if openCollectionEvent(uid, collectionPathname, updatedBrunoConfig)
or mountCollection(...) fails; change the sequence so you first attempt to open
and mount the new collection (dispatch(openCollectionEvent(...)) and await
dispatch(mountCollection(...))) and only after both succeed
dispatch(_removeCollection({ collectionUid })) and
dispatch(closeAllCollectionTabs({ collectionUid })), or alternatively implement
a failure rollback that re-dispatches the old collection state and reopens tabs
when mountCollection fails; ensure you reference the same
uid/collectionPathname/updatedBrunoConfig when performing the open/mount and use
collectionUid when removing/closing tabs so state remains consistent.
In `@packages/bruno-electron/src/ipc/collection.js`:
- Around line 2466-2517: The migration must be made transactional: instead of
writing final yml files and deleting .bru sources as you go, stage every
converted file using temporary names (e.g., create yml content via
stringifyCollection/stringifyFolder/stringifyRequest/stringifyEnvironment and
write to a safe temp pathname alongside the target using writeFile), keep track
of mappings from temp -> final and original -> backup, and only perform atomic
swaps (fs.renameSync temp -> final) and delete originals (fs.unlinkSync original
.bru and only remove collectionBruPath and brunoJsonPath) after all conversions
succeed; on any error, roll back by removing any staged temp files and leaving
originals untouched (or restore from backups if you implemented backup renames)
and rethrow/handle the error.
---
Nitpick comments:
In
`@packages/bruno-app/src/components/CollectionSettings/Overview/Migration/index.js`:
- Around line 53-72: The new migration CTA lacks a stable test id; add a
data-testid attribute to the Button that opens the confirm modal (the Button
with onClick={() => setShowConfirmModal(true)} and props disabled={isMigrating}
loading={isMigrating}) such as data-testid="migrate-to-yml-cta" and also add a
matching data-testid to the confirm button inside the Modal (the Modal using
title="Migrate to YML format" and handleConfirm={handleMigrate}) so Playwright
tests can reliably target both the CTA and the confirm action.
🪄 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: 82026683-25f1-4e3b-8a12-e58dda96e098
📒 Files selected for processing (15)
packages/bruno-app/src/components/CollectionSettings/Overview/Info/index.jspackages/bruno-app/src/components/CollectionSettings/Overview/Migration/StyledWrapper.jspackages/bruno-app/src/components/CollectionSettings/Overview/Migration/index.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-electron/src/ipc/collection.jstests/collection/migrate-to-yml/fixtures/collection/api/folder.brutests/collection/migrate-to-yml/fixtures/collection/api/get-users.brutests/collection/migrate-to-yml/fixtures/collection/bruno.jsontests/collection/migrate-to-yml/fixtures/collection/collection.brutests/collection/migrate-to-yml/fixtures/collection/environments/Local.brutests/collection/migrate-to-yml/fixtures/collection/environments/Production.brutests/collection/migrate-to-yml/fixtures/collection/ping.brutests/collection/migrate-to-yml/fixtures/collection/post-json.brutests/collection/migrate-to-yml/init-user-data/preferences.jsontests/collection/migrate-to-yml/migrate-to-yml.spec.ts
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (2)
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js (1)
3235-3256:⚠️ Potential issue | 🟠 MajorDon't tear down the live collection before the replacement mounts.
Lines 3240-3241 remove the collection and close all of its tabs before
openCollectionEvent()andmountCollection()have succeeded. If either step fails, the fallback only recreates bare collection state; it does not restore the user's tabs or mount state. Keep the existing collection alive until the replacement mount completes, or capture and restore that UI state during rollback.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js` around lines 3235 - 3256, The code removes the live collection (dispatch(_removeCollection) and dispatch(closeAllCollectionTabs)) before the new YAML-backed collection is opened and mounted, risking lost tabs/state on failure; change the flow so you first capture the current collection UI state (tabs and mount info), then invoke ipcRenderer and call dispatch(openCollectionEvent(...)) and await dispatch(mountCollection(...)) for the updatedBrunoConfig, and only after the mount succeeds dispatch _removeCollection/closeAllCollectionTabs for the old collection (or alternatively dispatch replacement actions that preserve tabs); on any error use the captured UI state plus oldBrunoConfig to fully restore tabs and mount state in the catch block (referencing openCollectionEvent, mountCollection, _removeCollection, closeAllCollectionTabs, oldBrunoConfig, updatedBrunoConfig, and reopenError).packages/bruno-electron/src/ipc/collection.js (1)
2469-2553:⚠️ Potential issue | 🔴 CriticalMake the on-disk migration atomic.
Lines 2524-2528 start deleting the source
.brufiles andbruno.jsonbefore the handler knows the rest of the migration has succeeded. If any later delete orgetCollectionStats()call fails, the catch block only removes the new.ymlfiles, so the collection can be left with neither the original sources nor the migrated output. Oncebruno.jsonis gone, the watcher restart path can also no longer reconstruct the original config. Stage the YML files first and only swap/delete originals after every conversion succeeds.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-electron/src/ipc/collection.js` around lines 2469 - 2553, The migration currently deletes originals (bruFilesToDelete and brunoJsonPath via fs.unlinkSync) before verifying conversion succeeded; move the deletion/swap so originals are only removed after conversion, stats and ymlBrunoConfig updates succeed. Concretely: keep collecting writtenYmlFiles and bruFilesToDelete and do not call fs.unlinkSync(bruFile) or fs.unlinkSync(brunoJsonPath) inside the try block before getCollectionStats(); instead, after awaiting getCollectionStats() and assigning ymlBrunoConfig.size/filesCount (but before returning ymlBrunoConfig), perform the deletion of each path in bruFilesToDelete and then unlink brunoJsonPath (or perform an atomic rename/swap if preferred). Ensure the catch block still only cleans up writtenYmlFiles and that watcher.addWatcher can read bruno.json if deletion never occurred.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 3233-3255: The rollback currently reopens the collection using
oldBrunoConfig which lacks opencollection and causes Redux to treat the restored
UI as BRU; change the catch rollback to reopen using updatedBrunoConfig (or
reload the brunoConfig from disk) when calling openCollectionEvent so the
restored collection format matches the migrated files—update the restore call
that currently references oldBrunoConfig to use updatedBrunoConfig (or invoke
the config reload helper before dispatching openCollectionEvent) and keep
mountCollection/openCollectionEvent usage consistent.
- Around line 3259-3260: The code unconditionally dispatches
toggleCollection(uid), which flips the collapsed state and can re-collapse a
migrated collection; instead, before dispatching, check the current collection
collapsed state (e.g., via the store/selector for collection with id uid or
using getState()) and only call dispatch(toggleCollection(uid)) if that
collection is currently collapsed, or replace the call with an explicit expand
action (e.g., dispatch(expandCollection(uid))) if such an action exists; update
the logic around toggleCollection, uid and the collection state check
accordingly.
---
Duplicate comments:
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 3235-3256: The code removes the live collection
(dispatch(_removeCollection) and dispatch(closeAllCollectionTabs)) before the
new YAML-backed collection is opened and mounted, risking lost tabs/state on
failure; change the flow so you first capture the current collection UI state
(tabs and mount info), then invoke ipcRenderer and call
dispatch(openCollectionEvent(...)) and await dispatch(mountCollection(...)) for
the updatedBrunoConfig, and only after the mount succeeds dispatch
_removeCollection/closeAllCollectionTabs for the old collection (or
alternatively dispatch replacement actions that preserve tabs); on any error use
the captured UI state plus oldBrunoConfig to fully restore tabs and mount state
in the catch block (referencing openCollectionEvent, mountCollection,
_removeCollection, closeAllCollectionTabs, oldBrunoConfig, updatedBrunoConfig,
and reopenError).
In `@packages/bruno-electron/src/ipc/collection.js`:
- Around line 2469-2553: The migration currently deletes originals
(bruFilesToDelete and brunoJsonPath via fs.unlinkSync) before verifying
conversion succeeded; move the deletion/swap so originals are only removed after
conversion, stats and ymlBrunoConfig updates succeed. Concretely: keep
collecting writtenYmlFiles and bruFilesToDelete and do not call
fs.unlinkSync(bruFile) or fs.unlinkSync(brunoJsonPath) inside the try block
before getCollectionStats(); instead, after awaiting getCollectionStats() and
assigning ymlBrunoConfig.size/filesCount (but before returning ymlBrunoConfig),
perform the deletion of each path in bruFilesToDelete and then unlink
brunoJsonPath (or perform an atomic rename/swap if preferred). Ensure the catch
block still only cleans up writtenYmlFiles and that watcher.addWatcher can read
bruno.json if deletion never occurred.
🪄 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: bc7ae1b6-af91-4268-a180-7e4aa66d370a
📒 Files selected for processing (2)
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-electron/src/ipc/collection.js
There was a problem hiding this comment.
♻️ Duplicate comments (1)
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js (1)
3238-3250:⚠️ Potential issue | 🟠 MajorCollection removed before replacement is ready.
The collection is removed from Redux and tabs are closed (lines 3238-3239) before
openCollectionEventandmountCollectioncomplete. If either fails, the collection disappears from the UI. The catch block at line 3251 attempts recovery but doesn't callmountCollection, leaving the collection in an unmounted state (no watcher, items won't load).Consider reordering so removal happens only after successful mount, or ensure the fallback also mounts the collection.
🔧 Suggested reordering approach
.then(async (updatedBrunoConfig) => { - // Remove old collection state so we can recreate it with the new yml config. - // openCollectionEvent requires no existing collection with the same pathname. - dispatch(_removeCollection({ collectionUid })); - dispatch(closeAllCollectionTabs({ collectionUid })); - try { + // Remove old collection state so we can recreate it with the new yml config. + // openCollectionEvent requires no existing collection with the same pathname. + dispatch(_removeCollection({ collectionUid })); + dispatch(closeAllCollectionTabs({ collectionUid })); + // Reopen the collection with updated config (now yml format) await dispatch(openCollectionEvent(uid, collectionPathname, updatedBrunoConfig)); // Mount the collection (starts the watcher and loads items) await dispatch(mountCollection({ collectionUid: uid, collectionPathname: collectionPathname, brunoConfig: updatedBrunoConfig })); } catch (reopenError) { // Files on disk are already yml, so restore with updatedBrunoConfig (not old bru config) await dispatch(openCollectionEvent(uid, collectionPathname, updatedBrunoConfig)); + await dispatch(mountCollection({ + collectionUid: uid, + collectionPathname: collectionPathname, + brunoConfig: updatedBrunoConfig + })); throw reopenError; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js` around lines 3238 - 3250, The code dispatches _removeCollection and closeAllCollectionTabs before attempting openCollectionEvent and mountCollection, so failures leave the collection removed/unmounted; change the flow so you first call await dispatch(openCollectionEvent(...)) and await dispatch(mountCollection(...)) and only after both succeed dispatch(_removeCollection({ collectionUid })) and dispatch(closeAllCollectionTabs({ collectionUid })), or alternatively keep the current removal ordering but update the catch block to call dispatch(mountCollection(...)) with the original/updated brunoConfig (and re-open via openCollectionEvent if needed) to ensure the collection is mounted and watcher/items are started on recovery; update references around openCollectionEvent, mountCollection, _removeCollection, and closeAllCollectionTabs accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 3238-3250: The code dispatches _removeCollection and
closeAllCollectionTabs before attempting openCollectionEvent and
mountCollection, so failures leave the collection removed/unmounted; change the
flow so you first call await dispatch(openCollectionEvent(...)) and await
dispatch(mountCollection(...)) and only after both succeed
dispatch(_removeCollection({ collectionUid })) and
dispatch(closeAllCollectionTabs({ collectionUid })), or alternatively keep the
current removal ordering but update the catch block to call
dispatch(mountCollection(...)) with the original/updated brunoConfig (and
re-open via openCollectionEvent if needed) to ensure the collection is mounted
and watcher/items are started on recovery; update references around
openCollectionEvent, mountCollection, _removeCollection, and
closeAllCollectionTabs accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2504a85f-aa63-441b-a012-49b00dd0c5c1
📒 Files selected for processing (2)
packages/bruno-app/src/components/CollectionSettings/Overview/Migration/index.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
✅ Files skipped from review due to trivial changes (1)
- packages/bruno-app/src/components/CollectionSettings/Overview/Migration/index.js
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/bruno-app/src/components/CollectionSettings/Overview/Migration/index.js (1)
24-26: ⚡ Quick winDo not silently swallow migration failures.
The empty catch drops the rejection context, which makes failed migrations look like no-ops and hurts diagnosability. Handle the error explicitly (toast/log/rethrow) while keeping the
finallyreset.Suggested minimal change
dispatch(migrateCollectionToYml(collection.uid)) - .catch(() => { }) + .catch((error) => { + toast.error(error?.message || 'Failed to migrate collection'); + }) .finally(() => setIsMigrating(false));🤖 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/CollectionSettings/Overview/Migration/index.js` around lines 24 - 26, The catch block in the migration promise chain (where migrateCollectionToYml is called) silently swallows errors with an empty handler, making failures invisible and hard to debug. Replace the empty catch block with explicit error handling that either logs the error, shows a toast notification, or rethrows it to provide visibility into migration failures, while keeping the finally block that resets setIsMigrating(false) intact.
🤖 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/RequestTabs/CollectionHeader/index.js`:
- Around line 602-620: The migrate pill button contains a nested interactive
element (the span with className pill-dismiss that has onClick and
role="button") inside the outer button, which violates HTML semantics and
creates keyboard accessibility issues. Refactor the structure by wrapping both
interactive elements in a parent container and making them sibling buttons: the
main outer button should handle the viewCollectionSettings action, and the
dismiss span with className pill-dismiss should be converted to a separate
sibling button that handles the dismissMigratePill action instead of being
nested as a child with onClick.
---
Nitpick comments:
In
`@packages/bruno-app/src/components/CollectionSettings/Overview/Migration/index.js`:
- Around line 24-26: The catch block in the migration promise chain (where
migrateCollectionToYml is called) silently swallows errors with an empty
handler, making failures invisible and hard to debug. Replace the empty catch
block with explicit error handling that either logs the error, shows a toast
notification, or rethrows it to provide visibility into migration failures,
while keeping the finally block that resets setIsMigrating(false) intact.
🪄 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: a750e444-052a-4154-a804-6d0565984a8e
📒 Files selected for processing (5)
packages/bruno-app/src/components/CollectionSettings/Overview/Migration/StyledWrapper.jspackages/bruno-app/src/components/CollectionSettings/Overview/Migration/index.jspackages/bruno-app/src/components/RequestTabs/CollectionHeader/StyledWrapper.jspackages/bruno-app/src/components/RequestTabs/CollectionHeader/index.jstests/collection/migrate-to-yml/migrate-to-yml-pill.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/bruno-app/src/components/CollectionSettings/Overview/Migration/StyledWrapper.js
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/bruno-app/src/components/RequestTabs/CollectionHeader/StyledWrapper.js (1)
194-200: ⚡ Quick winAlign
.display-iconblock with repo formatting rules.Please add spacing before
{and a trailing semicolon after theborder-radiusdeclaration to keep this block consistent with the project’s JS/styled-components style conventions.Proposed minimal diff
- .display-icon{ + .display-icon { padding: 4px; box-sizing: content-box; &:hover { background: ${(props) => props.theme.sidebar.collection.item.hoverBg}; - border-radius: ${(props) => props.theme.border.radius.sm} + border-radius: ${(props) => props.theme.border.radius.sm}; } }As per coding guidelines, statements should end with semicolons and punctuation/spacing should remain consistent.
🤖 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/RequestTabs/CollectionHeader/StyledWrapper.js` around lines 194 - 200, The `.display-icon` CSS block in StyledWrapper.js has two formatting inconsistencies with the project's style guidelines. Add a space before the opening brace after `.display-icon` (changing `.display-icon{` to `.display-icon {`), and add a trailing semicolon after the `border-radius` CSS property declaration within the `&:hover` block. These changes ensure the styled-components syntax adheres to the repository's formatting conventions for consistency.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/RequestTabs/CollectionHeader/StyledWrapper.js`:
- Around line 194-200: The `.display-icon` CSS block in StyledWrapper.js has two
formatting inconsistencies with the project's style guidelines. Add a space
before the opening brace after `.display-icon` (changing `.display-icon{` to
`.display-icon {`), and add a trailing semicolon after the `border-radius` CSS
property declaration within the `&:hover` block. These changes ensure the
styled-components syntax adheres to the repository's formatting conventions for
consistency.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 971fa1df-07be-4601-803e-c3f544b7a37a
📒 Files selected for processing (3)
packages/bruno-app/src/components/RequestTabs/CollectionHeader/StyledWrapper.jspackages/bruno-app/src/components/RequestTabs/CollectionHeader/index.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
💤 Files with no reviewable changes (1)
- packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js
utkarsh-bruno
left a comment
There was a problem hiding this comment.
I see the critical coderabbit review is already addressed. Looks good to me.
Description
JIRA
Contribution Checklist:
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
Summary
New Features
Tests