Files
openclaw/src/plugins/manifest-contract-runtime.test.ts
2026-05-02 07:51:17 +01:00

69 lines
1.8 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const loadPluginMetadataSnapshot = vi.hoisted(() => vi.fn());
vi.mock("./plugin-metadata-snapshot.js", () => ({
loadPluginMetadataSnapshot,
}));
import { resolveManifestContractRuntimePluginResolution } from "./manifest-contract-runtime.js";
describe("resolveManifestContractRuntimePluginResolution", () => {
beforeEach(() => {
loadPluginMetadataSnapshot.mockReset();
loadPluginMetadataSnapshot.mockReturnValue({
index: { plugins: [] },
plugins: [],
});
});
it("resolves contract plugins from the shared metadata snapshot", () => {
loadPluginMetadataSnapshot.mockReturnValue({
index: {
plugins: [
{
pluginId: "bundled-search",
origin: "bundled",
enabled: true,
enabledByDefault: true,
},
{
pluginId: "external-search",
origin: "global",
enabled: true,
enabledByDefault: true,
},
],
},
plugins: [
{
id: "bundled-search",
origin: "bundled",
contracts: { webSearchProviders: ["search"] },
},
{
id: "external-search",
origin: "global",
contracts: { webSearchProviders: ["search"] },
},
],
});
expect(
resolveManifestContractRuntimePluginResolution({
cfg: {},
contract: "webSearchProviders",
value: "search",
}),
).toEqual({
pluginIds: ["bundled-search", "external-search"],
bundledCompatPluginIds: ["bundled-search"],
});
expect(loadPluginMetadataSnapshot).toHaveBeenCalledWith({
config: {},
env: process.env,
preferPersisted: false,
});
});
});