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