Skip to content

CLI tests: the init --install test looks for npm-cli.js under npm's global prefix #196

Closed

Description

@FredApps

What went wrong?

Something else: a CLI test fails on machines where npm's global prefix is not where npm is installed.

DiffCI version

main at 40aa308 (CLI 0.3.54)

Command you ran

npm test in packages/diffci-cli

Environment

Ubuntu, Node.js 24.22.1, npm 11.21.1 installed in /usr/local, with a user-level npm prefix (prefix=~/.local), terminal.

What happens

tests/client/cli-agent.test.ts, test "initializes an installed npm project end to end and is idempotent", wraps the real npm in a shim. On Linux and macOS it finds the real npm's entry point with:

join(execFileSync(realNpm, ["root", "-g"], { encoding: "utf8" }).trim(), "npm", "bin", "npm-cli.js")

npm root -g names the configured global prefix, not the directory npm itself runs from. With a user prefix, a common setup that avoids sudo for global installs, that path does not exist, and the test fails inside diffci init --install:

✖ initializes an installed npm project end to end and is idempotent
  AssertionError [ERR_ASSERTION]: DiffCI init failed: could not install @diffci.com/[email protected]: node:internal/modules/cjs/loader:1568
  Error: Cannot find module '<home>/.local/lib/node_modules/npm/bin/npm-cli.js'

The npm on PATH is a link to its own bin/npm-cli.js (here /usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js).

What you expected

The test finds the npm-cli.js that the npm on PATH runs, by following that link, and falls back to npm root -g only when it is not a link to npm-cli.js.

Regression test

The linked pull request moves the lookup into tests/helpers/npm-cli.ts. The end-to-end test above fails on main on such a machine and passes with the change; tests/client/npm-cli-path.test.ts checks the lookup with a global prefix that does not contain npm.

Activity

  1. added a commit that references this issue on Nov 18, 2026
    5d38919
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions