|
| 1 | +import { describe, expect, test, it } from "bun:test"; |
1 | 2 | import { getModelStats } from "./modelStats"; |
2 | 3 |
|
3 | 4 | describe("getModelStats", () => { |
4 | | - it("should return model stats for claude-sonnet-4-5", () => { |
5 | | - const stats = getModelStats("anthropic:claude-sonnet-4-5"); |
| 5 | + describe("direct model lookups", () => { |
| 6 | + test("should find anthropic models by direct name", () => { |
| 7 | + const stats = getModelStats("anthropic:claude-opus-4-1"); |
| 8 | + expect(stats).not.toBeNull(); |
| 9 | + expect(stats?.max_input_tokens).toBeGreaterThan(0); |
| 10 | + expect(stats?.input_cost_per_token).toBeGreaterThan(0); |
| 11 | + }); |
6 | 12 |
|
7 | | - expect(stats).not.toBeNull(); |
8 | | - expect(stats?.input_cost_per_token).toBe(0.000003); |
9 | | - expect(stats?.output_cost_per_token).toBe(0.000015); |
10 | | - expect(stats?.max_input_tokens).toBe(200000); |
| 13 | + test("should find openai models by direct name", () => { |
| 14 | + const stats = getModelStats("openai:gpt-5"); |
| 15 | + expect(stats).not.toBeNull(); |
| 16 | + expect(stats?.max_input_tokens).toBeGreaterThan(0); |
| 17 | + }); |
| 18 | + |
| 19 | + test("should find models in models-extra.ts", () => { |
| 20 | + const stats = getModelStats("openai:gpt-5-pro"); |
| 21 | + expect(stats).not.toBeNull(); |
| 22 | + expect(stats?.max_input_tokens).toBe(400000); |
| 23 | + expect(stats?.input_cost_per_token).toBe(0.000015); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + describe("ollama model lookups with cloud suffix", () => { |
| 28 | + test("should find ollama gpt-oss:20b with cloud suffix", () => { |
| 29 | + const stats = getModelStats("ollama:gpt-oss:20b"); |
| 30 | + expect(stats).not.toBeNull(); |
| 31 | + expect(stats?.max_input_tokens).toBe(131072); |
| 32 | + expect(stats?.input_cost_per_token).toBe(0); // Local models are free |
| 33 | + expect(stats?.output_cost_per_token).toBe(0); |
| 34 | + }); |
| 35 | + |
| 36 | + test("should find ollama gpt-oss:120b with cloud suffix", () => { |
| 37 | + const stats = getModelStats("ollama:gpt-oss:120b"); |
| 38 | + expect(stats).not.toBeNull(); |
| 39 | + expect(stats?.max_input_tokens).toBe(131072); |
| 40 | + }); |
| 41 | + |
| 42 | + test("should find ollama deepseek-v3.1:671b with cloud suffix", () => { |
| 43 | + const stats = getModelStats("ollama:deepseek-v3.1:671b"); |
| 44 | + expect(stats).not.toBeNull(); |
| 45 | + expect(stats?.max_input_tokens).toBeGreaterThan(0); |
| 46 | + }); |
11 | 47 | }); |
12 | 48 |
|
13 | | - it("should handle model without provider prefix", () => { |
14 | | - const stats = getModelStats("claude-sonnet-4-5"); |
| 49 | + describe("ollama model lookups without cloud suffix", () => { |
| 50 | + test("should find ollama llama3.1 directly", () => { |
| 51 | + const stats = getModelStats("ollama:llama3.1"); |
| 52 | + expect(stats).not.toBeNull(); |
| 53 | + expect(stats?.max_input_tokens).toBeGreaterThan(0); |
| 54 | + }); |
15 | 55 |
|
16 | | - expect(stats).not.toBeNull(); |
17 | | - expect(stats?.input_cost_per_token).toBe(0.000003); |
| 56 | + test("should find ollama llama3:8b with size variant", () => { |
| 57 | + const stats = getModelStats("ollama:llama3:8b"); |
| 58 | + expect(stats).not.toBeNull(); |
| 59 | + expect(stats?.max_input_tokens).toBeGreaterThan(0); |
| 60 | + }); |
| 61 | + |
| 62 | + test("should find ollama codellama", () => { |
| 63 | + const stats = getModelStats("ollama:codellama"); |
| 64 | + expect(stats).not.toBeNull(); |
| 65 | + expect(stats?.max_input_tokens).toBeGreaterThan(0); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + describe("provider-prefixed lookups", () => { |
| 70 | + test("should find models with provider/ prefix", () => { |
| 71 | + // Some models in models.json use provider/ prefix |
| 72 | + const stats = getModelStats("ollama:llama2"); |
| 73 | + expect(stats).not.toBeNull(); |
| 74 | + expect(stats?.max_input_tokens).toBeGreaterThan(0); |
| 75 | + }); |
18 | 76 | }); |
19 | 77 |
|
20 | | - it("should return cache pricing when available", () => { |
21 | | - const stats = getModelStats("anthropic:claude-sonnet-4-5"); |
| 78 | + describe("unknown models", () => { |
| 79 | + test("should return null for completely unknown model", () => { |
| 80 | + const stats = getModelStats("unknown:fake-model-9000"); |
| 81 | + expect(stats).toBeNull(); |
| 82 | + }); |
| 83 | + |
| 84 | + test("should return null for known provider but unknown model", () => { |
| 85 | + const stats = getModelStats("ollama:this-model-does-not-exist"); |
| 86 | + expect(stats).toBeNull(); |
| 87 | + }); |
| 88 | + }); |
| 89 | + |
| 90 | + describe("model without provider prefix", () => { |
| 91 | + test("should handle model string without provider", () => { |
| 92 | + const stats = getModelStats("gpt-5"); |
| 93 | + expect(stats).not.toBeNull(); |
| 94 | + expect(stats?.max_input_tokens).toBeGreaterThan(0); |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
| 98 | + describe("existing test cases", () => { |
| 99 | + it("should return model stats for claude-sonnet-4-5", () => { |
| 100 | + const stats = getModelStats("anthropic:claude-sonnet-4-5"); |
| 101 | + |
| 102 | + expect(stats).not.toBeNull(); |
| 103 | + expect(stats?.input_cost_per_token).toBe(0.000003); |
| 104 | + expect(stats?.output_cost_per_token).toBe(0.000015); |
| 105 | + expect(stats?.max_input_tokens).toBe(200000); |
| 106 | + }); |
| 107 | + |
| 108 | + it("should handle model without provider prefix", () => { |
| 109 | + const stats = getModelStats("claude-sonnet-4-5"); |
| 110 | + |
| 111 | + expect(stats).not.toBeNull(); |
| 112 | + expect(stats?.input_cost_per_token).toBe(0.000003); |
| 113 | + }); |
| 114 | + |
| 115 | + it("should return cache pricing when available", () => { |
| 116 | + const stats = getModelStats("anthropic:claude-sonnet-4-5"); |
| 117 | + |
| 118 | + expect(stats?.cache_creation_input_token_cost).toBe(0.00000375); |
| 119 | + expect(stats?.cache_read_input_token_cost).toBe(3e-7); |
| 120 | + }); |
| 121 | + |
| 122 | + it("should return null for unknown models", () => { |
| 123 | + const stats = getModelStats("unknown:model"); |
22 | 124 |
|
23 | | - expect(stats?.cache_creation_input_token_cost).toBe(0.00000375); |
24 | | - expect(stats?.cache_read_input_token_cost).toBe(3e-7); |
| 125 | + expect(stats).toBeNull(); |
| 126 | + }); |
25 | 127 | }); |
26 | 128 |
|
27 | | - it("should return null for unknown models", () => { |
28 | | - const stats = getModelStats("unknown:model"); |
| 129 | + describe("model data validation", () => { |
| 130 | + test("should include cache costs when available", () => { |
| 131 | + const stats = getModelStats("anthropic:claude-opus-4-1"); |
| 132 | + // Anthropic models have cache costs |
| 133 | + if (stats) { |
| 134 | + expect(stats.cache_creation_input_token_cost).toBeDefined(); |
| 135 | + expect(stats.cache_read_input_token_cost).toBeDefined(); |
| 136 | + } |
| 137 | + }); |
29 | 138 |
|
30 | | - expect(stats).toBeNull(); |
| 139 | + test("should not include cache costs when unavailable", () => { |
| 140 | + const stats = getModelStats("ollama:llama3.1"); |
| 141 | + // Ollama models don't have cache costs in models.json |
| 142 | + if (stats) { |
| 143 | + expect(stats.cache_creation_input_token_cost).toBeUndefined(); |
| 144 | + expect(stats.cache_read_input_token_cost).toBeUndefined(); |
| 145 | + } |
| 146 | + }); |
31 | 147 | }); |
32 | 148 | }); |
0 commit comments