Files
openclaw/src/plugins/document-extractor-public-artifacts.test.ts
Vincent Koc e3cba98f39 refactor(pdf): move document extraction to plugin
* refactor(pdf): move document extraction to plugin

* fix(deps): sync document extract lockfile

* fix(pdf): harden document extraction plugin
2026-04-24 17:15:05 -07:00

56 lines
1.7 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const { publicArtifactModule } = vi.hoisted(() => ({
publicArtifactModule: {} as Record<string, unknown>,
}));
vi.mock("./public-surface-loader.js", () => ({
loadBundledPluginPublicArtifactModuleSync: vi.fn(() => publicArtifactModule),
resolveBundledPluginPublicArtifactPath: vi.fn(
() => "/repo/extensions/demo/document-extractor.ts",
),
}));
import { loadBundledDocumentExtractorEntriesFromDir } from "./document-extractor-public-artifacts.js";
describe("loadBundledDocumentExtractorEntriesFromDir", () => {
beforeEach(() => {
for (const key of Object.keys(publicArtifactModule)) {
delete publicArtifactModule[key];
}
});
it("isolates a throwing factory when another extractor factory succeeds", () => {
publicArtifactModule.createBrokenDocumentExtractor = () => {
throw new Error("native probe failed");
};
publicArtifactModule.createPdfDocumentExtractor = () => ({
id: "pdf",
label: "PDF",
mimeTypes: ["application/pdf"],
extract: vi.fn(),
});
expect(
loadBundledDocumentExtractorEntriesFromDir({
dirName: "demo",
pluginId: "demo",
}),
).toMatchObject([{ id: "pdf", pluginId: "demo" }]);
});
it("surfaces initialization failure when every matching factory throws", () => {
const cause = new Error("native probe failed");
publicArtifactModule.createPdfDocumentExtractor = () => {
throw cause;
};
expect(() =>
loadBundledDocumentExtractorEntriesFromDir({
dirName: "demo",
pluginId: "demo",
}),
).toThrow("Unable to initialize document extractors for plugin demo");
});
});