Files
openclaw/test/scripts/pnpm-runner.test.ts
Peter Steinberger b85a049da5 chore: migrate tooling and source installs to pnpm 12 (#131043)
* build: migrate tooling and source installs to pnpm 12

Pin the verified native toolchain without changing application dependency
versions. Preserve the existing release-age policy explicitly and separate
package-manager lock metadata from the application dependency graph.

Use exact checkout pins for bootstrap and rollback, approve only the native
pnpm installer where npm requires it, and retain global install ownership
without equating the CLI major to the storage layout. Verify the Docker
runtime toolchain offline as its non-root user.

Remove duplicate bootstrap paths and obsolete prune input, update native
CLI flags and regression fixtures, and preserve UTF-8 in macOS Bash
installer NDJSON output.

* fix(build): isolate production dependency installs for pnpm 12

Build production dependencies from the same frozen manifest inputs instead
of pruning the inherited development tree. pnpm 12's native hoisted
importer cannot rename lower-layer OverlayFS directories during pruning.
Preserve native addon outputs, workspace builds, and offline non-root
Corepack use while deleting the obsolete production-store seeder.

Exercise runtime assembly and explicitly consent to the local agent-plugin
E2E fixture under the current plugin capability contract.

Validated full Matrix image and offline non-root runtime, focused Docker
regressions, full checks with test types and architecture, docs, real
agent-plugin gateway E2E, and isolated Codex autoreview.

* test: align package smoke with pnpm 12 global installs

* test: follow native pnpm artifact approval in distribution guard

* test: modernize pnpm fixtures for v12

* test: align rebased update fixtures with pnpm 12

* test: retain sanitized upgrade restart diagnostics

* test: expose CI navigation failures and register diagnostics

* test: retain post-core outcomes and plugin artifact identity

* chore(tooling): group upgrade diagnostic entrypoints

* fix(update): support native pnpm global installs and source links

Qualify local source and archive specs, carry verified global ownership through pnpm configuration, and verify intentional checkout links with shared runtime-readiness checks. Preserve strict packaged-install verification and manager ownership safeguards.

Verified the production updater with pnpm 11.22 and 12 using default and custom roots, source links, and tarball updates.

* test: preserve survivor diagnostics after service sealing

Promote incomplete exit-zero runs before failure capture and exercise the sealed-service manager fixture without inventing successful child exits.

* fix(update): preserve legacy pnpm global ownership

Carry the verified root and bin through both pnpm and npm configuration dialects after original-environment probes. Real pnpm 10 custom-root updates and pnpm 11/12 source and tarball matrices pass without redirecting the caller or weakening ownership checks.

* test(update): verify wizard consent through checkout handoff

Use the prepared checkout and fresh-process finalization boundary introduced by the updater repair. Preserve explicit consent forwarding before and after the wizard subcommand without assuming plugin callbacks run in the old process.

* refactor(update): validate checkout build metadata records

Use the canonical record coercer instead of carrying an unchecked assertion into the shared runtime verifier. Remove the now-unused grandfathered assertion entry; no allowance is added.

* docs(sandbox): document standalone common-image inputs

* test(packaging): account for required native prebuilds

Align installer and release size budgets at 235 MiB for the required native payload added on main. Keep both loader layouts, upstream binaries, explicit overrides, and missing-data rejection intact. Exercise actual defaults and the one-byte boundary. Retain bounded stderr diagnostics for the intermittent Bun signal test without claiming a production signal fix.

* test: align refreshed installer fixtures with pnpm 12

* fix(test): share Bun smoke force-kill ownership

Record the successful force-kill once across the timer and post-close drain. Native Darwin traces reproduced both duplicate-signal orders; genuine permission failures and uncleared groups still fail without extending deadlines.
2026-08-28 17:43:09 -07:00

442 lines
13 KiB
TypeScript

// Pnpm Runner tests cover pnpm runner script behavior.
import { spawnSync } from "node:child_process";
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { createPnpmRunnerSpawnSpec, resolvePnpmRunner } from "../../scripts/pnpm-runner.mts";
import { buildCmdExeCommandLine } from "../../scripts/windows-cmd-helpers.mjs";
describe("resolvePnpmRunner", () => {
const posixIt = process.platform === "win32" ? it.skip : it;
it("uses npm_execpath when it points to a JS pnpm entrypoint", () => {
const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-"));
const npmExecPath = path.join(tempDir, "pnpm.cjs");
writeFileSync(npmExecPath, "console.log('pnpm');\n");
try {
expect(
resolvePnpmRunner({
npmExecPath,
nodeExecPath: "/usr/local/bin/node",
pnpmArgs: ["exec", "vitest", "run"],
platform: "linux",
}),
).toEqual({
command: "/usr/local/bin/node",
args: [npmExecPath, "exec", "vitest", "run"],
shell: false,
});
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});
it("uses npm_execpath when it points to a shebang pnpm script", () => {
const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-"));
const npmExecPath = path.join(tempDir, "pnpm");
writeFileSync(npmExecPath, "#!/usr/bin/env node\nconsole.log('pnpm');\n");
try {
expect(
resolvePnpmRunner({
npmExecPath,
nodeExecPath: "/usr/local/bin/node",
pnpmArgs: ["exec", "vitest", "run"],
platform: "linux",
}),
).toEqual({
command: "/usr/local/bin/node",
args: [npmExecPath, "exec", "vitest", "run"],
shell: false,
});
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});
it("prepends node args when launching pnpm through node", () => {
const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-"));
const npmExecPath = path.join(tempDir, "pnpm.cjs");
writeFileSync(npmExecPath, "console.log('pnpm');\n");
try {
expect(
resolvePnpmRunner({
npmExecPath,
nodeArgs: ["--no-maglev"],
nodeExecPath: "/usr/local/bin/node",
pnpmArgs: ["exec", "vitest", "run"],
platform: "linux",
}),
).toEqual({
command: "/usr/local/bin/node",
args: ["--no-maglev", npmExecPath, "exec", "vitest", "run"],
shell: false,
});
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});
it.each(["pnpm", "pnpm-native"])("executes native %s from npm_execpath directly", (basename) => {
const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-"));
const npmExecPath = path.join(tempDir, basename);
writeFileSync(npmExecPath, Buffer.from([0x7f, 0x45, 0x4c, 0x46]));
chmodSync(npmExecPath, 0o755);
try {
expect(
resolvePnpmRunner({
npmExecPath,
pnpmArgs: ["exec", "vitest", "run"],
platform: "linux",
}),
).toEqual({
command: npmExecPath,
args: ["exec", "vitest", "run"],
shell: false,
});
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});
posixIt("falls back to bare pnpm when native npm_execpath is not executable", () => {
const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-"));
const npmExecPath = path.join(tempDir, "pnpm");
writeFileSync(npmExecPath, Buffer.from([0x7f, 0x45, 0x4c, 0x46]));
chmodSync(npmExecPath, 0o644);
try {
expect(
resolvePnpmRunner({
npmExecPath,
env: { PATH: "" },
pnpmArgs: ["exec", "vitest", "run"],
platform: "linux",
}),
).toEqual({
command: "pnpm",
args: ["exec", "vitest", "run"],
shell: false,
});
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});
it.each(["pnpm.exe", "pnpm-native.exe"])("executes %s directly on Windows", (basename) => {
const npmExecPath = `C:\\Users\\test\\AppData\\Local\\pnpm\\${basename}`;
expect(
resolvePnpmRunner({
npmExecPath,
nodeArgs: ["--no-maglev"],
nodeExecPath: "C:\\Program Files\\nodejs\\node.exe",
pnpmArgs: ["exec", "vitest", "run"],
platform: "win32",
}),
).toEqual({
command: npmExecPath,
args: ["exec", "vitest", "run"],
shell: false,
});
});
posixIt("executes a shell npm_execpath with its own interpreter", () => {
const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-shell-"));
const npmExecPath = path.join(tempDir, "pnpm");
writeFileSync(npmExecPath, '#!/bin/sh\nprintf "%s\\n" "$@"\n');
chmodSync(npmExecPath, 0o755);
try {
const spec = createPnpmRunnerSpawnSpec({
npmExecPath,
pnpmArgs: ["literal & argument"],
stdio: "pipe",
});
const result = spawnSync(spec.command, spec.args, { ...spec.options, encoding: "utf8" });
expect(result.status, result.stderr).toBe(0);
expect(result.stdout).toBe("literal & argument\n");
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});
it("uses pnpm.cjs through node for Windows-style paths", () => {
const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-"));
const npmExecPath = path.join(tempDir, "pnpm.cjs");
writeFileSync(npmExecPath, "console.log('pnpm');\n");
try {
expect(
resolvePnpmRunner({
npmExecPath,
nodeExecPath: "C:\\Program Files\\nodejs\\node.exe",
pnpmArgs: ["exec", "vitest", "run"],
platform: "win32",
}),
).toEqual({
command: "C:\\Program Files\\nodejs\\node.exe",
args: [npmExecPath, "exec", "vitest", "run"],
shell: false,
});
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});
it("falls back to pnpm.cmd on Windows for a missing legacy pnpm 10 JS entrypoint", () => {
expect(
resolvePnpmRunner({
comSpec: "C:\\Windows\\System32\\cmd.exe",
env: { PATH: "" },
npmExecPath:
"C:\\Users\\test\\AppData\\Local\\Temp\\cache\\corepack\\v1\\pnpm\\10.32.1\\bin\\pnpm.mjs",
nodeExecPath: "C:\\Program Files\\nodejs\\node.exe",
pnpmArgs: ["exec", "vitest", "run"],
platform: "win32",
}),
).toEqual({
command: "C:\\Windows\\System32\\cmd.exe",
args: ["/d", "/s", "/c", "pnpm.cmd exec vitest run"],
shell: false,
windowsVerbatimArguments: true,
});
});
it("wraps an explicit pnpm.cmd path via cmd.exe on Windows", () => {
expect(
resolvePnpmRunner({
comSpec: "C:\\Windows\\System32\\cmd.exe",
npmExecPath: "C:\\Program Files\\pnpm\\pnpm.cmd",
pnpmArgs: ["exec", "vitest", "run", "-t", "path with spaces"],
platform: "win32",
}),
).toEqual({
command: "C:\\Windows\\System32\\cmd.exe",
args: [
"/d",
"/s",
"/c",
'""C:\\Program Files\\pnpm\\pnpm.cmd" exec vitest run -t "path with spaces""',
],
shell: false,
windowsVerbatimArguments: true,
});
});
it("falls back to bare pnpm on non-Windows when npm_execpath is missing", () => {
expect(
resolvePnpmRunner({
npmExecPath: "",
env: { PATH: "" },
pnpmArgs: ["exec", "vitest", "run"],
platform: "linux",
}),
).toEqual({
command: "pnpm",
args: ["exec", "vitest", "run"],
shell: false,
});
});
posixIt("does not resolve executables from the parent PATH for an explicit empty env", () => {
expect(
resolvePnpmRunner({
npmExecPath: "",
env: {},
pnpmArgs: ["exec", "vitest", "run"],
platform: "linux",
}),
).toEqual({
command: "pnpm",
args: ["exec", "vitest", "run"],
shell: false,
});
});
posixIt("resolves relative PATH entries from the child working directory", () => {
const childDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-child-"));
try {
expect(
resolvePnpmRunner({
cwd: childDir,
npmExecPath: "",
env: { PATH: "node_modules/.bin" },
pnpmArgs: ["exec", "vitest", "run"],
platform: "linux",
}),
).toEqual({
command: "pnpm",
args: ["exec", "vitest", "run"],
shell: false,
});
} finally {
rmSync(childDir, { recursive: true, force: true });
}
});
posixIt("uses Corepack when pnpm is not directly available on PATH", () => {
const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-corepack-"));
const corepackPath = path.join(tempDir, "corepack");
writeFileSync(corepackPath, "#!/bin/sh\nexit 0\n");
chmodSync(corepackPath, 0o755);
try {
expect(
resolvePnpmRunner({
npmExecPath: "",
env: { PATH: tempDir },
pnpmArgs: ["exec", "tsdown"],
platform: "darwin",
}),
).toEqual({
command: corepackPath,
args: ["pnpm", "exec", "tsdown"],
shell: false,
});
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});
posixIt("prefers a direct pnpm executable over Corepack", () => {
const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-path-"));
const pnpmPath = path.join(tempDir, "pnpm");
const corepackPath = path.join(tempDir, "corepack");
writeFileSync(pnpmPath, "#!/bin/sh\nexit 0\n");
writeFileSync(corepackPath, "#!/bin/sh\nexit 0\n");
chmodSync(pnpmPath, 0o755);
chmodSync(corepackPath, 0o755);
try {
expect(
resolvePnpmRunner({
npmExecPath: "",
env: { PATH: tempDir },
pnpmArgs: ["exec", "tsdown"],
platform: "darwin",
}),
).toEqual({
command: pnpmPath,
args: ["exec", "tsdown"],
shell: false,
});
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});
it("wraps pnpm.cmd via cmd.exe on Windows when npm_execpath is unavailable", () => {
expect(
resolvePnpmRunner({
comSpec: "C:\\Windows\\System32\\cmd.exe",
env: { PATH: "" },
npmExecPath: "",
pnpmArgs: ["exec", "vitest", "run", "-t", "path with spaces"],
platform: "win32",
}),
).toEqual({
command: "C:\\Windows\\System32\\cmd.exe",
args: ["/d", "/s", "/c", 'pnpm.cmd exec vitest run -t "path with spaces"'],
shell: false,
windowsVerbatimArguments: true,
});
});
it("ignores ambient ComSpec when defaulting the Windows cmd shim launcher", () => {
expect(
resolvePnpmRunner({
env: {
ComSpec: "C:\\Users\\test\\bin\\cmd.exe",
PATH: "",
SystemRoot: "D:\\Windows",
},
npmExecPath: "",
pnpmArgs: ["exec", "vitest", "run"],
platform: "win32",
}),
).toEqual({
command: "D:\\Windows\\System32\\cmd.exe",
args: ["/d", "/s", "/c", "pnpm.cmd exec vitest run"],
shell: false,
windowsVerbatimArguments: true,
});
});
it("uses Corepack on Windows when no pnpm shim is available", () => {
const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-corepack-"));
const corepackPath = path.join(tempDir, "corepack.cmd");
writeFileSync(corepackPath, "@exit /b 0\r\n");
try {
expect(
resolvePnpmRunner({
comSpec: "C:\\Windows\\System32\\cmd.exe",
npmExecPath: "",
env: { Path: tempDir, PATHEXT: ".CMD;.EXE" },
pnpmArgs: ["exec", "vitest", "run"],
platform: "win32",
}),
).toEqual({
command: "C:\\Windows\\System32\\cmd.exe",
args: [
"/d",
"/s",
"/c",
buildCmdExeCommandLine(corepackPath, ["pnpm", "exec", "vitest", "run"]),
],
shell: false,
windowsVerbatimArguments: true,
});
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});
it("escapes caret arguments for Windows cmd.exe", () => {
expect(
resolvePnpmRunner({
comSpec: "C:\\Windows\\System32\\cmd.exe",
env: { PATH: "" },
npmExecPath: "",
pnpmArgs: ["exec", "vitest", "-t", "@scope/pkg@^1.2.3"],
platform: "win32",
}),
).toEqual({
command: "C:\\Windows\\System32\\cmd.exe",
args: ["/d", "/s", "/c", "pnpm.cmd exec vitest -t @scope/pkg@^^1.2.3"],
shell: false,
windowsVerbatimArguments: true,
});
});
it("builds a shared spawn spec with inherited stdio and env overrides", () => {
const env = { PATH: "/custom/bin", FOO: "bar" };
expect(
createPnpmRunnerSpawnSpec({
cwd: "/repo",
detached: true,
npmExecPath: "",
pnpmArgs: ["exec", "vitest", "run"],
platform: "linux",
env,
}),
).toEqual({
command: "pnpm",
args: ["exec", "vitest", "run"],
options: {
cwd: "/repo",
detached: true,
stdio: "inherit",
env,
shell: false,
windowsVerbatimArguments: undefined,
},
});
});
});