Skip to content

fix: handle special characters in collection path for dotenv watcher#7190

Open
pooja-bruno wants to merge 2 commits intousebruno:mainfrom
pooja-bruno:fix/dotenv-watcher-special-chars-in-path
Open

fix: handle special characters in collection path for dotenv watcher#7190
pooja-bruno wants to merge 2 commits intousebruno:mainfrom
pooja-bruno:fix/dotenv-watcher-special-chars-in-path

Conversation

@pooja-bruno
Copy link
Collaborator

@pooja-bruno pooja-bruno commented Feb 18, 2026

Description

Issue: #7178
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.
Screen.Recording.2026-02-18.at.2.18.07.PM.mov

Summary by CodeRabbit

  • Bug Fixes

    • Improved .env file watching for more reliable detection of changes across collections and workspaces, with no public API changes.
    • Enhanced support for collections with special characters (e.g., brackets) in their names.
  • Tests

    • Added end-to-end test coverage validating .env file creation in collections with special characters.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2026

No actionable comments were generated in the recent review. 🎉


Walkthrough

Replaced glob-pattern .env watching with direct directory watching (chokidar) using disableGlobbing: true for both collection and workspace watchers; added a Playwright E2E test that verifies .env creation in collection paths containing special characters.

Changes

Cohort / File(s) Summary
Watcher Refactoring
packages/bruno-electron/src/app/dotenv-watcher.js
Replaced glob-based watch patterns with direct directory paths; added disableGlobbing: true to chokidar options; kept existing add/change/unlink handlers and existing poll intervals (100ms collection, 250ms workspace).
E2E Test Coverage
tests/dotenv/special-chars-collection-path/dotenv-special-chars.spec.ts
Added Playwright test that creates a collection with special characters, creates a scoped environment and a .env file via UI, asserts success toast and the presence of the .env badge; includes cleanup to close collections.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

size/S

Suggested reviewers

  • lohit-bruno
  • helloanoop
  • naman-bruno

Poem

A watcher trades its globs for paths so true,
chokidar listens with disableGlobbing: true,
Brackets no longer raise a fuss or fuss,
A test clicks, a toast sings, .env shows up — thus,
Small change, big sigh of stability from us. ✨

🚥 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 accurately summarizes the main change: fixing handling of special characters in collection paths for the dotenv watcher, which aligns with the core modifications to dotenv-watcher.js and the test addition.
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
🧪 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.

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/bruno-electron/src/app/dotenv-watcher.js (1)

197-207: Nit: path in closeAll shadows the module-level import.

The destructured path variable in both for...of loops is unused and shadows the path import at Line 2. Use _ or skip the key entirely.

🔧 Proposed fix
-    for (const [path, watcher] of this.collectionWatchers) {
+    for (const [, watcher] of this.collectionWatchers) {
       watcher.close();
     }
     this.collectionWatchers.clear();

-    for (const [path, watcher] of this.workspaceWatchers) {
+    for (const [, watcher] of this.workspaceWatchers) {
       watcher.close();
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-electron/src/app/dotenv-watcher.js` around lines 197 - 207,
The closeAll method currently destructures a `path` variable in both loops which
shadows the module-level `path` import and is unused; update the loops in
closeAll (referencing collectionWatchers and workspaceWatchers) to avoid binding
`path` — e.g., skip the key by using an ignored placeholder or iterate over the
Map/collection values (use `for (const [, watcher] of this.collectionWatchers)`
or `for (const watcher of this.collectionWatchers.values())`, and similarly for
workspaceWatchers) so the module-level `path` import is not shadowed.
tests/dotenv/special-chars-collection-path/dotenv-special-chars.spec.ts (2)

26-44: Prefer data-testid selectors over CSS class selectors.

Lines 26, 31, 35, and 43 all rely on CSS class names (.section-header, .section-actions button, .environment-name-input, .section-badge). These are brittle — any styling/refactoring change breaks the test silently. The environment-selector-trigger on Line 23 correctly uses data-testid; the same pattern should apply here.

As per coding guidelines: "Add data-testid to testable elements for Playwright."

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

In `@tests/dotenv/special-chars-collection-path/dotenv-special-chars.spec.ts`
around lines 26 - 44, The test uses brittle CSS class selectors
('.section-header', '.section-actions button', '.environment-name-input',
'.section-badge') via the locators dotEnvSection, addButton, nameInput, and
dotEnvBadge; update these to use stable data-testid attributes instead (e.g.,
data-testid="section-header", data-testid="section-actions",
data-testid="environment-name-input", data-testid="section-badge") and adjust
the calls that reference dotEnvSection, addButton, nameInput, and dotEnvBadge so
the locators use page.getByTestId or locator('[data-testid="..."]')
consistently.

9-46: Test only exercises () — consider expanding special-character coverage.

The test title and the PR fix claim to handle "special characters in path", but only parentheses () are exercised. Characters like [, ], {, }, !, and # are also interpreted specially by glob engines and would be valuable to cover, either as additional test() cases or parameterised with test.each. Based on coding guidelines: "Cover both the 'happy path' and the realistically problematic paths."

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

In `@tests/dotenv/special-chars-collection-path/dotenv-special-chars.spec.ts`
around lines 9 - 46, The test only covers parentheses in collectionName; update
the test suite to parameterize or add additional test cases that exercise other
glob-sensitive special characters (e.g., '[', ']', '{', '}', '!', '#') so the
watcher/path handling is validated more broadly: refactor the existing
test('should detect .env file in collection with brackets in folder name') to
use test.each or create separate test() entries that call the same helpers
(createTmpDir, createCollection, createEnvironment) with collectionName values
containing those characters, then repeat the same steps (environment selector
interactions and assertions using page.getByTestId, dotEnvSection, addButton,
nameInput, and final dotEnvBadge expectation) for each special-character name.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/dotenv/special-chars-collection-path/dotenv-special-chars.spec.ts`:
- Around line 34-36: The comment says "Type the .env file name and press Enter"
but the test only calls nameInput.press('Enter') without filling the input;
either update the comment to state that the default value is accepted or
explicitly fill the input before pressing Enter (e.g., call
nameInput.fill('.env') then nameInput.press('Enter')) to make intent explicit;
update the comment near the locator variable nameInput
('.environment-name-input') and the press('Enter') call accordingly.

---

Nitpick comments:
In `@packages/bruno-electron/src/app/dotenv-watcher.js`:
- Around line 197-207: The closeAll method currently destructures a `path`
variable in both loops which shadows the module-level `path` import and is
unused; update the loops in closeAll (referencing collectionWatchers and
workspaceWatchers) to avoid binding `path` — e.g., skip the key by using an
ignored placeholder or iterate over the Map/collection values (use `for (const
[, watcher] of this.collectionWatchers)` or `for (const watcher of
this.collectionWatchers.values())`, and similarly for workspaceWatchers) so the
module-level `path` import is not shadowed.

In `@tests/dotenv/special-chars-collection-path/dotenv-special-chars.spec.ts`:
- Around line 26-44: The test uses brittle CSS class selectors
('.section-header', '.section-actions button', '.environment-name-input',
'.section-badge') via the locators dotEnvSection, addButton, nameInput, and
dotEnvBadge; update these to use stable data-testid attributes instead (e.g.,
data-testid="section-header", data-testid="section-actions",
data-testid="environment-name-input", data-testid="section-badge") and adjust
the calls that reference dotEnvSection, addButton, nameInput, and dotEnvBadge so
the locators use page.getByTestId or locator('[data-testid="..."]')
consistently.
- Around line 9-46: The test only covers parentheses in collectionName; update
the test suite to parameterize or add additional test cases that exercise other
glob-sensitive special characters (e.g., '[', ']', '{', '}', '!', '#') so the
watcher/path handling is validated more broadly: refactor the existing
test('should detect .env file in collection with brackets in folder name') to
use test.each or create separate test() entries that call the same helpers
(createTmpDir, createCollection, createEnvironment) with collectionName values
containing those characters, then repeat the same steps (environment selector
interactions and assertions using page.getByTestId, dotEnvSection, addButton,
nameInput, and final dotEnvBadge expectation) for each special-character name.

Comment on lines +34 to +36
// Type the .env file name and press Enter
const nameInput = page.locator('.environment-name-input');
await nameInput.press('Enter');
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Misleading comment — no fill() is called before pressing Enter.

The comment reads "Type the .env file name and press Enter", but only nameInput.press('Enter') is invoked, silently relying on a default input value of .env. Either add an explicit fill() call (clearer intent, less brittle) or update the comment to reflect that the default name is accepted as-is.

🔧 Proposed clarification
-      // Type the .env file name and press Enter
-      const nameInput = page.locator('.environment-name-input');
-      await nameInput.press('Enter');
+      // Accept the default .env file name and press Enter
+      const nameInput = page.locator('.environment-name-input');
+      await expect(nameInput).toBeVisible();
+      await nameInput.press('Enter');
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Type the .env file name and press Enter
const nameInput = page.locator('.environment-name-input');
await nameInput.press('Enter');
// Accept the default .env file name and press Enter
const nameInput = page.locator('.environment-name-input');
await expect(nameInput).toBeVisible();
await nameInput.press('Enter');
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/dotenv/special-chars-collection-path/dotenv-special-chars.spec.ts`
around lines 34 - 36, The comment says "Type the .env file name and press Enter"
but the test only calls nameInput.press('Enter') without filling the input;
either update the comment to state that the default value is accepted or
explicitly fill the input before pressing Enter (e.g., call
nameInput.fill('.env') then nameInput.press('Enter')) to make intent explicit;
update the comment near the locator variable nameInput
('.environment-name-input') and the press('Enter') call accordingly.

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

Comments