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

provider-replay.test.ts

147 lines4.8 KB

1import { describe, expect, it } from 'vitest'
2import glmNative from './fixtures/zai-native-thinking-replay.json'
3import {
4 applyReplay,
5 deepseekEffortFacts,
6 explicitCardReplay,
7 parseDeepseekReplay,
8 parseGlmReplay,
9 parseKimiReplay,
10 loadReplayDoc,
11} from './provider-replay.ts'
12​
13import {
14 GLM_REPLAY_FIXTURE,
15 KIMI_REPLAY_FIXTURE,
16 DEEPSEEK_REPLAY_FIXTURE,
17} from './fixtures/provider-replay.ts'
18​
19describe('provider-owned reasoning and replay evidence', () => {
20 it('includes the exact GLM-4.5 model named by the native interleaved tool-turn rule', () => {
21 const ids = parseGlmReplay(glmNative.markdown)
22 expect(ids).toContain('glm-4.5')
23 expect(ids).not.toContain('glm-4.5-air')
24 expect(ids).not.toContain('glm-5.3-flashx')
25 const variant = parseGlmReplay(
26 glmNative.markdown.replace(
27 'supported since GLM-4.5',
28 'supported since GLM-4.5-Air',
29 ),
30 )
31 expect(variant).toContain('glm-4.5-air')
32 expect(variant).not.toContain('glm-4.5')
33 })
34 it('does not infer mandatory thinking from native effort values', () => {
35 expect(
36 deepseekEffortFacts({ supported_levels: ['high', 'max'] })?.reasoning,
37 ).toEqual({ mode: 'effort', mandatory: null, efforts: ['high', 'max'] })
38 expect(
39 deepseekEffortFacts({ supported_levels: ['none', 'high'] })?.reasoning
40 .mandatory,
41 ).toBeNull()
42 expect(deepseekEffortFacts(undefined)).toBeNull()
43 })
44 it.each([
45 {},
46 'bad',
47 { supported_levels: [] },
48 { supported_levels: [null] },
49 { supported_levels: 'high' },
50 ])('does not swallow malformed effort metadata %j', (value) => {
51 if (typeof value === 'object' && Object.keys(value).length === 0)
52 expect(deepseekEffortFacts(value)).toBeNull()
53 else expect(() => deepseekEffortFacts(value)).toThrow(/unreadable/)
54 })
55 it('requires the native DeepSeek conditional tool contract', () => {
56 expect(parseDeepseekReplay(DEEPSEEK_REPLAY_FIXTURE)).toBe(true)
57 expect(() =>
58 parseDeepseekReplay('response exposes reasoning_content'),
59 ).toThrow(/no verified/)
60 })
61 it('binds GLM replay only to explicitly named models', () => {
62 expect(parseGlmReplay(GLM_REPLAY_FIXTURE)).toEqual([
63 'glm-5.2',
64 'glm-5.3',
65 'glm-5.3-flash',
66 ])
67 expect(() =>
68 parseGlmReplay(GLM_REPLAY_FIXTURE.replace('preserved', 'omitted')),
69 ).toThrow(/no verified/)
70 expect(parseGlmReplay(GLM_REPLAY_FIXTURE)).not.toContain('glm-5.3-flashx')
71 })
72 it('binds exact Kimi ids including the explicitly documented highspeed variant', () => {
73 expect(parseKimiReplay(KIMI_REPLAY_FIXTURE)).toEqual([
74 'kimi-k3',
75 'kimi-k2.7-code',
76 'kimi-k2.7-code-highspeed',
77 'kimi-k2.6',
78 ])
79 expect(() => parseKimiReplay('A model returns reasoning_content.')).toThrow(
80 /no verified/,
81 )
82 })
83 it('does not mistake output-only documentation for replay evidence', () => {
84 expect(explicitCardReplay('Output supports reasoning_content.')).toBe(false)
85 expect(
86 explicitCardReplay(
87 'Clients must pass back the complete assistant message, including reasoning_content.',
88 ),
89 ).toBe(true)
90 })
91 it('preserves other sourced fields and provenance while leaving unknown wire fields null', () => {
92 const source = {
93 derivation: 'docs-derived' as const,
94 sourceUrl: 'https://example.com/native',
95 sourceHash: 'hash',
96 }
97 const model = applyReplay(
98 {
99 rawId: 'synthetic',
100 activity: 'chat',
101 factSources: { reasoning: { derivation: 'listing' } },
102 },
103 source,
104 )
105 expect(model.requestMap).toMatchObject({
106 replayReasoningContent: true,
107 thinking: null,
108 maxTokensField: null,
109 developerRole: null,
110 })
111 expect(model.factSources?.reasoning).toEqual({ derivation: 'listing' })
112 expect(model.factSources?.requestMap).toEqual(source)
113 expect(model.factSources?.requestMapFields?.replayReasoningContent).toEqual(
114 source,
115 )
116 const original = {
117 derivation: 'upstream-spec' as const,
118 sourceUrl: 'https://example.com/spec',
119 }
120 const enriched = applyReplay(
121 {
122 ...model,
123 requestMap: { ...model.requestMap!, maxTokensField: 'max_tokens' },
124 factSources: { requestMap: original },
125 },
126 source,
127 )
128 expect(enriched.requestMap?.maxTokensField).toBe('max_tokens')
129 expect(enriched.factSources?.requestMap).toEqual(original)
130 expect(
131 enriched.factSources?.requestMapFields?.replayReasoningContent,
132 ).toEqual(source)
133 })
134})
135​
136it('reports native docs fetch failures instead of claiming unknown replay is false', async () => {
137 const original = globalThis.fetch
138 globalThis.fetch = () =>
139 Promise.resolve(new Response('unavailable', { status: 503 }))
140 try {
141 await expect(loadReplayDoc('https://example.com/native')).rejects.toThrow(
142 /503/,
143 )
144 } finally {
145 globalThis.fetch = original
146 }
147})