Skip to content

fix(workspace): heal legacy object entries in lastOpenedWorkspaces#8769

Open
vijayh-bruno wants to merge 1 commit into
usebruno:mainfrom
vijayh-bruno:fix/workspace-preferences-schema
Open

fix(workspace): heal legacy object entries in lastOpenedWorkspaces#8769
vijayh-bruno wants to merge 1 commit into
usebruno:mainfrom
vijayh-bruno:fix/workspace-preferences-schema

Conversation

@vijayh-bruno

@vijayh-bruno vijayh-bruno commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Description

Problem:

Workspaces disappearing after upgrade when preferences.jsonworkspaces.lastOpenedWorkspaces contains legacy object entries mixed with string paths. Startup code assumed every entry was a string and called
path.join(entry, 'workspace.yml'). On an object entry, this threw a TypeError, which aborted workspace resolution and made the handler return an empty list. So one bad entry wiped out every workspace, leaving only the default "My Workspace".

Fix:

  • Normalise entries in the store: keep strings, recover the path from an
    object's pathname, drop anything unusable, and de-duplicate. So callers
    only ever see a string-only list.

  • migrate() runs once on load and rewrites preferences.json to the clean string-only array, scrubbing the legacy/experimental build-related objects from disk.

  • Guard isValidWorkspacePathOnDisk against non-string input as defense.

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.

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

    • Improved handling of previously saved workspaces by removing duplicates and ignoring invalid entries.
    • Added compatibility for older saved workspace formats.
    • Prevented workspace validation errors when invalid or empty paths are provided.
  • Tests

    • Added coverage for invalid workspace path inputs across supported validation options.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Electron workspace handling now normalizes persisted workspace entries, migrates legacy values, de-duplicates paths, and rejects invalid startup path inputs before filesystem checks. Tests cover non-string inputs with and without configuration validation.

Changes

Workspace handling

Layer / File(s) Summary
Normalize and migrate persisted workspaces
packages/bruno-electron/src/store/last-opened-workspaces.js
Legacy workspace objects are converted to valid path strings, duplicates are removed, persisted values are migrated when needed, and getAll() returns normalized data.
Guard workspace path validation
packages/bruno-electron/src/utils/workspace-startup.js, packages/bruno-electron/tests/utils/workspace-startup.spec.js
Non-string or empty workspace paths now return false before filesystem access, with tests covering both validation modes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: naman-bruno, bijin-bruno, utkarsh-bruno

Poem

Old paths shed their object skin,
Duplicates drift away,
Invalid inputs meet a guard,
Before the disk can say.
Workspaces start more neatly today.

🚥 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 matches the main change: migrating and normalizing legacy lastOpenedWorkspaces entries.
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: 1

🧹 Nitpick comments (1)
packages/bruno-electron/src/store/last-opened-workspaces.js (1)

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

Add focused coverage for the persistence migration.

The supplied tests cover startup input validation but not legacy pathname recovery, invalid-entry removal, duplicate collapse, or rewrite-on-change behavior. Add behavior-level tests for these cases before merging.

As per coding guidelines, meaningful code changes must add or update deterministic behavior-driven tests.

Also applies to: 45-55

🤖 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/store/last-opened-workspaces.js` around lines 10
- 28, Add deterministic behavior-driven tests for normalizeWorkspaceEntry and
normalizeWorkspaceEntries covering legacy object pathname recovery, removal of
invalid entries, collapsing duplicate string/pathname values, and persistence
rewriting when normalized data differs from stored data. Keep existing startup
validation coverage intact and assert observable persisted output rather than
implementation details.

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-electron/tests/utils/workspace-startup.spec.js`:
- Around line 123-124: Update both isValidWorkspacePathOnDisk expectations in
the workspace startup test to use an OS-neutral temporary path built with
path.join(os.tmpdir(), 'ws') instead of the hardcoded '/tmp/ws', adding the
required path and os imports if absent.

---

Nitpick comments:
In `@packages/bruno-electron/src/store/last-opened-workspaces.js`:
- Around line 10-28: Add deterministic behavior-driven tests for
normalizeWorkspaceEntry and normalizeWorkspaceEntries covering legacy object
pathname recovery, removal of invalid entries, collapsing duplicate
string/pathname values, and persistence rewriting when normalized data differs
from stored data. Keep existing startup validation coverage intact and assert
observable persisted output rather than implementation details.
🪄 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 Plus

Run ID: fdfe67c8-62b6-45c9-bd4f-db66edd9733c

📥 Commits

Reviewing files that changed from the base of the PR and between c70c5fe and 20e6d87.

📒 Files selected for processing (3)
  • packages/bruno-electron/src/store/last-opened-workspaces.js
  • packages/bruno-electron/src/utils/workspace-startup.js
  • packages/bruno-electron/tests/utils/workspace-startup.spec.js

Comment on lines +123 to +124
expect(isValidWorkspacePathOnDisk({ pathname: '/tmp/ws' })).toBe(false);
expect(isValidWorkspacePathOnDisk({ pathname: '/tmp/ws' }, { validateConfig: true })).toBe(false);

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use an OS-neutral temporary path in the test.

The new fixtures hardcode /tmp/ws. Although the guard returns before filesystem access today, this embeds Unix-only path syntax in a cross-platform test suite. Use path.join(os.tmpdir(), 'ws') instead.

As per path instructions, use os.tmpdir() instead of hardcoded /tmp and build paths with path.join() or path.resolve().

🤖 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/tests/utils/workspace-startup.spec.js` around lines
123 - 124, Update both isValidWorkspacePathOnDisk expectations in the workspace
startup test to use an OS-neutral temporary path built with
path.join(os.tmpdir(), 'ws') instead of the hardcoded '/tmp/ws', adding the
required path and os imports if absent.

Source: Path instructions

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.

1 participant