Repository navigation
fix(ssh): probe npm via prepended PATH, not colocated with node (#9165) - #9255
Conversation
The remote Node/npm toolchain gate invoked npm by its absolute path <nodeBinDir>/npm (POSIX) / npm.cmd (Windows, behind a Test-Path colocation check). But deploy (commandWithNodePath) runs bare `npm` with nodeBinDir merely prepended to PATH, so npm can resolve from anywhere on PATH. A host whose only resolvable node has npm elsewhere on PATH (e.g. node symlinked into a dir without npm) deployed fine on v1.4.144, but after upgrade the candidate is rejected with no fallback → SSH/relay connection fails to establish. Make the probe resolve npm exactly the way deploy does — bare `npm --version` under the same prepended PATH — so it still confirms npm is runnable (the #8450 concern) without requiring colocation. Windows now prepends the backslash-form dir (matching deploy) so bare-command PATH lookup resolves reliably.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughSSH Node toolchain probes on POSIX and Windows now prepend the candidate Node directory to 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
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.
🧹 Nitpick comments (1)
src/main/ssh/ssh-remote-node-toolchain-probe.ts (1)
31-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueEnsure missing
npmcauses a non-zero exit code in PowerShell.In PowerShell, if an external command like
npmis not found, it throws a non-terminatingCommandNotFoundExceptionwhich sets$?to$falsebut does not update$LASTEXITCODE. As a result, ifnpmis missing, the script will silently exit with0(the success code inherited from the precedingnode --version). While the downstream version parser handles this gracefully by failing to find the NPM version in the output, it is safer and structurally cleaner to explicitly exit with a non-zero code upon failure.
src/main/ssh/ssh-remote-node-toolchain-probe.ts#L31-L34: Add a check for$?after runningnpmto ensure a non-zero exit if it is missing or fails.src/main/ssh/ssh-remote-node-toolchain-probe.test.ts#L22-L25: Update the assertions to expect the new$?check.♻️ Proposed refactor
src/main/ssh/ssh-remote-node-toolchain-probe.ts`Write-Output ${powerShellLiteral(NPM_VERSION_MARKER)}`, '& npm --version', + 'if (-not $?) { exit 1 }', 'exit $LASTEXITCODE'
src/main/ssh/ssh-remote-node-toolchain-probe.test.tsexpect(probe).toContain("& 'C:/Program Files/nodejs/node.exe' --version") expect(probe).toContain('& npm --version') + expect(probe).toContain('if (-not $?) { exit 1 }') })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f588f907-8c9a-4a15-adc5-75144a009863
📒 Files selected for processing (4)
src/main/ssh/ssh-remote-node-resolution.test.tssrc/main/ssh/ssh-remote-node-resolution.tssrc/main/ssh/ssh-remote-node-toolchain-probe.test.tssrc/main/ssh/ssh-remote-node-toolchain-probe.ts
…lyai#9165) (stablyai#9255) * fix(ssh): probe npm via prepended PATH, not colocated with node (stablyai#9165) The remote Node/npm toolchain gate invoked npm by its absolute path <nodeBinDir>/npm (POSIX) / npm.cmd (Windows, behind a Test-Path colocation check). But deploy (commandWithNodePath) runs bare `npm` with nodeBinDir merely prepended to PATH, so npm can resolve from anywhere on PATH. A host whose only resolvable node has npm elsewhere on PATH (e.g. node symlinked into a dir without npm) deployed fine on v1.4.144, but after upgrade the candidate is rejected with no fallback → SSH/relay connection fails to establish. Make the probe resolve npm exactly the way deploy does — bare `npm --version` under the same prepended PATH — so it still confirms npm is runnable (the stablyai#8450 concern) without requiring colocation. Windows now prepends the backslash-form dir (matching deploy) so bare-command PATH lookup resolves reliably. * test(ssh): cover split Node npm PATH resolution
Fixes #9165.
Problem
The remote Node/npm toolchain gate added in the upgrade is stricter than the deploy it guards:
ssh-remote-commands.ts,commandWithNodePath) prependsnodeBinDirto PATH and runs barenpm— so npm can resolve from anywhere on PATH.ssh-remote-node-toolchain-probe.ts) invoked npm by absolute path<nodeBinDir>/npm(POSIX) /<nodeBinDir>/npm.cmd(Windows, behind aTest-Pathcolocation check).A host whose only resolvable node has npm elsewhere on PATH (e.g. node symlinked into a dir without npm) resolved and deployed fine on v1.4.144, but after upgrade the candidate is rejected with no fallback → SSH/relay connection fails to establish. Failure is loud (not data loss) and the population is narrow — standard nvm/fnm/volta/apt/brew installs all colocate node+npm — hence P1.
Fix
Make the probe resolve npm exactly the way deploy does — bare
npm --versionunder the same prepended PATH — so it still confirms npm is runnable (the #8450 concern that motivated the gate) without demanding colocation:PATH=<nodeBinDir>:$PATH npm --version.Test-Pathcolocation gate, prepends the dir to PATH (backslash form, matching deploy, so bare-command PATH lookup resolves reliably), and runs& npm --version.Verification
ssh-remote-node-toolchain-probe.test.ts+ssh-remote-node-resolution.test.ts: 38 passed.tsconfig.node.json) and oxlint on the touched files: clean.The change only relaxes the probe toward deploy's real behavior, so it cannot accept a toolchain deploy would then fail on.