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

kimi-code-docs.test.ts

135 lines4.3 KB

1import { readFileSync } from 'node:fs'
2import { describe, expect, it } from 'vitest'
3import {
4 KIMI_CODE_MODELS_URL,
5 kimiCodeChatRoute,
6 parseKimiCodeModels,
7} from './kimi-code-docs.ts'
8​
9const html = readFileSync(
10 new URL('./fixtures/kimi-code-models.html.txt', import.meta.url),
11 'utf8',
13const source = {
14 derivation: 'docs-derived' as const,
15 sourceUrl: KIMI_CODE_MODELS_URL,
16 sourceHash: 'test-fixture',
18​
19describe('native Kimi Coding model documentation', () => {
20 it('reads all native IDs and their own context cells', () => {
21 const models = parseKimiCodeModels(html, source)
22 expect(models.map((model) => model.rawId)).toEqual([
23 'k3',
24 'k3-256k',
25 'kimi-for-coding',
26 'kimi-for-coding-highspeed',
27 ])
28 expect(models.map((model) => model.contextWindow)).toEqual([
29 1048576, 262144, 1048576, 262144,
30 ])
31 expect(models[0]?.providerMetadata?.['Availability (new plans)']).toContain(
32 '1M context for Pro and above',
33 )
34 expect(
35 models.every(
36 (model) =>
37 model.pricing === null &&
38 model.maxOutput === null &&
39 model.displayName === null &&
40 model.requestMap === null,
41 ),
42 ).toBe(true)
43 })
44 it('reads model-specific effort values without inferring mandatory thinking', () => {
45 const models = parseKimiCodeModels(html, source)
46 expect(models[0]?.reasoning).toEqual({
47 mode: 'effort',
48 mandatory: null,
49 efforts: ['low', 'high', 'max'],
50 })
51 expect(models[3]?.reasoning).toBeNull()
52 expect(models[3]?.capabilities).toEqual(['reasoning'])
53 })
54 it('publishes stated media inputs and leaves output unsourced', () => {
55 const models = parseKimiCodeModels(html, source)
56 expect(models[1]?.modalities).toEqual({ input: ['image'], output: null })
57 expect(models[2]?.modalities).toEqual({
58 input: ['image', 'video'],
59 output: null,
60 })
61 expect(models[2]?.factSources?.modalities).toMatchObject({
62 sourceUrl: KIMI_CODE_MODELS_URL,
63 })
64 })
65 it('reads a newly named model rather than using a static ID registry', () => {
66 const changed = html.replace(
67 /(<th[^>]*><code[^>]*>)k3(<\/code>)/,
68 '$1future-model$2',
69 )
70 expect(parseKimiCodeModels(changed, source)[0]?.rawId).toBe('future-model')
71 })
72 it('returns null for a legitimately absent fact row', () => {
73 const changed = html.replace(
74 /<tr\b[^>]*><td\b[^>]*>Context window<\/td>[\s\S]*?<\/tr>/,
75 '',
76 )
77 expect(
78 parseKimiCodeModels(changed, source).every(
79 (model) => model.contextWindow === null,
80 ),
81 ).toBe(true)
82 })
83 it('rejects HTML shells, table-width changes and duplicate native IDs', () => {
84 expect(() => parseKimiCodeModels('<html>login</html>', source)).toThrow(
85 /Model ID table/,
86 )
87 expect(() =>
88 parseKimiCodeModels(html.replace(/<td\b[^>]*>Regular<\/td>/, ''), source),
89 ).toThrow(/widths/)
90 expect(() =>
91 parseKimiCodeModels(
92 html.replace(/(<th[^>]*><code[^>]*>)k3-256k(<\/code>)/, '$1k3$2'),
93 source,
94 ),
95 ).toThrow(/duplicate/)
96 })
97 it('rejects unreadable stated context or media facts rather than substituting null', () => {
98 expect(() =>
99 parseKimiCodeModels(
100 html.replace('1048576</code>', 'unknown</code>'),
101 source,
102 ),
103 ).toThrow(/context window/)
104 expect(() =>
105 parseKimiCodeModels(html.replace('Image, video', 'Image, radar'), source),
106 ).toThrow(/modalities/)
107 })
108})
109​
110describe('Kimi Code Base URLs table (issue #716)', () => {
111 const current = readFileSync(
112 new URL('./fixtures/kimi-code-models-2026-11-21.html.txt', import.meta.url),
113 'utf8',
114 )
115 it('reads the Chat Completions base path for each region', () => {
116 expect(kimiCodeChatRoute(current, 'China')).toBe(
117 'coding/v1/chat/completions',
118 )
119 expect(kimiCodeChatRoute(current, 'Overseas')).toBe(
120 'coding/v1/chat/completions',
121 )
122 })
123 it('states no chat route when the protocol row does not name Chat Completions', () => {
124 // The earlier page said only "OpenAI compatible".
125 expect(() => kimiCodeChatRoute(html, 'China')).toThrow(/Chat Completions/)
126 })
127 it('throws when the region has no URL', () => {
128 expect(() =>
129 kimiCodeChatRoute(
130 current.replaceAll('Overseas <code', 'Abroad <code'),
131 'Overseas',
132 ),
133 ).toThrow(/Overseas/)
134 })
135})