Open History to see the last commit
1import hostDocs from '../fixtures/host-native-reasoning.json'
2import { readFileSync } from 'node:fs'
3
4import { afterEach, describe, expect, it } from 'vitest'
5
6import { classifyAndBundle } from '#/server/ingest/sync.ts'
7import { providerRegistry } from '#/server/providers/index.ts'
8
9import {
10 buildHuggingFaceSpec,
11 HUGGINGFACE_MODELS_URL,
12 HUGGINGFACE_SPEC_RAW_URL,
13 parseHuggingFaceModels,
14 provider,
15} from './huggingface.ts'
16
17const fixture = (name: string) =>
18 readFileSync(
19 new URL(
20 `../fixtures/huggingface-chat-completion-${name}.json`,
21 import.meta.url,
22 ),
23 'utf8',
24 )
25/** huggingface.js `chat-completion/spec/{input,output}.json` (2026-10-06). */
26const INPUT = fixture('input')
27const OUTPUT = fixture('output')
28
29const host = (name: string, rest: Record<string, unknown>) => ({
30 provider: name,
31 status: 'live',
32 is_free: false,
33 is_model_author: false,
34 ...rest,
35})
36/** featherless-ai is live but publishes no figures, so it is not `:fastest`. */
37const SILENT = host('featherless-ai', {})
38
39const model = (id: string, providers: unknown, output = ['text']) => ({
40 id,
41 created: 1785918179,
42 architecture: { input_modalities: ['text'], output_modalities: output },
43 providers,
44})
45
46/** Rows shaped like https://router.huggingface.co/v1/models (2026-10-06). */
47const FIXTURE = {
48 object: 'list',
49 data: [
50 model('agree/all', [
51 host('nscale', {
52 context_length: 40960,
53 pricing: { input: 0.07, output: 0.2 },
54 supports_tools: true,
55 supports_structured_output: false,
56 throughput: 79.9,
57 }),
58 host('deepinfra', {
59 context_length: 40960,
60 pricing: { input: 0.07, output: 0.2 },
61 supports_tools: true,
62 supports_structured_output: false,
63 throughput: 15.2,
64 }),
65 ]),
66 // An unprobed host is not the default route and does not veto it.
67 model('agree/but-one-silent', [
68 host('nscale', {
69 context_length: 40960,
70 pricing: { input: 0.07, output: 0.2 },
71 supports_tools: false,
72 supports_structured_output: false,
73 throughput: 79.9,
74 }),
75 SILENT,
76 ]),
77 // inclusionAI/Ling-3.0-flash and tencent/Hy4-preview: the same price
78 // with float noise on one side.
79 model('agree/float-noise', [
80 host('novita', {
81 context_length: 131072,
82 pricing: { input: 0.06, output: 2.501 },
83 supports_tools: true,
84 supports_structured_output: true,
85 throughput: 60,
86 }),
87 host('deepinfra', {
88 context_length: 131072,
89 pricing: { input: 0.060000000000000005, output: 2.5010000000000003 },
90 supports_tools: true,
91 supports_structured_output: true,
92 }),
93 ]),
94 // ibm-granite/granite-4.2-3b: one provider, noisy figures.
95 model('single/float-noise', [
96 host('deepinfra', {
97 context_length: 131072,
98 pricing: { input: 0.030000000000000002, output: 0.12000000000000001 },
99 supports_tools: true,
100 supports_structured_output: true,
101 throughput: 60,
102 }),
103 ]),
104 // deepseek-ai/DeepSeek-V4.1-Flash: same context, different prices, one
105 // provider with no price, structured output split.
106 model('split/price', [
107 host('novita', {
108 context_length: 1048576,
109 pricing: { input: 0.3, output: 1.2 },
110 supports_tools: true,
111 supports_structured_output: false,
112 throughput: 102.2,
113 }),
114 host('fireworks-ai', {
115 context_length: 1048576,
116 supports_tools: true,
117 supports_structured_output: true,
118 throughput: 126.4,
119 }),
120 host('deepinfra', {
121 context_length: 1048576,
122 pricing: { input: 0.2, output: 0.6 },
123 supports_tools: true,
124 supports_structured_output: true,
125 throughput: 106,
126 }),
127 ]),
128 model('split/context', [
129 host('novita', {
130 context_length: 1000000,
131 pricing: { input: 0.42, output: 3 },
132 supports_tools: true,
133 supports_structured_output: true,
134 throughput: 39,
135 }),
136 host('cerebras', {
137 context_length: 65536,
138 pricing: { input: 0.42, output: 3 },
139 supports_tools: true,
140 supports_structured_output: true,
141 throughput: 172,
142 }),
143 ]),
144 model('unranked/only', [SILENT]),
145 model('promo/free', [
146 host('novita', {
147 context_length: 8192,
148 pricing: { input: 0.1, output: 0.2 },
149 is_free: true,
150 supports_tools: false,
151 supports_structured_output: false,
152 throughput: 50,
153 }),
154 ]),
155 // Same throughput: context is shared, the prices are not.
156 model('route/tie', [
157 host('novita', {
158 context_length: 4096,
159 pricing: { input: 0.2, output: 0.4 },
160 supports_tools: true,
161 supports_structured_output: false,
162 throughput: 40,
163 }),
164 host('deepinfra', {
165 context_length: 4096,
166 pricing: { input: 0.5, output: 0.9 },
167 supports_tools: true,
168 supports_structured_output: false,
169 throughput: 40,
170 }),
171 ]),
172 model('route/tie-price', [
173 host('novita', {
174 context_length: 8192,
175 pricing: { input: 0.2, output: 0.4 },
176 supports_tools: true,
177 supports_structured_output: true,
178 throughput: 40,
179 }),
180 host('together', {
181 context_length: 8192,
182 pricing: { input: 0.2, output: 0.4 },
183 supports_tools: true,
184 supports_structured_output: true,
185 throughput: 40,
186 }),
187 ]),
188 // `:fastest` is highest throughput, not the lowest output price.
189 model('route/fast-not-cheap', [
190 host('cerebras', {
191 context_length: 65536,
192 pricing: { input: 0.9, output: 2 },
193 supports_tools: true,
194 supports_structured_output: false,
195 throughput: 200,
196 }),
197 host('novita', {
198 context_length: 1000000,
199 pricing: { input: 0.1, output: 0.2 },
200 supports_tools: false,
201 supports_structured_output: true,
202 throughput: 20,
203 }),
204 ]),
205 // The fastest host publishes no context. The slower one does not fill it.
206 model('route/fast-no-context', [
207 host('cerebras', {
208 pricing: { input: 0.1, output: 0.1 },
209 supports_tools: false,
210 supports_structured_output: false,
211 throughput: 1000,
212 }),
213 host('novita', {
214 context_length: 16384,
215 pricing: { input: 0.02, output: 0.05 },
216 supports_tools: false,
217 supports_structured_output: false,
218 throughput: 80,
219 }),
220 ]),
221 // An error host is not the route, even with a higher throughput.
222 model('route/error-faster', [
223 host('fireworks-ai', {
224 status: 'error',
225 context_length: 1000,
226 pricing: { input: 9, output: 9 },
227 supports_tools: false,
228 supports_structured_output: false,
229 throughput: 500,
230 }),
231 host('novita', {
232 context_length: 8192,
233 pricing: { input: 0.1, output: 0.2 },
234 supports_tools: true,
235 supports_structured_output: false,
236 throughput: 10,
237 }),
238 ]),
239 model('image/model', [], ['image']),
240 ],
241}
242
243const listing = { derivation: 'listing', sourceUrl: HUGGINGFACE_MODELS_URL }
244
245const originalFetch = globalThis.fetch
246
247afterEach(() => {
248 globalThis.fetch = originalFetch
249})
250
251describe('huggingface listing', () => {
252 it('stores a fact only when every provider states it and agrees', async () => {
253 const { models, docsFailures } = await parseHuggingFaceModels(FIXTURE)
254 expect(docsFailures).toEqual({ failed: 0, skipped: 0, first: [] })
255 const byId = Object.fromEntries(models.map((m) => [m.rawId, m]))
256
257 expect(byId['agree/all']).toMatchObject({
258 activity: 'chat',
259 contextWindow: 40960,
260 capabilities: ['tools'],
261 pricing: {
262 tables: {
263 rate: {
264 base: { input_tokens: 0.07 / 1e6, output_tokens: 0.2 / 1e6 },
265 },
266 },
267 source: { url: HUGGINGFACE_MODELS_URL },
268 },
269 factSources: {
270 contextWindow: {
271 ...listing,
272 path: 'providers[provider=nscale].context_length',
273 },
274 pricing: { ...listing, path: 'providers[provider=nscale].pricing' },
275 capabilities: {
276 tools: {
277 ...listing,
278 path: 'providers[provider=nscale].supports_tools',
279 },
280 },
281 },
282 })
283
284 // `agree/all`: every host says no structured output. That is a stated
285 // no, and it says nothing about plain `response_format`.
286 expect(byId['agree/all']?.unsupportedCapabilities).toEqual([
287 'structured_outputs',
288 ])
289 expect(byId['agree/all']?.factSources?.capabilities).toMatchObject({
290 structured_outputs: {
291 ...listing,
292 path: 'providers[provider=nscale].supports_structured_output',
293 },
294 })
295 expect(byId['promo/free']?.unsupportedCapabilities).toEqual([
296 'tools',
297 'structured_outputs',
298 ])
299
300 expect(byId['agree/but-one-silent']).toMatchObject({
301 contextWindow: 40960,
302 capabilities: [],
303 unsupportedCapabilities: ['tools', 'structured_outputs'],
304 pricing: {
305 tables: {
306 rate: {
307 base: { input_tokens: 0.07 / 1e6, output_tokens: 0.2 / 1e6 },
308 },
309 },
310 },
311 factSources: {
312 contextWindow: {
313 ...listing,
314 path: 'providers[provider=nscale].context_length',
315 },
316 pricing: { ...listing, path: 'providers[provider=nscale].pricing' },
317 capabilities: {
318 tools: {
319 ...listing,
320 path: 'providers[provider=nscale].supports_tools',
321 },
322 structured_outputs: {
323 ...listing,
324 path: 'providers[provider=nscale].supports_structured_output',
325 },
326 },
327 },
328 })
329 expect(byId['agree/float-noise']?.pricing).toMatchObject({
330 tables: {
331 rate: {
332 base: { input_tokens: 0.06 / 1e6, output_tokens: 2.501 / 1e6 },
333 },
334 },
335 })
336 expect(byId['single/float-noise']?.pricing).toMatchObject({
337 tables: {
338 rate: {
339 base: { input_tokens: 0.03 / 1e6, output_tokens: 0.12 / 1e6 },
340 },
341 },
342 })
343
344 expect(byId['split/price']).toMatchObject({
345 contextWindow: 1048576,
346 pricing: null,
347 capabilities: ['tools', 'structured_outputs', 'response_format'],
348 })
349 expect(byId['split/price']?.factSources).toEqual({
350 contextWindow: {
351 ...listing,
352 path: 'providers[provider=fireworks-ai].context_length',
353 },
354 capabilities: {
355 tools: {
356 ...listing,
357 path: 'providers[provider=fireworks-ai].supports_tools',
358 },
359 structured_outputs: {
360 ...listing,
361 path: 'providers[provider=fireworks-ai].supports_structured_output',
362 },
363 response_format: {
364 ...listing,
365 path: 'providers[provider=fireworks-ai].supports_structured_output',
366 },
367 },
368 })
369
370 expect(byId['split/context']).toMatchObject({
371 contextWindow: 65536,
372 capabilities: ['tools', 'structured_outputs', 'response_format'],
373 factSources: {
374 contextWindow: {
375 ...listing,
376 path: 'providers[provider=cerebras].context_length',
377 },
378 pricing: { ...listing, path: 'providers[provider=cerebras].pricing' },
379 },
380 })
381 expect(byId['split/context']?.pricing).not.toBeNull()
382
383 expect(byId['route/tie']).toMatchObject({
384 contextWindow: 4096,
385 pricing: null,
386 capabilities: ['tools'],
387 factSources: {
388 contextWindow: {
389 ...listing,
390 path: 'providers[provider=deepinfra,novita].context_length',
391 },
392 capabilities: {
393 tools: {
394 ...listing,
395 path: 'providers[provider=deepinfra,novita].supports_tools',
396 },
397 },
398 },
399 })
400 expect(byId['route/tie-price']).toMatchObject({
401 contextWindow: 8192,
402 factSources: {
403 pricing: {
404 ...listing,
405 path: 'providers[provider=novita,together].pricing',
406 },
407 },
408 })
409 expect(byId['route/tie-price']?.pricing).toMatchObject({
410 tables: {
411 rate: {
412 base: { input_tokens: 0.2 / 1e6, output_tokens: 0.4 / 1e6 },
413 },
414 },
415 })
416 expect(byId['route/fast-not-cheap']).toMatchObject({
417 contextWindow: 65536,
418 capabilities: ['tools'],
419 factSources: {
420 pricing: { ...listing, path: 'providers[provider=cerebras].pricing' },
421 },
422 })
423 expect(byId['route/fast-not-cheap']?.pricing).toMatchObject({
424 tables: {
425 rate: { base: { input_tokens: 0.9 / 1e6, output_tokens: 2 / 1e6 } },
426 },
427 })
428 expect(byId['route/fast-no-context']).toMatchObject({
429 contextWindow: null,
430 capabilities: [],
431 factSources: {
432 pricing: { ...listing, path: 'providers[provider=cerebras].pricing' },
433 },
434 })
435 expect(byId['route/error-faster']).toMatchObject({
436 contextWindow: 8192,
437 capabilities: ['tools'],
438 factSources: {
439 contextWindow: {
440 ...listing,
441 path: 'providers[provider=novita].context_length',
442 },
443 pricing: { ...listing, path: 'providers[provider=novita].pricing' },
444 },
445 })
446
447 expect(byId['unranked/only']).toMatchObject({
448 contextWindow: null,
449 pricing: null,
450 capabilities: null,
451 factSources: {},
452 })
453 // A promo is not the standard price; settled "no" flags are an empty list.
454 expect(byId['promo/free']).toMatchObject({
455 contextWindow: 8192,
456 pricing: null,
457 capabilities: [],
458 })
459 expect(byId['image/model']).toMatchObject({
460 activity: 'image',
461 pricing: null,
462 })
463
464 // No price is said, not left out: the poller then drops a stored card
465 // instead of keeping it as a parser miss.
466 for (const row of models) {
467 expect(row.absent).toEqual(
468 row.pricing === null ? { pricing: 'cleared' } : undefined,
469 )
470 }
471 // A zero quote and a null `pricing` both state no price.
472 const none = await parseHuggingFaceModels({
473 data: [
474 model('zero/quote', [
475 host('novita', { pricing: { input: 0, output: 0 } }),
476 ]),
477 model('null/quote', [host('novita', { pricing: null })]),
478 ...FIXTURE.data,
479 ],
480 })
481 expect(none.docsFailures.failed).toBe(0)
482 for (const row of none.models.slice(0, 2)) {
483 expect(row).toMatchObject({
484 pricing: null,
485 absent: { pricing: 'cleared' },
486 })
487 }
488 })
489
490 // `cleared` drops a stored card, so nothing the parser cannot read may
491 // come out as "no price".
492 it('throws on a listing-wide reshape instead of clearing', async () => {
493 const replay = (edit: (json: string) => string) =>
494 parseHuggingFaceModels(JSON.parse(edit(JSON.stringify(FIXTURE))))
495 // The listing with its price keys renamed, then with numbers as strings.
496 await expect(
497 replay((json) =>
498 json
499 .replaceAll('"input":', '"prompt":')
500 .replaceAll('"output":', '"completion":'),
501 ),
502 ).rejects.toThrow(
503 /^huggingface: (\d+) of \1 provider prices are in an unread shape$/,
504 )
505 await expect(
506 replay((json) => json.replace(/"(input|output)":([\d.]+)/g, '"$1":"$2"')),
507 ).rejects.toThrow(
508 /^huggingface: (\d+) of \1 provider prices are in an unread shape$/,
509 )
510 // Prices moved out of the entries altogether.
511 await expect(
512 replay((json) => json.replaceAll('"pricing":', '"rates":')),
513 ).rejects.toThrow('no provider entry states a price')
514
515 const ranked = host('nscale', {
516 context_length: 40960,
517 pricing: { input: 0.07, output: 0.2 },
518 })
519 for (const providers of [
520 { nscale: ranked },
521 [ranked, 'featherless-ai'],
522 undefined,
523 ]) {
524 await expect(
525 parseHuggingFaceModels({
526 data: [...FIXTURE.data, model('x/y', providers)],
527 }),
528 ).rejects.toThrow('a providers list is in an unread shape')
529 }
530 // More than a tenth of the stated prices unreadable is a reshape too.
531 const odd = (id: string) =>
532 model(id, [{ ...ranked, pricing: { input: 0.07 } }])
533 await expect(
534 parseHuggingFaceModels({
535 data: [...FIXTURE.data, odd('a/1'), odd('a/2'), odd('a/3'), odd('a/4')],
536 }),
537 ).rejects.toThrow(
538 /^huggingface: 4 of \d+ provider prices are in an unread shape$/,
539 )
540 })
541
542 it('withholds only that row’s price when one entry’s price is unreadable', async () => {
543 const ranked = host('nscale', {
544 context_length: 40960,
545 pricing: { input: 0.07, output: 0.2 },
546 })
547 const clean = await parseHuggingFaceModels(FIXTURE)
548 for (const pricing of [
549 0.07,
550 '0.07',
551 { input: 0.07 },
552 { input: -1, output: 1 },
553 ]) {
554 const { models, docsFailures } = await parseHuggingFaceModels({
555 data: [
556 // A second, readable entry: the row still cannot be settled.
557 model('x/y', [ranked, { ...ranked, provider: 'novita', pricing }]),
558 ...FIXTURE.data,
559 ],
560 })
561 expect(docsFailures).toEqual({
562 failed: 1,
563 skipped: 0,
564 first: [
565 {
566 source: `${HUGGINGFACE_MODELS_URL}#x/y`,
567 error:
568 'huggingface: the price of provider entry "novita" is in an unread shape',
569 elapsedMs: expect.any(Number) as number,
570 },
571 ],
572 })
573 // Kept as stored, not cleared; its other facts are read as usual.
574 expect(models[0]).toMatchObject({
575 rawId: 'x/y',
576 contextWindow: 40960,
577 pricing: null,
578 absent: { pricing: 'unavailable' },
579 })
580 const facts = ({ pricing: card, ...rest }: (typeof models)[number]) => ({
581 ...rest,
582 priced: card !== null,
583 })
584 expect(models.slice(1).map(facts)).toEqual(clean.models.map(facts))
585 }
586 })
587
588 it('leaves context and flags null when their fields change type', async () => {
589 const {
590 models: [row],
591 } = await parseHuggingFaceModels({
592 data: [
593 model('x/y', [
594 host('nscale', {
595 context_length: '40960',
596 pricing: { input: 0.07, output: 0.2 },
597 supports_tools: 'yes',
598 }),
599 ]),
600 ],
601 })
602 expect(row).toMatchObject({ contextWindow: null, capabilities: null })
603 })
604
605 it('throws when a provider status is not live or error', async () => {
606 await expect(
607 parseHuggingFaceModels({
608 data: [
609 model('x/y', [
610 host('novita', {
611 status: 'staging',
612 context_length: 8192,
613 pricing: { input: 0.1, output: 0.2 },
614 throughput: 10,
615 }),
616 ]),
617 ],
618 }),
619 ).rejects.toThrow('status is in an unread shape')
620 })
621
622 it('throws on a payload that lists nothing', async () => {
623 await expect(parseHuggingFaceModels({ data: [] })).rejects.toThrow(
624 'listed no ids',
625 )
626 await expect(parseHuggingFaceModels('<html>')).rejects.toThrow(
627 'no data array',
628 )
629 })
630})
631
632// Ids from the live router listing (2026-11-21), where `owned_by` equals the
633// id's owner on all 159 rows.
634describe('huggingface upstream identity', () => {
635 it('names the repo owner, through its namespace', () => {
636 const stated = (rawId: string) => {
637 const identity = provider.upstreamModelIdentity?.(rawId)
638 if (!identity) return null
639 const target = providerRegistry.find(
640 (p) =>
641 p.id === identity.providerNamespace ||
642 p.modelNamespaces?.includes(identity.providerNamespace),
643 )
644 return [target?.id ?? null, identity.rawId]
645 }
646 expect(stated('CohereLabs/command-a-vision-07-2025')).toEqual([
647 'cohere',
648 'command-a-vision-07-2025',
649 ])
650 expect(stated('inclusionAI/Ling-3.1-flash')).toEqual([
651 'ant-ling',
652 'Ling-3.1-flash',
653 ])
654 // A publisher with no API row here is still stated; it resolves nowhere.
655 expect(stated('cyankiwi/Qwen3.5-9B-AWQ-4bit')).toEqual([
656 null,
657 'Qwen3.5-9B-AWQ-4bit',
658 ])
659 expect(provider.upstreamModelIdentity?.('Qwen3.8-27B')).toBeNull()
660 expect(
661 provider.upstreamModelIdentity?.('Qwen/Qwen3.8-27B')?.source,
662 ).toEqual({
663 derivation: 'listing',
664 sourceUrl: HUGGINGFACE_MODELS_URL,
665 path: 'data[].id',
666 })
667 })
668})
669
670describe('huggingface spec', () => {
671 it('wraps the published schemas into one chat path', () => {
672 const spec = buildHuggingFaceSpec(INPUT, OUTPUT)
673 expect(Object.keys(spec.paths ?? {})).toEqual(['/v1/chat/completions'])
674 expect(JSON.stringify(spec)).not.toContain('#/$defs/')
675
676 const { endpoints, warnings } = classifyAndBundle(provider, {
677 specs: [spec],
678 sources: [{ url: 'x', hash: 'y' }],
679 outputStrategy: 'post-200',
680 })
681 expect(endpoints).toHaveLength(1)
682 const [endpoint] = endpoints
683 expect(endpoint).toMatchObject({
684 activity: 'chat',
685 derivation: 'generated',
686 })
687 expect(warnings).toEqual([])
688 expect(Object.keys(endpoint?.input?.$defs ?? {})).toHaveLength(16)
689 expect(endpoint?.output).toBeDefined()
690 expect(
691 provider.generationEndpointId?.({ rawId: 'a/b', activity: 'chat' }),
692 ).toBe('v1/chat/completions')
693 expect(
694 provider.generationEndpointId?.({ rawId: 'a/b', activity: 'image' }),
695 ).toBeNull()
696 })
697
698 it('throws on a file that is not the published schema', () => {
699 const renamed = INPUT.replace('"ChatCompletionInput"', '"ChatInput"')
700 const noMessages = INPUT.replace('"messages": {', '"msgs": {')
701 for (const [input, output] of [
702 ['<!doctype html><title>Not found</title>', OUTPUT],
703 [INPUT, '{}'],
704 [renamed, OUTPUT],
705 [noMessages, OUTPUT],
706 [INPUT, INPUT],
707 ]) {
708 expect(() => buildHuggingFaceSpec(input ?? '', output ?? '')).toThrow(
709 /^huggingface: /,
710 )
711 }
712 })
713
714 it('throws on an HTML body served for either schema file', () => {
715 const html = '<!doctype html><html><body>Not found</body></html>'
716 expect(() => buildHuggingFaceSpec(html, OUTPUT)).toThrow('is not JSON')
717 expect(() => buildHuggingFaceSpec(INPUT, html)).toThrow('is not JSON')
718 })
719
720 it('fetches the listing and both schema files', async () => {
721 const urls: Array<string> = []
722 globalThis.fetch = ((url: string) => {
723 urls.push(String(url))
724 const body: Record<string, string> = {
725 [HUGGINGFACE_MODELS_URL]: JSON.stringify(FIXTURE),
726 ['https://huggingface.co/docs/inference-providers/tasks/chat-completion']:
727 hostDocs.hf,
728 [`${HUGGINGFACE_SPEC_RAW_URL}/input.json`]: INPUT,
729 [`${HUGGINGFACE_SPEC_RAW_URL}/output.json`]: OUTPUT,
730 }
731 const text = body[String(url)]
732 return text === undefined
733 ? Promise.reject(new Error(`unexpected fetch: ${String(url)}`))
734 : Promise.resolve(new Response(text))
735 }) as typeof fetch
736
737 const listed = await provider.listModels({})
738 const spec = await provider.fetchSpec({})
739
740 expect(listed.models).toHaveLength(FIXTURE.data.length)
741 expect(listed.docsFailures).toEqual({ failed: 0, skipped: 0, first: [] })
742 expect(spec.specs).toHaveLength(1)
743 expect(spec.sources[0]?.hash).toMatch(/^[0-9a-f]{64}$/)
744 expect(urls).toHaveLength(4)
745 })
746
747 it('lists models when the chat guide has no recommended-models section', async () => {
748 const guide =
749 '<h1>Chat Completion</h1><p>reasoning_effort support is provider and model-dependent.</p>'
750 globalThis.fetch = ((url: string) => {
751 const body: Record<string, string> = {
752 [HUGGINGFACE_MODELS_URL]: JSON.stringify(FIXTURE),
753 ['https://huggingface.co/docs/inference-providers/tasks/chat-completion']:
754 guide,
755 }
756 const text = body[String(url)]
757 return text === undefined
758 ? Promise.reject(new Error(`unexpected fetch: ${String(url)}`))
759 : Promise.resolve(new Response(text))
760 }) as typeof fetch
761
762 const listed = await provider.listModels({})
763
764 expect(listed.models.map((row) => row.rawId)).toEqual(
765 FIXTURE.data.map((row) => row.id),
766 )
767 expect(listed.docsFailures?.failed).toBe(1)
768 expect(listed.docsFailures?.first[0]).toMatchObject({
769 source:
770 'https://huggingface.co/docs/inference-providers/tasks/chat-completion',
771 error: 'huggingface: native recommendation section missing',
772 })
773 for (const row of listed.models) {
774 expect(row.absent?.reasoning).toBe('unavailable')
775 const caps = row.capabilities
776 const flags = Array.isArray(caps) ? caps : []
777 expect(flags).not.toContain('reasoning')
778 }
779 const priced = listed.models.find((row) => row.rawId === 'agree/all')
780 expect(priced?.pricing).toBeTruthy()
781 expect(priced?.absent?.pricing).toBeUndefined()
782 })
783})