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

cloudflare-native-final-controls.test.ts

65 lines2.4 KB

1import { expect, it } from 'vitest'
2import docs from './fixtures/cloudflare-native-final-controls.json'
3import { parseCatalogModel } from './adapters/cloudflare-ai-gateway.ts'
4​
5const source = {
6 url: 'https://raw.githubusercontent.com/cloudflare/cloudflare-docs/production/src/content/catalog-models/',
7 hash: 'native-fixture',
8 extractedAt: '2026-10-09T00:00:00.000Z',
9}
10it('sources adaptive mode, operational always-on semantics and accepted efforts from exact owned Opus card', () => {
11 const doc = docs[0]!
12 expect(doc.description).toContain('adaptive thinking that is always on')
13 const result = parseCatalogModel(doc, source, { schemaShared: true })
14 expect(result.reasoning).toEqual({
15 mode: 'adaptive',
16 mandatory: true,
17 efforts: ['low', 'medium', 'high', 'xhigh', 'max'],
18 })
19 expect(result.requestMap?.thinking?.off).toBeNull()
20 expect(result.factSources?.reasoning?.sourceUrl).toBe(source.url)
21 const noDeclaration = { ...doc, metadata: { Architecture: 'Transformer' } }
22 expect(
23 parseCatalogModel(noDeclaration, source, { schemaShared: true }).reasoning,
24 ).toBeUndefined()
25 const withoutControl = structuredClone(doc)
26 delete (withoutControl.schema.input.properties as Record<string, unknown>)
27 .thinking
28 expect(
29 parseCatalogModel(withoutControl, source, { schemaShared: true }).reasoning,
30 ).toBeUndefined()
31})
32it('sources only the exact owned Responses reasoning field without inferring mandatory or off', () => {
33 const doc = docs[1]!
34 const result = parseCatalogModel(doc, source, { schemaShared: true })
35 expect(result.reasoning).toEqual({
36 mode: 'effort',
37 mandatory: null,
38 efforts: ['low', 'medium', 'high'],
39 })
40 expect(result.requestMap?.thinking?.off).toBeNull()
41 for (const changed of [
42 { ...doc, metadata: {} },
43 { ...doc, tags: [] },
44 ])
45 expect(
46 parseCatalogModel(changed, source, { schemaShared: true }).reasoning,
47 ).toBeUndefined()
48 const qualified = structuredClone(doc)
49 Object.assign(
50 qualified.schema.input.properties.reasoning!.properties.effort,
51 {
52 description: 'Availability and accepted values are model-dependent.',
53 },
54 )
55 expect(
56 parseCatalogModel(qualified, source, { schemaShared: true }).reasoning,
57 ).toBeUndefined()
58 expect(
59 parseCatalogModel(
60 { ...doc, metadata: { ...doc.metadata, Reasoning: 'No' } },
61 source,
62 { schemaShared: true },
63 ).reasoning,
64 ).toBeUndefined()
65})