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

neon.test.ts

120 lines3.4 KB

1import { describe, expect, it } from 'vitest'
2​
3import { parseNeonModels, provider } from './neon.ts'
4​
5const source = {
6 url: 'https://neon.com/models.json',
7 hash: 'h',
8 extractedAt: 't',
9}
10​
11const chat = {
12 id: 'claude-opus-5-5',
13 name: 'Claude Opus 5.5',
14 lab: 'anthropic',
15 released: true,
16 reasoning: true,
17 reasoning_options: [{ type: 'effort', values: ['low', 'high', 'max'] }],
18 tool_call: true,
19 temperature: false,
20 structured_output: true,
21 open_weights: false,
22 knowledge: '2026-01-31',
23 release_date: '2026-09-01',
24 modalities: { input: ['text', 'image', 'pdf'], output: ['text'] },
25 limit: { context: 1_000_000, output: 128_000 },
26 cost: { input: 4, output: 20, cache_read: 0.4, cache_write: 5 },
28​
29describe('neon catalog', () => {
30 it('reads a chat row with a USD-per-million card', () => {
31 const [model] = parseNeonModels({ neon: { models: { x: chat } } }, source)
32 expect(model).toMatchObject({
33 rawId: 'claude-opus-5-5',
34 activity: 'chat',
35 contextWindow: 1_000_000,
36 maxOutput: 128_000,
37 capabilities: ['tools', 'structured_outputs'],
38 unsupportedCapabilities: ['temperature'],
39 reasoning: {
40 mode: 'effort',
41 mandatory: null,
42 efforts: ['low', 'high', 'max'],
43 },
44 knowledgeCutoff: '2026-01-31',
45 openWeights: false,
46 releasedAt: Math.floor(Date.parse('2026-09-01') / 1000),
47 })
48 const card = model?.pricing as {
49 tables: { rate: { base: Record<string, number> } }
50 }
51 expect(card.tables.rate.base).toMatchObject({
52 input_tokens: 4 / 1e6,
53 output_tokens: 20 / 1e6,
54 cache_read_tokens: 0.4 / 1e6,
55 })
56 })
57​
58 it('maps embeddings, drops decisions and unreleased rows, and reads none as switchable', () => {
59 const models = parseNeonModels(
60 {
61 neon: {
62 models: {
63 a: {
64 id: 'bge-large-en',
65 released: true,
66 type: 'embedding',
67 cost: { input: 0.1 },
68 },
69 b: {
70 id: 'jev',
71 released: true,
72 type: 'decision',
73 cost: { input: 0.04 },
74 },
75 c: { ...chat, id: 'soon', released: false },
76 d: {
77 ...chat,
78 id: 'gpt-5-5',
79 reasoning_options: [{ type: 'effort', values: ['none', 'low'] }],
80 },
81 e: {
82 ...chat,
83 id: 'budget',
84 reasoning_options: [{ type: 'budget_tokens' }],
85 },
86 },
87 },
88 },
89 source,
90 )
91 expect(models.map((m) => [m.rawId, m.activity])).toEqual([
92 ['bge-large-en', 'embeddings'],
93 ['gpt-5-5', 'chat'],
94 ['budget', 'chat'],
95 ])
96 expect(models[1]?.reasoning).toEqual({
97 mode: 'effort',
98 mandatory: false,
99 efforts: ['none', 'low'],
100 })
101 expect(models[2]?.reasoning).toEqual({ mode: 'budget', mandatory: null })
102 })
103​
104 it('refuses a cost that is not a price', () => {
105 expect(() =>
106 parseNeonModels(
107 { neon: { models: { a: { ...chat, cost: { input: 'free' } } } } },
108 source,
109 ),
110 ).toThrow('cost.input')
111 })
112​
113 it('binds /v1 routes on the branch host', () => {
114 expect(provider.classify('/v1/chat/completions', {})).toBe('chat')
115 expect(provider.classify('/v1/embeddings', {})).toBe('embeddings')
116 expect(
117 provider.generationEndpointId?.({ rawId: 'x', activity: 'chat' }),
118 ).toBe('v1/chat/completions')
119 })
120})