Skip to content

feat(collections): enhance collection management by adding reset functionality and improving tab restoration logic - #8651

Closed
utkarsh-bruno wants to merge 10 commits into
usebruno:mainfrom
utkarsh-bruno:feat/migrate-to-yml
Closed

utkarsh-bruno wants to merge 10 commits into
usebruno:mainfrom
utkarsh-bruno:feat/migrate-to-yml

Conversation

@utkarsh-bruno

@utkarsh-bruno utkarsh-bruno commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Added resetCollectionForReopen action to clear stale items and environments when reopening collections.
  • Updated openCollectionEvent to ensure proper handling of existing collections and prevent stale data.
  • Enhanced tab restoration logic to avoid wiping open tabs when all snapshot tabs are stale.
  • Introduced tests for new functionality and improved existing tests for collection and tab management.

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.

Summary by CodeRabbit

  • New Features

    • Added the ability to cancel an in-progress “migrate to YML” from the migration dialog.
  • Bug Fixes

    • Reopening collections now refreshes contents, clears stale in-memory data, and avoids restoring outdated tabs.
    • Removing collections (and removing from workspace) now clears relevant cached indices and request UID/config data.
    • Folder seq metadata no longer defaults to position 1 and is preserved only when explicitly provided.
  • Improvements

    • Migration to YML is safer with conflict checks, rollback on failure, cancellation support, and automatic reload on completion.

…tionality and improving tab restoration logic
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

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

Walkthrough

Existing collection reopening resets stale Redux state before remounting. BRU-to-YML migration uses cancellable plan-and-apply IPC with rollback handling, while collection removal clears scoped caches. YML folder sequence fields are preserved only when explicitly numeric.

Changes

Collection reopen and tab restoration

Layer / File(s) Summary
Workspace-aware reopen flow
packages/bruno-app/src/providers/ReduxStore/slices/collections/*, packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js
Existing collections reset items, environments, and format state before remounting; workspace reconciliation, mount ordering, and validation coverage were updated.
Snapshot and tab restoration guards
packages/bruno-app/src/providers/ReduxStore/slices/tabs*
Stale .bru/.yml request tabs are filtered during restoration, while in-place tab-path migration is removed.

BRU-to-YML migration

Layer / File(s) Summary
Migration orchestration and cancellation
packages/bruno-app/src/components/CollectionSettings/..., packages/bruno-app/src/providers/ReduxStore/slices/collections/*, packages/bruno-electron/src/services/snapshot/index.js
Migration closes tabs, resets collection state, supports cancellation, and removes prior in-place migration actions and snapshot path remapping.
Planned migration and rollback
packages/bruno-electron/src/ipc/collection.js
Migration parses and validates files before writing, detects collisions, reloads watchers, supports cancellation, and removes generated outputs on failure.

Collection deletion cleanup

Layer / File(s) Summary
Scoped cache teardown
packages/bruno-electron/src/cache/*, packages/bruno-electron/src/ipc/*, packages/bruno-electron/src/services/mount/*, packages/bruno-electron/src/store/*
Removed collections clear mount indexes, stored Bruno configuration, and request UID caches.

Folder sequence serialization

Layer / File(s) Summary
Optional folder sequence handling
packages/bruno-filestore/src/formats/yml/*Folder*
Folder parsing and serialization omit absent sequence values and preserve explicit numeric values through tests.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • usebruno/bruno#8553: Overlaps with migration orchestration and removal of in-place tab-path rewriting.
  • usebruno/bruno#8450: Directly overlaps with snapshot tab path handling during BRU-to-YML migration.
  • usebruno/bruno#8609: Overlaps with restoreTabs filtering of stale .bru/.yml request paths.

Suggested reviewers: helloanoop, lohit-bruno, naman-bruno, sid-bruno, bijin-bruno

Poem

BRU files march to YML bright,
Watchers pause, then spring to light.
Stale tabs drift away,
Old caches lose their stay,
And folder seqs keep order right.

🚥 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 clearly summarizes the main changes: collection reset functionality and improved tab restoration logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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-electron/src/ipc/collection.js`:
- Around line 2720-2740: Update the migration flow around rollback, source
deletion, and the post-write cleanup paths so rollback is permitted only before
the commit point established after successfully writing opencollection.yml.
After BRU source deletion begins, handle cleanup, statistics, and remount
failures without invoking rollback or deleting migrated YML outputs; use the
existing writtenYmlFiles, movedUids, and rolledBack state consistently.
- Around line 2827-2837: The migration write phase in the conversion plan must
not overwrite pre-existing YML targets. Before the first write in the loop over
conversionPlan, validate every ymlPath for collisions and abort before writing
if any target already exists; alternatively, preserve original contents and
restore them during rollback. Ensure writtenYmlFiles and rollback deletion only
include files created by this migration.
- Around line 2703-2705: Move the bruno.json read and parse in the collection
synchronization flow before removeWatcher, or include both operations within the
same guarded try/recovery scope. Ensure failures in readFileSync or JSON.parse
do not leave the watcher permanently detached, while preserving the existing
brunoConfig loading behavior.
🪄 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: c6fc1f7b-8c92-4888-af39-582dd6ebb062

📥 Commits

Reviewing files that changed from the base of the PR and between 227138b and 01c1c7f.

📒 Files selected for processing (21)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/file-mode.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/migrate-in-place.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/tabs-migrate.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/tabs.js
  • packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js
  • packages/bruno-app/src/utils/snapshot/index.js
  • packages/bruno-app/src/utils/snapshot/index.spec.js
  • packages/bruno-electron/src/app/collection-watcher.js
  • packages/bruno-electron/src/cache/requestUids.js
  • packages/bruno-electron/src/ipc/collection.js
  • packages/bruno-electron/src/ipc/mount.js
  • packages/bruno-electron/src/services/mount/file-index.js
  • packages/bruno-electron/src/services/mount/manager.js
  • packages/bruno-electron/src/store/bruno-config.js
  • packages/bruno-filestore/src/formats/yml/parseFolder.spec.ts
  • packages/bruno-filestore/src/formats/yml/parseFolder.ts
  • packages/bruno-filestore/src/formats/yml/stringifyFolder.spec.ts
  • packages/bruno-filestore/src/formats/yml/stringifyFolder.ts

Comment on lines +2703 to +2705
const brunoJsonPath = path.join(collectionPathname, 'bruno.json');
const brunoJsonContent = fs.readFileSync(brunoJsonPath, 'utf8');
const brunoConfig = JSON.parse(brunoJsonContent);

@coderabbitai coderabbitai Bot Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Load the configuration before detaching the watcher.

These reads occur after removeWatcher but outside the guarded try. Missing or malformed bruno.json therefore leaves live synchronization permanently detached. Read/parse first, or include watcher removal and configuration loading in the same recovery scope.

🧰 Tools
🪛 ast-grep (0.44.1)

[warning] 2703-2703: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.readFileSync(brunoJsonPath, 'utf8')
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(detect-non-literal-fs-filename)

🤖 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-electron/src/ipc/collection.js` around lines 2703 - 2705, Move
the bruno.json read and parse in the collection synchronization flow before
removeWatcher, or include both operations within the same guarded try/recovery
scope. Ensure failures in readFileSync or JSON.parse do not leave the watcher
permanently detached, while preserving the existing brunoConfig loading
behavior.

✅ Addressed in commit 88c19f6

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/bruno-electron/src/ipc/collection.js (1)

2764-2806: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Yield during phase-one conversion so cancellation can be processed.

This loop uses synchronous reads and parsing without an await, blocking Electron’s main event loop. The cancellation IPC cannot update migrationCancellations until planning finishes, making cancellation ineffective during the longest phase.

Proposed fix
       for (const bruFilePath of bruFiles) {
+        await new Promise((resolve) => setImmediate(resolve));
         checkCancelled();
         const basename = path.basename(bruFilePath);
         const dirname = path.dirname(bruFilePath);
🤖 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-electron/src/ipc/collection.js` around lines 2764 - 2806,
Update the phase-one conversion loop around the bruFiles iteration to yield to
the event loop between synchronous read/parse operations, allowing cancellation
IPC to update migrationCancellations while planning is in progress. Preserve the
existing checkCancelled behavior, conversionPlan population, and parseErrors
handling.
🤖 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/CollectionSettings/Overview/Migration/MigrateToYmlModal/index.js`:
- Around line 51-59: Update the backup export control in MigrateToYmlModal to be
disabled whenever isMigrating is true, preventing ZIP export during migration
and cancellation. Preserve the existing export-disabled behavior by combining
this condition with the current isExporting state.

---

Outside diff comments:
In `@packages/bruno-electron/src/ipc/collection.js`:
- Around line 2764-2806: Update the phase-one conversion loop around the
bruFiles iteration to yield to the event loop between synchronous read/parse
operations, allowing cancellation IPC to update migrationCancellations while
planning is in progress. Preserve the existing checkCancelled behavior,
conversionPlan population, and parseErrors handling.
🪄 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: 503f5638-0a47-484c-91a6-6f392c8fc969

📥 Commits

Reviewing files that changed from the base of the PR and between 88c19f6 and 692dbb0.

📒 Files selected for processing (8)
  • packages/bruno-app/src/components/CollectionSettings/Overview/Migration/MigrateToYmlModal/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/migrate-in-place.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/tabs-migrate.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/tabs.js
  • packages/bruno-electron/src/ipc/collection.js
  • packages/bruno-electron/src/services/snapshot/index.js
💤 Files with no reviewable changes (3)
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/migrate-in-place.spec.js
  • packages/bruno-electron/src/services/snapshot/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/tabs.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-app/src/providers/ReduxStore/slices/tabs-migrate.spec.js

@sid-bruno

sid-bruno commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

Assume I have a git tracked folder and I revert the migration on the same collection, I no longer see the Migrate To YML button anymore. Is that expected ? Can be moved out of scope for the current version but would like to know if it is considered a valid scenario

…k config only, preventing stale format issues after migration
@utkarsh-bruno

Copy link
Copy Markdown
Collaborator Author

Assume I have a git tracked folder and I revert the migration on the same collection, I no longer see the Migrate To YML button anymore. Is that expected ? Can be moved out of scope for the current version but would like to know if it is considered a valid scenario

added a small change to read it the format from the disk and not falling back to the prev.
The issue currently is that there will be duplicate file (.yml and .bru) that the user will be able to see on the sidebar.
This is because of another issue with the watcher, for example, if I delete the collection folder from the directory, the collection is still visible on bruno. That fix should take care of the duplicate files as well.

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.

3 participants