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

replay-extra-native.test.ts

110 lines3.8 KB

1import { expect, it } from 'vitest'
2import fixture from './fixtures/replay-extra-native.json'
3import {
4 zaiSpecFacts,
5 parseZaiModels,
6 ZAI_OPENAPI_URL,
7} from './adapters/zai.ts'
8import {
9 parseTogetherNativeThinking,
10 applyTogetherNativeThinking,
11} from './together-native-thinking.ts'
12​
13const source = { url: ZAI_OPENAPI_URL, hash: 'native-source-hash' }
14it('sources exact ZAI request-variant replay rules without copying sibling facts or stamping non-reasoning models', () => {
15 const facts = zaiSpecFacts(fixture.spec, source)
16 for (const id of [
17 'glm-4.5-air',
18 'glm-4.7-flashx',
19 'glm-4.6v-flash',
20 'glm-5.3-flashx',
21 ]) {
22 expect(facts.get(id)?.replayReasoningContent).toMatchObject({
23 derivation: 'upstream-spec',
24 sourceUrl: ZAI_OPENAPI_URL,
25 })
26 expect(facts.get(id)?.replayReasoningContent?.path).toContain('model=' + id)
27 }
28 expect(facts.has('glm-unpublished-sibling')).toBe(false)
29 const models = parseZaiModels(
30 { ...source, text: JSON.stringify(fixture.spec) },
31 fixture.zaiDocs.pricing,
32 fixture.zaiDocs.overview,
33 fixture.zaiDocs.thinking,
34 '2026-10-09T00:00:00Z',
35 )
36 expect(
37 models.find((x) => x.rawId === 'glm-4.5-air')?.requestMap
38 ?.replayReasoningContent,
39 ).toBe(true)
40 expect(
41 models.find((x) => x.rawId === 'glm-5.3-flashx')?.factSources
42 ?.requestMapFields?.replayReasoningContent?.sourceUrl,
43 ).toBe(ZAI_OPENAPI_URL)
44 expect(
45 models.find((x) => x.rawId === 'glm-4-32b-0414-128k')?.requestMap,
46 ).toBeUndefined()
47})
48it('honors explicit native ZAI property model restrictions and leaves unsupported prose unsourced', () => {
49 const spec = structuredClone(fixture.spec)
50 const field = spec.components.schemas.ChatThinking.properties.clear_thinking
51 field.description += ' Only supported by GLM-4.7.'
52 const facts = zaiSpecFacts(spec, source)
53 expect(facts.get('glm-4.7')?.replayReasoningContent).toBeDefined()
54 expect(facts.get('glm-4.5-air')?.replayReasoningContent).toBeUndefined()
55 field.description = 'Retains some history.'
56 expect(
57 zaiSpecFacts(spec, source).get('glm-4.7')?.replayReasoningContent,
58 ).toBeUndefined()
59 field.description = 'Only supports GLM-4.7+.'
60 expect(() => zaiSpecFacts(spec, source)).toThrow(
61 'unreadable clear_thinking model restriction',
62 )
63})
64it('sources Together Kimi K3 replay only from the exact native history instruction', () => {
65 const parsed = parseTogetherNativeThinking(fixture.kimiMarkdown)
66 expect(parsed.replay).toEqual(['moonshotai/Kimi-K3'])
67 const doc = {
68 ...parsed,
69 url: fixture.kimiSourceUrl,
70 hash: 'native-kimi-hash',
71 }
72 const result = applyTogetherNativeThinking(
73 { rawId: 'moonshotai/Kimi-K3', activity: 'chat' },
74 [doc],
75 )
76 expect(result.requestMap?.replayReasoningContent).toBe(true)
77 expect(
78 result.factSources?.requestMapFields?.replayReasoningContent?.sourceUrl,
79 ).toBe(fixture.kimiSourceUrl)
80 expect(result.requestMap?.maxTokensField).toBeNull()
81 expect(
82 applyTogetherNativeThinking(
83 { rawId: 'moonshotai/Kimi-K2.7-Code', activity: 'chat' },
84 [doc],
85 ).requestMap,
86 ).toBeUndefined()
87 expect(
88 parseTogetherNativeThinking(
89 fixture.kimiMarkdown.replace(
90 'Return the complete assistant message on every turn, `reasoning_content` included',
91 'Return visible content only',
92 ),
93 ).replay,
94 ).toEqual([])
95})
96​
97it('does not source Together replay from fenced or negated history instructions', () => {
98 const instruction =
99 'Return the complete assistant message on every turn, `reasoning_content` included'
100 for (const replacement of [
101 'Do not ' + instruction,
102 '\n```text\n' + instruction + '\n```\n',
103 ]) {
104 expect(
105 parseTogetherNativeThinking(
106 fixture.kimiMarkdown.replace(instruction, replacement),
107 ).replay,
108 ).toEqual([])
109 }
110})