mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 05:20:41 +00:00
105 lines
2.5 KiB
TypeScript
105 lines
2.5 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { resolvePluginDocumentExtractors } from "./document-extractors.runtime.js";
|
|
|
|
vi.mock("./document-extractor-public-artifacts.js", () => ({
|
|
loadBundledDocumentExtractorEntriesFromDir: vi.fn(
|
|
({ dirName }: { dirName: string; pluginId: string }) =>
|
|
dirName === "document-extract"
|
|
? [
|
|
{
|
|
id: "pdf",
|
|
label: "PDF",
|
|
mimeTypes: ["application/pdf"],
|
|
pluginId: "document-extract",
|
|
extract: vi.fn(),
|
|
},
|
|
]
|
|
: null,
|
|
),
|
|
}));
|
|
|
|
vi.mock("./manifest-registry-installed.js", () => ({
|
|
loadPluginManifestRegistryForInstalledIndex: vi.fn(() => ({
|
|
plugins: [
|
|
{
|
|
id: "document-extract",
|
|
origin: "bundled",
|
|
enabledByDefault: true,
|
|
channels: [],
|
|
cliBackends: [],
|
|
providers: [],
|
|
legacyPluginIds: [],
|
|
contracts: { documentExtractors: ["pdf"] },
|
|
},
|
|
{
|
|
id: "openai",
|
|
origin: "bundled",
|
|
enabledByDefault: true,
|
|
channels: [],
|
|
cliBackends: [],
|
|
providers: ["openai", "openai-codex"],
|
|
legacyPluginIds: [],
|
|
contracts: {},
|
|
},
|
|
],
|
|
})),
|
|
}));
|
|
|
|
vi.mock("./plugin-registry.js", () => ({
|
|
loadPluginRegistrySnapshot: vi.fn(() => ({ plugins: [] })),
|
|
loadPluginManifestRegistryForPluginRegistry: vi.fn(() => ({
|
|
plugins: [
|
|
{
|
|
id: "document-extract",
|
|
origin: "bundled",
|
|
enabledByDefault: true,
|
|
channels: [],
|
|
cliBackends: [],
|
|
providers: [],
|
|
legacyPluginIds: [],
|
|
contracts: { documentExtractors: ["pdf"] },
|
|
},
|
|
{
|
|
id: "openai",
|
|
origin: "bundled",
|
|
enabledByDefault: true,
|
|
channels: [],
|
|
cliBackends: [],
|
|
providers: ["openai", "openai-codex"],
|
|
legacyPluginIds: [],
|
|
contracts: {},
|
|
},
|
|
],
|
|
})),
|
|
}));
|
|
|
|
vi.mock("./manifest-registry.js", () => ({
|
|
resolveManifestContractOwnerPluginId: vi.fn(() => undefined),
|
|
}));
|
|
|
|
describe("resolvePluginDocumentExtractors", () => {
|
|
it("respects global plugin disablement", () => {
|
|
expect(
|
|
resolvePluginDocumentExtractors({
|
|
config: {
|
|
plugins: {
|
|
enabled: false,
|
|
},
|
|
},
|
|
}),
|
|
).toEqual([]);
|
|
});
|
|
|
|
it("does not expand an operator plugin allowlist", () => {
|
|
expect(
|
|
resolvePluginDocumentExtractors({
|
|
config: {
|
|
plugins: {
|
|
allow: ["openai"],
|
|
},
|
|
},
|
|
}),
|
|
).toEqual([]);
|
|
});
|
|
});
|