2026-03-12 15:31:31 +00:00
|
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
|
import { resolvePluginProviders } from "./providers.js";
|
|
|
|
|
|
|
|
|
|
const loadOpenClawPluginsMock = vi.fn();
|
|
|
|
|
|
|
|
|
|
vi.mock("./loader.js", () => ({
|
|
|
|
|
loadOpenClawPlugins: (...args: unknown[]) => loadOpenClawPluginsMock(...args),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
describe("resolvePluginProviders", () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
loadOpenClawPluginsMock.mockReset();
|
|
|
|
|
loadOpenClawPluginsMock.mockReturnValue({
|
2026-03-16 01:21:49 +00:00
|
|
|
providers: [{ pluginId: "google", provider: { id: "demo-provider" } }],
|
2026-03-12 15:31:31 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("forwards an explicit env to plugin loading", () => {
|
|
|
|
|
const env = { OPENCLAW_HOME: "/srv/openclaw-home" } as NodeJS.ProcessEnv;
|
|
|
|
|
|
|
|
|
|
const providers = resolvePluginProviders({
|
|
|
|
|
workspaceDir: "/workspace/explicit",
|
|
|
|
|
env,
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-16 01:21:49 +00:00
|
|
|
expect(providers).toEqual([{ id: "demo-provider", pluginId: "google" }]);
|
2026-03-12 15:31:31 +00:00
|
|
|
expect(loadOpenClawPluginsMock).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
workspaceDir: "/workspace/explicit",
|
|
|
|
|
env,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-03-15 16:09:29 -07:00
|
|
|
|
|
|
|
|
it("can augment restrictive allowlists for bundled provider compatibility", () => {
|
|
|
|
|
resolvePluginProviders({
|
|
|
|
|
config: {
|
|
|
|
|
plugins: {
|
|
|
|
|
allow: ["openrouter"],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
bundledProviderAllowlistCompat: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(loadOpenClawPluginsMock).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
config: expect.objectContaining({
|
|
|
|
|
plugins: expect.objectContaining({
|
2026-03-16 01:21:49 +00:00
|
|
|
allow: expect.arrayContaining(["openrouter", "google", "kilocode", "moonshot"]),
|
2026-03-15 16:09:29 -07:00
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-03-15 17:50:16 -07:00
|
|
|
it("can enable bundled provider plugins under Vitest when no explicit plugin config exists", () => {
|
|
|
|
|
resolvePluginProviders({
|
|
|
|
|
env: { VITEST: "1" } as NodeJS.ProcessEnv,
|
|
|
|
|
bundledProviderVitestCompat: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(loadOpenClawPluginsMock).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
config: expect.objectContaining({
|
|
|
|
|
plugins: expect.objectContaining({
|
|
|
|
|
enabled: true,
|
|
|
|
|
allow: expect.arrayContaining(["openai", "moonshot", "zai"]),
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-03-16 01:21:49 +00:00
|
|
|
|
|
|
|
|
it("does not reintroduce the retired google auth plugin id into compat allowlists", () => {
|
|
|
|
|
resolvePluginProviders({
|
|
|
|
|
config: {
|
|
|
|
|
plugins: {
|
|
|
|
|
allow: ["openrouter"],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
bundledProviderAllowlistCompat: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const call = loadOpenClawPluginsMock.mock.calls.at(-1)?.[0];
|
|
|
|
|
const allow = call?.config?.plugins?.allow;
|
|
|
|
|
|
|
|
|
|
expect(allow).toContain("google");
|
|
|
|
|
expect(allow).not.toContain("google-gemini-cli-auth");
|
|
|
|
|
});
|
2026-03-12 15:31:31 +00:00
|
|
|
});
|