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

native-reasoning-followup.test.ts

150 lines5.4 KB

1import { requestUrl } from '#/lib/text.ts'
2import { afterEach, expect, it } from 'vitest'
3import awsDocs from './fixtures/native-reasoning-followup.json'
4import { bedrockReasoning, parseBedrockCard } from './bedrock-cards.ts'
5import {
6 openaiModelFacts,
7 OPENAI_MODELS_INDEX_URL,
8 OPENAI_PRICING_URL,
9} from './openai-model-docs.ts'
10import { keepValidReasoning } from './reasoning-config.ts'
11import { docsRun } from './model-facts.ts'
12​
13const originalFetch = globalThis.fetch
14afterEach(() => {
15 globalThis.fetch = originalFetch
16})
17const source = (id: string) => ({
18 url: 'https://docs.aws.amazon.com/bedrock/latest/userguide/' + id,
19 hash: 'h',
20 extractedAt: 't',
21})
22it('keeps mandatory unknown when native AWS cards only state defaults or effort names', () => {
23 expect(
24 parseBedrockCard(
25 awsDocs['model-card-anthropic-claude-sonnet-5-5.md'],
26 source('sonnet'),
27 )?.reasoning?.mandatory,
28 ).toBeNull()
29 expect(
30 parseBedrockCard(awsDocs['model-card-xai-grok-4-6.md'], source('grok'))
31 ?.reasoning?.mandatory,
32 ).toBeNull()
33 expect(
34 parseBedrockCard(
35 awsDocs['model-card-anthropic-claude-haiku-5-5.md'],
36 source('haiku'),
37 )?.reasoning?.mandatory,
38 ).toBe(false)
39 expect(
40 parseBedrockCard(
41 awsDocs['model-card-anthropic-claude-mythos-5-1.md'],
42 source('mythos'),
43 )?.reasoning?.mandatory,
44 ).toBe(true)
45 expect(
46 bedrockReasoning('Supported (adaptive thinking is on by default)'),
47 ).toEqual({ mode: 'adaptive', mandatory: null })
48 expect(
49 bedrockReasoning(
50 'Supported (configurable: low, high; cannot be turned off)',
51 )?.mandatory,
52 ).toBe(true)
53 expect(
54 bedrockReasoning('Supported (configurable: low, high; can be turned off)')
55 ?.mandatory,
56 ).toBe(false)
57})
58it('reads AWS capability ticks and its explicitly honored effort mode', () => {
59 for (const id of ['model-card-google-gemma-4-31b.md'] as const) {
60 const parsed = parseBedrockCard(awsDocs[id], source(id))
61 expect(parsed?.capabilities).toContain('reasoning')
62 expect(parsed?.reasoning).toEqual({ mode: 'effort', mandatory: null })
63 }
64})
65it('ignores illustrative AWS effort values without a native normative declaration', () => {
66 const card =
67 awsDocs['model-card-openai-gpt-6-1-sol.md'] +
68 '\n**Reasoning effort**\n\nFor example, try `low` or `high`.\n```\nSet reasoning effort to `none`, `max`.\n```\n'
69 expect(parseBedrockCard(card, source('example'))?.reasoning).toBeNull()
70})
71it('clears prior guessed reasoning when fresh docs contain no sourced control', () => {
72 const fresh = { rawId: 'o3', reasoning: null }
73 expect(
74 keepValidReasoning('openai', fresh, {
75 reasoning: { mode: 'effort', mandatory: true, efforts: ['low', 'high'] },
76 factSources: null,
77 }).reasoning,
78 ).toBeNull()
79})
80const pricing = `Specialized models
81​
82Prices per 1M tokens.
83​
84Standard
85​
86### Grouped Pricing Table data
87​
88| Category | Model | Input | Cached input | Output |
89| --- | --- | --- | --- | --- |
90| Search | gpt-5-search-api | $1.25 | $0.125 | $10.00 |
92for (const malformed of [false, true])
93 it(
94 'marks ' +
95 (malformed ? 'unparseable' : 'failed') +
96 ' native OpenAI pages unavailable rather than returning unknown facts',
97 async () => {
98 globalThis.fetch = async (input) => {
99 const url = requestUrl(input)
100 if (url === OPENAI_MODELS_INDEX_URL)
101 return new Response('[Model](/api/docs/models/gpt-5.md)')
102 if (url === OPENAI_PRICING_URL) return new Response(pricing)
103 if (url.endsWith('/gpt-5.md'))
104 return malformed
105 ? new Response('# Unexpected page')
106 : new Response('outage', { status: 503 })
107 throw new Error('unexpected source ' + url)
108 }
109 const run = docsRun()
110 const row = (await openaiModelFacts(['gpt-5'], undefined, run))('gpt-5')
111 expect(row.reasoning).toBeUndefined()
112 expect(row.absent?.reasoning).toBe('unavailable')
113 expect(
114 run.first.find((failure) => failure.source.endsWith('/gpt-5.md'))
115 ?.error,
116 ).toContain(malformed ? 'no Model ID' : '503')
117 },
118 )
119​
120for (const reverse of [false, true])
121 it(
122 'prefers model-owned page facts over alias snapshot facts regardless of listing order ' +
123 reverse,
124 async () => {
125 const own =
126 'Model ID: `gpt-5.6-sol`\nReasoning.effort supports: low, high.\n\n## Model details\n\n- Reasoning token support\n'
127 const alias =
128 'Model ID: `gpt-daybreak-blue-latest`\n\n## Model details\n\n- Default snapshot: `gpt-5.6-sol`\n- Reasoning token support\n'
129 globalThis.fetch = async (input) => {
130 const url = requestUrl(input)
131 if (url === OPENAI_MODELS_INDEX_URL)
132 return new Response(
133 '[Own](/api/docs/models/gpt-5.6-sol.md) [Alias](/api/docs/models/gpt-daybreak-blue-latest.md)',
134 )
135 if (url === OPENAI_PRICING_URL) return new Response(pricing)
136 if (url.endsWith('/gpt-5.6-sol.md')) return new Response(own)
137 if (url.endsWith('/gpt-daybreak-blue-latest.md'))
138 return new Response(alias)
139 throw new Error('unexpected source ' + url)
140 }
141 const ids = ['gpt-5.6-sol', 'gpt-daybreak-blue-latest']
142 if (reverse) ids.reverse()
143 const facts = await openaiModelFacts(ids)
144 expect(facts('gpt-5.6-sol').reasoning?.efforts).toEqual(['low', 'high'])
145 expect(facts('gpt-daybreak-blue-latest').reasoning).toBeNull()
146 expect(facts('gpt-5.6-sol').factSources?.reasoning?.sourceUrl).toContain(
147 '/gpt-5.6-sol.md',
148 )
149 },
150 )