Skip to content

remove activeEnvironmentUid and migration#7545

Merged
bijin-bruno merged 3 commits intousebruno:mainfrom
naman-bruno:rm/activeEnvironmentUid
Mar 23, 2026
Merged

remove activeEnvironmentUid and migration#7545
bijin-bruno merged 3 commits intousebruno:mainfrom
naman-bruno:rm/activeEnvironmentUid

Conversation

@naman-bruno
Copy link
Copy Markdown
Collaborator

@naman-bruno naman-bruno commented Mar 22, 2026

Description

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

  • Refactor

    • Per-workspace global environment selection is now persisted and restored separately for each workspace; selections survive restarts and workspace switching.
    • Workspace config files no longer store active environment entries; legacy selections are migrated into per-workspace persistence.
    • Closing a workspace clears its per-workspace active global environment selection.
  • Tests

    • Added end-to-end tests and fixtures validating migration and per-workspace environment persistence.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 22, 2026

Walkthrough

Migrates active global environment selection out of workspace.yml into a per-workspace persisted store, removes file-based selection APIs and the Redux selectWorkspaceEnvironment thunk, updates IPC handlers and migration logic, and adds integration tests and test helpers for migration and per-workspace persistence.

Changes

Cohort / File(s) Summary
Redux Action Removal
packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js
Removed exported selectWorkspaceEnvironment thunk; no replacement thunk added.
Global Environments Store
packages/bruno-electron/src/store/global-environments.js
Added per-workspace mapping activeGlobalEnvironmentUidByWorkspace and methods: getActiveGlobalEnvironmentUidForWorkspace, setActiveGlobalEnvironmentUidForWorkspace, removeActiveGlobalEnvironmentUidForWorkspace; setActiveGlobalEnvironmentUid relocated within class.
IPC: global environments
packages/bruno-electron/src/ipc/global-environments.js
Refactored IPC handlers (renderer:select-global-environment, renderer:delete-global-environment, renderer:get-global-environments) to accept/return workspace-scoped data and added migrateActiveGlobalEnvironmentUid(workspacePath) for migration from file/legacy store.
IPC: workspace
packages/bruno-electron/src/ipc/workspace.js
Removed renderer:select-workspace-environment handler; renderer:close-workspace now clears per-workspace active global env via globalEnvironmentsStore.removeActiveGlobalEnvironmentUidForWorkspace(workspacePath).
Workspace file/store handling
packages/bruno-electron/src/store/default-workspace.js, packages/bruno-electron/src/store/workspace-environments.js, packages/bruno-electron/src/utils/workspace-config.js
Stopped reading/writing activeEnvironmentUid in workspace.yml; removed per-workspace active-environment API from GlobalEnvironmentsManager; getGlobalEnvironments now returns only globalEnvironments.
Tests & Fixtures
tests/environments/.../fixtures/workspace/*, tests/environments/.../init-user-data/*, tests/environments/global-env-migration-from-file/*, tests/environments/global-env-workspace-persistence/*
Added fixtures and Playwright/Electron integration tests verifying migration from workspace.yml and per-workspace persistence across restarts.
Test helpers
tests/utils/page/actions.ts
Added createWorkspace(page, workspaceName) and switchWorkspace(page, workspaceName) helpers and exported them.

Sequence Diagram

sequenceDiagram
    participant User as User (UI)
    participant App as Electron Renderer
    participant IPC as Main IPC Handlers
    participant Store as globalEnvironmentsStore
    participant File as workspace.yml

    User->>App: choose environment in UI
    App->>IPC: renderer:select-global-environment { environmentUid, workspacePath }

    alt workspacePath provided
        IPC->>Store: setActiveGlobalEnvironmentUidForWorkspace(workspacePath, environmentUid || null)
        Store-->>IPC: ack
    else no workspacePath
        IPC->>Store: setActiveGlobalEnvironmentUid(environmentUid || null)
        Store-->>IPC: ack
    end

    Note over App,IPC: On startup — get and migrate active selection
    App->>IPC: renderer:get-global-environments (workspacePath)
    IPC->>Store: getActiveGlobalEnvironmentUidForWorkspace(workspacePath)
    alt uid in per-workspace store
        Store-->>IPC: return uid
    else migrate from file
        IPC->>File: read workspace.yml (activeEnvironmentUid?)
        alt uid in file
            File-->>IPC: return fileUid
            IPC->>Store: setActiveGlobalEnvironmentUidForWorkspace(workspacePath, migratedUid)
            IPC->>File: remove activeEnvironmentUid from workspace.yml
        else check legacy global store
            IPC->>Store: getActiveGlobalEnvironmentUid()
            Store-->>IPC: return legacyUid
            IPC->>Store: setActiveGlobalEnvironmentUidForWorkspace(workspacePath, migratedUid)
        end
    end
    IPC-->>App: { globalEnvironments, activeGlobalEnvironmentUid }
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • lohit-bruno
  • bijin-bruno
  • helloanoop

Poem

🌱 Files once held the active key, now stores tend every room,
Per-workspace memories wake and sleep inside the Electron bloom.
Tests march in to guard the path, migrations hum along,
UIDs find new nests to keep, and startup sings a steadier song. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: removal of activeEnvironmentUid and related migration logic from the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
tests/environments/global-env-migration-from-file/fixtures/workspace/workspace.yml (1)

6-8: Align single-collection fixture naming with convention.

Line 8 currently references collections/test-collection. If this scenario has only one collection fixture, prefer singular naming (collection/...) and keep this path aligned to reduce fixture-layout drift across e2e suites.

Based on learnings, "In Bruno e2e tests, organize fixture directories by collection count: use fixtures/collection (singular) when there is a single collection, and fixtures/collections (plural) when there are multiple collection directories inside the fixtures folder."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@tests/environments/global-env-migration-from-file/fixtures/workspace/workspace.yml`
around lines 6 - 8, The workspace.yml fixture lists a single collection under
the collections array with path "collections/test-collection"; rename the
fixture path to the singular convention by changing that path to
"collection/test-collection" (keeping the collection name "Test Collection"
unchanged) so the fixture directory follows the single-collection naming scheme
used across Bruno e2e tests.
tests/environments/global-env-migration-from-file/global-env-migration-from-file.spec.ts (1)

13-26: Consider extracting hash functions to a shared utility.

The simpleHash and generateUidBasedOnHash functions are duplicated from packages/bruno-electron/src/utils/common.js. If the production implementation changes, this test could pass while actual behavior differs.

Consider exporting these from a shared location or importing directly from the source (if build setup permits).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@tests/environments/global-env-migration-from-file/global-env-migration-from-file.spec.ts`
around lines 13 - 26, The test duplicates the hashing logic (simpleHash and
generateUidBasedOnHash) from packages/bruno-electron/src/utils/common.js which
can drift from production; replace the inline functions by importing the
canonical implementations (simpleHash and/or generateUidBasedOnHash) from that
shared util or move the functions into a shared test-usable utility module and
import them in global-env-migration-from-file.spec.ts so the test uses the same
hashing code as production (update import statements and remove the local
function definitions).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@tests/environments/global-env-migration-from-file/fixtures/workspace/workspace.yml`:
- Around line 6-8: The workspace.yml fixture lists a single collection under the
collections array with path "collections/test-collection"; rename the fixture
path to the singular convention by changing that path to
"collection/test-collection" (keeping the collection name "Test Collection"
unchanged) so the fixture directory follows the single-collection naming scheme
used across Bruno e2e tests.

In
`@tests/environments/global-env-migration-from-file/global-env-migration-from-file.spec.ts`:
- Around line 13-26: The test duplicates the hashing logic (simpleHash and
generateUidBasedOnHash) from packages/bruno-electron/src/utils/common.js which
can drift from production; replace the inline functions by importing the
canonical implementations (simpleHash and/or generateUidBasedOnHash) from that
shared util or move the functions into a shared test-usable utility module and
import them in global-env-migration-from-file.spec.ts so the test uses the same
hashing code as production (update import statements and remove the local
function definitions).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f0f99758-3e1a-40c8-843f-ad6f211c78e1

📥 Commits

Reviewing files that changed from the base of the PR and between 646c908 and 07a24f8.

📒 Files selected for processing (16)
  • packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js
  • packages/bruno-electron/src/ipc/global-environments.js
  • packages/bruno-electron/src/ipc/workspace.js
  • packages/bruno-electron/src/store/default-workspace.js
  • packages/bruno-electron/src/store/global-environments.js
  • packages/bruno-electron/src/store/workspace-environments.js
  • packages/bruno-electron/src/utils/workspace-config.js
  • tests/environments/global-env-migration-from-file/fixtures/workspace/collections/test-collection/bruno.json
  • tests/environments/global-env-migration-from-file/fixtures/workspace/environments/Alpha.yml
  • tests/environments/global-env-migration-from-file/fixtures/workspace/environments/Beta.yml
  • tests/environments/global-env-migration-from-file/fixtures/workspace/workspace.yml
  • tests/environments/global-env-migration-from-file/global-env-migration-from-file.spec.ts
  • tests/environments/global-env-migration-from-file/init-user-data/preferences.json
  • tests/environments/global-env-workspace-persistence/global-env-workspace-persistence.spec.ts
  • tests/environments/global-env-workspace-persistence/init-user-data/preferences.json
  • tests/utils/page/actions.ts
💤 Files with no reviewable changes (2)
  • packages/bruno-electron/src/utils/workspace-config.js
  • packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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/global-environments.js (1)

93-114: Add JSDoc to the new workspace-scoped API methods.

Please add brief JSDoc for getActiveGlobalEnvironmentUidForWorkspace, setActiveGlobalEnvironmentUidForWorkspace, and removeActiveGlobalEnvironmentUidForWorkspace.

As per coding guidelines "Add JSDoc comments to abstractions for additional details."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-electron/src/store/global-environments.js` around lines 93 -
114, Add JSDoc blocks above the three new workspace-scoped methods
getActiveGlobalEnvironmentUidForWorkspace,
setActiveGlobalEnvironmentUidForWorkspace, and
removeActiveGlobalEnvironmentUidForWorkspace describing their purpose and usage;
include `@param` tags (workspacePath: string) for all methods, an additional
`@param` (uid: string|null|undefined) for
setActiveGlobalEnvironmentUidForWorkspace, and `@returns` tags for
getActiveGlobalEnvironmentUidForWorkspace (string|undefined) and void for the
setters/removers, keeping the descriptions concise and matching the existing
coding style.
🤖 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-electron/src/store/global-environments.js`:
- Around line 93-114: Normalize workspacePath before using it as an object key
in getActiveGlobalEnvironmentUidForWorkspace,
setActiveGlobalEnvironmentUidForWorkspace, and
removeActiveGlobalEnvironmentUidForWorkspace: compute a single canonical key
(e.g., run the incoming workspacePath through a deterministic normalizer that
resolves/normalizes separators and collapses equivalent forms and applies a
consistent case strategy such as toLowerCase() on platforms or paths meant to be
case-insensitive), then use that canonical key for mapping reads, writes and
deletes instead of the raw workspacePath; ensure the same normalizer is applied
both when reading (get...) and when writing/removing (set... / remove...) so
stored entries are always found and removed reliably.

---

Nitpick comments:
In `@packages/bruno-electron/src/store/global-environments.js`:
- Around line 93-114: Add JSDoc blocks above the three new workspace-scoped
methods getActiveGlobalEnvironmentUidForWorkspace,
setActiveGlobalEnvironmentUidForWorkspace, and
removeActiveGlobalEnvironmentUidForWorkspace describing their purpose and usage;
include `@param` tags (workspacePath: string) for all methods, an additional
`@param` (uid: string|null|undefined) for
setActiveGlobalEnvironmentUidForWorkspace, and `@returns` tags for
getActiveGlobalEnvironmentUidForWorkspace (string|undefined) and void for the
setters/removers, keeping the descriptions concise and matching the existing
coding style.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d6c848b5-6d57-425e-8a5d-f06c610616ac

📥 Commits

Reviewing files that changed from the base of the PR and between 07a24f8 and b0fe901.

📒 Files selected for processing (3)
  • packages/bruno-electron/src/ipc/global-environments.js
  • packages/bruno-electron/src/ipc/workspace.js
  • packages/bruno-electron/src/store/global-environments.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-electron/src/ipc/global-environments.js

Comment thread packages/bruno-electron/src/store/global-environments.js
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/bruno-electron/src/store/global-environments.js (1)

104-110: Consider using strict equality for uid check.

The uid || null expression coerces any falsy value (empty string, 0) to null. If UIDs are always non-empty strings, this is fine. Otherwise, a more explicit check may be warranted.

Optional: explicit null handling
   setActiveGlobalEnvironmentUidForWorkspace(workspacePath, uid) {
     if (!workspacePath) return;
     const key = posixifyPath(workspacePath);
     const mapping = this.store.get('activeGlobalEnvironmentUidByWorkspace', {});
-    mapping[key] = uid || null;
+    mapping[key] = uid != null ? uid : null;
     this.store.set('activeGlobalEnvironmentUidByWorkspace', mapping);
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-electron/src/store/global-environments.js` around lines 104 -
110, In setActiveGlobalEnvironmentUidForWorkspace, avoid coercing falsy uids to
null via `uid || null`; instead explicitly handle absent values so valid falsy
UIDs (e.g., empty string or 0) are preserved — for example assign `mapping[key]
= uid == null ? null : uid` (or `typeof uid === 'undefined' ? null : uid`)
before calling `this.store.set('activeGlobalEnvironmentUidByWorkspace',
mapping)`; this change lives alongside posixifyPath, mapping, and the
store.get/store.set usage in that function.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/bruno-electron/src/store/global-environments.js`:
- Around line 104-110: In setActiveGlobalEnvironmentUidForWorkspace, avoid
coercing falsy uids to null via `uid || null`; instead explicitly handle absent
values so valid falsy UIDs (e.g., empty string or 0) are preserved — for example
assign `mapping[key] = uid == null ? null : uid` (or `typeof uid === 'undefined'
? null : uid`) before calling
`this.store.set('activeGlobalEnvironmentUidByWorkspace', mapping)`; this change
lives alongside posixifyPath, mapping, and the store.get/store.set usage in that
function.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 56bb3815-8305-41da-86c2-fb75a4668790

📥 Commits

Reviewing files that changed from the base of the PR and between b0fe901 and 1c00f36.

📒 Files selected for processing (1)
  • packages/bruno-electron/src/store/global-environments.js

@bijin-bruno bijin-bruno merged commit f1d7f00 into usebruno:main Mar 23, 2026
10 of 11 checks passed
chirag-bruno pushed a commit to chirag-bruno/bruno that referenced this pull request Mar 24, 2026
* remove activeEnvironmentUid and migration

* fix: no environment handling

* fix: standardize workspace path handling
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.

2 participants