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

azure.test.ts

200 lines6.6 KB

1import { afterEach, describe, expect, it } from 'vitest'
2​
3import { AZURE_MODELS_URL, AZURE_REASONING_URL } from '../azure-models.ts'
4import { AZURE_PRICES_URL, AZURE_PRICING_PAGE_URL } from '../azure-pricing.ts'
5import { AZURE_SPEC_URL, provider } from './azure.ts'
6​
7/** Excerpts of the two Learn articles' markdown twins (2026-10-06). */
8const MODELS = `::: zone pivot="azure-openai"
9​
10## O-Series models
11​
12| Model ID | Description | Max request (tokens) | Training data (up to) |
13| --- | --- | --- | --- |
14\`o3-deep-research\` is only available with Foundry Agent Service. The \`o9\` family is not a model.
15​
16| \`o3\` (2025-04-16) | - Chat Completions API. - Structured outputs. - Text and image processing. - Functions, tools, and parallel tool calling. | Input: 200,000 Output: 100,000 | May 31, 2024 |
17​
18## Image generation models
19​
20| Model ID | Max request (characters) |
21| --- | --- |
22| \`gpt-image-2\` | 4,000 |
23​
24::: zone-end
26​
27const REASONING = [
28 '| **Feature** | **o3**,**2025-04-16** |',
29 '| --- | --- |',
30 '| **Reasoning effort** | ✅ |',
31 '| Chat Completions API | ✅ |',
32 '',
33 "`max` works only with GPT-6 or GPT-5.6 models and the Responses API. `xhigh` works only with GPT-6, GPT-5.6, GPT-5.5, GPT-5.4, and `gpt-5.1-codex-max` models. `minimal` works only with the original GPT-5 reasoning models. `minimal` doesn't work with `gpt-5.1` or greater. **Options (model-dependent)**: `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`",
34 '^5^`gpt-5-pro` only supports `reasoning_effort``high`, this is the default value even when not explicitly passed to the model.',
35 "^7^`gpt-5.6`, `gpt-5.5`, `gpt-5.4`, `gpt-5.2`, `gpt-5.1`, `gpt-5.1-codex`, `gpt-5.1-codex-max`, and `gpt-5.1-codex-mini` support `'None'` as a value for the `reasoning_effort` parameter.",
36 '^\\*^`gpt-5-codex` also does not support `reasoning_effort``minimal`.',
37].join('\n')
38​
39const CHAT_SPEC = {
40 openapi: '3.2.0',
41 paths: {
42 '/chat/completions': {
43 post: {
44 requestBody: {
45 content: {
46 'application/json': {
47 schema: {
48 properties: {
49 messages: { type: 'array' },
50 max_completion_tokens: { type: 'integer' },
51 max_tokens: {
52 description:
53 'This value is now deprecated in favor of `max_completion_tokens`, and is not compatible with o1 series models.',
54 },
55 },
56 },
57 },
58 },
59 },
60 },
61 },
62 },
64​
65const PAGE_TWO = 'https://prices.azure.com/api/retail/prices?page=2'
66const PRICES: Record<string, unknown> = {
67 [AZURE_PRICES_URL]: {
68 Items: [
69 { skuName: 'o3 0416 Inp glbl', unitOfMeasure: '1K', retailPrice: 0.002 },
70 ],
71 NextPageLink: PAGE_TWO,
72 },
73 [PAGE_TWO]: {
74 Items: [
75 { skuName: 'o3 0416 Outp glbl', unitOfMeasure: '1K', retailPrice: 0.008 },
76 {
77 skuName: 'o3-deep research 0626-inp-glbl',
78 unitOfMeasure: '1M',
79 retailPrice: 10,
80 },
81 ],
82 NextPageLink: null,
83 },
85const PRICING_PAGE =
86 '<td>GPT-5.4 (&lt;272k context length)</td><td>GPT-5.4 (&gt;272k context length)</td>'
87​
88const originalFetch = globalThis.fetch
89​
90afterEach(() => {
91 globalThis.fetch = originalFetch
92})
93​
94function stubFetch(
95 models: string,
96 urls: Array<string> = [],
97 pricingPage = PRICING_PAGE,
98 reasoning = REASONING,
99) {
100 globalThis.fetch = ((input: string, init?: RequestInit) => {
101 const url = String(input)
102 urls.push(url)
103 if (url === AZURE_MODELS_URL || url === AZURE_REASONING_URL) {
104 expect(new Headers(init?.headers).get('Accept')).toBe('text/markdown')
105 return Promise.resolve(
106 new Response(url === AZURE_MODELS_URL ? models : reasoning),
107 )
108 }
109 if (url in PRICES) return Promise.resolve(Response.json(PRICES[url]))
110 if (url === AZURE_PRICING_PAGE_URL) {
111 return Promise.resolve(new Response(pricingPage))
112 }
113 if (url === AZURE_SPEC_URL) {
114 return Promise.resolve(Response.json(CHAT_SPEC))
115 }
116 return Promise.reject(new Error(`unexpected fetch: ${url}`))
117 }) as typeof fetch
119​
120describe('azure', () => {
121 it('lists the tabulated models with facts, price, and sources', async () => {
122 stubFetch(MODELS)
123 const { models } = await provider.listModels({})
124​
125 expect(models.map((model) => [model.rawId, model.activity])).toEqual([
126 ['o3', 'chat'],
127 ['gpt-image-2', 'image'],
128 // Named in prose and metered: kept, with no facts. `o9` is dropped.
129 ['o3-deep-research', null],
130 ])
131 const o3 = models[0]
132 expect(o3).toMatchObject({
133 contextWindow: 200_000,
134 maxOutput: 100_000,
135 modalities: { input: ['text', 'image'], output: null },
136 capabilities: [
137 'reasoning',
138 'tools',
139 'structured_outputs',
140 'response_format',
141 ],
142 schemaEndpointId: 'chat/completions',
143 reasoning: {
144 mode: 'effort',
145 mandatory: null,
146 efforts: ['low', 'medium', 'high'],
147 },
148 requestMap: {
149 thinking: {
150 on: { reasoning_effort: 'high' },
151 off: null,
152 },
153 maxTokensField: 'max_completion_tokens',
154 reasoningEffort: true,
155 },
156 pricing: {
157 tables: { rate: { base: { input_tokens: 2e-6, output_tokens: 8e-6 } } },
158 },
159 })
160 expect(o3?.factSources?.pricing?.sourceUrl).toBe(AZURE_PRICES_URL)
161 expect(o3?.factSources?.maxOutput?.sourceUrl).toBe(AZURE_MODELS_URL)
162 expect(models[1]?.pricing).toBeNull()
163 })
164​
165 it('throws when the pricing page labels no threshold', async () => {
166 stubFetch(MODELS, [], '<td>GPT-5.4 Global</td>')
167 await expect(provider.listModels({})).rejects.toThrow(
168 'labels no context-length threshold',
169 )
170 })
171​
172 it('throws when the reasoning article states no effort rules', async () => {
173 stubFetch(
174 MODELS,
175 [],
176 PRICING_PAGE,
177 '| **Feature** | **o3** |\n| --- |\n| **Reasoning effort** | ✅ |\n',
178 )
179 await expect(provider.listModels({})).rejects.toThrow(
180 'effort options did not parse',
181 )
182 })
183​
184 it('throws when the models article tabulates nothing', async () => {
185 stubFetch('::: zone pivot="azure-openai"\n\nNo tables.\n')
186 await expect(provider.listModels({})).rejects.toThrow('parsed 0 model rows')
187 })
188​
189 it("fetches Azure's own v1 spec and classifies its chat routes", async () => {
190 const urls: Array<string> = []
191 stubFetch(MODELS, urls)
192 const spec = await provider.fetchSpec({})
193​
194 expect(urls).toEqual([AZURE_SPEC_URL])
195 expect(spec.sources[0]?.url).toBe(AZURE_SPEC_URL)
196 expect(spec.specRevision).toBe(spec.sources[0]?.hash)
197 expect(provider.classify('/responses', {})).toBe('chat')
198 expect(provider.classify('/fine_tuning/jobs', {})).toBeNull()
199 })
200})