Open History to see the last commit
1import { price } from '@modelschemas/rate-card'
2import { describe, expect, it } from 'vitest'
3
4import { mistralModelPage, tip } from './fixtures/mistral-model-page.ts'
5import {
6 copyMistralAliasFacts,
7 indexMistralApiIds,
8 indexMistralModalities,
9 mistralIndexSlugFor,
10 mistralModelPricing,
11 mistralRateCard,
12 parseMistralApiIds,
13 parseMistralModelIndex,
14 parseMistralPageMaxOutput,
15 parseMistralPageFeatures,
16 parseMistralPageModalities,
17 parseMistralPagePrice,
18 parseMistralPricing,
19 parseMistralSamePrice,
20 withDocumentInput,
21} from './mistral-pricing.ts'
22
23const PAGE = `<h2>Flagship models</h2>
24<p>Prices /M Tokens</p>
25<table>
26<tr><td><a href="/models/mistral-large-3-25-12">Mistral Large 3</a></td><td>$0.5</td><td>$0.05</td><td>$1.5</td></tr>
27<tr><td><a href="/models/codestral-embed-25-05">Codestral Embed</a></td><td>$0.15</td><td>$0.015</td><td>—</td></tr>
28</table>
29<h2>Specialized models</h2>
30<p>Prices as marked</p>
31<table>
32<tr><td><a href="/models/ocr-4-1">OCR 4.1</a></td><td>$4 /1000 Pages</td><td>$0.4 /1000 Pages</td><td>—</td></tr>
33<tr><td><a href="/models/voxtral-mini-transcribe-26-02">Voxtral</a></td><td>$0.003 /Min</td><td>—</td><td>—</td></tr>
34<tr><td><a href="/models/voxtral-tts-26-03">TTS</a></td><td>$0 /M Chars</td><td>$0 /M Chars</td><td>$16 /M Chars</td></tr>
35<tr><td><a href="/models/mixed-units">Mixed</a></td><td>$1 /Min</td><td>—</td><td>$2 /M Chars</td></tr>
36<tr><td><a href="/models/leanstral-1-5">Leanstral</a></td><td>Free</td><td>Free</td><td>Free</td></tr>
37</table>
38<h2>Code models</h2>
39<p>Prices /M Tokens</p>
40<table>
41<tr><td><a href="/models/codestral-25-08">Codestral</a></td><td>$0.3</td><td>$0.03</td><td>$0.9</td></tr>
42</table>`
43
44describe('mistral pricing page', () => {
45 it('reads per-million tables and unit rows, and skips free or mixed units', () => {
46 const rates = parseMistralPricing(PAGE)
47 expect(rates.get('mistral-large-3-25-12')).toEqual({
48 kind: 'tokens',
49 rates: {
50 input_tokens: 0.5 / 1e6,
51 cache_read_tokens: 0.05 / 1e6,
52 output_tokens: 1.5 / 1e6,
53 },
54 })
55 const codestral = rates.get('codestral-25-08')
56 expect(codestral?.kind === 'tokens' && codestral.rates.output_tokens).toBe(
57 0.9 / 1e6,
58 )
59 expect(rates.get('codestral-embed-25-05')).toEqual({
60 kind: 'tokens',
61 rates: {
62 input_tokens: 0.15 / 1e6,
63 cache_read_tokens: 0.015 / 1e6,
64 },
65 })
66 expect(rates.get('ocr-4-1')).toEqual({
67 kind: 'unit',
68 meters: [
69 { param: 'pages', rate: 4 / 1000 },
70 { param: 'cached_pages', rate: 0.4 / 1000, default: 0 },
71 ],
72 })
73 expect(rates.get('voxtral-mini-transcribe-26-02')).toEqual({
74 kind: 'unit',
75 meters: [{ param: 'audio_minutes', rate: 0.003 }],
76 })
77 expect(rates.get('voxtral-tts-26-03')).toEqual({
78 kind: 'unit',
79 meters: [{ param: 'output_characters', rate: 16 / 1e6 }],
80 })
81 expect(rates.has('mixed-units')).toBe(false)
82 expect(rates.has('leanstral-1-5')).toBe(false)
83 expect(rates.has('mistral-embed')).toBe(false)
84 })
85
86 it('uses the current sale amount, including an unreadable historical quote', () => {
87 const sale = `<h2>Flagship</h2><p>Prices /M Tokens</p><table>
88<tr><td><a href="/models/synthetic-sale">Sale</a></td>
89<td><del><span>Original price: </span>$9</del><ins><span>Sale price: </span>$3</ins></td>
90<td><del>unknown historical amount</del><ins>$0.2</ins></td>
91<td><del>$12</del><ins>$4</ins></td></tr></table>`
92 expect(parseMistralPricing(sale).get('synthetic-sale')).toEqual({
93 kind: 'tokens',
94 rates: {
95 input_tokens: 3 / 1e6,
96 cache_read_tokens: 0.2 / 1e6,
97 output_tokens: 4 / 1e6,
98 },
99 })
100 })
101
102 it.each([
103 '<del>$9</del>',
104 '<del>$9</del><ins>unknown</ins>',
105 '<del>$9</del><ins>$3</ins><ins>$2</ins>',
106 ])(
107 'fails unreadable current sale markup instead of using the old rate: %s',
108 (cell) => {
109 const html = `<h2>Flagship</h2><p>Prices /M Tokens</p><table>
110<tr><td><a href="/models/synthetic-sale">Sale</a></td><td>${cell}</td><td>$1</td><td>$4</td></tr></table>`
111 expect(() => parseMistralPricing(html)).toThrow(/current sale price/)
112 },
113 )
114
115 it('compiles a unit card from the parsed meters', () => {
116 const row = parseMistralPricing(PAGE).get('ocr-4-1')
117 expect(row?.kind).toBe('unit')
118 if (row?.kind !== 'unit') return
119 const card = mistralRateCard(row, {
120 url: 'https://docs.mistral.ai/inference/pricing',
121 hash: 'a'.repeat(64),
122 extractedAt: '2026-10-03T00:00:00.000Z',
123 })
124 expect(card).not.toBeNull()
125 if (!card) return
126 expect(price(card, {}, { pages: 1000 })).toBeCloseTo(4, 9)
127 expect(price(card, {}, { pages: 1000, cached_pages: 1000 })).toBeCloseTo(
128 4.4,
129 9,
130 )
131 const audio = parseMistralPricing(PAGE).get('voxtral-mini-transcribe-26-02')
132 if (audio?.kind !== 'unit') throw new Error('expected an audio unit row')
133 const audioCard = mistralRateCard(audio, {
134 url: 'https://docs.mistral.ai/inference/pricing',
135 hash: 'b'.repeat(64),
136 extractedAt: '2026-10-03T00:00:00.000Z',
137 })
138 if (!audioCard) throw new Error('expected an audio card')
139 expect(price(audioCard, {}, { audio_minutes: 10 })).toBeCloseTo(0.03, 9)
140 })
141
142 it('refuses a priced slug whose model page named no API ids', () => {
143 const rates = parseMistralPricing(PAGE)
144 expect(() =>
145 indexMistralApiIds(rates, [
146 {
147 slug: 'mistral-large-3-25-12',
148 ids: ['mistral-large-2512'],
149 hash: 'a',
150 },
151 ]),
152 ).toThrow(
153 'mistral model pages: no API ids for codestral-embed-25-05, ocr-4-1, voxtral-mini-transcribe-26-02, voxtral-tts-26-03, codestral-25-08',
154 )
155 })
156
157 it('copies a changelog same-price chat id and skips unpriced rows', () => {
158 const rates = parseMistralPricing(PAGE)
159 const byId = indexMistralApiIds(rates, [
160 {
161 slug: 'mistral-large-3-25-12',
162 ids: ['mistral-large-2512'],
163 hash: 'a',
164 },
165 { slug: 'codestral-embed-25-05', ids: ['codestral-embed'], hash: 'b' },
166 { slug: 'codestral-25-08', ids: ['zai-glm-5-3'], hash: 'c' },
167 {
168 slug: 'ocr-4-1',
169 ids: ['mistral-ocr-4-1', 'mistral-ocr-latest'],
170 hash: 'd',
171 },
172 {
173 slug: 'voxtral-mini-transcribe-26-02',
174 ids: ['voxtral-mini-2602'],
175 hash: 'e',
176 },
177 { slug: 'voxtral-tts-26-03', ids: ['voxtral-mini-tts-2603'], hash: 'f' },
178 ])
179 const changelog = `
180 Z.ai GLM 5.2 ( zai-glm-5-2 ) is deprecated and retires on October 31, 2026.
181 Use Z.ai GLM 5.3 ( zai-glm-5-3 ) instead, at the same price.
182 OCR 4.0 ( mistral-ocr-4-0 ) is deprecated. Use OCR 4.1 ( mistral-ocr-4-1 ) instead, at the same price.
183 Leanstral 1.5 ( labs-leanstral-1-5 ) is deprecated and retires on September 30, 2026.
184 `
185 for (const [from, to] of parseMistralSamePrice(changelog)) {
186 const row = byId.get(to)
187 if (!row || byId.has(from)) continue
188 byId.set(from, row)
189 }
190 const glm = byId.get('zai-glm-5-2')
191 expect(glm?.kind === 'tokens' && glm.rates.output_tokens).toBe(0.9 / 1e6)
192 expect(byId.get('mistral-ocr-latest')?.kind).toBe('unit')
193 expect(byId.get('voxtral-mini-2602')?.kind).toBe('unit')
194 expect(byId.has('mistral-ocr-4-0')).toBe(false)
195 expect(byId.has('voxtral-mini-realtime-2602')).toBe(false)
196 expect(byId.has('labs-leanstral-1-5')).toBe(false)
197 expect(byId.has('magistral-medium-latest')).toBe(false)
198 })
199
200 it('reads the API ids a model page lists for the slug', () => {
201 const html =
202 'other "names":["docs","agents"] payload names\\":[\\"mistral-large-2512\\",\\"mistral-large-latest\\"]'
203 expect(parseMistralApiIds(html, 'mistral-large-3-25-12')).toEqual([
204 'mistral-large-2512',
205 'mistral-large-latest',
206 ])
207 })
208})
209
210describe('mistral model page modalities', () => {
211 const parse = (...blocks: Array<Array<unknown>>) =>
212 parseMistralPageModalities(mistralModelPage(['m-1'], blocks))
213 const base = [tip('Text input'), tip('Text output')]
214
215 it('reads the tooltips of the Modalities block', () => {
216 expect(
217 parse([tip('Image input'), tip('Text input'), tip('Text output')]),
218 ).toEqual({ input: ['text', 'image'], output: ['text'] })
219 expect(parse([tip('Audio input'), tip('Text output')])).toEqual({
220 input: ['audio'],
221 output: ['text'],
222 })
223 // The side is matched whatever its case.
224 expect(
225 parse([tip('Text Input'), tip('Image input'), tip('Text OUTPUT')]),
226 ).toEqual({ input: ['text', 'image'], output: ['text'] })
227 // A reasoning marker is not a medium; the page's "Max output" span is
228 // outside the block.
229 expect(parse([...base, tip('Reasoning output')])).toEqual({
230 input: ['text'],
231 output: ['text'],
232 })
233 // A label served as its own lazy row.
234 expect(
235 parseMistralPageModalities(
236 mistralModelPage(
237 ['m-1'],
238 [
239 [
240 tip('Text input'),
241 [
242 '$',
243 '$L4f',
244 'k',
245 {
246 children: [['$', '$L50', null, { asChild: true }], '$Lc0'],
247 },
248 ],
249 ],
250 ],
251 { c0: ['$', '$L51', null, { children: 'Text output' }] },
252 ),
253 ),
254 ).toEqual({ input: ['text'], output: ['text'] })
255 // A tooltip that gains a prop or a key is still a tooltip.
256 expect(
257 parse([
258 ...base,
259 tip('Image input', { side: 'top' }),
260 [
261 '$',
262 '$L4f',
263 'audio',
264 {
265 children: [
266 ['$', '$L50', null, { asChild: true }],
267 ['$', '$L51', 'k1', { children: 'Audio input' }],
268 ],
269 },
270 ],
271 ]),
272 ).toEqual({ input: ['text', 'image', 'audio'], output: ['text'] })
273 })
274
275 it.each([
276 ['an unknown medium', tip('Hologram input')],
277 ['a two-word medium', tip('Point cloud input')],
278 ['a medium with a digit', tip('3D input')],
279 ['a hyphenated medium', tip('3D-mesh input')],
280 ['a plural', tip('Images input')],
281 ['a reworded label', tip('Input: Image')],
282 ['a label with no side', tip('Accepts images')],
283 ['an empty tooltip', tip('')],
284 ['a tooltip that is not text', tip(['$', 'b', null, { children: 'x' }])],
285 ['reasoning as an input', tip('Reasoning input')],
286 ])('reads nothing when the block holds %s', (_name, extra) => {
287 expect(parse([...base, extra])).toBeNull()
288 })
289
290 // A tooltip the walk cannot reach must not be dropped and the rest kept.
291 const image = tip('Image input')
292 const el = (tag: string, props: object) => ['$', tag, null, props]
293 const trigger = (asChild: unknown) =>
294 el('$L4f', {
295 children: [
296 el('$L50', asChild === undefined ? {} : { asChild }),
297 el('$L51', { children: 'Image input' }),
298 ],
299 })
300 it.each([
301 ['a reference with no row', '$Lnope'],
302 ['a tooltip in a Suspense', el('$Sreact.suspense', { children: '$Lc1' })],
303 ['a tooltip under a `content` prop', el('$L60', { content: image })],
304 ['a tooltip under a `fallback` prop', el('div', { fallback: image })],
305 ['object-valued children', el('div', { children: { nested: image } })],
306 ['a trigger with no asChild', trigger(undefined)],
307 ['a trigger with asChild "true"', trigger('true')],
308 ['a lone icon', el('svg', { 'aria-label': 'Image input' })],
309 ['text', 'Image input'],
310 ])('reads nothing when the block holds %s', (_name, extra) => {
311 expect(
312 parseMistralPageModalities(
313 mistralModelPage(['m-1'], [[...base, extra]], { c1: image }),
314 ),
315 ).toBeNull()
316 })
317
318 it('follows a reference to a tooltip, and reads through plain wrappers', () => {
319 const full = { input: ['text', 'image'], output: ['text'] }
320 for (const extra of ['$Lc1', [[image]], el('div', { children: [image] })]) {
321 expect(
322 parseMistralPageModalities(
323 mistralModelPage(['m-1'], [[...base, extra]], { c1: image }),
324 ),
325 ).toEqual(full)
326 }
327 // The arrows between the two sides are not tooltips.
328 const arrows = el('div', {
329 className: 'flex',
330 children: [el('svg', {}), el('svg', {})],
331 })
332 expect(
333 parse([tip('Text input'), image, arrows, tip('Text output')]),
334 ).toEqual(full)
335 })
336
337 it('reads nothing from one side, no block, or blocks that differ', () => {
338 expect(parse([tip('Text input'), tip('Image input')])).toBeNull()
339 expect(parse([tip('Text input'), tip('Reasoning output')])).toBeNull()
340 expect(parse()).toBeNull()
341 expect(parseMistralPageModalities('<h1>Mistral Medium</h1>')).toBeNull()
342 // The page renders the block once per layout; both must agree, so a
343 // second model's block cannot be merged in.
344 expect(parse(base, base)).toEqual({ input: ['text'], output: ['text'] })
345 expect(parse(base, [tip('Audio input'), tip('Audio output')])).toBeNull()
346 // Tooltips outside a Modalities block are not read.
347 expect(
348 parseMistralPageModalities(
349 `<script>self.__next_f.push([1,${JSON.stringify(
350 `1:${JSON.stringify(base)}\n`,
351 )}])</script>`,
352 ),
353 ).toBeNull()
354 })
355
356 it('refuses a poll in which no model page states modalities', async () => {
357 const original = globalThis.fetch
358 globalThis.fetch = ((url: string) => {
359 const href = String(url)
360 const body = href.endsWith('/pricing')
361 ? PAGE
362 : href.endsWith('/changelogs')
363 ? ''
364 : mistralModelPage([href.slice(href.lastIndexOf('/') + 1)], [])
365 return Promise.resolve(new Response(body))
366 }) as typeof fetch
367 try {
368 await expect(mistralModelPricing()).rejects.toThrow(
369 /mistral model pages: 0 of \d+ state modalities/,
370 )
371 } finally {
372 globalThis.fetch = original
373 }
374 })
375
376 it('drops an API id two pages state differently', () => {
377 const text = { input: ['text'], output: ['text'] }
378 const vision = { input: ['text', 'image'], output: ['text'] }
379 const byId = indexMistralModalities([
380 { slug: 'a-1', ids: ['a-1', 'a-latest'], hash: 'h1', modalities: text },
381 { slug: 'a-2', ids: ['a-2', 'a-latest'], hash: 'h2', modalities: vision },
382 { slug: 'b-1', ids: ['b-1'], hash: 'h3', modalities: null },
383 ])
384 expect([...byId.keys()]).toEqual(['a-1', 'a-2'])
385 expect(byId.get('a-2')).toEqual({
386 modalities: vision,
387 url: 'https://docs.mistral.ai/models/a-2',
388 hash: 'h2',
389 })
390 })
391})
392
393describe('mistral model page price and max output', () => {
394 const widget = {
395 type: 'custom',
396 free: false,
397 input: [
398 { type: 'range', price: 0.004, denominator: '/Min' },
399 { type: 'flat', price: 0.1, denominator: '/M Tokens' },
400 ],
401 output: [{ type: 'range', price: 0.4, denominator: '/M Tokens' }],
402 }
403 const page = (extra: Record<string, unknown>) =>
404 mistralModelPage(['voxtral-small-2507'], [[tip('Text input')]], extra)
405
406 it('keeps native OCR annotated-page pricing distinct from ordinary pages', () => {
407 // OCR 4.1's source widget names both denominators; numbers here are synthetic.
408 const ocr = {
409 type: 'custom',
410 free: false,
411 input: [
412 { type: 'flat', price: 7, denominator: '/1000 Pages' },
413 { type: 'flat', price: 11, denominator: '/1000 Annotated Pages' },
414 ],
415 output: [],
416 }
417 expect(parseMistralPagePrice(page({ a1: ocr }))).toEqual({
418 kind: 'unit',
419 meters: [
420 { param: 'pages', rate: 7 / 1000 },
421 { param: 'annotated_pages', rate: 11 / 1000, default: 0 },
422 ],
423 })
424 expect(() =>
425 parseMistralPagePrice(
426 page({
427 a1: {
428 ...ocr,
429 input: [
430 ocr.input[0],
431 {
432 type: 'flat',
433 originalPrice: 11,
434 denominator: '/1000 Annotated Pages',
435 },
436 ],
437 },
438 }),
439 ),
440 ).toThrow('unreadable amount')
441 expect(() =>
442 parseMistralPagePrice(
443 page({
444 a1: {
445 ...ocr,
446 input: [
447 ocr.input[0],
448 { type: 'flat', price: -1, denominator: '/1000 Annotated Pages' },
449 ],
450 },
451 }),
452 ),
453 ).toThrow('negative amount')
454 })
455
456 it('reads mixed units and uses the current widget price', () => {
457 expect(parseMistralPagePrice(page({ a1: widget }))).toEqual({
458 kind: 'tokens',
459 rates: {
460 audio_minutes: 0.004,
461 input_tokens: 0.1 / 1e6,
462 output_tokens: 0.4 / 1e6,
463 },
464 })
465 const card = mistralRateCard(
466 parseMistralPagePrice(page({ a1: widget })) ?? {
467 kind: 'tokens',
468 rates: {},
469 },
470 {
471 url: 'https://docs.mistral.ai/models/voxtral-small-25-07',
472 hash: 'c'.repeat(64),
473 extractedAt: '2026-10-08T00:00:00.000Z',
474 },
475 )
476 expect(card).not.toBeNull()
477 if (!card) return
478 expect(
479 price(card, {}, { input_tokens: 1_000_000, output_tokens: 1_000_000 }),
480 ).toBeCloseTo(0.5, 9)
481 expect(
482 price(
483 card,
484 {},
485 {
486 input_tokens: 1_000_000,
487 output_tokens: 1_000_000,
488 audio_minutes: 2,
489 },
490 ),
491 ).toBeCloseTo(0.508, 9)
492 expect(
493 parseMistralPagePrice(
494 page({
495 a3: {
496 type: 'custom',
497 free: false,
498 input: [
499 {
500 price: 0.68,
501 originalPrice: 1.36,
502 denominator: '/M Tokens',
503 label: 'Input',
504 },
505 {
506 price: 0.07,
507 originalPrice: 0.14,
508 denominator: '/M Tokens',
509 label: 'Cached input',
510 },
511 ],
512 output: [
513 {
514 price: 2.09,
515 originalPrice: 4.18,
516 denominator: '/M Tokens',
517 label: 'Output',
518 },
519 ],
520 },
521 }),
522 ),
523 ).toEqual({
524 kind: 'tokens',
525 rates: {
526 input_tokens: 0.68 / 1e6,
527 cache_read_tokens: 0.07 / 1e6,
528 output_tokens: 2.09 / 1e6,
529 },
530 })
531 })
532
533 it('rejects a missing current widget price rather than using originalPrice', () => {
534 expect(() =>
535 parseMistralPagePrice(
536 page({
537 a1: {
538 type: 'custom',
539 free: false,
540 input: [{ originalPrice: 9, denominator: '/M Tokens' }],
541 output: [{ price: 4, denominator: '/M Tokens' }],
542 },
543 }),
544 ),
545 ).toThrow(/unreadable amount/)
546 })
547
548 it('stores no card for a free widget and throws when widgets disagree', () => {
549 expect(
550 parseMistralPagePrice(
551 page({
552 a1: { type: 'flat', free: true, price: 0, denominator: '/M Tokens' },
553 }),
554 ),
555 ).toBeNull()
556 expect(() =>
557 parseMistralPagePrice(
558 page({
559 a1: widget,
560 a2: {
561 type: 'custom',
562 free: false,
563 input: [{ price: 1, denominator: '/M Tokens' }],
564 output: [{ price: 2, denominator: '/M Tokens' }],
565 },
566 }),
567 ),
568 ).toThrow(/widgets disagree/)
569 })
570
571 it('reads the Max output stat as 1024-based tokens', () => {
572 const stat = (label: string, value: string) => [
573 [
574 '$',
575 'span',
576 null,
577 {
578 className: 'uppercase',
579 children: ['$undefined', label],
580 },
581 ],
582 [
583 '$',
584 'div',
585 null,
586 {
587 className: 'text-lg font-bold font-mono text-primary-soft',
588 children: value,
589 },
590 ],
591 ]
592 expect(
593 parseMistralPageMaxOutput(page({ aa: stat('Max output', '128k') })),
594 ).toBe(128 * 1024)
595 // The context stat is not a max-output cap.
596 expect(
597 parseMistralPageMaxOutput(page({ aa: stat('Context', '1M') })),
598 ).toBeNull()
599 expect(
600 parseMistralPageMaxOutput(
601 page({
602 aa: stat('Max output', '128k'),
603 ab: stat('Max output', '256k'),
604 }),
605 ),
606 ).toBeNull()
607 })
608
609 it('matches one index slug and no more', () => {
610 const slugs = parseMistralModelIndex(
611 '<a href="/models/overview">o</a><a href="/models/voxtral-small-25-07">v</a><a href="/models/leanstral-1-5">l</a><a href="/models/zai-glm-5-2">g</a> /models/page-abc',
612 )
613 const set = new Set(slugs)
614 expect(slugs).toEqual([
615 'voxtral-small-25-07',
616 'leanstral-1-5',
617 'zai-glm-5-2',
618 ])
619 expect(mistralIndexSlugFor('voxtral-small-2507', set)).toBe(
620 'voxtral-small-25-07',
621 )
622 expect(mistralIndexSlugFor('labs-leanstral-1-5', set)).toBe('leanstral-1-5')
623 expect(mistralIndexSlugFor('zai-glm-5-2', set)).toBe('zai-glm-5-2')
624 expect(mistralIndexSlugFor('mistral-medium-2604', set)).toBeNull()
625 expect(mistralIndexSlugFor('magistral-medium-latest', set)).toBeNull()
626 })
627})
628
629describe('mistral alias facts', () => {
630 it('copies one agreed fact onto mutual aliases and skips a conflict', () => {
631 const source = {
632 derivation: 'docs-derived' as const,
633 sourceUrl: 'https://docs.mistral.ai/models/mistral-small-4-0-26-03',
634 }
635 const models = [
636 {
637 rawId: 'mistral-small-latest',
638 modalities: { input: ['text'], output: ['text'] },
639 maxOutput: 131072,
640 factSources: { modalities: source, maxOutput: source },
641 },
642 { rawId: 'mistral-vibe-cli-fast' },
643 {
644 rawId: 'left',
645 pricing: { price: 1 },
646 },
647 {
648 rawId: 'right',
649 pricing: { price: 2 },
650 },
651 { rawId: 'neither' },
652 ]
653 copyMistralAliasFacts(
654 models,
655 new Map([
656 ['mistral-small-latest', ['mistral-vibe-cli-fast']],
657 ['mistral-vibe-cli-fast', ['mistral-small-latest']],
658 ['left', ['right', 'neither']],
659 ['right', ['left']],
660 ['neither', ['left']],
661 ]),
662 )
663 expect(models[1]).toMatchObject({
664 modalities: { input: ['text'], output: ['text'] },
665 maxOutput: 131072,
666 factSources: { modalities: source, maxOutput: source },
667 })
668 expect(models[4]?.pricing).toBeUndefined()
669 })
670})
671
672describe('usdExpr', () => {
673 it('throws rather than compose a non-USD card and drop its currency', async () => {
674 const { compileTokenCard } = await import('@modelschemas/rate-card')
675 const { usdExpr } = await import('./mistral-pricing.ts')
676 const source = {
677 url: 'https://example.test/pricing',
678 hash: 'a'.repeat(64),
679 extractedAt: '2026-10-07T00:00:00Z',
680 }
681 const usd = compileTokenCard({ input_tokens: 1e-6 }, [], source)
682 const yuan = compileTokenCard({ input_tokens: 1e-6 }, [], source, {
683 currency: 'CNY',
684 })
685 if (!usd || !yuan) throw new Error('did not compile')
686 expect(usdExpr(usd)).toBe(usd.price)
687 expect(() => usdExpr(yuan)).toThrow('cannot extend a CNY card')
688 })
689})
690
691describe('mistral model page features', () => {
692 // The live shape (2026-10-22): a "Features" heading, then a grid of
693 // `div`s keyed by feature id; later ones arrive as lazy rows.
694 const feature = (id: string, disabled: unknown = '$undefined') => [
695 '$',
696 'div',
697 id,
698 { className: 'flex flex-col', 'aria-disabled': disabled, children: [] },
699 ]
700 const page = (grid: Array<unknown>, extra: Record<string, unknown> = {}) =>
701 mistralModelPage(['m-1'], [[tip('Text input'), tip('Text output')]], {
702 f: [
703 '$',
704 '$L5b',
705 null,
706 {
707 children: [
708 [
709 '$',
710 '$L1c',
711 null,
712 { children: ['$', '$L1d', null, { children: 'Features' }] },
713 ],
714 ['$', 'div', null, { className: 'grid', children: grid }],
715 ],
716 },
717 ],
718 ...extra,
719 })
720
721 it('reads feature ids, lazy rows followed', () => {
722 const html = page([feature('function-calling'), '$Lf2'], {
723 f2: feature('document-qna'),
724 })
725 expect(parseMistralPageFeatures(html)).toEqual([
726 'function-calling',
727 'document-qna',
728 ])
729 })
730
731 it('throws on a grid it cannot fully read or grids that disagree', () => {
732 expect(() =>
733 parseMistralPageFeatures(page([feature('x'), '$Lmissing'])),
734 ).toThrow('Features grid')
735 expect(() => parseMistralPageFeatures(page([feature('x', true)]))).toThrow(
736 'Features grid',
737 )
738 const twice = page([feature('x')], {
739 ab: [
740 '$',
741 'div',
742 null,
743 {
744 children: [
745 [
746 '$',
747 '$L1c',
748 null,
749 { children: ['$', '$L1d', null, { children: 'Features' }] },
750 ],
751 ['$', 'div', null, { children: [feature('y')] }],
752 ],
753 },
754 ],
755 })
756 expect(() => parseMistralPageFeatures(twice)).toThrow('Features grid')
757 })
758
759 it('reads nothing from a page with no Features grid', () => {
760 expect(parseMistralPageFeatures('<h1>no payload</h1>')).toBeNull()
761 })
762
763 it('adds file input only for document-qna on stated modalities', () => {
764 const text = { input: ['text', 'image'], output: ['text'] }
765 expect(withDocumentInput(text, ['document-qna'])).toEqual({
766 input: ['text', 'image', 'file'],
767 output: ['text'],
768 })
769 expect(withDocumentInput(text, ['function-calling'])).toBe(text)
770 expect(withDocumentInput(text, null)).toBe(text)
771 expect(withDocumentInput(null, ['document-qna'])).toBeNull()
772 })
773})