Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import { makerNamesProvider } from '#/server/first-party.ts'
4import { openRouterVariantUpstream } from '#/server/providers/openrouter.ts'
5import { originNameKey } from './origin-key.ts'
6
7describe('originNameKey (#719)', () => {
8 const prefixes = new Set(['anthropic', 'google', 'mistral', 'meta'])
9 it.each([
10 ['claude-fable-5', 'claude-fable-5'],
11 ['Claude-Fable-5', 'claude-fable-5'],
12 ['anthropic/claude-opus-4.5', 'claude-opus-4-5'],
13 ['google/gemma-4-31B-it', 'gemma-4-31b-it'],
14 // Bedrock form: the maker before a dot, Bedrock's version after.
15 ['anthropic.claude-fable-5-v1:0', 'claude-fable-5'],
16 ['mistral.mistral-large-2407-v1:0', 'mistral-large-2407'],
17 // A maker's own version and an unknown prefix stay.
18 ['cohere.embed-v4:0', 'cohere-embed-v4:0'],
19 ['meta-llama/llama-9-70b', 'meta-llama/llama-9-70b'],
20 ['accounts/fireworks/models/x', 'accounts/fireworks/models/x'],
21 // Only one prefix is dropped, and no Bedrock version off a slash id.
22 ['anthropic/anthropic/x-v1:0', 'anthropic/x-v1:0'],
23 ['gpt-4.1', 'gpt-4-1'],
24 ])('%s → %s', (rawId, key) => {
25 expect(originNameKey(rawId, prefixes)).toBe(key)
26 })
27})
28
29describe('makerNamesProvider (#719)', () => {
30 const gemini = new Set(['gemini', 'google', 'googleaistudio'])
31 it.each([
32 ['Google DeepMind', gemini, true],
33 ['Google', gemini, true],
34 ['Meta', gemini, false],
35 ['Z.ai', new Set(['mistral']), false],
36 ['Mistral AI', new Set(['mistral']), true],
37 ['ByteDance', new Set(['byteplus', 'bytedance']), true],
38 ['DeepSeek', new Set(['byteplus', 'bytedance']), false],
39 // Groq claims no namespace: every maker its listing names is another.
40 ['Meta', new Set(['groq']), false],
41 ['meta-llama', new Set(['groq']), false],
42 ['OpenAI', new Set(['groq']), false],
43 ['Alibaba Cloud', new Set(['groq']), false],
44 ['Z.ai', new Set(['groq']), false],
45 // The same names at the provider that is the maker.
46 ['meta-llama', new Set(['meta']), true],
47 ['Alibaba Cloud', new Set(['dashscope', 'alibaba', 'qwen']), true],
48 ['Z.ai', new Set(['zai', 'zaiorg']), true],
49 ] as const)('%s', (maker, names, expected) => {
50 expect(makerNamesProvider(maker, names)).toBe(expected)
51 })
52})
53
54describe('openRouterVariantUpstream (#719)', () => {
55 it('states the base of a variant only when the listing gives both one canonical_slug', () => {
56 const out = openRouterVariantUpstream([
57 { id: 'anthropic/claude-opus-5', canonical_slug: 'anthropic/opus-5-1' },
58 {
59 id: 'anthropic/claude-opus-5:batch',
60 canonical_slug: 'anthropic/opus-5-1',
61 },
62 { id: 'openai/gpt-9:free', canonical_slug: 'openai/gpt-9-free' },
63 { id: 'openai/gpt-9', canonical_slug: 'openai/gpt-9-2026' },
64 { id: 'qwen/q-1:free', canonical_slug: 'qwen/q-1' },
65 ])
66 expect([...out.keys()]).toEqual(['anthropic/claude-opus-5:batch'])
67 expect(out.get('anthropic/claude-opus-5:batch')).toEqual({
68 providerNamespace: 'anthropic',
69 rawId: 'claude-opus-5',
70 source: {
71 derivation: 'listing',
72 sourceUrl: 'https://openrouter.ai/api/v1/models',
73 path: 'data[].canonical_slug',
74 variant: 'batch',
75 },
76 })
77 })
78})