Skip to content

fix(secrets): block duplicate secret names to prevent value loss#8750

Open
pooja-bruno wants to merge 4 commits into
usebruno:mainfrom
pooja-bruno:fix/env-duplicate-secret-names
Open

fix(secrets): block duplicate secret names to prevent value loss#8750
pooja-bruno wants to merge 4 commits into
usebruno:mainfrom
pooja-bruno:fix/env-duplicate-secret-names

Conversation

@pooja-bruno

@pooja-bruno pooja-bruno commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes a data-loss bug in the Secrets tab (collection and global environments).

Adding two secrets with the same name and saving silently dropped the first one's value. Secret values are persisted in a separate name-keyed store and re-hydrated by first-match on read, so a second secret with a duplicate name overwrote the first on save. (The Variables tab is unaffected those values live inline in the .bru/env file, so duplicates are allowed there and lose nothing.

JIRA

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

  • New Features
    • Environment tabs now show live <sup> counts for enabled variables/secrets with non-empty names.
    • “Unsaved” status is reflected directly on the tab count badge styling.
  • Bug Fixes
    • Saves (including save-all) are blocked when multiple secret rows share the same name.
    • Inline validation highlights the most recently edited duplicate entry.
    • Duplicate-name save failures now display a dedicated error toast.
  • Tests
    • Expanded Playwright/Jest coverage for tab count/unsaved indicators and duplicate-secret save prevention.
Screen.Recording.2026-07-23.at.6.16.36.PM.mov

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Duplicate secret names are now validated in environment editors and save flows. Inline errors target the edited row, duplicate saves show a dedicated toast, and environment tabs display enabled-variable counts with unsaved styling. Tests and locators cover both collection and global environments.

Changes

Environment validation and indicators

Layer / File(s) Summary
Duplicate secret detection and save guards
packages/bruno-app/src/utils/environments.js, packages/bruno-app/src/utils/environments.spec.js, packages/bruno-app/src/providers/ReduxStore/slices/{collections/actions.js,global-environments.js}
Adds duplicate secret-name detection and rejects collection or global environment saves containing duplicates.
Editor validation and save error handling
packages/bruno-app/src/components/EnvironmentVariablesTable/index.js, packages/bruno-app/src/components/RequestTabs/RequestTab/index.js, tests/utils/page/*, tests/environments/environment-tabs/environment-tabs.spec.ts
Targets inline errors to the most recently edited duplicate row, validates active and all-tab saves, and displays dedicated duplicate-name toasts with coverage for both environment types.
Count-based environment tab indicators
packages/bruno-app/src/components/{Environments,WorkspaceHome}/.../EnvironmentDetails/*, tests/utils/page/locators.ts, tests/environments/environment-tabs/environment-tabs.spec.ts
Replaces draft icons with enabled named-variable counts and marks changed counts as unsaved. Tests verify per-tab count and save behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

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

Sequence Diagram(s)

sequenceDiagram
  participant EnvironmentEditor
  participant SaveFlow
  participant RequestTab
  participant Toast
  EnvironmentEditor->>SaveFlow: submit environment variables
  SaveFlow->>SaveFlow: detect duplicate secret names
  SaveFlow-->>RequestTab: reject duplicate save
  RequestTab->>Toast: show duplicate-name error
Loading

Poem

Secrets align in tidy rows,
Duplicate names now raise a sign,
Tabs count softly as change grows,
Unsaved badges brightly shine.
Save flows guard the finish line.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: blocking duplicate secret names to prevent lost values.
✨ 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: 2

Caution

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

⚠️ Outside diff range comments (1)
packages/bruno-app/src/components/RequestTabs/RequestTab/index.js (1)

257-281: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use showSaveError in both Save & Close flows.

The handlers at Lines 443-446 and 494-497 still replace the duplicate-secret rejection with generic errors, so closing a tab after creating duplicate secrets does not show the new actionable message.

Proposed fix
- .catch((err) => {
-   console.log('err', err);
-   toast.error('Failed to save environment');
- });
+ .catch(showSaveError);

Apply the equivalent change to the global-environment Save & Close handler.

🤖 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/components/RequestTabs/RequestTab/index.js` around
lines 257 - 281, Update both Save & Close handlers, including the
global-environment handler, to use the existing showSaveError callback when
their save promises reject. Replace the generic error toast handling while
preserving the current success behavior and duplicate-secret message.
🤖 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/environments/environment-tabs/environment-tabs.spec.ts`:
- Around line 181-207: Update the environment-tab scenarios at
tests/environments/environment-tabs/environment-tabs.spec.ts:181-207 and
:579-605 to assert the visible Variables and Secrets tab-count text after each
row is added and again after saving, using the expected enabled-item counts.
Retain the existing unsaved-class assertions, and apply the same count-text
coverage to the global-environments scenario.

In `@tests/utils/page/actions.ts`:
- Around line 844-855: Update addDuplicateRow so its CodeMirror editor click
targets the left edge, matching addRowToActiveTab, before typing the duplicate
value. Preserve the existing duplicate-row selection and keyboard typing flow.

---

Outside diff comments:
In `@packages/bruno-app/src/components/RequestTabs/RequestTab/index.js`:
- Around line 257-281: Update both Save & Close handlers, including the
global-environment handler, to use the existing showSaveError callback when
their save promises reject. Replace the generic error toast handling while
preserving the current success behavior and duplicate-secret message.
🪄 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: b84263fd-cecb-42a7-8215-f1a973fd1c07

📥 Commits

Reviewing files that changed from the base of the PR and between d57f859 and 8f6e529.

📒 Files selected for processing (14)
  • packages/bruno-app/src/components/EnvironmentVariablesTable/index.js
  • packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/StyledWrapper.js
  • packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/index.js
  • packages/bruno-app/src/components/RequestTabs/RequestTab/index.js
  • packages/bruno-app/src/components/WorkspaceHome/WorkspaceEnvironments/EnvironmentList/EnvironmentDetails/StyledWrapper.js
  • packages/bruno-app/src/components/WorkspaceHome/WorkspaceEnvironments/EnvironmentList/EnvironmentDetails/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js
  • packages/bruno-app/src/utils/environments.js
  • packages/bruno-app/src/utils/environments.spec.js
  • tests/environments/environment-tabs/environment-tabs.spec.ts
  • tests/utils/page/actions.ts
  • tests/utils/page/locators.ts
  • tests/utils/page/toast.ts

Comment thread tests/environments/environment-tabs/environment-tabs.spec.ts
Comment thread tests/utils/page/actions.ts Outdated

@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: 2

🧹 Nitpick comments (1)
tests/environments/environment-tabs/environment-tabs.spec.ts (1)

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

Keep selectors in shared page locators.

  • tests/environments/environment-tabs/environment-tabs.spec.ts#L13-L13: move the row-name-input locator to tests/utils/page/locators.ts.
  • tests/environments/environment-tabs/environment-tabs.spec.ts#L203-L211: use toastByMessage() for success-toast assertions.
  • tests/environments/environment-tabs/environment-tabs.spec.ts#L654-L662: use toastByMessage() for success-toast assertions.

As per path instructions, specs should consume page-module locators and reusable toast locator builders.

🤖 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/environments/environment-tabs/environment-tabs.spec.ts` at line 13, The
environment-tabs spec should use shared locators instead of defining or
asserting UI selectors locally: move varNameInput into
tests/utils/page/locators.ts, update its usages to consume the shared page
locator, and replace the success-toast assertions at
tests/environments/environment-tabs/environment-tabs.spec.ts lines 203-211 and
654-662 with toastByMessage().

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 `@tests/environments/environment-tabs/environment-tabs.spec.ts`:
- Around line 444-448: Remove the negative success-toast assertions from both
affected test steps in
tests/environments/environment-tabs/environment-tabs.spec.ts at lines 444-448
and 892-896. Keep the saveEnvironment call and positive DUPLICATE_SECRET_TOAST
visibility assertion, and do not add other negative toast assertions.
- Around line 873-904: The existing global-environment coverage only verifies
duplicate secret rejection; add a Variables-tab case that creates duplicate
variable names and confirms saving succeeds. Anchor the test near “blocks saving
two secrets that share a name,” use the global environment setup and Variables
tab, and assert the successful-save toast without expecting duplicate-variable
errors.

---

Nitpick comments:
In `@tests/environments/environment-tabs/environment-tabs.spec.ts`:
- Line 13: The environment-tabs spec should use shared locators instead of
defining or asserting UI selectors locally: move varNameInput into
tests/utils/page/locators.ts, update its usages to consume the shared page
locator, and replace the success-toast assertions at
tests/environments/environment-tabs/environment-tabs.spec.ts lines 203-211 and
654-662 with toastByMessage().
🪄 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: 71b6a738-033d-463b-bcf4-824e6c18486f

📥 Commits

Reviewing files that changed from the base of the PR and between 8f6e529 and 72de188.

📒 Files selected for processing (1)
  • tests/environments/environment-tabs/environment-tabs.spec.ts

Comment thread tests/environments/environment-tabs/environment-tabs.spec.ts Outdated
Comment thread tests/environments/environment-tabs/environment-tabs.spec.ts
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