From d41f3d6eb6c75dd0281964cb6542de2192e80a2e Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 11 Apr 2026 01:31:54 +0100 Subject: [PATCH] fix(ci): type usage command cost mocks --- .../reply/commands-session-usage.test.ts | 59 ++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/src/auto-reply/reply/commands-session-usage.test.ts b/src/auto-reply/reply/commands-session-usage.test.ts index 97380f32459..d6cbfd844aa 100644 --- a/src/auto-reply/reply/commands-session-usage.test.ts +++ b/src/auto-reply/reply/commands-session-usage.test.ts @@ -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>(async () => null), +); const loadCostUsageSummaryMock = vi.hoisted(() => - vi.fn(async () => ({ + vi.fn<() => Promise>(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 { + 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, + }), }); });