Skip to content

feat(filesystem)/decouple display names from filesystem names & resolve collisions silently - #8586

Closed
sachin-thakur-bruno wants to merge 13 commits into
usebruno:release/v4.1.0from
sachin-thakur-bruno:feat/app-naming-collisions
Closed

sachin-thakur-bruno wants to merge 13 commits into
usebruno:release/v4.1.0from
sachin-thakur-bruno:feat/app-naming-collisions

Conversation

@sachin-thakur-bruno

@sachin-thakur-bruno sachin-thakur-bruno commented Jul 13, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Previously, we used the same value for both an item's display name (what users see) and its filesystem name (the file/folder on disk). This meant duplicate names caused filesystem conflicts, leading to failed clone/paste operations, path already exists errors, and inconsistent error messages exposing filesystem paths and IPC details.

This PR separates those two concepts.

Users can now freely use duplicate display names, while we automatically resolves any filesystem collisions by appending numeric suffixes (name, name1, name2, ...). Filesystem naming becomes an implementation detail instead of something users have to manage.

JIRA

Screen.Recording.2026-07-14.at.2.06.57.PM.mov

Behavior changes

  • Duplicate display names are now allowed for collections, folders, and requests.
  • Clone and copy/paste always use <source> copy as the display name.
    • Requests and folders clone immediately without a modal.
    • Collections still show a clone dialog because a destination location must be chosen.
  • Creating or renaming an item preserves exactly what the user entered.
  • Moving or dragging items preserves the display name, even when filesystem collisions occur.
  • Filesystem collisions are resolved automatically by suffixing only the on-disk name.
  • Raw filesystem paths, IPC errors, and inconsistent duplicate-name errors are no longer shown to users.
  • The only user-facing error is when the duplicate limit is reached:
    • Too many items named "<name>" (limit 200). Please use a different name.

Implementation

Shared naming utilities (@usebruno/common)

Introduced a shared src/utils/naming.ts containing:

  • sanitizeName
  • validateName
  • validateNameError
  • nextSuffixedName

Both the renderer and Electron use these utilities, ensuring validation rules and suffix generation remain consistent.


Collision-safe filesystem primitives (bruno-electron)

Added a set of reusable helpers in packages/bruno-electron/src/utils/filesystem.js.

Atomic creation

writeFileUnique and mkdirUnique use exclusive filesystem operations (wx and non-recursive mkdir) so the filesystem itself resolves races.

If two operations attempt the same name simultaneously:

  • one succeeds,
  • the other retries with the next suffix.

This fixes the rapid double-paste race that previously resulted in path already exists errors.

Efficient suffix generation

A single readdir pass is used as a hint to jump directly to the first available suffix while still filling gaps, avoiding repeated filesystem scans.

Collision-safe rename and move

getUniqueRenamePath and getUniqueTargetPath ensure rename and move operations also avoid collisions.

They additionally detect when the source and destination refer to the same inode, allowing case-only renames (login → Login) to occur in place on case-insensitive filesystems instead of incorrectly generating suffixed names.

Long filename handling

Names are truncated before writing to disk, reserving space for:

  • the file extension
  • the largest possible numeric suffix

This guarantees the final filename never exceeds the filesystem's 255-character limit.

Duplicate limit

A MAX_DUPLICATE_NAMES = 200 safeguard prevents infinite retry loops. If no unique name can be found within that limit, a friendly validation message is shown instead of exposing filesystem errors.


IPC and renderer integration

All create, clone, paste, rename, move, transient, and scratch-save flows now use the shared filesystem primitives.

During rename or move operations, item UIDs are also remapped (moveRequestUid) so open tabs, drafts, and item identity remain intact.


Bug fix: duplicate folder after case-only rename

On case-insensitive filesystems, renaming a folder such as:

auth → Auth

previously produced two sidebar entries even though only a single directory existed on disk.

The issue was caused by folders reconciling watcher events using case-sensitive filenames, while requests already reconciled using UIDs.

The fix has two parts:

  1. The Electron rename flow now remaps the folder UID using moveRequestUid(oldPath, newPath), ensuring watcher events continue using the existing identity.
  2. The renderer now reconciles collectionAddDirectoryEvent by UID instead of filename, updating the existing node rather than creating a duplicate.

This also preserves folder identity during normal renames while leaving new-folder creation and cross-collection moves unchanged.


Tests

End-to-end tests live under tests/naming-collisions/.

Each test validates both:

  • the display name shown in the sidebar
  • the actual filename or directory created on disk

Coverage highlights

  • Requests and folders

    • Clone, create, rename, copy/paste, and drag/drop all handle filesystem collisions correctly.
    • Duplicate display names render side by side.
    • Works for both .bru and .yml formats.
    • Reserved names remain blocked.
    • Open tabs continue tracking renamed or moved items.
    • Case-only renames work correctly.
    • Existing filesystem names created outside Bruno are preserved or suffixed as needed.
  • Collections

    • Clone still uses a modal because a destination must be selected.
    • New collections never reuse an existing directory name.
  • App items

    • Clone remains unavailable for app items while continuing to work for folders and requests.
  • Race conditions

    • Two immediate paste operations (Cmd/Ctrl + V) create two separate files without errors.

The MAX_DUPLICATE_NAMES limit is covered by Electron unit tests rather than end-to-end tests, since creating 200 duplicate items through the UI would be impractical.

Two existing drag-and-drop tests were updated to reflect the new silent collision behavior instead of expecting duplicate-name error toasts.

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

Summary

  • New Features

    • Enabled one-click cloning for sidebar items (requests and folders), including keyboard-triggered clone.
    • Clone/copy/collisions now automatically resolve to unique filesystem names with suffixed variants.
  • Bug Fixes

    • Improved duplicate-name handling across create, clone, copy/paste, drag/drop, move, and rename—reducing “already exists” interruptions.
    • Fixed case-only rename behavior on case-insensitive filesystems and preserved open tabs during folder renames.
  • Tests

    • Added extensive end-to-end coverage for naming-collision, clone, and rename scenarios (including long and reserved-name cases).

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This change centralizes filesystem naming rules and adds collision handling across collection creation, cloning, copying, renaming, moving, and request saving. Renderer actions use Electron-resolved paths, while sidebar cloning and collision tests are updated.

Changes

Collision-safe collection operations

Layer / File(s) Summary
Shared naming contracts
packages/bruno-common/src/utils/*, packages/bruno-app/src/utils/common/regex.js
Naming sanitization, validation, error reporting, and suffix generation are centralized and re-exported.
Filesystem and IPC handling
packages/bruno-electron/src/utils/filesystem.js, packages/bruno-electron/src/ipc/collection.js
Unique creation, collision-safe rename/move/copy, recursive cloning, and per-directory locking are added.
Renderer and sidebar integration
packages/bruno-app/src/providers/ReduxStore/slices/collections/*, packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js
Renderer duplicate checks are removed, Electron paths are propagated, case-only folder renames are reconciled, and folder/request cloning becomes one-click.
Validation coverage and test utilities
packages/bruno-electron/src/utils/tests/*, tests/collection/moving-requests/*, tests/naming-collisions/*, tests/utils/page/*
Tests cover collision suffixing, reserved names, long names, races, cloning, copy/paste, renaming, moving, transient saves, and BRU/YML formats.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Sidebar
  participant ReduxActions
  participant CollectionIPC
  participant Filesystem
  User->>Sidebar: Create, clone, paste, rename, or move item
  Sidebar->>ReduxActions: Dispatch collection action
  ReduxActions->>CollectionIPC: Request filesystem operation
  CollectionIPC->>Filesystem: Create or resolve unique target
  Filesystem-->>CollectionIPC: Return actual pathname
  CollectionIPC-->>ReduxActions: Return operation result
  ReduxActions-->>Sidebar: Update tree and opened item path
Loading

Possibly related PRs

Suggested reviewers: helloanoop, bijin-bruno, lohit-bruno, naman-bruno

Poem

Names may clash, but paths unite,
Suffixes bloom by filesystem light.
Folders clone and requests flow,
Tabs keep pace wherever they go.
Atomic writes guard every door.

🚥 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: decoupling display names from filesystem names and resolving collisions silently.
✨ 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.

@sachin-thakur-bruno sachin-thakur-bruno changed the title Feat/app naming collisions feat(sidebar-collections) adds name collissions for drag and drop actions Jul 13, 2026
@sachin-thakur-bruno sachin-thakur-bruno changed the title feat(sidebar-collections) adds name collissions for drag and drop actions feat(filesystem)/adds naming collisions for collection, requests and folders for all actions Jul 13, 2026
@sachin-thakur-bruno sachin-thakur-bruno changed the title feat(filesystem)/adds naming collisions for collection, requests and folders for all actions feat(filesystem)/Decouple display names from filesystem names & resolve collisions silently Jul 13, 2026
@sachin-thakur-bruno sachin-thakur-bruno changed the title feat(filesystem)/Decouple display names from filesystem names & resolve collisions silently feat(filesystem)/decouple display names from filesystem names & resolve collisions silently Jul 13, 2026

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

🧹 Nitpick comments (2)
tests/collection/moving-requests/cross-collection-drag-drop-folder.spec.ts (1)

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

Move the new collection locators into the page module.

Use centralized collection actions rather than adding raw #sidebar-collection-name selectors to the spec.

As per path instructions, modified specs should centralize locators and interactions under tests/utils/page/*.

🤖 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/collection/moving-requests/cross-collection-drag-drop-folder.spec.ts`
around lines 180 - 191, Move the new source/target collection locators and click
interactions out of the spec and into the appropriate page module under
tests/utils/page. Add reusable collection actions there, then update the test to
call those methods instead of using raw `#sidebar-collection-name` selectors or
locally constructed collection containers.

Source: Path instructions

tests/naming-collisions/long-names.spec.ts (1)

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

Add a multibyte long-name collision case.

The ASCII-only input cannot catch byte-limit overflow for emoji or CJK names. Add a duplicate multibyte name and verify both generated files remain within the supported component limit.

As per coding guidelines, tests should cover realistically problematic edge cases.

🤖 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/naming-collisions/long-names.spec.ts` around lines 11 - 35, Add a
multibyte duplicate-name case alongside the ASCII case in the long-name
collision test, using an emoji or CJK name long enough to challenge the
filesystem byte limit. Create two requests through createRequestViaModal, verify
both display names appear, and assert the generated .bru filenames are distinct
and each remains within the supported component limit.

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/src/ipc/collection.js`:
- Around line 1619-1654: Update the missing-target handling in the
renderer:move-item IPC handler to reject or throw an explicit error when
targetDirname does not exist, rather than returning undefined. Preserve the
existing successful move and same-folder no-op results so
handleMoveToNewLocation receives newPathname only for completed moves and
surfaces failures to callers.
- Around line 192-199: Remove filesystem paths from the user-facing errors in
the collection creation validation, clone-collection validation, and
renderer:move-item-cross-format existence checks. Keep the existing error
context, but replace interpolated values from path.join(collectionLocation,
collectionFolderName), sourcePathname, and targetDirname with non-sensitive
names or static messages.

In `@packages/bruno-electron/src/utils/filesystem.js`:
- Around line 201-218: Update mkdirUnique and getUniqueRenamePath to reserve
space for their generated suffixes and file extensions before constructing
candidate names, matching the truncation approach used by writeFileUnique.
Ensure collision candidates remain within the filesystem basename limit while
preserving existing uniqueness behavior.
- Around line 378-403: Make getUniqueRenamePath collision-safe by rechecking
each selected candidate against the live filesystem immediately before returning
it, including case-insensitive name collisions, rather than relying only on the
initial readdirSync snapshot. Ensure the rename/copy callers revalidate the
target before applying fs.renameSync or fsExtra.move. Update copyPathTo to
detect symlinked directories and handle them through the directory/relink path
instead of copyFile.

In `@tests/collection/moving-requests/cross-collection-drag-drop-folder.spec.ts`:
- Around line 171-174: Remove the negative toast assertion using
page.getByText(/already exists/i) from the cross-collection drag-and-drop test.
Keep the source disappearance and destination count assertions that verify
successful collision resolution, without adding replacement toast checks.

In `@tests/collection/moving-requests/cross-collection-drag-drop-request.spec.ts`:
- Line 95: Remove the negative toast assertions from
tests/collection/moving-requests/cross-collection-drag-drop-request.spec.ts
lines 95-95 and tests/naming-collisions/race-and-transient.spec.ts lines 43-44.
Keep the existing successful filesystem/UI outcome checks, including the polled
file result in the naming-collisions test.

In `@tests/naming-collisions/folder/clone.spec.ts`:
- Around line 64-81: Add user-visible sidebar assertions to the affected tests:
in tests/naming-collisions/folder/clone.spec.ts lines 64-81, verify the cloned
Users folder and its nested request/subfolder appear; in
tests/naming-collisions/folder/copy-paste.spec.ts lines 61-76, verify Users copy
appears under Target; in tests/naming-collisions/folder/drag-drop.spec.ts lines
20-45, verify both target folders appear and the source folder disappears; and
in lines 48-72, verify Auth appears in the target and disappears from the
source, while retaining the existing disk-state assertions.

In `@tests/naming-collisions/folder/rename.spec.ts`:
- Around line 195-200: Update the “Renamed in place: single Auth” test to
validate the exact directory entry casing using fs.readdirSync(collDir), rather
than relying on existsSync for the Auth path. Assert that the returned entries
contain Auth and do not contain the suffixed variants, while remaining
filesystem-case-behavior agnostic.

In `@tests/naming-collisions/request/create.spec.ts`:
- Around line 1-2: Replace the platform-based case-sensitivity assumption in the
test with a runtime probe of the temporary directory’s filesystem behavior. Use
the probe result to select the expected filename, preserving the existing
naming-collision assertions while supporting mounts whose case sensitivity
differs from the host OS.

In `@tests/naming-collisions/request/rename.spec.ts`:
- Around line 195-199: Replace the process.platform branch in the rename
collision test with filesystem capability detection using testDir: create a
temporary filename and its case-variant, observe whether the filesystem treats
them as the same path, clean up the probe files, then assert Login.bru for
case-sensitive behavior and Login1.bru for case-insensitive behavior. Do not
assume semantics from the operating system.

In `@tests/utils/page/naming-collisions.ts`:
- Around line 8-14: Update itemByTitle and itemRow in
buildNamingCollisionLocators to use page.getByTitle(title, { exact: true })
instead of interpolating title into CSS selectors, while preserving the existing
row filter behavior in itemRow.

---

Nitpick comments:
In `@tests/collection/moving-requests/cross-collection-drag-drop-folder.spec.ts`:
- Around line 180-191: Move the new source/target collection locators and click
interactions out of the spec and into the appropriate page module under
tests/utils/page. Add reusable collection actions there, then update the test to
call those methods instead of using raw `#sidebar-collection-name` selectors or
locally constructed collection containers.

In `@tests/naming-collisions/long-names.spec.ts`:
- Around line 11-35: Add a multibyte duplicate-name case alongside the ASCII
case in the long-name collision test, using an emoji or CJK name long enough to
challenge the filesystem byte limit. Create two requests through
createRequestViaModal, verify both display names appear, and assert the
generated .bru filenames are distinct and each remains within the supported
component limit.
🪄 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: 28efd9a7-435b-4dd4-ab36-ee29f2c09aa1

📥 Commits

Reviewing files that changed from the base of the PR and between b382a65 and d4897c0.

📒 Files selected for processing (30)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-app/src/utils/common/regex.js
  • packages/bruno-common/src/utils/index.ts
  • packages/bruno-common/src/utils/naming.spec.ts
  • packages/bruno-common/src/utils/naming.ts
  • packages/bruno-electron/src/ipc/collection.js
  • packages/bruno-electron/src/utils/filesystem.js
  • packages/bruno-electron/src/utils/tests/filesystem/index.spec.js
  • tests/collection/moving-requests/cross-collection-drag-drop-folder.spec.ts
  • tests/collection/moving-requests/cross-collection-drag-drop-request.spec.ts
  • tests/naming-collisions/collection/clone.spec.ts
  • tests/naming-collisions/collection/create.spec.ts
  • tests/naming-collisions/folder/clone.spec.ts
  • tests/naming-collisions/folder/copy-paste.spec.ts
  • tests/naming-collisions/folder/create.spec.ts
  • tests/naming-collisions/folder/drag-drop.spec.ts
  • tests/naming-collisions/folder/rename.spec.ts
  • tests/naming-collisions/long-names.spec.ts
  • tests/naming-collisions/race-and-transient.spec.ts
  • tests/naming-collisions/request/clone.spec.ts
  • tests/naming-collisions/request/copy-paste.spec.ts
  • tests/naming-collisions/request/create.spec.ts
  • tests/naming-collisions/request/drag-drop.spec.ts
  • tests/naming-collisions/request/rename.spec.ts
  • tests/naming-collisions/utils.ts
  • tests/utils/page/index.ts
  • tests/utils/page/locators.ts
  • tests/utils/page/naming-collisions.ts

Comment on lines 171 to 174
// New behavior: the collision is resolved silently (folder directory suffixed on disk).
// No error toast is shown, and no flow fails just because a folder name already exists.
await expect(page.getByText(/already exists/i)).toHaveCount(0);

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

Remove the negative toast assertion.

The source disappearance and destination count already verify successful collision resolution; asserting that error text never appears adds brittle toast coupling.

Based on learnings, Bruno E2E tests should not add negative assertions about toast notifications.

🤖 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/collection/moving-requests/cross-collection-drag-drop-folder.spec.ts`
around lines 171 - 174, Remove the negative toast assertion using
page.getByText(/already exists/i) from the cross-collection drag-and-drop test.
Keep the source disappearance and destination count assertions that verify
successful collision resolution, without adding replacement toast checks.

Source: Learnings

Comment on lines +195 to +200
await test.step('Renamed in place: single "Auth" in the sidebar, no suffixed variant', async () => {
await expect(nc.itemByTitle('Auth')).toHaveCount(1);
const collDir = findCollectionDir(testDir);
expect(fs.existsSync(path.join(collDir, 'Auth'))).toBe(true);
expect(fs.existsSync(path.join(collDir, 'Auth1'))).toBe(false);
expect(fs.existsSync(path.join(collDir, 'auth1'))).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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Verify the directory entry’s exact casing.

existsSync(path.join(collDir, 'Auth')) passes on case-insensitive filesystems even if the stored name remains auth. Assert the exact entry returned by fs.readdirSync(collDir) instead.

As per path instructions, tests must not assume case-sensitive or case-insensitive filesystem behavior.

🤖 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/naming-collisions/folder/rename.spec.ts` around lines 195 - 200, Update
the “Renamed in place: single Auth” test to validate the exact directory entry
casing using fs.readdirSync(collDir), rather than relying on existsSync for the
Auth path. Assert that the returned entries contain Auth and do not contain the
suffixed variants, while remaining filesystem-case-behavior agnostic.

Source: Path instructions

Comment thread tests/utils/page/naming-collisions.ts Resolved
// Uses for...of so nested async writes are actually awaited (a plain
// forEach(async) would resolve the handler before children were written).
const parseCollectionItems = async (items = [], currentPath) => {
for (const item of items) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Uses for...of so nested async writes are actually awaited.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
putComment timed out

@sachin-thakur-bruno
sachin-thakur-bruno changed the base branch from main to release/v4.1.0 July 15, 2026 06:00
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