mirror of https://github.com/openclaw/openclaw.git
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const resolveProviderUsageAuthWithPluginMock = vi.fn(
|
|
async (..._args: unknown[]): Promise<unknown> => null,
|
|
);
|
|
|
|
vi.mock("../plugins/provider-runtime.js", async () => {
|
|
const actual = await vi.importActual<typeof import("../plugins/provider-runtime.js")>(
|
|
"../plugins/provider-runtime.js",
|
|
);
|
|
return {
|
|
...actual,
|
|
resolveProviderUsageAuthWithPlugin: resolveProviderUsageAuthWithPluginMock,
|
|
};
|
|
});
|
|
|
|
let resolveProviderAuths: typeof import("./provider-usage.auth.js").resolveProviderAuths;
|
|
|
|
describe("resolveProviderAuths plugin boundary", () => {
|
|
beforeAll(async () => {
|
|
({ resolveProviderAuths } = await import("./provider-usage.auth.js"));
|
|
});
|
|
|
|
beforeEach(() => {
|
|
resolveProviderUsageAuthWithPluginMock.mockReset();
|
|
resolveProviderUsageAuthWithPluginMock.mockResolvedValue(null);
|
|
});
|
|
|
|
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",
|
|
},
|
|
]);
|
|
});
|
|
});
|