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