Open History to see the last commit
1import { readFileSync } from 'node:fs'
2import { describe, expect, it } from 'vitest'
3import { KIMI_CODE_MODELS_URL, parseKimiCodeModels } from './kimi-code-docs.ts'
4
5const html = readFileSync(
6 new URL('./fixtures/kimi-code-models.html.txt', import.meta.url),
7 'utf8',
8)
9const source = {
10 derivation: 'docs-derived' as const,
11 sourceUrl: KIMI_CODE_MODELS_URL,
12 sourceHash: 'test-fixture',
13}
14
15describe('native Kimi Coding model documentation', () => {
16 it('reads all native IDs and their own context cells', () => {
17 const models = parseKimiCodeModels(html, source)
18 expect(models.map((model) => model.rawId)).toEqual([
19 'k3',
20 'k3-256k',
21 'kimi-for-coding',
22 'kimi-for-coding-highspeed',
23 ])
24 expect(models.map((model) => model.contextWindow)).toEqual([
25 1048576, 262144, 1048576, 262144,
26 ])
27 expect(models[0]?.providerMetadata?.['Availability (new plans)']).toContain(
28 '1M context for Pro and above',
29 )
30 expect(
31 models.every(
32 (model) =>
33 model.pricing === null &&
34 model.maxOutput === null &&
35 model.displayName === null &&
36 model.requestMap === null,
37 ),
38 ).toBe(true)
39 })
40 it('reads model-specific effort values without inferring mandatory thinking', () => {
41 const models = parseKimiCodeModels(html, source)
42 expect(models[0]?.reasoning).toEqual({
43 mode: 'effort',
44 mandatory: null,
45 efforts: ['low', 'high', 'max'],
46 })
47 expect(models[3]?.reasoning).toBeNull()
48 expect(models[3]?.capabilities).toEqual(['reasoning'])
49 })
50 it('publishes stated media inputs and leaves output unsourced', () => {
51 const models = parseKimiCodeModels(html, source)
52 expect(models[1]?.modalities).toEqual({ input: ['image'], output: null })
53 expect(models[2]?.modalities).toEqual({
54 input: ['image', 'video'],
55 output: null,
56 })
57 expect(models[2]?.factSources?.modalities).toMatchObject({
58 sourceUrl: KIMI_CODE_MODELS_URL,
59 })
60 })
61 it('reads a newly named model rather than using a static ID registry', () => {
62 const changed = html.replace(
63 /(<th[^>]*><code[^>]*>)k3(<\/code>)/,
64 '$1future-model$2',
65 )
66 expect(parseKimiCodeModels(changed, source)[0]?.rawId).toBe('future-model')
67 })
68 it('returns null for a legitimately absent fact row', () => {
69 const changed = html.replace(
70 /<tr\b[^>]*><td\b[^>]*>Context window<\/td>[\s\S]*?<\/tr>/,
71 '',
72 )
73 expect(
74 parseKimiCodeModels(changed, source).every(
75 (model) => model.contextWindow === null,
76 ),
77 ).toBe(true)
78 })
79 it('rejects HTML shells, table-width changes and duplicate native IDs', () => {
80 expect(() => parseKimiCodeModels('<html>login</html>', source)).toThrow(
81 /Model ID table/,
82 )
83 expect(() =>
84 parseKimiCodeModels(html.replace(/<td\b[^>]*>Regular<\/td>/, ''), source),
85 ).toThrow(/widths/)
86 expect(() =>
87 parseKimiCodeModels(
88 html.replace(/(<th[^>]*><code[^>]*>)k3-256k(<\/code>)/, '$1k3$2'),
89 source,
90 ),
91 ).toThrow(/duplicate/)
92 })
93 it('rejects unreadable stated context or media facts rather than substituting null', () => {
94 expect(() =>
95 parseKimiCodeModels(
96 html.replace('1048576</code>', 'unknown</code>'),
97 source,
98 ),
99 ).toThrow(/context window/)
100 expect(() =>
101 parseKimiCodeModels(html.replace('Image, video', 'Image, radar'), source),
102 ).toThrow(/modalities/)
103 })
104})