mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
fix(ci): type usage command cost mocks
This commit is contained in:
@@ -1,14 +1,35 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type {
|
||||
CostUsageSummary,
|
||||
CostUsageTotals,
|
||||
SessionCostSummary,
|
||||
} from "../../infra/session-cost-usage.js";
|
||||
import { handleUsageCommand } from "./commands-session.js";
|
||||
import type { HandleCommandsParams } from "./commands-types.js";
|
||||
|
||||
const resolveSessionAgentIdMock = vi.hoisted(() => vi.fn(() => "main"));
|
||||
const loadSessionCostSummaryMock = vi.hoisted(() => vi.fn(async () => null));
|
||||
const loadSessionCostSummaryMock = vi.hoisted(() =>
|
||||
vi.fn<() => Promise<SessionCostSummary | null>>(async () => null),
|
||||
);
|
||||
const loadCostUsageSummaryMock = vi.hoisted(() =>
|
||||
vi.fn(async () => ({
|
||||
vi.fn<() => Promise<CostUsageSummary>>(async () => ({
|
||||
updatedAt: 0,
|
||||
days: 30,
|
||||
daily: [],
|
||||
totals: { totalCost: 0, missingCostEntries: 0 },
|
||||
totals: {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
totalTokens: 0,
|
||||
totalCost: 0,
|
||||
inputCost: 0,
|
||||
outputCost: 0,
|
||||
cacheReadCost: 0,
|
||||
cacheWriteCost: 0,
|
||||
missingCostEntries: 0,
|
||||
},
|
||||
})),
|
||||
);
|
||||
|
||||
@@ -59,18 +80,42 @@ function buildUsageParams(): HandleCommandsParams {
|
||||
} as unknown as HandleCommandsParams;
|
||||
}
|
||||
|
||||
function buildCostTotals(overrides: Partial<CostUsageTotals> = {}): CostUsageTotals {
|
||||
return {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
totalTokens: 0,
|
||||
totalCost: 0,
|
||||
inputCost: 0,
|
||||
outputCost: 0,
|
||||
cacheReadCost: 0,
|
||||
cacheWriteCost: 0,
|
||||
missingCostEntries: 0,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("handleUsageCommand", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
resolveSessionAgentIdMock.mockReturnValue("target");
|
||||
loadSessionCostSummaryMock.mockResolvedValue({
|
||||
totalCost: 1.23,
|
||||
totalTokens: 100,
|
||||
missingCostEntries: 0,
|
||||
...buildCostTotals({
|
||||
totalCost: 1.23,
|
||||
totalTokens: 100,
|
||||
missingCostEntries: 0,
|
||||
}),
|
||||
});
|
||||
loadCostUsageSummaryMock.mockResolvedValue({
|
||||
updatedAt: 0,
|
||||
days: 30,
|
||||
daily: [],
|
||||
totals: { totalCost: 4.56, missingCostEntries: 0 },
|
||||
totals: buildCostTotals({
|
||||
totalCost: 4.56,
|
||||
missingCostEntries: 0,
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user