mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-20 06:20:55 +00:00
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { createProviderUsageFetch } from "../test-utils/provider-usage-fetch.js";
|
|
|
|
const resolveProviderUsageSnapshotWithPluginMock = vi.fn();
|
|
|
|
vi.mock("../config/config.js", () => ({
|
|
loadConfig: () => ({}),
|
|
}));
|
|
|
|
vi.mock("../plugins/provider-runtime.js", () => ({
|
|
resolveProviderUsageSnapshotWithPlugin: (...args: unknown[]) =>
|
|
resolveProviderUsageSnapshotWithPluginMock(...args),
|
|
}));
|
|
|
|
import { loadProviderUsageSummary } from "./provider-usage.load.js";
|
|
|
|
const usageNow = Date.UTC(2026, 0, 7, 0, 0, 0);
|
|
|
|
describe("provider-usage.load plugin seam", () => {
|
|
beforeEach(() => {
|
|
resolveProviderUsageSnapshotWithPluginMock.mockReset();
|
|
resolveProviderUsageSnapshotWithPluginMock.mockResolvedValue(null);
|
|
});
|
|
|
|
it("prefers plugin-owned usage snapshots before the legacy core switch", async () => {
|
|
resolveProviderUsageSnapshotWithPluginMock.mockResolvedValueOnce({
|
|
provider: "github-copilot",
|
|
displayName: "Copilot",
|
|
windows: [{ label: "Plugin", usedPercent: 11 }],
|
|
});
|
|
const mockFetch = createProviderUsageFetch(async () => {
|
|
throw new Error("legacy fetch should not run");
|
|
});
|
|
|
|
await expect(
|
|
loadProviderUsageSummary({
|
|
now: usageNow,
|
|
auth: [{ provider: "github-copilot", token: "copilot-token" }],
|
|
fetch: mockFetch as unknown as typeof fetch,
|
|
}),
|
|
).resolves.toEqual({
|
|
updatedAt: usageNow,
|
|
providers: [
|
|
{
|
|
provider: "github-copilot",
|
|
displayName: "Copilot",
|
|
windows: [{ label: "Plugin", usedPercent: 11 }],
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(mockFetch).not.toHaveBeenCalled();
|
|
expect(resolveProviderUsageSnapshotWithPluginMock).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
provider: "github-copilot",
|
|
context: expect.objectContaining({
|
|
provider: "github-copilot",
|
|
token: "copilot-token",
|
|
timeoutMs: 5_000,
|
|
}),
|
|
}),
|
|
);
|
|
});
|
|
});
|