mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:20:43 +00:00
test: align contract inventory with package excludes
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { uniqueSortedStrings } from "../../plugin-sdk/test-helpers/string-utils.js";
|
||||
import { loadPluginManifestRegistry, type PluginManifestRecord } from "../manifest-registry.js";
|
||||
@@ -9,6 +11,34 @@ import {
|
||||
} from "./registry.js";
|
||||
|
||||
describe("plugin contract registry", () => {
|
||||
function collectExcludedPackagedExtensionDirs(): ReadonlySet<string> {
|
||||
const packageJson = JSON.parse(
|
||||
fs.readFileSync(path.join(process.cwd(), "package.json"), "utf-8"),
|
||||
) as {
|
||||
files?: unknown;
|
||||
};
|
||||
if (!Array.isArray(packageJson.files)) {
|
||||
return new Set();
|
||||
}
|
||||
const excluded = new Set<string>();
|
||||
for (const entry of packageJson.files) {
|
||||
if (typeof entry !== "string") {
|
||||
continue;
|
||||
}
|
||||
const match = /^!dist\/extensions\/([^/]+)\/\*\*$/u.exec(entry);
|
||||
if (match?.[1]) {
|
||||
excluded.add(match[1]);
|
||||
}
|
||||
}
|
||||
return excluded;
|
||||
}
|
||||
|
||||
const excludedPackagedExtensionDirs = collectExcludedPackagedExtensionDirs();
|
||||
|
||||
function isPackagedCorePluginId(pluginId: string): boolean {
|
||||
return !excludedPackagedExtensionDirs.has(pluginId);
|
||||
}
|
||||
|
||||
function expectUniqueIds(ids: readonly string[]) {
|
||||
expect(ids).toEqual([...new Set(ids)]);
|
||||
}
|
||||
@@ -24,7 +54,7 @@ describe("plugin contract registry", () => {
|
||||
|
||||
function resolveBundledManifestPluginIds(predicate: (plugin: PluginManifestRecord) => boolean) {
|
||||
return loadPluginManifestRegistry({})
|
||||
.plugins.filter((plugin) => predicate(plugin))
|
||||
.plugins.filter((plugin) => isPackagedCorePluginId(plugin.id) && predicate(plugin))
|
||||
.map((plugin) => plugin.id)
|
||||
.toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
@@ -176,7 +206,7 @@ describe("plugin contract registry", () => {
|
||||
const bundledWebSearchPluginIds = resolveManifestContractPluginIds({
|
||||
contract: "webSearchProviders",
|
||||
origin: "bundled",
|
||||
});
|
||||
}).filter(isPackagedCorePluginId);
|
||||
|
||||
expect(
|
||||
uniqueSortedStrings(
|
||||
|
||||
Reference in New Issue
Block a user