Skip to content

fix(ssh): probe npm via prepended PATH, not colocated with node (#9165) - #9255

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-9165-npm-path-probe
Jul 18, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-9165-npm-path-probe

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Fixes #9165.

Problem

The remote Node/npm toolchain gate added in the upgrade is stricter than the deploy it guards:

  • Deploy (ssh-remote-commands.ts, commandWithNodePath) prepends nodeBinDir to PATH and runs bare npm — so npm can resolve from anywhere on PATH.
  • The gate (ssh-remote-node-toolchain-probe.ts) invoked npm by absolute path <nodeBinDir>/npm (POSIX) / <nodeBinDir>/npm.cmd (Windows, behind a Test-Path colocation 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 --version under the same prepended PATH — so it still confirms npm is runnable (the #8450 concern that motivated the gate) without demanding colocation:

Verification

  • ssh-remote-node-toolchain-probe.test.ts + ssh-remote-node-resolution.test.ts: 38 passed.
  • Typecheck (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.

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

coderabbitai Bot commented Jul 18, 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 62f29550-163e-492e-8f80-8095f197de14

📥 Commits

Reviewing files that changed from the base of the PR and between 09f2e4d and 56ebe9c.

📒 Files selected for processing (3)
  • src/main/ssh/ssh-remote-node-resolution.test.ts
  • src/main/ssh/ssh-remote-node-resolution.ts
  • src/main/ssh/ssh-remote-node-toolchain-probe.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/ssh/ssh-remote-node-resolution.ts
  • src/main/ssh/ssh-remote-node-toolchain-probe.ts

📝 Walkthrough

Walkthrough

SSH Node toolchain probes on POSIX and Windows now prepend the candidate Node directory to PATH and invoke bare npm --version instead of an explicit npm binary path. Tests were updated to expect the new commands, and the node toolchain requirement comment now documents PATH-based npm resolution.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is off-template; it omits the required Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections. Rewrite the PR description to follow the repository template and fill in every required section, including testing and review/security notes.
Linked Issues check ⚠️ Warning This PR relaxes the linked issue's colocated Node+npm requirement by allowing npm from PATH, so it does not match the stated fix. Either enforce a colocated Node+npm toolchain as required, or update the linked issue requirements to allow PATH-resolved npm.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the SSH npm resolution change and matches the main code and test updates.
Out of Scope Changes check ✅ Passed The changes stay within SSH Node/npm probing tests, command generation, and comments, with no unrelated functionality added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@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)
src/main/ssh/ssh-remote-node-toolchain-probe.ts (1)

31-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Ensure missing npm causes a non-zero exit code in PowerShell.

In PowerShell, if an external command like npm is not found, it throws a non-terminating CommandNotFoundException which sets $? to $false but does not update $LASTEXITCODE. As a result, if npm is missing, the script will silently exit with 0 (the success code inherited from the preceding node --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 running npm to 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.ts

     expect(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

📥 Commits

Reviewing files that changed from the base of the PR and between 2f5fc65 and 09f2e4d.

📒 Files selected for processing (4)
  • src/main/ssh/ssh-remote-node-resolution.test.ts
  • src/main/ssh/ssh-remote-node-resolution.ts
  • src/main/ssh/ssh-remote-node-toolchain-probe.test.ts
  • src/main/ssh/ssh-remote-node-toolchain-probe.ts

@brennanb2025
brennanb2025 merged commit 3e276d7 into main Jul 18, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant