Skip to content

fix(drivers): check a relative driver folder once in the Windows npm lookup - #1833

Merged
ralphstodomingo merged 1 commit into
mainfrom
fix/1832-windows-npm-relative-cwd
Nov 30, 2026
Merged

ralphstodomingo merged 1 commit into
mainfrom
fix/1832-windows-npm-relative-cwd

Conversation

@ralphstodomingo

@ralphstodomingo ralphstodomingo commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #1832

Type of change

  • Bug fix

What does this PR do?

On Windows, after a failed npm run, findOnWindowsPath checks whether cmd.exe could find npm: the current directory first, then each PATH entry. The current-directory entry was cwd itself, and each candidate was resolved against cwd again, so a relative driver folder (a relative ALTIMATE_DRIVER_DIR) was probed as <folder>\<folder>\npm.cmd. An npm in that folder was missed, and a real install failure was reported as "npm is not available". cwd is now resolved once and that folder is probed.

Claims:

  • C1: With a relative cwd, the current-directory probe looks only in that folder, once per PATHEXT extension; a relative PATH entry is still read from it.
  • C2: The default file probe answers false, without throwing, for a path under a file, a missing path, and a path inside a folder it may not read.
  • C3: On Windows, a spawn error, a throwing spawn and a timeout settle as 127, 127 and 124 without looking npm up, even when the shell closes afterwards.

Residuals:

  • R1: The Windows-only test of the default probe on real folders, and C2's unreadable-folder case on Windows, don't run in CI (no Windows runner for this package). They were run on Windows 11 by hand (below).

How did you verify your code works?

  • Fail on main: the relative-cwd test fails without the fix.
  • Real Windows 11: with the process in a folder holding rel-drivers\npm.cmd and npm not on PATH, the lookup for npm from the relative folder rel-drivers comes back empty on main and finds its npm.cmd with this change. The test file there: every lookup and npm-runner test passes, including the Windows-only one; 3 POSIX-quoting tests fail there on main too.
  • Local (Linux): the 90 tests in test/resolve-unit.test.ts pass; typecheck clean.

Cost side effects

None.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
  • I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"

🤖 Generated with Claude Code

https://claude.ai/code/session_01YNQjkagE4uMJQBGtuEq7oN


Summary by cubic

Fixes Windows npm lookup so a relative driver folder (a relative ALTIMATE_DRIVER_DIR) is probed correctly. Previously, after a failed npm run, findOnWindowsPath resolved the current directory against itself, so an npm in that folder was missed and a real install failure was reported as "npm is not available".

Adds tests for the relative-folder probe, the default file probe, and the Windows paths that skip looking up npm. Closes #1832.

Written for commit a98ef0e. Summary will update on new commits.

View guided diff Turn on auto-fix

Summary by CodeRabbit

  • Bug Fixes
    • Improved npm command discovery on Windows when using a relative working directory.
    • Invalid or unusable PATH entries are skipped so valid npm locations can still be found.
    • Windows launch failures now return a consistent error code, and timeouts retain their timeout result during process shutdown.

…lookup

A relative cwd (relative ALTIMATE_DRIVER_DIR) was resolved against itself, so
npm in that folder was missed. Resolve it once. Adds tests for the default
file probe and the Windows paths that never look npm up.

Closes #1832.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YNQjkagE4uMJQBGtuEq7oN
@ralphstodomingo ralphstodomingo self-assigned this Nov 25, 2026
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Windows npm lookup now resolves the working directory before building candidate paths. Tests cover relative working directories, invalid PATH entries, regular-file probes, and runNpm spawn-error and timeout outcomes.

Changes: Windows npm resolution

Layer / File(s) Summary
Windows lookup and spawn checks
packages/drivers/src/resolve.ts, packages/drivers/test/resolve-unit.test.ts
findOnWindowsPath uses an absolute working directory when building candidate paths. The _testing object exposes isRegularFile. Tests cover relative working directories, file and missing-directory PATH entries, regular-file probe failures, and runNpm spawn and timeout outcomes.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

Suggested reviewers: hkaltai, sahrizvi, anandgupta42

Merge Risk: Minimal · up to a98ef

This fixes Windows npm lookup when the driver folder is a relative path, and the added tests cover the surrounding failure paths. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a fix in the drivers package that resolves a relative driver folder once in the Windows npm lookup. The raw summary confirms that findOnWindowsPath now resolves cwd on…
Description check Passed The description follows the template. It has the issue link (Closes #1832), the type of change (Bug fix checked), a 'What does this PR do?' section with the cause and the fix, a verification section, …
Linked Issues check Passed Issue #1832 has one coding objective: on Windows, the current-directory npm probe must resolve a relative cwd once and probe that folder once. In packages/drivers/src/resolve.ts, findOnWindowsPath now…
Out of Scope Changes check Passed The diff touches two files. In resolve.ts, the change is the cwd-resolution fix (plus a comment) and the addition of isRegularFile to the _testing export. The export supports the default-probe tes…
Full details: Title check

Explanation

The title names the main change: a fix in the drivers package that resolves a relative driver folder once in the Windows npm lookup. The raw summary confirms that findOnWindowsPath now resolves cwd once before building candidate paths. The title is specific and matches the linked issue and the description.

Full details: Description check

Explanation

The description follows the template. It has the issue link (Closes #1832), the type of change (Bug fix checked), a 'What does this PR do?' section with the cause and the fix, a verification section, the cost side effects section ('None'), and the checklist. It also adds numbered claims and residuals. The cost side effects section is filled in. The description is detailed and matches the summary and objectives. Verification is described with Windows 11 and Linux results.

Full details: Linked Issues check

Explanation

Issue #1832 has one coding objective: on Windows, the current-directory npm probe must resolve a relative cwd once and probe that folder once. In packages/drivers/src/resolve.ts, findOnWindowsPath now sets here = path.win32.resolve(cwd) once. The current-directory entry uses here, and each candidate is built as path.win32.resolve(here, dir, command + ext). The old code resolved cwd against itself, which produced the doubled folder. The fix addresses that defect. Relative PATH entries still resolve against the same folder, as before.

The issue's test requests are also covered in packages/drivers/test/resolve-unit.test.ts: (1) a relative-cwd test that checks each PATHEXT probe once and a relative PATH entry; (2) a default isRegularFile test (exported via _testing) for a folder, a missing path, a path under a file, and an unreadable folder, where the unreadable case runs only on non-Windows non-root hosts; (3) runNpm tests on win32 for a spawn error (127), a throwing spawn (127), and a timeout with a later close of 1 (124), each asserting no npm lookup. The PATH-entries-as-files test is Windows-only and returns early on Linux, so it does not run in this environment. The PR states this residual and reports a manual Windows 11 run. No unmet coding requirement was found.

Full details: Out of Scope Changes check

Explanation

The diff touches two files. In resolve.ts, the change is the cwd-resolution fix (plus a comment) and the addition of isRegularFile to the _testing export. The export supports the default-probe tests required by #1832. In resolve-unit.test.ts, all added tests cover the relative-cwd fix, the default probe, or the win32 spawn/timeout paths named in #1832. No unrelated behavior or file changes were found. The diff contains no cost side effects. Residual limits: the Windows-only real-folder test was checked from the diff only. Its run on Windows 11 is reported by the author and was not repeated here.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks the paths with care,
Resolves the folder once, right there.
It skips the files that cannot run,
And marks a timed-out task as done.
Then hops away beneath the moon.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a8b8e8d9-2554-4cad-92f6-d3d3e7ad65a0
Commits

Reviewing files that changed from the base of the PR and between e116170 and a98ef0e.

Files selected for processing: 2

  • packages/drivers/src/resolve.ts
  • packages/drivers/test/resolve-unit.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@ralphstodomingo

Copy link
Copy Markdown
Contributor Author

@codex review against the numbered claims and the disclosed residuals in this PR's description: report only a reproducible trace that violates a numbered claim, or a defect the residuals don't disclose. Name the claim, the input, and the line.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T04:44:41.352841Z a98ef0e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: a98ef0e248

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ralphstodomingo
ralphstodomingo marked this pull request as ready for review November 25, 2026 04:57

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/drivers/src/resolve.ts Resolved
Comment thread packages/drivers/src/resolve.ts Resolved
@kilo-code-bot

kilo-code-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 2

The core fix is correct: resolving the cwd once makes the current-directory probe name <folder>\npm.CMD instead of <folder>\<folder>\npm.CMD, and for an absolute cwd the results are unchanged (here equals the old cwd argument). The remaining findings are about the diagnosis path's robustness and test surface only.

Issue Details (click to expand)

WARNING

File Line Issue
packages/drivers/src/resolve.ts 883 path.win32.resolve(cwd) now runs unconditionally and calls process.cwd() for a relative cwd, which throws ENOENT when the working directory was removed. The throw happens inside runNpm's close handler (line 1103), so the install promise never settles and the real npm failure is lost. This file already guards that case with safeCwd() (lines 202-214).

SUGGESTION

File Line Issue
packages/drivers/src/resolve.ts 1119 The @internal note says "only for focused lifecycle and queue unit tests", but isRegularFile is exported for resolution tests.
packages/drivers/test/resolve-unit.test.ts 1245 Duplicates the 124/"Timed out" assertions already made in runNpm timeout (lines 1044-1068); only the empty-lookups win32 expectation is new.
Files Reviewed (2 files)
  • packages/drivers/src/resolve.ts - 2 issues
  • packages/drivers/test/resolve-unit.test.ts - 1 issue

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash-1017 · Input: 83.3K · Output: 32K · Cached: 1.2M

Review guidance: REVIEW.md from base branch main

@dev-punia-altimate

Copy link
Copy Markdown
Contributor

🤖 Code Review — OpenCodeReview (Gemini) — No Issues Found

No comments generated. Looks good to me.

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

Peer review (Claude + Codex Sol 6.1 + lead), with one convergence round. The fix is correct and minimal: cwd is resolved once, so an absolute cwd probes the same paths as before, and relative PATH entries are still read from the driver folder. Covers all of #1832. bun test test/resolve-unit.test.ts on the head: 90 pass, 0 fail. Codex separately reproduced the regression on base and saw it fixed on head. Approving.

Nit

  • packages/drivers/test/resolve-unit.test.ts L1146: if (process.platform !== "win32") return makes the test report pass on Linux/macOS instead of skip. No CI job runs the drivers suite on Windows, so findOnWindowsPath with the default isRegularFile is never checked end to end in CI. Only the direct isRegularFile tests cover it, as R1 notes. test.skipIf(process.platform !== "win32")(...) would make that visible in the output.

@ralphstodomingo
ralphstodomingo merged commit 2ca1603 into main Nov 30, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

drivers: on Windows, a relative driver folder makes the npm lookup check it twice

3 participants