mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 20:20:42 +00:00
87 lines
3.1 KiB
TypeScript
87 lines
3.1 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { mkdtempSync, rmSync, mkdirSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { dirname, join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
const CHECK_SCRIPT = "scripts/check-openclaw-package-tarball.mjs";
|
|
|
|
function withTarball(
|
|
inventory: string[],
|
|
files: Record<string, string>,
|
|
testBody: (tarball: string) => void,
|
|
version = "0.0.0",
|
|
) {
|
|
const root = mkdtempSync(join(tmpdir(), "openclaw-package-tarball-test-"));
|
|
try {
|
|
const packageRoot = join(root, "package");
|
|
mkdirSync(join(packageRoot, "dist"), { recursive: true });
|
|
writeFileSync(join(packageRoot, "package.json"), JSON.stringify({ name: "openclaw", version }));
|
|
writeFileSync(
|
|
join(packageRoot, "dist", "postinstall-inventory.json"),
|
|
JSON.stringify(inventory),
|
|
);
|
|
for (const [relativePath, body] of Object.entries(files)) {
|
|
const filePath = join(packageRoot, relativePath);
|
|
mkdirSync(dirname(filePath), { recursive: true });
|
|
writeFileSync(filePath, body);
|
|
}
|
|
|
|
const tarball = join(root, "openclaw.tgz");
|
|
const pack = spawnSync("tar", ["-czf", tarball, "-C", root, "package"], {
|
|
encoding: "utf8",
|
|
});
|
|
expect(pack.status, pack.stderr).toBe(0);
|
|
testBody(tarball);
|
|
} finally {
|
|
rmSync(root, { recursive: true, force: true });
|
|
}
|
|
}
|
|
|
|
describe("check-openclaw-package-tarball", () => {
|
|
it("allows legacy private QA inventory entries omitted from shipped tarballs through 2026.4.25", () => {
|
|
withTarball(
|
|
["dist/index.js", "dist/extensions/qa-channel/runtime-api.js"],
|
|
{ "dist/index.js": "export {};\n" },
|
|
(tarball) => {
|
|
const result = spawnSync("node", [CHECK_SCRIPT, tarball], { encoding: "utf8" });
|
|
|
|
expect(result.status, result.stderr).toBe(0);
|
|
expect(result.stderr).toContain("legacy inventory references omitted private QA");
|
|
expect(result.stdout).toContain("OpenClaw package tarball integrity passed.");
|
|
},
|
|
"2026.4.25-beta.10",
|
|
);
|
|
});
|
|
|
|
it("rejects legacy private QA inventory omissions for newer packages", () => {
|
|
withTarball(
|
|
["dist/index.js", "dist/extensions/qa-channel/runtime-api.js"],
|
|
{ "dist/index.js": "export {};\n" },
|
|
(tarball) => {
|
|
const result = spawnSync("node", [CHECK_SCRIPT, tarball], { encoding: "utf8" });
|
|
|
|
expect(result.status).not.toBe(0);
|
|
expect(result.stderr).toContain(
|
|
"inventory references missing tar entry dist/extensions/qa-channel/runtime-api.js",
|
|
);
|
|
expect(result.stderr).not.toContain("legacy inventory references omitted private QA");
|
|
},
|
|
"2026.4.26",
|
|
);
|
|
});
|
|
|
|
it("still rejects non-legacy missing inventory entries", () => {
|
|
withTarball(
|
|
["dist/index.js", "dist/cli.js"],
|
|
{ "dist/index.js": "export {};\n" },
|
|
(tarball) => {
|
|
const result = spawnSync("node", [CHECK_SCRIPT, tarball], { encoding: "utf8" });
|
|
|
|
expect(result.status).not.toBe(0);
|
|
expect(result.stderr).toContain("inventory references missing tar entry dist/cli.js");
|
|
},
|
|
);
|
|
});
|
|
});
|