From 25d21d01dfee87e6e49c67588dccf1705ed7aeff Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 26 Feb 2026 07:46:23 -0500 Subject: [PATCH] plugins: add bundled source resolver tests --- src/plugins/bundled-sources.test.ts | 97 +++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/plugins/bundled-sources.test.ts diff --git a/src/plugins/bundled-sources.test.ts b/src/plugins/bundled-sources.test.ts new file mode 100644 index 000000000000..437b06c193ee --- /dev/null +++ b/src/plugins/bundled-sources.test.ts @@ -0,0 +1,97 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; +import { findBundledPluginByNpmSpec, resolveBundledPluginSources } from "./bundled-sources.js"; + +const discoverOpenClawPluginsMock = vi.fn(); +const loadPluginManifestMock = vi.fn(); + +vi.mock("./discovery.js", () => ({ + discoverOpenClawPlugins: (...args: unknown[]) => discoverOpenClawPluginsMock(...args), +})); + +vi.mock("./manifest.js", () => ({ + loadPluginManifest: (...args: unknown[]) => loadPluginManifestMock(...args), +})); + +describe("bundled plugin sources", () => { + beforeEach(() => { + discoverOpenClawPluginsMock.mockReset(); + loadPluginManifestMock.mockReset(); + }); + + it("resolves bundled sources keyed by plugin id", () => { + discoverOpenClawPluginsMock.mockReturnValue({ + candidates: [ + { + origin: "global", + rootDir: "/global/feishu", + packageName: "@openclaw/feishu", + packageManifest: { install: { npmSpec: "@openclaw/feishu" } }, + }, + { + origin: "bundled", + rootDir: "/app/extensions/feishu", + packageName: "@openclaw/feishu", + packageManifest: { install: { npmSpec: "@openclaw/feishu" } }, + }, + { + origin: "bundled", + rootDir: "/app/extensions/feishu-dup", + packageName: "@openclaw/feishu", + packageManifest: { install: { npmSpec: "@openclaw/feishu" } }, + }, + { + origin: "bundled", + rootDir: "/app/extensions/msteams", + packageName: "@openclaw/msteams", + packageManifest: { install: { npmSpec: "@openclaw/msteams" } }, + }, + ], + diagnostics: [], + }); + + loadPluginManifestMock.mockImplementation((rootDir: string) => { + if (rootDir === "/app/extensions/feishu") { + return { ok: true, manifest: { id: "feishu" } }; + } + if (rootDir === "/app/extensions/msteams") { + return { ok: true, manifest: { id: "msteams" } }; + } + return { + ok: false, + error: "invalid manifest", + manifestPath: `${rootDir}/openclaw.plugin.json`, + }; + }); + + const map = resolveBundledPluginSources({}); + + expect(Array.from(map.keys())).toEqual(["feishu", "msteams"]); + expect(map.get("feishu")).toEqual({ + pluginId: "feishu", + localPath: "/app/extensions/feishu", + npmSpec: "@openclaw/feishu", + }); + }); + + it("finds bundled source by npm spec", () => { + discoverOpenClawPluginsMock.mockReturnValue({ + candidates: [ + { + origin: "bundled", + rootDir: "/app/extensions/feishu", + packageName: "@openclaw/feishu", + packageManifest: { install: { npmSpec: "@openclaw/feishu" } }, + }, + ], + diagnostics: [], + }); + loadPluginManifestMock.mockReturnValue({ ok: true, manifest: { id: "feishu" } }); + + const resolved = findBundledPluginByNpmSpec({ spec: "@openclaw/feishu" }); + const missing = findBundledPluginByNpmSpec({ spec: "@openclaw/not-found" }); + + expect(resolved?.pluginId).toBe("feishu"); + expect(resolved?.localPath).toBe("/app/extensions/feishu"); + expect(missing).toBeUndefined(); + }); +});