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

extract-vercel-pricing.test.ts

145 lines3.9 KB

1import { describe, expect, it } from 'vitest'
2import { compileOpenRouterPricing } from '@modelschemas/rate-card'
3​
4import {
5 compileVercelEndpointRange,
6 vercelEndpointsUrl,
7 vercelRangePath,
8 VERCEL_PRICING_EXTRACT_CRON,
9} from './extract-vercel-pricing.ts'
10import { SPEC_SYNC_SHARD_CRONS } from './sync.ts'
11​
12const source = {
13 url: 'https://ai-gateway.vercel.sh/v1/models/alibaba/qwen-3-235b/endpoints',
14 hash: 'ab'.repeat(32),
15 extractedAt: '2026-10-23T00:00:00.000Z',
17​
18function endpoint(
19 provider: string,
20 prompt: string,
21 completion: string,
22 status = 0,
23) {
24 return {
25 provider_name: provider,
26 status,
27 pricing: {
28 prompt,
29 completion,
30 request: '0',
31 image: '0',
32 },
33 }
35​
36describe('compileVercelEndpointRange', () => {
37 it('ranges status-0 routes and names the inline cards by provider', () => {
38 const { range, skipped } = compileVercelEndpointRange(
39 'alibaba/qwen-3-235b',
40 {
41 data: {
42 endpoints: [
43 endpoint('deepinfra', '0.00000009', '0.00000055'),
44 endpoint('vertex', '0.00000022', '0.00000088'),
45 ],
46 },
47 },
48 source,
49 )
50 expect(skipped).toEqual([])
51 expect(range?.currency).toBe('USD')
52 expect(range?.inputPerMillion).toEqual({ min: 0.09, max: 0.22 })
53 expect(range?.routes.map((route) => route.provider)).toEqual([
54 'deepinfra',
55 'vertex',
56 ])
57 expect(range?.routes[0]?.card).toEqual(
58 compileOpenRouterPricing(
59 endpoint('deepinfra', '0.00000009', '0.00000055').pricing,
60 source,
61 ),
62 )
63 expect(range?.routes[0]?.model).toBe('deepinfra')
64 })
65​
66 it('omits a non-zero status and names it, and refuses when a price is missing', () => {
67 const down = compileVercelEndpointRange(
68 'm',
69 {
70 data: {
71 endpoints: [
72 endpoint('deepinfra', '0.00000009', '0.00000055'),
73 endpoint('vertex', '0.00000022', '0.00000088', 1),
74 endpoint('bedrock', '0.0000001', '0.0000002'),
75 ],
76 },
77 },
78 source,
79 )
80 expect(down.skipped).toEqual(['vertex'])
81 expect(vercelRangePath(down.skipped)).toBe(
82 'data.endpoints[status=0].pricing; skipped status!=0: vertex',
83 )
84 expect(down.range?.routes).toHaveLength(2)
85​
86 const gap = compileVercelEndpointRange(
87 'm',
88 {
89 data: {
90 endpoints: [
91 endpoint('deepinfra', '0.00000009', '0.00000055'),
92 {
93 provider_name: 'vertex',
94 status: 0,
95 pricing: { prompt: '0', completion: '0' },
96 },
97 ],
98 },
99 },
100 source,
101 )
102 expect(gap.range).toBeNull()
103 })
104​
105 it('refuses a tiered endpoint price instead of storing part of the range', () => {
106 const { range } = compileVercelEndpointRange(
107 'm',
108 {
109 data: {
110 endpoints: [
111 endpoint('deepinfra', '0.00000009', '0.00000055'),
112 {
113 provider_name: 'vertex',
114 status: 0,
115 pricing: {
116 prompt: '0.00000022',
117 completion: '0.00000088',
118 overrides: [{ min_prompt_tokens: 1000, prompt: '0.0000004' }],
119 },
120 },
121 ],
122 },
123 },
124 source,
125 )
126 expect(range).toBeNull()
127 })
128})
129​
130describe('VERCEL_PRICING_EXTRACT_CRON', () => {
131 it('is a daily firing of its own, not the models poll', async () => {
132 expect(VERCEL_PRICING_EXTRACT_CRON).toBe('0 4 * * *')
133 expect(
134 (SPEC_SYNC_SHARD_CRONS as ReadonlyArray<string>).includes(
135 VERCEL_PRICING_EXTRACT_CRON,
136 ),
137 ).toBe(false)
138 const fs = await import('node:fs/promises')
139 const raw = await fs.readFile('wrangler.jsonc', 'utf8')
140 expect(raw).toContain(`"${VERCEL_PRICING_EXTRACT_CRON}"`)
141 expect(vercelEndpointsUrl('alibaba/qwen-3-235b')).toBe(
142 'https://ai-gateway.vercel.sh/v1/models/alibaba/qwen-3-235b/endpoints',
143 )
144 })
145})