Skip to content

fix(electron): Install packages dialog reports npm not on PATH when Node.js and npm are installed - #8253

Merged
engineering-bruno merged 9 commits into
usebruno:mainfrom
utkarsh-bruno:fix/BRU-3531
Jun 12, 2026
Merged

engineering-bruno merged 9 commits into
usebruno:mainfrom
utkarsh-bruno:fix/BRU-3531

Conversation

@utkarsh-bruno

@utkarsh-bruno utkarsh-bruno commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

https://usebruno.atlassian.net/browse/BRU-3531

Postman package install showed “npm was not found on your PATH” even when Node/npm worked in the terminal..
Bruno’s main process couldn’t reliably find the user’s Node/npm at install time.

Apps launched from Finder/Dock get a minimal PATH, without NVM/FNM/Homebrew paths that the terminal has.

Wrong spawn target — Spawning npm / npm.cmd directly failed on Windows after CVE-2024-27980 (EINVAL for .cmd without shell).

The fix resolves the user’s system Node, runs npm-cli.js via node (no shell), prepends shell PATH from login config, and waits for shell-env before installing.

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.

Summary by CodeRabbit

  • Bug Fixes

    • Installer waits for the shell environment before installing and returns clearer, specific error codes for install failures.
  • Improvements

    • More reliable, cross-platform npm invocation via Node.
    • Shell PATH is now merged/prepended into the process environment.
    • Client-side package name validation before install.
  • Tests

    • Expanded tests for resolution, spawn options, env merging, timeouts, output truncation, and error mappings.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f2f7d634-ca5c-42dd-b1ee-2985b73455a8

📥 Commits

Reviewing files that changed from the base of the PR and between 224beb2 and 5b0ad12.

📒 Files selected for processing (2)
  • packages/bruno-app/src/hooks/useResizablePanel/index.js
  • packages/bruno-electron/src/ipc/collection.js
✅ Files skipped from review due to trivial changes (1)
  • packages/bruno-app/src/hooks/useResizablePanel/index.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-electron/src/ipc/collection.js

Walkthrough

Prepends shell-derived PATH into process.env, adds Node/npm resolution and spawn helpers, runs npm via node + npm-cli.js with cross-platform spawn options and structured error codes, expands tests, and awaits shell-env readiness before IPC-triggered installs.

Changes

Robust npm package installation with shell environment and cross-platform resolution

Layer / File(s) Summary
Shell environment PATH initialization
packages/bruno-requests/src/utils/shell-env.ts, packages/bruno-requests/src/utils/shell-env.spec.ts
initializeShellEnv prepends shell-derived PATH to process.env.PATH using path.delimiter (or sets it when missing); tests added for both scenarios.
Node/npm resolution helpers
packages/bruno-electron/src/utils/install-packages.js
Adds resolveNodeExecutable, resolveNpmCli, cached resolveNpmInvocation/clearNpmInvocationCache, buildSafeEnv, buildSpawnOptions, Windows batch detection, and related constants.
NPM install orchestration and exports
packages/bruno-electron/src/utils/install-packages.js
runNpmInstall accepts resolveNpmInvocationFn, returns {success:false, errorCode:'NPM_NOT_FOUND'} when npm can't be resolved, spawns node <npm-cli.js> with safe env/options, adjusts spawn/error mapping, and exports the new helpers/constants and isValidNpmPackageName.
Tests: fixtures, spawn behavior, and error paths
packages/bruno-electron/tests/utils/install-packages.spec.js
Adds fixture-backed tests for node/npm layouts; validates resolution caching, PATH building, spawn options (shell/windows behavior), runNpmInstall spawn args/env, deduping, timeout, output truncation, and error-code semantics.
IPC handler integration
packages/bruno-electron/src/ipc/collection.js
renderer:install-postman-packages handler now awaits waitForShellEnv() after package validation and before calling runNpmInstall.
Minor comment cleanup
packages/bruno-app/src/hooks/useResizablePanel/index.js
Reflowed a useEffect comment; no behavioral changes.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

Suggested Reviewers

  • lohit-bruno
  • helloanoop
  • naman-bruno
  • bijin-bruno

Poem

🔧 Shell paths now prepared and ready,
node runs npm-cli steady and steady,
Windows quirks handled with careful hands,
tests verify env, spawn, and timeout bands,
installs now wait for shells before they’re steady.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: resolving npm detection issues when Node.js and npm are installed but not found on PATH.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

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

✨ 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 and usage tips.

@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

🤖 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/tests/utils/install-packages.spec.js`:
- Around line 252-291: The tests still assert on the old
runNpmInstall(npmCommand, platform) contract; update them so runNpmInstall()
assertions verify the new resolved invocation shape (spawnFn called with
nodePath as the command and args beginning with npmCliPath followed by install
args), and move the Windows shell-specific assertions into tests for
buildSpawnOptions() (assert buildSpawnOptions() returns shell: true when
npmCliPath is a .cmd on win32 and shell: false for bare npm). Locate references
to runNpmInstall, buildSpawnOptions, nodePath and npmCliPath in the test file
and change the expectations accordingly so runNpmInstall tests only assert the
resolved command/args/cwd and buildSpawnOptions tests assert shell behavior.

In `@packages/bruno-requests/src/utils/shell-env.ts`:
- Around line 34-36: The PATH handling logic skips when process.env.PATH is the
empty string; change the branch around key === 'PATH' so it treats an empty PATH
like a missing one — for example, in the key === 'PATH' branch set
process.env.PATH = process.env.PATH ?
`${value}${path.delimiter}${process.env.PATH}` : value; and keep the existing
else if (!(key in process.env)) behavior for other keys; update the code that
references key, process.env.PATH and path.delimiter accordingly.
🪄 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: 7f448aa7-c1b6-4033-a552-f4b16849ab07

📥 Commits

Reviewing files that changed from the base of the PR and between 13363d7 and 374394f.

📒 Files selected for processing (5)
  • packages/bruno-electron/src/ipc/collection.js
  • packages/bruno-electron/src/utils/install-packages.js
  • packages/bruno-electron/tests/utils/install-packages.spec.js
  • packages/bruno-requests/src/utils/shell-env.spec.ts
  • packages/bruno-requests/src/utils/shell-env.ts

sid-bruno
sid-bruno previously approved these changes Jun 12, 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.

🧹 Nitpick comments (1)
packages/bruno-electron/tests/utils/install-packages.spec.js (1)

97-97: ⚡ Quick win

Consider restoring process.env in afterEach for test isolation.

Multiple tests mutate process.env.PATH, process.env.NVM_BIN, and process.env.FNM_MULTISHELL_PATH without restoration. While Jest runs same-file tests serially (reducing risk), global mutations can cause flakiness if execution order changes or tests run in parallel.

♻️ Suggested pattern for environment isolation

Add to affected describe blocks (e.g., resolveNodeExecutable, buildSafeEnv, runNpmInstall):

 describe('resolveNodeExecutable', () => {
   let existsSyncSpy;
+  let savedEnv;

   beforeEach(() => {
+    savedEnv = { ...process.env };
     existsSyncSpy = jest.spyOn(fs, 'existsSync').mockReturnValue(false);
     delete process.env.NVM_BIN;
     delete process.env.FNM_MULTISHELL_PATH;
     delete process.env.PATH;
   });

   afterEach(() => {
+    process.env = savedEnv;
     existsSyncSpy.mockRestore();
   });

Apply similar pattern to buildSafeEnv and runNpmInstall suites.

Also applies to: 104-104, 148-148, 160-160, 234-234, 263-263

🤖 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-electron/tests/utils/install-packages.spec.js` at line 97,
Tests directly mutate process.env (e.g., process.env.PATH, process.env.NVM_BIN,
process.env.FNM_MULTISHELL_PATH) in suites like resolveNodeExecutable,
buildSafeEnv, and runNpmInstall; add an afterEach that restores the original env
by capturing const ORIGINAL_ENV = { ...process.env } at the start of each
describe (or top of file) and then assigning process.env = { ...ORIGINAL_ENV }
in afterEach to guarantee isolation and avoid flakiness when other tests run or
order changes.
🤖 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.

Nitpick comments:
In `@packages/bruno-electron/tests/utils/install-packages.spec.js`:
- Line 97: Tests directly mutate process.env (e.g., process.env.PATH,
process.env.NVM_BIN, process.env.FNM_MULTISHELL_PATH) in suites like
resolveNodeExecutable, buildSafeEnv, and runNpmInstall; add an afterEach that
restores the original env by capturing const ORIGINAL_ENV = { ...process.env }
at the start of each describe (or top of file) and then assigning process.env =
{ ...ORIGINAL_ENV } in afterEach to guarantee isolation and avoid flakiness when
other tests run or order changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8d9c6240-2c66-4f1a-949b-3b04dffd461e

📥 Commits

Reviewing files that changed from the base of the PR and between 0299e1a and 224beb2.

📒 Files selected for processing (1)
  • packages/bruno-electron/tests/utils/install-packages.spec.js

@engineering-bruno
engineering-bruno merged commit 1472f6b into usebruno:main Jun 12, 2026
18 of 19 checks passed
abhishekp-bruno pushed a commit to abhishekp-bruno/bruno that referenced this pull request Jun 17, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Jul 22, 2026
3 of 6 tasks
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.

3 participants