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

host-native-reasoning.test.ts

127 lines4.0 KB

1import { afterEach, expect, it, vi } from 'vitest'
2import docs from './fixtures/host-native-reasoning.json'
3import { docsRun } from './model-facts.ts'
4import type { ModelInfo } from './types.ts'
5import {
6 fireworksHostedReasoning,
7 nativeReasoningCapability,
8 parseFireworksNativeReasoning,
9 parseHfHostedReasoning,
10} from './native-host-reasoning.ts'
11​
12afterEach(() => {
13 vi.unstubAllGlobals()
14})
15​
16it('extracts exact hosted model links only from native explicit reasoning recommendations', () => {
17 expect(parseHfHostedReasoning(docs.hf)).toEqual([
18 'Qwen/Qwen3-4B-Thinking-2507',
19 'deepseek-ai/DeepSeek-R1',
20 'zai-org/GLM-4.5V',
21 ])
22 expect(() =>
23 parseHfHostedReasoning('<li>reasoning capabilities</li>'),
24 ).toThrow()
25 expect(() =>
26 parseHfHostedReasoning(
27 docs.hf.replaceAll('https://huggingface.co/', 'https://example.com/'),
28 ),
29 ).toThrow()
30})
31it('reads positive native Fireworks metadata without inferring undocumented controls', () => {
32 for (const [id, body] of Object.entries(docs.fireworks)) {
33 expect(
34 parseFireworksNativeReasoning(body, 'accounts/fireworks/models/' + id),
35 ).toBe(!id.startsWith('glm'))
36 }
37 expect(
38 parseFireworksNativeReasoning(
39 { name: 'm', description: 'Does not provide reasoning capabilities.' },
40 'm',
41 ),
42 ).toBe(false)
43 for (const description of [
44 'Lacks reasoning capabilities.',
45 'Does not support reasoning. Reasoning capabilities are available only on another model.',
46 ])
47 expect(parseFireworksNativeReasoning({ name: 'm', description }, 'm')).toBe(
48 false,
49 )
50 expect(() =>
51 parseFireworksNativeReasoning(
52 { name: 'other', description: 'reasoning capabilities' },
53 'm',
54 ),
55 ).toThrow()
56 expect(() => parseFireworksNativeReasoning({ name: 'm' }, 'm')).toThrow()
57})
58it('preserves populated flags, unknown controls, and unrelated provenance', () => {
59 const source = {
60 derivation: 'listing' as const,
61 sourceUrl: 'https://api.fireworks.ai/v1/accounts/fireworks/models/m',
62 path: 'description',
63 }
64 const model = {
65 rawId: 'm',
66 capabilities: { tools: true, structured: false },
67 reasoning: null,
68 factSources: { capabilities: { tools: source } },
69 }
70 const next = nativeReasoningCapability(model, source)
71 expect(next.capabilities).toEqual({
72 tools: true,
73 structured: false,
74 reasoning: true,
75 })
76 expect(next.reasoning).toBeNull()
77 expect(next.factSources?.capabilities?.tools).toEqual(source)
78 expect(() =>
79 nativeReasoningCapability(
80 { ...model, capabilities: { reasoning: false } },
81 source,
82 ),
83 ).toThrow()
84 expect(() =>
85 nativeReasoningCapability(
86 { ...model, unsupportedCapabilities: ['reasoning'] },
87 source,
88 ),
89 ).toThrow()
90})
91it('keeps a row whose Fireworks metadata is forbidden and reports the failure', async () => {
92 const forbidden = 'accounts/fireworks/models/minimax-m3p1-flash'
93 const open = 'accounts/fireworks/models/minimax-m3'
94 vi.stubGlobal(
95 'fetch',
96 vi.fn((url: string) =>
97 Promise.resolve(
98 url.endsWith(forbidden)
99 ? new Response('{ "code": 7, "details": [], "message": "" }', {
100 status: 403,
101 statusText: 'Forbidden',
102 })
103 : new Response(
104 JSON.stringify({
105 name: open,
106 description: 'A model with strong reasoning capabilities.',
107 }),
108 ),
109 ),
110 ),
111 )
112 const row = (rawId: string): ModelInfo => ({
113 rawId,
114 activity: 'chat',
115 capabilities: ['tools'],
116 reasoning: null,
117 })
118 const run = docsRun()
119 const kept = await fireworksHostedReasoning(row(forbidden), 'key', run)
120 expect(kept.absent).toEqual({ capabilities: 'unavailable' })
121 expect(kept.capabilities).toEqual(['tools'])
122 expect(run.failed).toBe(1)
123 expect(run.first[0]?.source).toBe('https://api.fireworks.ai/v1/' + forbidden)
124 const read = await fireworksHostedReasoning(row(open), 'key', run)
125 expect(read.capabilities).toEqual(['tools', 'reasoning'])
126 expect(read.absent).toBeUndefined()
127})