|
| 1 | +import { describe, it, expect, beforeAll } from 'vitest' |
| 2 | + |
| 3 | +import { getModelCosts, getShortModelName, loadPricing } from '../src/models.js' |
| 4 | + |
| 5 | +beforeAll(async () => { |
| 6 | + await loadPricing() |
| 7 | +}) |
| 8 | + |
| 9 | +describe('getModelCosts', () => { |
| 10 | + it('does not match short canonical against longer pricing key', () => { |
| 11 | + const costs = getModelCosts('gpt-4') |
| 12 | + if (costs) { |
| 13 | + expect(costs.inputCostPerToken).not.toBe(2.5e-6) |
| 14 | + } |
| 15 | + }) |
| 16 | + |
| 17 | + it('returns correct pricing for gpt-4o vs gpt-4o-mini', () => { |
| 18 | + const mini = getModelCosts('gpt-4o-mini') |
| 19 | + const full = getModelCosts('gpt-4o') |
| 20 | + expect(mini).not.toBeNull() |
| 21 | + expect(full).not.toBeNull() |
| 22 | + expect(mini!.inputCostPerToken).toBeLessThan(full!.inputCostPerToken) |
| 23 | + }) |
| 24 | + |
| 25 | + it('returns fallback pricing for known Claude models', () => { |
| 26 | + const costs = getModelCosts('claude-opus-4-6-20260205') |
| 27 | + expect(costs).not.toBeNull() |
| 28 | + expect(costs!.inputCostPerToken).toBe(5e-6) |
| 29 | + }) |
| 30 | +}) |
| 31 | + |
| 32 | +describe('getShortModelName', () => { |
| 33 | + it('maps gpt-4o-mini correctly (not gpt-4o)', () => { |
| 34 | + expect(getShortModelName('gpt-4o-mini-2024-07-18')).toBe('GPT-4o Mini') |
| 35 | + }) |
| 36 | + |
| 37 | + it('maps gpt-4o correctly', () => { |
| 38 | + expect(getShortModelName('gpt-4o-2024-08-06')).toBe('GPT-4o') |
| 39 | + }) |
| 40 | + |
| 41 | + it('maps gpt-4.1-mini correctly (not gpt-4.1)', () => { |
| 42 | + expect(getShortModelName('gpt-4.1-mini-2025-04-14')).toBe('GPT-4.1 Mini') |
| 43 | + }) |
| 44 | + |
| 45 | + it('maps gpt-5.4-mini correctly (not gpt-5.4)', () => { |
| 46 | + expect(getShortModelName('gpt-5.4-mini')).toBe('GPT-5.4 Mini') |
| 47 | + }) |
| 48 | + |
| 49 | + it('maps claude-opus-4-6 with date suffix', () => { |
| 50 | + expect(getShortModelName('claude-opus-4-6-20260205')).toBe('Opus 4.6') |
| 51 | + }) |
| 52 | +}) |
0 commit comments