Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

ids.test.ts

74 lines2.1 KB

1import { describe, expect, it } from 'vitest'
2import {
3 isRoutingAlias,
4 rejectRoutingAliases,
5 toModelConstName,
6 toNativeProviderId,
7} from './ids'
8​
9describe('isRoutingAlias', () => {
10 it('treats a leading tilde as a routing alias', () => {
11 expect(isRoutingAlias('~anthropic/claude-haiku-latest')).toBe(true)
12 })
13​
14 it('does not treat a stable model id as an alias', () => {
15 expect(isRoutingAlias('anthropic/claude-opus-4.6')).toBe(false)
16 })
17})
18​
19describe('rejectRoutingAliases', () => {
20 it('drops alias ids and keeps stable ids', () => {
21 const kept = rejectRoutingAliases([
22 { id: '~anthropic/claude-haiku-latest' },
23 { id: 'openai/gpt-5.5' },
24 { id: 'anthropic/claude-opus-4.6' },
25 ])
26 expect(kept.map((m) => m.id)).toEqual([
27 'openai/gpt-5.5',
28 'anthropic/claude-opus-4.6',
29 ])
30 })
31})
32​
33describe('toNativeProviderId', () => {
34 it('hyphenates Anthropic OpenRouter version dots', () => {
35 expect(toNativeProviderId('claude-fable-5.1', 'anthropic')).toBe(
36 'claude-fable-5-1',
37 )
38 expect(toNativeProviderId('claude-haiku-4.5', 'anthropic')).toBe(
39 'claude-haiku-4-5',
40 )
41 })
42​
43 it('leaves OpenAI, Gemini, and Grok ids unchanged', () => {
44 expect(toNativeProviderId('gpt-5.2', 'openai')).toBe('gpt-5.2')
45 expect(toNativeProviderId('gemini-3.1-pro', 'gemini')).toBe(
46 'gemini-3.1-pro',
47 )
48 expect(toNativeProviderId('grok-4.5', 'grok')).toBe('grok-4.5')
49 })
50})
51​
52describe('toModelConstName', () => {
53 it('turns a stable OpenRouter id into a JS identifier', () => {
54 expect(toModelConstName('anthropic/claude-opus-4.6')).toBe(
55 'ANTHROPIC_CLAUDE_OPUS_4_6',
56 )
57 })
58​
59 it('turns a stripped provider id into a JS identifier', () => {
60 expect(toModelConstName('gpt-5.6-luna-pro')).toBe('GPT_5_6_LUNA_PRO')
61 })
62​
63 it('maps a leading tilde so an OpenRouter alias is a valid JS identifier', () => {
64 expect(toModelConstName('~anthropic/claude-haiku-latest')).toBe(
65 '_ANTHROPIC_CLAUDE_HAIKU_LATEST',
66 )
67 })
68​
69 it('fails loud when the id cannot become a JS identifier', () => {
70 expect(() => toModelConstName('openai/gpt-5.5!')).toThrow(
71 /valid JS identifier/i,
72 )
73 })
74})