|
1 | 1 | import { describe, it, expect } from '@jest/globals'; |
2 | | -import { |
3 | | - checkOrganizationModelRestrictions, |
4 | | - estimateChatTokens_ignoringToolDefinitions, |
5 | | -} from './llm-proxy-helpers'; |
6 | | -import type { OpenRouterChatCompletionRequest } from './providers/openrouter/types'; |
| 2 | +import { checkOrganizationModelRestrictions } from './llm-proxy-helpers'; |
7 | 3 |
|
8 | 4 | describe('checkOrganizationModelRestrictions', () => { |
9 | 5 | describe('enterprise plan - model deny list restrictions', () => { |
@@ -209,58 +205,3 @@ describe('checkOrganizationModelRestrictions', () => { |
209 | 205 | }); |
210 | 206 | }); |
211 | 207 | }); |
212 | | - |
213 | | -describe('estimateChatTokens', () => { |
214 | | - it('should estimate tokens from valid messages', () => { |
215 | | - const body = { |
216 | | - model: 'anthropic/claude-3-opus', |
217 | | - messages: [ |
218 | | - { role: 'user', content: 'Hello, how are you?' }, |
219 | | - { role: 'assistant', content: 'I am doing well, thank you!' }, |
220 | | - ], |
221 | | - } as OpenRouterChatCompletionRequest; |
222 | | - |
223 | | - const result = estimateChatTokens_ignoringToolDefinitions(body); |
224 | | - |
225 | | - expect(result.estimatedInputTokens).toBeGreaterThan(0); |
226 | | - expect(result.estimatedOutputTokens).toBeGreaterThan(0); |
227 | | - }); |
228 | | - |
229 | | - it('should handle missing messages gracefully (regression test for KILOCODE-WEB-5ND)', () => { |
230 | | - // This test ensures we don't crash when messages is undefined/null/invalid |
231 | | - // which can happen with malformed API requests from abuse attempts |
232 | | - const undefinedMessages = { model: 'test' } as OpenRouterChatCompletionRequest; |
233 | | - const nullMessages = { |
234 | | - model: 'test', |
235 | | - messages: null, |
236 | | - } as unknown as OpenRouterChatCompletionRequest; |
237 | | - |
238 | | - expect(estimateChatTokens_ignoringToolDefinitions(undefinedMessages)).toEqual({ |
239 | | - estimatedInputTokens: 0, |
240 | | - estimatedOutputTokens: 0, |
241 | | - }); |
242 | | - expect(estimateChatTokens_ignoringToolDefinitions(nullMessages)).toEqual({ |
243 | | - estimatedInputTokens: 0, |
244 | | - estimatedOutputTokens: 0, |
245 | | - }); |
246 | | - }); |
247 | | - |
248 | | - it('should handle content parts with undefined text', () => { |
249 | | - const body = { |
250 | | - model: 'test', |
251 | | - messages: [ |
252 | | - { |
253 | | - role: 'user', |
254 | | - content: [ |
255 | | - { type: 'text', text: undefined }, |
256 | | - { type: 'text', text: 'hello' }, |
257 | | - ], |
258 | | - }, |
259 | | - ], |
260 | | - } as unknown as OpenRouterChatCompletionRequest; |
261 | | - |
262 | | - const result = estimateChatTokens_ignoringToolDefinitions(body); |
263 | | - expect(result.estimatedInputTokens).toBeGreaterThan(0); |
264 | | - expect(result.estimatedOutputTokens).toBeGreaterThan(0); |
265 | | - }); |
266 | | -}); |
0 commit comments