Files
openclaw/src/infra/provider-usage.auth.plugin.test.ts
2026-03-27 17:57:23 +00:00

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",
},
]);
});
});