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

seed-providers.test.ts

73 lines2.0 KB

1import { describe, expect, it } from 'vitest'
2​
3import { providerSeeds, seedFromAdapter } from './seed-providers.ts'
4import type { ProviderConfig } from '#/server/providers/types.ts'
5​
6const CORE_IDS = [
7 'openai',
8 'anthropic',
9 'gemini',
10 'grok',
11 'elevenlabs',
12 'openrouter',
13 'fal',
14 'byteplus',
15] as const
16​
17describe('providerSeeds', () => {
18 it('includes the original 8 providers and keeps every id unique', () => {
19 const ids = providerSeeds.map((p) => p.id)
20 expect(ids.slice(0, CORE_IDS.length)).toEqual([...CORE_IDS])
21 expect(new Set(ids).size).toBe(ids.length)
22 for (const id of ids) {
23 expect(id).toMatch(/^[a-z0-9]+(-[a-z0-9]+)*$/)
24 }
25 })
26​
27 it('uses https spec sources and models endpoints', () => {
28 for (const p of providerSeeds) {
29 expect(p.specSourceUrl).toMatch(/^https:\/\//)
30 expect(p.modelsEndpoint).toMatch(/^https:\/\//)
31 }
32 })
33​
34 it('keeps OpenRouter keyless', () => {
35 const openrouter = providerSeeds.find((p) => p.id === 'openrouter')
36 expect(openrouter?.authEnvVar).toBeNull()
37 })
38})
39​
40describe('seedFromAdapter', () => {
41 const stub = {
42 id: 'acme',
43 displayName: 'Acme',
44 specSourceUrl: 'https://example.com/openapi.json',
45 modelsEndpoint: 'https://api.example.com/v1/models',
46 authEnvVar: 'MISTRAL_API_KEY',
47 defaultDerivation: 'upstream-spec',
48 fetchSpec: () =>
49 Promise.resolve({
50 specs: [],
51 sources: [],
52 outputStrategy: 'post-200' as const,
53 }),
54 listModels: () => Promise.resolve({ models: [] }),
55 classify: () => null,
56 } satisfies ProviderConfig
57​
58 it('copies seed metadata off the adapter', () => {
59 expect(seedFromAdapter(stub)).toEqual({
60 id: 'acme',
61 displayName: 'Acme',
62 specSourceUrl: 'https://example.com/openapi.json',
63 modelsEndpoint: 'https://api.example.com/v1/models',
64 authEnvVar: 'MISTRAL_API_KEY',
65 })
66 })
67​
68 it('rejects an adapter with no spec source', () => {
69 const { specSourceUrl: _drop, ...rest } = stub
70 void _drop
71 expect(() => seedFromAdapter(rest)).toThrow(/specSourceUrl/)
72 })
73})