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

glm-coding-docs.test.ts

164 lines5.1 KB

1import { readFileSync } from 'node:fs'
2import { describe, expect, it } from 'vitest'
3import { parseGlmCodingModels } from './glm-coding-docs.ts'
4import type { CodingDoc, CodingLocale } from './glm-coding-docs.ts'
5​
6function docs(locale: CodingLocale) {
7 const host = locale === 'en' ? 'docs.z.ai' : 'docs.bigmodel.cn'
8 const load = (file: string): CodingDoc => ({
9 text: readFileSync(
10 new URL(`./fixtures/${host}-${file}.md.txt`, import.meta.url),
11 'utf8',
12 ),
13 url: `https://${host}/${file}.md`,
14 hash: 'native-fixture',
15 })
16 return {
17 overview: load('overview'),
18 latest: load('latest-model'),
19 thinking: load('thinking'),
20 }
22describe('native GLM Coding sources', () => {
23 for (const locale of ['en', 'zh'] as const) {
24 it(`sources supported ${locale} plan facts without routed legacy ids or borrowed bodies`, () => {
25 const rows = parseGlmCodingModels(docs(locale), locale)
26 expect(rows.map((row) => row.rawId)).toEqual(['glm-5.3', 'glm-5.3-flash'])
27 expect(rows.map((row) => row.contextWindow)).toEqual([1000000, 1000000])
28 expect(rows.map((row) => row.modalities)).toEqual([
29 { input: ['text'], output: null },
30 { input: ['image'], output: null },
31 ])
32 for (const row of rows) {
33 expect(row.pricing).toBeNull()
34 expect(row.absent?.pricing).toBe('cleared')
35 expect(row.schemaEndpointId).toBeNull()
36 expect(row.maxOutput).toBeNull()
37 expect(row.reasoning).toEqual({
38 mode: 'effort',
39 mandatory: true,
40 efforts: ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'],
41 })
42 expect(row.requestMap?.thinking).toEqual({
43 on: { reasoning_effort: 'high' },
44 off: null,
45 levels: {
46 off: null,
47 minimal: 'low',
48 low: 'low',
49 medium: 'high',
50 high: 'high',
51 xhigh: 'max',
52 max: 'max',
53 },
54 })
55 expect(row.requestMap?.maxTokensField).toBeNull()
56 expect(row.requestMap?.developerRole).toBeNull()
57 expect(row.requestMap?.toolStream).toBeNull()
58 expect(row.requestMap?.replayReasoningContent).toBeNull()
59 }
60 })
61 }
62 it('fails missing or malformed supported-model and effort scopes', () => {
63 const d = docs('en')
64 expect(() =>
65 parseGlmCodingModels(
66 { ...d, overview: { ...d.overview, text: 'No supported model list' } },
67 'en',
68 ),
69 ).toThrow('native overview document heading')
70 expect(() =>
71 parseGlmCodingModels(
72 {
73 ...d,
74 thinking: {
75 ...d.thinking,
76 text: d.thinking.text.replace(
77 'mapped to `low`',
78 'mapped elsewhere',
79 ),
80 },
81 },
82 'en',
83 ),
84 ).toThrow('unreadable Coding effort clause')
85 })
86 it('leaves absent setting facts null but throws on a recognized unreadable context', () => {
87 const d = docs('en')
88 const latest = {
89 ...d.latest,
90 text: d.latest.text
91 .split('\n')
92 .filter((line) => !/Context Window Size/.test(line))
93 .join('\n'),
94 }
95 expect(
96 parseGlmCodingModels({ ...d, latest }, 'en')[0]?.contextWindow,
97 ).toBeNull()
98 expect(() =>
99 parseGlmCodingModels(
100 {
101 ...d,
102 latest: {
103 ...d.latest,
104 text: d.latest.text.replace('Size to 1000000', 'Size to many'),
105 },
106 },
107 'en',
108 ),
109 ).toThrow('unreadable plan context')
110 })
111})
112​
113for (const locale of ['en', 'zh'] as const) {
114 it(`rejects HTML in every ${locale} native source instead of clearing facts`, () => {
115 const d = docs(locale)
116 for (const role of ['overview', 'latest', 'thinking'] as const)
117 expect(() =>
118 parseGlmCodingModels(
119 {
120 ...d,
121 [role]: {
122 ...d[role],
123 text: '<!DOCTYPE html><html>Not Found</html>',
124 },
125 },
126 locale,
127 ),
128 ).toThrow('returned HTML')
129 })
131it('rejects fractional or comma-formatted recognized context settings', () => {
132 const d = docs('en')
133 for (const malformed of ['1000000.5', '1000000,5', '1,000,000'])
134 expect(() =>
135 parseGlmCodingModels(
136 {
137 ...d,
138 latest: {
139 ...d.latest,
140 text: d.latest.text.replace(
141 'Size to 1000000',
142 `Size to ${malformed}`,
143 ),
144 },
145 },
146 'en',
147 ),
148 ).toThrow('unreadable plan context setting')
149})
150it('does not infer forced thinking merely from a remapped none value or claim a complete capability list', () => {
151 const d = docs('en')
152 const thinking = {
153 ...d.thinking,
154 text: d.thinking.text
155 .split('\n')
156 .filter((line) => !/no longer support disabling thinking/.test(line))
157 .join('\n'),
158 }
159 const rows = parseGlmCodingModels({ ...d, thinking }, 'en')
160 expect(rows.every((row) => row.reasoning?.mandatory === null)).toBe(true)
161 expect(rows.every((row) => row.exactCapabilities === undefined)).toBe(true)
162 expect(rows[0]?.requestMap?.thinking?.levels?.minimal).toBe('low')
163 expect(rows[0]?.requestMap?.thinking?.off).toBeNull()
164})