From c507a4f9d5fbeaaa1d7297b35a23249e7df3cde0 Mon Sep 17 00:00:00 2001 From: Paul Holstein <44263169+holstein13@users.noreply.github.com> Date: Mon, 23 Feb 2026 12:34:18 -0500 Subject: [PATCH] fix: warn on unknown model pricing lookups Add console.warn when calculateMessageCost encounters an unknown model, so pricing.json gaps are visible rather than silently returning $0. Update tests to expect the warning. Co-Authored-By: Claude Opus 4.6 --- src/shared/utils/pricing.ts | 7 ++++++- test/main/utils/costCalculation.test.ts | 4 +++- test/shared/utils/pricing.test.ts | 7 ++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/shared/utils/pricing.ts b/src/shared/utils/pricing.ts index 3da30f64..0e3b800a 100644 --- a/src/shared/utils/pricing.ts +++ b/src/shared/utils/pricing.ts @@ -73,7 +73,12 @@ export function calculateMessageCost( cacheCreationTokens: number ): number { const pricing = getPricing(modelName); - if (!pricing) return 0; + if (!pricing) { + if (inputTokens > 0 || outputTokens > 0) { + console.warn(`[pricing] No pricing data for model "${modelName}", cost will be $0`); + } + return 0; + } const inputCost = calculateTieredCost( inputTokens, diff --git a/test/main/utils/costCalculation.test.ts b/test/main/utils/costCalculation.test.ts index b46f96b9..1843daea 100644 --- a/test/main/utils/costCalculation.test.ts +++ b/test/main/utils/costCalculation.test.ts @@ -2,7 +2,7 @@ * Tests for cost calculation in jsonl.ts */ -import { describe, it, expect } from 'vitest'; +import { describe, it, expect, vi } from 'vitest'; import { calculateMetrics } from '@main/utils/jsonl'; import type { ParsedMessage } from '@main/types'; @@ -84,6 +84,7 @@ describe('Cost Calculation', () => { }); it('should return 0 cost when model pricing not found', () => { + const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); const messages: ParsedMessage[] = [ { type: 'assistant', @@ -103,6 +104,7 @@ describe('Cost Calculation', () => { const metrics = calculateMetrics(messages); expect(metrics.costUsd).toBe(0); + warnSpy.mockRestore(); }); }); diff --git a/test/shared/utils/pricing.test.ts b/test/shared/utils/pricing.test.ts index dff7e6e1..7b872cb7 100644 --- a/test/shared/utils/pricing.test.ts +++ b/test/shared/utils/pricing.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect } from 'vitest'; +import { describe, it, expect, vi } from 'vitest'; import { getPricing, calculateTieredCost, @@ -55,8 +55,13 @@ describe('Shared Pricing Module', () => { }); it('should return 0 for unknown models', () => { + const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); const cost = calculateMessageCost('unknown-model', 1000, 500, 0, 0); expect(cost).toBe(0); + expect(warnSpy).toHaveBeenCalledWith( + '[pricing] No pricing data for model "unknown-model", cost will be $0' + ); + warnSpy.mockRestore(); }); it('should include cache token costs', () => {