mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 12:11:20 +00:00
test(plugins): reuse tracked temp helpers in package contract tests
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync } from "node:fs";
|
||||
import { existsSync, mkdirSync, readdirSync, readFileSync } from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import os from "node:os";
|
||||
import { dirname, join, relative, resolve } from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import * as tar from "tar";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { pluginSdkEntrypoints } from "../../plugin-sdk/entrypoints.js";
|
||||
import { cleanupTrackedTempDirs, makeTrackedTempDir } from "../test-helpers/fs-fixtures.js";
|
||||
|
||||
const ROOT_DIR = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
const REPO_ROOT = resolve(ROOT_DIR, "..");
|
||||
@@ -17,6 +17,7 @@ const PUBLIC_CONTRACT_REFERENCE_FILES = [
|
||||
const PLUGIN_SDK_SUBPATH_PATTERN = /openclaw\/plugin-sdk\/([a-z0-9][a-z0-9-]*)\b/g;
|
||||
const NPM_PACK_MAX_BUFFER_BYTES = 64 * 1024 * 1024;
|
||||
const WINDOWS_UNSAFE_CMD_CHARS_RE = /[&|<>^%\r\n]/;
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
function collectPluginSdkPackageExports(): string[] {
|
||||
const packageJson = JSON.parse(readFileSync(resolve(REPO_ROOT, "package.json"), "utf8")) as {
|
||||
@@ -224,20 +225,16 @@ function packOpenClawToTempDir(packDir: string): string {
|
||||
async function readPackedRootPackageJson(archivePath: string): Promise<{
|
||||
dependencies?: Record<string, string>;
|
||||
}> {
|
||||
const extractDir = mkdtempSync(join(os.tmpdir(), "openclaw-packed-root-package-json-"));
|
||||
try {
|
||||
await tar.x({
|
||||
file: archivePath,
|
||||
cwd: extractDir,
|
||||
filter: (entryPath) => entryPath === "package/package.json",
|
||||
strict: true,
|
||||
});
|
||||
return JSON.parse(readFileSync(join(extractDir, "package", "package.json"), "utf8")) as {
|
||||
dependencies?: Record<string, string>;
|
||||
};
|
||||
} finally {
|
||||
rmSync(extractDir, { recursive: true, force: true });
|
||||
}
|
||||
const extractDir = makeTrackedTempDir("openclaw-packed-root-package-json", tempDirs);
|
||||
await tar.x({
|
||||
file: archivePath,
|
||||
cwd: extractDir,
|
||||
filter: (entryPath) => entryPath === "package/package.json",
|
||||
strict: true,
|
||||
});
|
||||
return JSON.parse(readFileSync(join(extractDir, "package", "package.json"), "utf8")) as {
|
||||
dependencies?: Record<string, string>;
|
||||
};
|
||||
}
|
||||
|
||||
function collectExtensionFiles(dir: string): string[] {
|
||||
@@ -294,6 +291,10 @@ function collectExtensionCoreImportLeaks(): Array<{ file: string; specifier: str
|
||||
}
|
||||
|
||||
describe("plugin-sdk package contract guardrails", () => {
|
||||
afterEach(() => {
|
||||
cleanupTrackedTempDirs(tempDirs);
|
||||
});
|
||||
|
||||
it("keeps package.json exports aligned with built plugin-sdk entrypoints", () => {
|
||||
expect(collectPluginSdkPackageExports()).toEqual([...pluginSdkEntrypoints].toSorted());
|
||||
});
|
||||
@@ -365,26 +366,22 @@ describe("plugin-sdk package contract guardrails", () => {
|
||||
});
|
||||
|
||||
it("keeps matrix crypto WASM in the packed artifact manifest", async () => {
|
||||
const tempRoot = mkdtempSync(join(os.tmpdir(), "openclaw-matrix-wasm-pack-"));
|
||||
try {
|
||||
const packDir = join(tempRoot, "pack");
|
||||
mkdirSync(packDir, { recursive: true });
|
||||
const tempRoot = makeTrackedTempDir("openclaw-matrix-wasm-pack", tempDirs);
|
||||
const packDir = join(tempRoot, "pack");
|
||||
mkdirSync(packDir, { recursive: true });
|
||||
|
||||
const archivePath = packOpenClawToTempDir(packDir);
|
||||
const packedPackageJson = await readPackedRootPackageJson(archivePath);
|
||||
const matrixPackageJson = readMatrixPackageJson();
|
||||
const bedrockPackageJson = readAmazonBedrockPackageJson();
|
||||
const archivePath = packOpenClawToTempDir(packDir);
|
||||
const packedPackageJson = await readPackedRootPackageJson(archivePath);
|
||||
const matrixPackageJson = readMatrixPackageJson();
|
||||
const bedrockPackageJson = readAmazonBedrockPackageJson();
|
||||
|
||||
expect(packedPackageJson.dependencies?.["@matrix-org/matrix-sdk-crypto-wasm"]).toBe(
|
||||
matrixPackageJson.dependencies?.["@matrix-org/matrix-sdk-crypto-wasm"],
|
||||
);
|
||||
expect(packedPackageJson.dependencies?.["@aws-sdk/client-bedrock"]).toBe(
|
||||
bedrockPackageJson.dependencies?.["@aws-sdk/client-bedrock"],
|
||||
);
|
||||
expect(packedPackageJson.dependencies?.["@openclaw/plugin-package-contract"]).toBeUndefined();
|
||||
} finally {
|
||||
rmSync(tempRoot, { recursive: true, force: true });
|
||||
}
|
||||
expect(packedPackageJson.dependencies?.["@matrix-org/matrix-sdk-crypto-wasm"]).toBe(
|
||||
matrixPackageJson.dependencies?.["@matrix-org/matrix-sdk-crypto-wasm"],
|
||||
);
|
||||
expect(packedPackageJson.dependencies?.["@aws-sdk/client-bedrock"]).toBe(
|
||||
bedrockPackageJson.dependencies?.["@aws-sdk/client-bedrock"],
|
||||
);
|
||||
expect(packedPackageJson.dependencies?.["@openclaw/plugin-package-contract"]).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps extension sources on public sdk or local package seams", () => {
|
||||
|
||||
Reference in New Issue
Block a user