Skip to content

fix: window normlize path comparison#7240

Merged
bijin-bruno merged 1 commit intousebruno:mainfrom
naman-bruno:bugfix/normalize-path-win
Feb 20, 2026
Merged

fix: window normlize path comparison#7240
bijin-bruno merged 1 commit intousebruno:mainfrom
naman-bruno:bugfix/normalize-path-win

Conversation

@naman-bruno
Copy link
Collaborator

@naman-bruno naman-bruno commented Feb 20, 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

  • Bug Fixes
    • Enhanced collection file detection and environment folder handling to work consistently across different operating systems through improved path comparison logic.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2026

Walkthrough

This PR standardizes path comparisons across collection and environment handling code by normalizing file paths before equality checks. Changes span utility helpers and their consumers to ensure consistent cross-platform path handling without altering functional behavior.

Changes

Cohort / File(s) Summary
Path Normalization Utilities
packages/bruno-electron/src/utils/filesystem.js
Updated four exported helper predicates (isDotEnvFile, isBrunoConfigFile, isBruEnvironmentConfig, isCollectionRootBruFile) to normalize directory paths using path.normalize() before comparison against target paths.
Path Normalization in Consumers
packages/bruno-electron/src/app/collection-watcher.js, packages/bruno-electron/src/ipc/collection.js
Applied normalized path comparisons in collection watcher predicates and findCollectionPathByItemPath() to ensure consistent handling of environment directories and collection root files across OS-specific path formats.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

size/M

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • bijin-bruno

Poem

🛤️ Paths once tangled, now they align,
Normalized across every design,
Windows and Unix, in harmony they dwell,
Cross-platform robustness—cast normalization's spell! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title correctly identifies the main objective: fixing Windows path normalization for comparisons. It's specific to the core change across multiple files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
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.

Caution

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

⚠️ Outside diff range comments (1)
packages/bruno-electron/src/ipc/collection.js (1)

103-106: ⚠️ Potential issue | 🟡 Minor

isTransientPath not normalized — inconsistent with the rest of this PR.

transientBase is constructed via path.join (OS backslashes on Windows), while filePath may arrive with forward slashes. The raw startsWith can return false when it should return true, causing findCollectionPathByItemPath to skip the metadata.json lookup and return the temp directory path instead of the real collection path — breaking getCollectionFormat and downstream operations for transient requests on Windows.

Note that renderer:delete-transient-requests (line 1052) already normalises both sides correctly; isTransientPath should do the same.

🛠️ Proposed fix
 const isTransientPath = (filePath) => {
   const transientBase = getTransientDirectoryBase();
-  return filePath.startsWith(transientBase + path.sep) || filePath.startsWith(transientBase);
+  const normalizedFilePath = path.normalize(filePath);
+  const normalizedBase = path.normalize(transientBase);
+  return normalizedFilePath.startsWith(normalizedBase + path.sep) || normalizedFilePath === normalizedBase;
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-electron/src/ipc/collection.js` around lines 103 - 106,
isTransientPath uses raw startsWith with transientBase (from
getTransientDirectoryBase) but doesn't normalize filePath, causing mismatches on
Windows; update isTransientPath to normalize both transientBase and filePath
(e.g., via path.normalize or replacing forward slashes) and ensure comparisons
use normalized forms (and keep the existing path.sep check behavior). Locate the
isTransientPath function and modify it to call path.normalize (or equivalent) on
filePath and transientBase before doing startsWith so
findCollectionPathByItemPath and related code (e.g.,
renderer:delete-transient-requests behavior) behave consistently across
platforms.
🧹 Nitpick comments (2)
packages/bruno-electron/src/app/collection-watcher.js (1)

35-72: LGTM — all three local predicates are consistently updated.

Side note: isBrunoConfigFile and isEnvironmentsFolder here duplicate isBrunoConfigFile / isBruEnvironmentConfig from utils/filesystem.js. Both copies are now in sync, but consolidating to the shared exports whenever convenient would reduce future drift.

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

In `@packages/bruno-electron/src/app/collection-watcher.js` around lines 35 - 72,
This duplicates predicates isBrunoConfigFile and isEnvironmentsFolder already
exported from utils/filesystem.js (the latter named isBruEnvironmentConfig
there); replace the local implementations in collection-watcher.js with imports
from utils/filesystem.js and use those imported functions (isBrunoConfigFile,
isBruEnvironmentConfig) instead of the local isBrunoConfigFile and
isEnvironmentsFolder to avoid drift and keep logic centralized.
packages/bruno-electron/src/utils/filesystem.js (1)

441-475: LGTM — normalization is symmetric and consistent across all four predicates.

path.normalize is the right call for separator-style differences on Windows. One note for posterity: it does not case-fold, so if a collectionPath ever arrives with a different casing than the watcher-reported dirname (e.g. user-typed path in a config), the equality check would still fail. path.normalize(x).toLowerCase() guarded by isWindowsOS() would close that gap if it proves necessary.

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

In `@packages/bruno-electron/src/utils/filesystem.js` around lines 441 - 475, The
four path-equality predicates (isDotEnvFile, isBrunoConfigFile,
isBruEnvironmentConfig, isCollectionRootBruFile) use path.normalize but don't
case-fold on Windows; update each to, when running on Windows (use an
isWindowsOS() helper), compare path.normalize(dirname).toLowerCase() ===
path.normalize(target).toLowerCase() (where target is collectionPath or
envDirectory) so casing differences don't break equality; keep non-Windows
behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/bruno-electron/src/ipc/collection.js`:
- Around line 103-106: isTransientPath uses raw startsWith with transientBase
(from getTransientDirectoryBase) but doesn't normalize filePath, causing
mismatches on Windows; update isTransientPath to normalize both transientBase
and filePath (e.g., via path.normalize or replacing forward slashes) and ensure
comparisons use normalized forms (and keep the existing path.sep check
behavior). Locate the isTransientPath function and modify it to call
path.normalize (or equivalent) on filePath and transientBase before doing
startsWith so findCollectionPathByItemPath and related code (e.g.,
renderer:delete-transient-requests behavior) behave consistently across
platforms.

---

Nitpick comments:
In `@packages/bruno-electron/src/app/collection-watcher.js`:
- Around line 35-72: This duplicates predicates isBrunoConfigFile and
isEnvironmentsFolder already exported from utils/filesystem.js (the latter named
isBruEnvironmentConfig there); replace the local implementations in
collection-watcher.js with imports from utils/filesystem.js and use those
imported functions (isBrunoConfigFile, isBruEnvironmentConfig) instead of the
local isBrunoConfigFile and isEnvironmentsFolder to avoid drift and keep logic
centralized.

In `@packages/bruno-electron/src/utils/filesystem.js`:
- Around line 441-475: The four path-equality predicates (isDotEnvFile,
isBrunoConfigFile, isBruEnvironmentConfig, isCollectionRootBruFile) use
path.normalize but don't case-fold on Windows; update each to, when running on
Windows (use an isWindowsOS() helper), compare
path.normalize(dirname).toLowerCase() === path.normalize(target).toLowerCase()
(where target is collectionPath or envDirectory) so casing differences don't
break equality; keep non-Windows behavior unchanged.

@bijin-bruno bijin-bruno merged commit 689e0c6 into usebruno:main Feb 20, 2026
8 checks passed
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