Repository navigation
fix(electron): Install packages dialog reports npm not on PATH when Node.js and npm are installed - #8253
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughPrepends 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. ChangesRobust npm package installation with shell environment and cross-platform resolution
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly Related PRs
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 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
📒 Files selected for processing (5)
packages/bruno-electron/src/ipc/collection.jspackages/bruno-electron/src/utils/install-packages.jspackages/bruno-electron/tests/utils/install-packages.spec.jspackages/bruno-requests/src/utils/shell-env.spec.tspackages/bruno-requests/src/utils/shell-env.ts
Co-authored-by: Sid <[email protected]>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/bruno-electron/tests/utils/install-packages.spec.js (1)
97-97: ⚡ Quick winConsider restoring
process.envinafterEachfor test isolation.Multiple tests mutate
process.env.PATH,process.env.NVM_BIN, andprocess.env.FNM_MULTISHELL_PATHwithout 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
describeblocks (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
buildSafeEnvandrunNpmInstallsuites.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
📒 Files selected for processing (1)
packages/bruno-electron/tests/utils/install-packages.spec.js
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:
Summary by CodeRabbit
Bug Fixes
Improvements
Tests