diff --git a/packages/sdk/src/package.e2e.test.ts b/packages/sdk/src/package.e2e.test.ts index 77ef75fbb04..e1a6b61017e 100644 --- a/packages/sdk/src/package.e2e.test.ts +++ b/packages/sdk/src/package.e2e.test.ts @@ -6,6 +6,7 @@ import { createServer, type Server } from "node:http"; import os from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it, vi } from "vitest"; +import { resolveNpmRunner } from "../../../scripts/npm-runner.mjs"; import { createPnpmRunnerSpawnSpec } from "../../../scripts/pnpm-runner.mjs"; import { getWindowsSystem32ExePath } from "../../../src/infra/windows-install-roots.js"; import { createNodeEvalArgs } from "../../../src/test-utils/node-process.js"; @@ -162,6 +163,24 @@ function runPnpmCommand( }); } +function runNpmCommand( + args: string[], + options: { cwd: string; timeoutMs?: number }, +): Promise { + const env = createCommandEnv(); + const runner = resolveNpmRunner({ + env, + npmArgs: args, + }); + return runCommand(runner.command, runner.args, { + cwd: options.cwd, + env: runner.env ?? env, + shell: runner.shell, + timeoutMs: options.timeoutMs, + windowsVerbatimArguments: runner.windowsVerbatimArguments, + }); +} + function normalizeWorkspaceDependencies( dependencies: Record | undefined, ): Record | undefined { @@ -340,7 +359,7 @@ describe("OpenClaw SDK package e2e", () => { } for (const packageRoot of packageRoots) { const stagingRoot = await createPackStagingRoot(packageRoot, tempDir); - await runCommand("npm", ["pack", "--ignore-scripts", "--pack-destination", tempDir], { + await runNpmCommand(["pack", "--ignore-scripts", "--pack-destination", tempDir], { cwd: stagingRoot, }); } @@ -363,13 +382,9 @@ describe("OpenClaw SDK package e2e", () => { ); await fs.writeFile(path.join(tempDir, ".npmrc"), `@openclaw:registry=${registry.registryUrl}`); try { - await runCommand( - "npm", - ["install", "--ignore-scripts", "--no-audit", "--no-fund", sdkTarball], - { - cwd: tempDir, - }, - ); + await runNpmCommand(["install", "--ignore-scripts", "--no-audit", "--no-fund", sdkTarball], { + cwd: tempDir, + }); } finally { await registry.close(); }