Repository navigation
fix(snapshot): normalize renderer:get-last-opened-workspaces output to avoid reactivating a deleted workspace - #8033
Conversation
WalkthroughThis PR normalizes workspace paths when handling snapshot-driven opens, adjusts switch logic for ChangesStale Workspace Snapshot Restoration
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly Related PRs
Suggested Reviewers
🚥 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: 1
🧹 Nitpick comments (1)
tests/snapshots/workspace.spec.ts (1)
55-58: ⚡ Quick winPrefer event-driven waits over hardcoded timeouts.
page.waitForTimeout(2000)is a magic sleep. Per guidelines, replace brittle timeouts with event-driven waits. If the intent is to ensure snapshot persistence before closing, consider waiting for a specific IPC completion or a UI indicator.🤖 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 `@tests/snapshots/workspace.spec.ts` around lines 55 - 58, The test currently uses a brittle sleep (page.waitForTimeout(2000)) inside the test.step before calling closeElectronApp; replace this with an event-driven wait that confirms snapshot persistence (e.g., wait for a specific IPC completion event, a network/IPC response, or a UI indicator) instead of a fixed timeout. Update the test.step to remove page.waitForTimeout and instead await a durable signal such as page.waitForSelector(...) for a saved indicator, page.waitForFunction(...) that checks the app state, or an IPC event listener that resolves when the snapshot save completes, then call closeElectronApp(app).
🤖 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/snapshots/workspace.spec.ts`:
- Line 12: The test in tests/snapshots/workspace.spec.ts uses an empty
description (the call to test('', async ({ launchElectronApp, createTmpDir }) =>
{ ... })) which makes reports unreadable; replace the empty string with a
concise, meaningful description summarizing what the test asserts (e.g., "opens
workspace and matches snapshot" or similar) so test runner output is clear—edit
the test(...) invocation in that file to provide the new description string.
---
Nitpick comments:
In `@tests/snapshots/workspace.spec.ts`:
- Around line 55-58: The test currently uses a brittle sleep
(page.waitForTimeout(2000)) inside the test.step before calling
closeElectronApp; replace this with an event-driven wait that confirms snapshot
persistence (e.g., wait for a specific IPC completion event, a network/IPC
response, or a UI indicator) instead of a fixed timeout. Update the test.step to
remove page.waitForTimeout and instead await a durable signal such as
page.waitForSelector(...) for a saved indicator, page.waitForFunction(...) that
checks the app state, or an IPC event listener that resolves when the snapshot
save completes, then call closeElectronApp(app).
🪄 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: 644b27bd-dd82-4fae-85dc-e2cceca4d591
📒 Files selected for processing (2)
packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.jstests/snapshots/workspace.spec.ts
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent Bruno from reactivating a workspace that has been deleted from disk by normalizing workspace path comparisons during snapshot hydration, and it adds an end-to-end snapshot test to cover the “deleted workspace” restoration scenario.
Changes:
- Normalize
workspacePathvssnapshot.activeWorkspacePathcomparisons when deciding whether to switch workspaces onworkspaceOpenedEvent. - When opening the default workspace, fall back to it if the snapshot’s active workspace path is no longer present in the persisted “last opened workspaces” list.
- Add a new Playwright Electron snapshot spec that deletes a workspace directory and asserts the app restores the default workspace state after restart.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/snapshots/workspace.spec.ts | Adds an e2e snapshot test to validate default workspace restoration when the previously active workspace has been deleted. |
| packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js | Normalizes workspace path comparisons and adds logic to avoid switching to a stale/deleted workspace referenced by snapshot state. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
renderer:get-last-opened-workspaces output to avoid reactivating a deleted workspacerenderer:get-last-opened-workspaces output to avoid reactivating a deleted workspace
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/utils/page/actions.ts (1)
1435-1446: ⚡ Quick winUse typed parameters and wrap in
test.stepfor better reporting.The function uses
anytypes forappandpage, reducing type safety.ElectronApplicationandPagetypes are imported and available. Additionally, per coding guidelines,test.stepshould be used extensively for better report readability—similar helpers in this file wrap their logic intest.step.♻️ Refactor for type safety and reporting
-const openWorkspaceFromDialog = async (app: any, page: any, targetPath: string) => { - await app.evaluate( - ({ dialog }: { dialog: DialogOptions }, workspacePath: string) => { - dialog.showOpenDialog = () => - Promise.resolve({ canceled: false, filePaths: [workspacePath] }); - }, - targetPath - ); - - await page.getByTestId('workspace-menu').click(); - await page.locator('.dropdown-item').filter({ hasText: 'Open workspace' }).click(); -}; +const openWorkspaceFromDialog = async (app: ElectronApplication, page: Page, targetPath: string) => { + await test.step(`Open workspace from dialog: ${targetPath}`, async () => { + await app.evaluate( + ({ dialog }: { dialog: DialogOptions }, workspacePath: string) => { + dialog.showOpenDialog = () => + Promise.resolve({ canceled: false, filePaths: [workspacePath] }); + }, + targetPath + ); + + await page.getByTestId('workspace-menu').click(); + await page.locator('.dropdown-item').filter({ hasText: 'Open workspace' }).click(); + }); +};As per coding guidelines, promote the use of
test.stepas much as possible so the generated reports are easier to read.🤖 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 `@tests/utils/page/actions.ts` around lines 1435 - 1446, The helper openWorkspaceFromDialog uses untyped parameters and lacks test.step wrappers; change its signature to use ElectronApplication and Page (instead of any), and wrap each logical action (stubbing dialog.showOpenDialog via app.evaluate and the UI clicks via page.getByTestId/locator) in test.step calls for clearer reporting; update references inside the evaluate callback to match the typed invocation and ensure the Promise.resolve stub remains unchanged while preserving the passed targetPath argument.tests/snapshots/workspace.spec.ts (1)
50-50: ⚡ Quick winDocument the
waitForTimeoutusage or replace with event-driven wait.Each test uses
page.waitForTimeout(2000)before closing the app without explanation. Per coding guidelines,waitForTimeoutshould be reduced unless absolutely necessary. If the wait is necessary to allow workspace snapshot writes to complete, add a comment explaining this; otherwise, consider using an event-driven alternative (e.g.,app.evaluateto verify the snapshot file has been written).📝 Example: Add explanatory comment
+ // Wait for workspace snapshot to be persisted to disk before closing await page.waitForTimeout(2000); await closeElectronApp(app);Higher-effort alternative: Use
app.evaluateto poll for snapshot file modification time or expose an IPC event when snapshot writes complete.As per coding guidelines, try to reduce usage of
page.waitForTimeout();in code unless absolutely necessary and the locator cannot be found using existingexpect()playwright calls.Also applies to: 94-94, 138-138, 193-193, 243-243
🤖 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 `@tests/snapshots/workspace.spec.ts` at line 50, Replace the blind sleeps (calls to page.waitForTimeout(2000)) with either a short explanatory comment if the delay is truly required for async snapshot writes, or—preferably—an event-driven wait: have the test use app.evaluate / page.evaluate to poll for the workspace snapshot file modification or expose/listen to an IPC/event like "snapshot-saved" so the test waits for that signal (replace occurrences of page.waitForTimeout at the spots in tests/snapshots/workspace.spec.ts). If you keep the wait, add a concise comment explaining why 2000ms is necessary and reference the snapshot write operation; otherwise implement the file-existence or IPC-based check to deterministically wait for snapshot completion.
🤖 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 `@tests/snapshots/workspace.spec.ts`:
- Line 50: Replace the blind sleeps (calls to page.waitForTimeout(2000)) with
either a short explanatory comment if the delay is truly required for async
snapshot writes, or—preferably—an event-driven wait: have the test use
app.evaluate / page.evaluate to poll for the workspace snapshot file
modification or expose/listen to an IPC/event like "snapshot-saved" so the test
waits for that signal (replace occurrences of page.waitForTimeout at the spots
in tests/snapshots/workspace.spec.ts). If you keep the wait, add a concise
comment explaining why 2000ms is necessary and reference the snapshot write
operation; otherwise implement the file-existence or IPC-based check to
deterministically wait for snapshot completion.
In `@tests/utils/page/actions.ts`:
- Around line 1435-1446: The helper openWorkspaceFromDialog uses untyped
parameters and lacks test.step wrappers; change its signature to use
ElectronApplication and Page (instead of any), and wrap each logical action
(stubbing dialog.showOpenDialog via app.evaluate and the UI clicks via
page.getByTestId/locator) in test.step calls for clearer reporting; update
references inside the evaluate callback to match the typed invocation and ensure
the Promise.resolve stub remains unchanged while preserving the passed
targetPath argument.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4deb18ba-ec0c-484a-9436-fca762650d25
📒 Files selected for processing (2)
tests/snapshots/workspace.spec.tstests/utils/page/actions.ts
… to avoid reactivating a deleted workspace (usebruno#8033) * fix: normalize workspace paths during workspace switch to prevent stale state * chore: test text * tests(snapshot): more workspace coverage
… to avoid reactivating a deleted workspace (usebruno#8033) * fix: normalize workspace paths during workspace switch to prevent stale state * chore: test text * tests(snapshot): more workspace coverage
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
Bug Fixes
Tests