Files
openclaw/test/scripts/package-git-fixture.test.ts
Peter Steinberger f6131a4fbf build(deps): remove npm shrinkwrap; mirror pnpm lock into transient package locks (#114006)
* build(deps): remove npm shrinkwrap; mirror pnpm lock into transient package locks

npm 12 removed shrinkwrap (command + tarball/root loading). Delete all 82
committed npm-shrinkwrap.json files and stop publishing lockfiles; keep
pnpm-lock.yaml as the single reviewed dependency boundary. The generator
becomes scripts/generate-npm-package-lock.mjs and feeds plugin bundling via
a transient package-lock.json + npm ci (works on npm 11 and 12). Tarball
validation treats the published 2026.7.2 beta train as a shrinkwrap
transition; self-update npm detection now uses install topology instead of
the shipped shrinkwrap.

* fix(deps): repair lint, deadcode, and test-type lanes for the npm 12 migration

- sort integrity comparisons with an explicit comparator (oxlint)
- keep resolveBunGlobalNodeModules module-local (knip unused-export gate)
- model npm pack --json as npm<=11 array / npm 12 name-keyed object
- default calver destructuring in the tarball test fixture
2026-07-26 01:29:55 -04:00

73 lines
3.0 KiB
TypeScript

// Package git fixture tests cover package-derived Docker git install fixtures.
import { spawnSync } from "node:child_process";
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { useAutoCleanupTempDirTracker } from "../helpers/temp-dir.js";
describe("package git fixture", () => {
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
it("stages bundled ai runtime as a local file dependency", async () => {
const root = tempDirs.make("openclaw-package-git-fixture-");
writeFileSync(path.join(root, ".gitignore"), "dist/\n");
mkdirSync(path.join(root, "node_modules", "@openclaw", "ai"), { recursive: true });
writeFileSync(
path.join(root, "package.json"),
`${JSON.stringify(
{
dependencies: { "@openclaw/ai": "2026.6.11", chalk: "5.6.2" },
bundleDependencies: ["@openclaw/ai", "chalk"],
},
null,
2,
)}\n`,
);
writeFileSync(
path.join(root, "node_modules", "@openclaw", "ai", "package.json"),
`${JSON.stringify({ name: "@openclaw/ai", version: "2026.6.11" })}\n`,
);
const result = spawnSync(
process.execPath,
["scripts/e2e/lib/package-git-fixture.mjs", "prepare", root],
{ cwd: process.cwd(), encoding: "utf8" },
);
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
expect(readFileSync(path.join(root, ".gitignore"), "utf8").split(/\r?\n/u)).toEqual(
expect.arrayContaining(["dist/", "node_modules", "**/node_modules/", "pnpm-lock.yaml"]),
);
const packageJson = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8"));
expect(packageJson.dependencies["@openclaw/ai"]).toBe("file:.openclaw-fixture/packages/ai");
expect(packageJson.bundleDependencies).toEqual(["chalk"]);
expect(
JSON.parse(
readFileSync(
path.join(root, ".openclaw-fixture", "packages", "ai", "package.json"),
"utf8",
),
).name,
).toBe("@openclaw/ai");
mkdirSync(path.join(root, "node_modules", "chalk"), { recursive: true });
writeFileSync(path.join(root, "node_modules", "chalk", "package.json"), "{}\n");
mkdirSync(path.join(root, ".openclaw-fixture", "packages", "ai", "node_modules", "zod"), {
recursive: true,
});
writeFileSync(
path.join(root, ".openclaw-fixture", "packages", "ai", "node_modules", "zod", "package.json"),
"{}\n",
);
writeFileSync(path.join(root, "pnpm-lock.yaml"), "lockfileVersion: '9.0'\n");
expect(spawnSync("git", ["init", "-q", root], { encoding: "utf8" }).status).toBe(0);
expect(spawnSync("git", ["-C", root, "add", "-A"], { encoding: "utf8" }).status).toBe(0);
const staged = spawnSync("git", ["-C", root, "diff", "--cached", "--name-only"], {
encoding: "utf8",
});
expect(staged.status).toBe(0);
expect(staged.stdout).not.toContain("node_modules");
expect(staged.stdout).not.toContain("pnpm-lock.yaml");
});
});