Skip to content

fix(workspaces): switch to default workspace on close so header shows correct name#8425

Open
ravindra-bruno wants to merge 6 commits into
usebruno:mainfrom
ravindra-bruno:fix/bru-3663
Open

fix(workspaces): switch to default workspace on close so header shows correct name#8425
ravindra-bruno wants to merge 6 commits into
usebruno:mainfrom
ravindra-bruno:fix/bru-3663

Conversation

@ravindra-bruno

@ravindra-bruno ravindra-bruno commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Description

BRU3663

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

  • Bug Fixes
    • Closing a workspace now also cleans up its scratch collection in the app state (when present).
    • If the closed workspace was the active one, the app now switches back to the default workspace.
    • More resilient behavior when a workspace ID can’t be found, avoiding unnecessary IPC calls.
  • Tests
    • Added Jest coverage for workspace close behavior (scratch cleanup, active-workspace switching, and error handling).
    • Added an end-to-end Playwright test to confirm returning to the default workspace and restoring collections.
@coderabbitai

coderabbitai Bot commented Jun 30, 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

closeWorkspaceAction now removes a scratch collection when present, removes the workspace, and switches to the default workspace if the closed workspace was active. New Jest and Playwright tests cover the updated close flow.

Changes

Workspace Close Cleanup

Layer / File(s) Summary
closeWorkspaceAction cleanup logic
packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js
Dispatches removeCollection when scratchCollectionUid exists, removes the workspace, and switches to the default workspace UID when the closed workspace was active.
closeWorkspaceAction Jest coverage
packages/bruno-app/src/providers/ReduxStore/slices/workspaces/closeWorkspaceAction.spec.js
Mocks IPC and supporting modules, builds minimal workspace state for the thunk, and asserts IPC pathname usage, conditional scratch removal, workspace removal, default-workspace switching, and the missing-UID error path.
workspace close Playwright coverage
tests/workspace/close-workspace-returns-to-default.spec.ts
Sets up two workspaces in Electron, closes the active secondary workspace through the UI, and verifies the app returns to the default workspace with the prior collection visible again.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • usebruno/bruno#6457: Changes the same closeWorkspaceAction flow in packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js.
  • usebruno/bruno#7462: Updates related workspace lifecycle Redux logic that also manages scratch collection cleanup and active-workspace transitions.

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • bijin-bruno
  • naman-bruno

Poem

A workspace shuts with tidy grace,
Scratch collections leave the place.
Default returns to take the helm,
While tests keep watch across the realm.

🚥 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 reflects the main behavior change: switching back to the default workspace after closing one.
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

🧹 Nitpick comments (1)
packages/bruno-app/src/providers/ReduxStore/slices/workspaces/closeWorkspaceAction.spec.js (1)

10-10: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the pathname fixtures OS-agnostic.

These test fixtures hardcode POSIX separators ('/default', '/team'), which bakes Unix-shaped paths into a cross-platform Electron suite. Build them with path.join()/path.resolve() instead so the tests exercise realistic Windows/macOS/Linux inputs too. As per path instructions, "File paths must use path.join() or path.resolve() instead of hardcoded / or \\ separators'."

Also applies to: 46-47, 53-54, 60-61, 67-68, 74-75, 81-82

🤖 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/providers/ReduxStore/slices/workspaces/closeWorkspaceAction.spec.js`
at line 10, The workspace pathname fixtures in closeWorkspaceAction.spec.js are
hardcoded with POSIX separators, so update the test data to build paths using
path.join() or path.resolve() instead of literal slash-based strings. Apply this
to DEFAULT_WORKSPACE and the other workspace fixtures in the spec, and ensure
the tests reference these path utilities consistently so the suite stays
OS-agnostic across Windows, macOS, and Linux.

Source: Path instructions

🤖 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/providers/ReduxStore/slices/workspaces/actions.js`:
- Around line 1003-1009: Switch the active workspace before calling
removeWorkspace so the store never points at a deleted workspace during the
close flow. In the workspace-close logic around removeWorkspace and
switchWorkspace, keep the fallback selection based on
getState().workspaces.workspaces and dispatch
switchWorkspace(defaultWorkspace.uid) first when wasActive is true, then
removeWorkspace(workspaceUid) afterward. This preserves a valid
activeWorkspaceUid for the header immediately after closing the current
workspace.

In
`@packages/bruno-app/src/providers/ReduxStore/slices/workspaces/closeWorkspaceAction.spec.js`:
- Around line 59-64: The workspace-closing spec assertions are too indirect and
can miss the real behavior. Update the tests around closeWorkspaceAction/run so
they assert the exact dispatched action or thunk result: for the
no-scratch-collection case, verify no removeCollection action with a real
payload is dispatched, and for the active-workspace path, spy on or assert
switchWorkspace(DEFAULT_WORKSPACE.uid) directly rather than only checking that
some thunk was dispatched. Use the existing closeWorkspaceAction,
removeCollection, and switchWorkspace symbols to locate the relevant
expectations and make the tests fail on the wrong behavior.
- Around line 27-41: The `run()` helper in `closeWorkspaceAction.spec.js` uses a
stateless `dispatch = jest.fn()`, so `getState()` never reflects reducer updates
and can hide ordering bugs in `closeWorkspaceAction`. Replace it with a small
mocked store/reducer setup that mutates the workspace state when
`removeWorkspace()` and related actions are dispatched, then continue asserting
against the observed `dispatched` and `thunks` from `closeWorkspaceAction` to
verify the real sequencing and fallback behavior.

---

Nitpick comments:
In
`@packages/bruno-app/src/providers/ReduxStore/slices/workspaces/closeWorkspaceAction.spec.js`:
- Line 10: The workspace pathname fixtures in closeWorkspaceAction.spec.js are
hardcoded with POSIX separators, so update the test data to build paths using
path.join() or path.resolve() instead of literal slash-based strings. Apply this
to DEFAULT_WORKSPACE and the other workspace fixtures in the spec, and ensure
the tests reference these path utilities consistently so the suite stays
OS-agnostic across Windows, macOS, and Linux.
🪄 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: 6f2aed2f-b00f-46e8-a3c6-79afb0eda6e8

📥 Commits

Reviewing files that changed from the base of the PR and between 49b9af1 and 26238c9.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js
  • packages/bruno-app/src/providers/ReduxStore/slices/workspaces/closeWorkspaceAction.spec.js
@helloanoop

Copy link
Copy Markdown
Contributor

@ravindra-bruno Can we get a e2e test for this in place ?

@ravindra-bruno

Copy link
Copy Markdown
Collaborator Author

@ravindra-bruno Can we get a e2e test for this in place ?

Added the e2e tests for the closing workspace and returning to default.

@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

🤖 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 `@tests/workspace/close-workspace-returns-to-default.spec.ts`:
- Around line 33-57: The workspace-close spec is using brittle CSS class and
index-based selectors for the workspace switcher and actions menu. Update the
locators in close-workspace-returns-to-default.spec.ts to use stable test ids,
roles, labels, or existing helper-backed selectors instead of .switcher-name,
.workspace-actions-trigger, and .first(). Prefer storing these stable locators
in variables and reusing them in the affected test steps so the assertions and
clicks remain resilient to UI refactors.
🪄 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: beadaed6-90a8-46f9-9bf5-0b8894760112

📥 Commits

Reviewing files that changed from the base of the PR and between 953a71b and e157bea.

📒 Files selected for processing (1)
  • tests/workspace/close-workspace-returns-to-default.spec.ts
Comment thread tests/workspace/close-workspace-returns-to-default.spec.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants