* plugins: add bundled source resolver * plugins: add bundled source resolver tests * cli: fallback npm 404 plugin installs to bundled sources * plugins: use bundled source resolver during updates * protocol: regenerate macos gateway swift models * protocol: regenerate shared swift models * Revert "protocol: regenerate shared swift models" This reverts commit 6a2b08c47d2636610efbf16fc210d4114b05b4b4. * Revert "protocol: regenerate macos gateway swift models" This reverts commit 27c03010c6b9da07b404c93cdb0a1c2a3db671f5.
98 lines
3.1 KiB
TypeScript
98 lines
3.1 KiB
TypeScript
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();
|
|
});
|
|
});
|