mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-01 04:11:03 +00:00
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const resolveProviderUsageAuthWithPluginMock = vi.fn(
|
|
async (..._args: unknown[]): Promise<unknown> => null,
|
|
);
|
|
|
|
vi.mock("../plugins/provider-runtime.js", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("../plugins/provider-runtime.js")>();
|
|
return {
|
|
...actual,
|
|
resolveProviderUsageAuthWithPlugin: resolveProviderUsageAuthWithPluginMock,
|
|
};
|
|
});
|
|
|
|
let resolveProviderAuths: typeof import("./provider-usage.auth.js").resolveProviderAuths;
|
|
|
|
describe("resolveProviderAuths plugin boundary", () => {
|
|
beforeEach(async () => {
|
|
vi.resetModules();
|
|
resolveProviderUsageAuthWithPluginMock.mockReset();
|
|
resolveProviderUsageAuthWithPluginMock.mockResolvedValue(null);
|
|
({ resolveProviderAuths } = await import("./provider-usage.auth.js"));
|
|
});
|
|
|
|
it("prefers plugin-owned usage auth when available", async () => {
|
|
resolveProviderUsageAuthWithPluginMock.mockResolvedValueOnce({
|
|
token: "plugin-zai-token",
|
|
});
|
|
|
|
await expect(
|
|
resolveProviderAuths({
|
|
providers: ["zai"],
|
|
}),
|
|
).resolves.toEqual([
|
|
{
|
|
provider: "zai",
|
|
token: "plugin-zai-token",
|
|
},
|
|
]);
|
|
});
|
|
});
|