Repository navigation
feat(filesystem)/decouple display names from filesystem names & resolve collisions silently - #8586
sachin-thakur-bruno wants to merge 13 commits into
Conversation
WalkthroughThis 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. ChangesCollision-safe collection operations
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
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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: 11
🧹 Nitpick comments (2)
tests/collection/moving-requests/cross-collection-drag-drop-folder.spec.ts (1)
180-191: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMove the new collection locators into the page module.
Use centralized collection actions rather than adding raw
#sidebar-collection-nameselectors 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 winAdd 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
📒 Files selected for processing (30)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/index.jspackages/bruno-app/src/utils/common/regex.jspackages/bruno-common/src/utils/index.tspackages/bruno-common/src/utils/naming.spec.tspackages/bruno-common/src/utils/naming.tspackages/bruno-electron/src/ipc/collection.jspackages/bruno-electron/src/utils/filesystem.jspackages/bruno-electron/src/utils/tests/filesystem/index.spec.jstests/collection/moving-requests/cross-collection-drag-drop-folder.spec.tstests/collection/moving-requests/cross-collection-drag-drop-request.spec.tstests/naming-collisions/collection/clone.spec.tstests/naming-collisions/collection/create.spec.tstests/naming-collisions/folder/clone.spec.tstests/naming-collisions/folder/copy-paste.spec.tstests/naming-collisions/folder/create.spec.tstests/naming-collisions/folder/drag-drop.spec.tstests/naming-collisions/folder/rename.spec.tstests/naming-collisions/long-names.spec.tstests/naming-collisions/race-and-transient.spec.tstests/naming-collisions/request/clone.spec.tstests/naming-collisions/request/copy-paste.spec.tstests/naming-collisions/request/create.spec.tstests/naming-collisions/request/drag-drop.spec.tstests/naming-collisions/request/rename.spec.tstests/naming-collisions/utils.tstests/utils/page/index.tstests/utils/page/locators.tstests/utils/page/naming-collisions.ts
| // 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); | ||
|
|
There was a problem hiding this comment.
📐 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
| 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); |
There was a problem hiding this comment.
🎯 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
| // 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) { |
There was a problem hiding this comment.
Uses for...of so nested async writes are actually awaited.
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
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 existserrors, 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
<source> copyas the display name.Too many items named "<name>" (limit 200). Please use a different name.Implementation
Shared naming utilities (
@usebruno/common)Introduced a shared
src/utils/naming.tscontaining:sanitizeNamevalidateNamevalidateNameErrornextSuffixedNameBoth 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
writeFileUniqueandmkdirUniqueuse exclusive filesystem operations (wxand non-recursivemkdir) so the filesystem itself resolves races.If two operations attempt the same name simultaneously:
This fixes the rapid double-paste race that previously resulted in
path already existserrors.Efficient suffix generation
A single
readdirpass 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
getUniqueRenamePathandgetUniqueTargetPathensure 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:
This guarantees the final filename never exceeds the filesystem's 255-character limit.
Duplicate limit
A
MAX_DUPLICATE_NAMES = 200safeguard 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:
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:
moveRequestUid(oldPath, newPath), ensuring watcher events continue using the existing identity.collectionAddDirectoryEventby 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:
Coverage highlights
Requests and folders
.bruand.ymlformats.Collections
App items
Race conditions
Cmd/Ctrl + V) create two separate files without errors.The
MAX_DUPLICATE_NAMESlimit 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:
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
Bug Fixes
Tests