Files
openclaw-zero-token/plugins/contracts/loader.contract.test.ts
sjhu 571e14a236 feat: upgrade to upstream v2026.3.28
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
2026-03-30 17:58:12 +08:00

105 lines
3.9 KiB
TypeScript

import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { withBundledPluginAllowlistCompat } from "../bundled-compat.js";
import { resolveBundledWebSearchPluginIds } from "../bundled-web-search.js";
import { loadPluginManifestRegistry } from "../manifest-registry.js";
import { __testing as providerTesting } from "../providers.js";
import { resolveBundledPluginWebSearchProviders } from "../web-search-providers.js";
import { providerContractCompatPluginIds } from "./registry.js";
import { uniqueSortedStrings } from "./testkit.js";
function resolveBundledManifestProviderPluginIds() {
return uniqueSortedStrings(
loadPluginManifestRegistry({})
.plugins.filter((plugin) => plugin.origin === "bundled" && plugin.providers.length > 0)
.map((plugin) => plugin.id),
);
}
function expectPluginAllowlistContains(
allow: string[] | undefined,
pluginIds: string[],
expectedExtraEntry?: string,
) {
expect(allow).toEqual(expect.arrayContaining(pluginIds));
if (expectedExtraEntry) {
expect(allow).toContain(expectedExtraEntry);
}
}
function createAllowlistCompatConfig(pluginIds: string[]) {
return withBundledPluginAllowlistCompat({
config: {
plugins: {
allow: [demoAllowEntry],
},
},
pluginIds,
});
}
const demoAllowEntry = "demo-allowed";
describe("plugin loader contract", () => {
let providerPluginIds: string[] = [];
let manifestProviderPluginIds: string[] = [];
let compatPluginIds: string[] = [];
let compatConfig: ReturnType<typeof withBundledPluginAllowlistCompat>;
let vitestCompatConfig: ReturnType<typeof providerTesting.withBundledProviderVitestCompat>;
let webSearchPluginIds: string[] = [];
let bundledWebSearchPluginIds: string[] = [];
let webSearchAllowlistCompatConfig: ReturnType<typeof withBundledPluginAllowlistCompat>;
beforeAll(() => {
providerPluginIds = uniqueSortedStrings(providerContractCompatPluginIds);
manifestProviderPluginIds = resolveBundledManifestProviderPluginIds();
compatPluginIds = providerTesting.resolveBundledProviderCompatPluginIds({
config: {
plugins: {
allow: [demoAllowEntry],
},
},
});
compatConfig = createAllowlistCompatConfig(compatPluginIds);
vitestCompatConfig = providerTesting.withBundledProviderVitestCompat({
config: undefined,
pluginIds: providerPluginIds,
env: { VITEST: "1" } as NodeJS.ProcessEnv,
});
webSearchPluginIds = uniqueSortedStrings(
resolveBundledPluginWebSearchProviders({}).map((entry) => entry.pluginId),
);
bundledWebSearchPluginIds = uniqueSortedStrings(resolveBundledWebSearchPluginIds({}));
webSearchAllowlistCompatConfig = createAllowlistCompatConfig(webSearchPluginIds);
});
beforeEach(() => {
vi.restoreAllMocks();
});
it("keeps bundled provider compatibility wired to the provider registry", () => {
expect(providerPluginIds).toEqual(manifestProviderPluginIds);
const sortedCompatPluginIds = uniqueSortedStrings(compatPluginIds);
expect(sortedCompatPluginIds).toEqual(manifestProviderPluginIds);
expect(sortedCompatPluginIds).toEqual(expect.arrayContaining(providerPluginIds));
expectPluginAllowlistContains(compatConfig?.plugins?.allow, providerPluginIds, demoAllowEntry);
});
it("keeps vitest bundled provider enablement wired to the provider registry", () => {
expect(providerPluginIds).toEqual(manifestProviderPluginIds);
expect(vitestCompatConfig?.plugins?.enabled).toBe(true);
expectPluginAllowlistContains(vitestCompatConfig?.plugins?.allow, providerPluginIds);
});
it("keeps bundled web search loading scoped to the web search registry", () => {
expect(bundledWebSearchPluginIds).toEqual(webSearchPluginIds);
});
it("keeps bundled web search allowlist compatibility wired to the web search registry", () => {
expectPluginAllowlistContains(
webSearchAllowlistCompatConfig?.plugins?.allow,
webSearchPluginIds,
demoAllowEntry,
);
});
});