Open History to see the last commit
1import { afterEach, describe, expect, it, vi } from 'vitest'
2
3import { BYTEPLUS_MODEL_LIST_URL } from './byteplus-pricing.ts'
4import type { ByteplusDoc } from './byteplus-pricing.ts'
5import {
6 byteplusServerTools,
7 parseByteplusMcpSupport,
8} from './byteplus-tools.ts'
9import { docsRun } from './model-facts.ts'
10
11/** A one-table model-list document, in the page's zone layout. */
12function doc(rows: Array<Array<string>>): ByteplusDoc {
13 const data: ByteplusDoc['data'] = {
14 '0': { ops: [{ insert: '*', attributes: { aceTable: 'rows cols' } }] },
15 rows: { ops: rows.map((_, r) => ({ insert: { id: `r${String(r)}` } })) },
16 cols: {
17 ops: (rows[0] ?? []).map((_, c) => ({ insert: { id: `c${String(c)}` } })),
18 },
19 }
20 rows.forEach((cells, r) => {
21 cells.forEach((text, c) => {
22 data[`xr${String(r)}xc${String(c)}`] = { ops: [{ insert: `${text}\n` }] }
23 })
24 })
25 return { data }
26}
27
28// The model list's Tool use table as served on 2026-10-22, cut down.
29const HEADER = [
30 'Model ID',
31 'Function calling\nResponses API & Chat API',
32 'MCP\nResponses API',
33]
34
35describe('parseByteplusMcpSupport', () => {
36 it('reads each row of the Tool use table', () => {
37 const support = parseByteplusMcpSupport(
38 doc([
39 HEADER,
40 ['dola-seed-2-1-turbo-260628', 'Supported', 'Supported'],
41 ['seed-2-0-code-preview-260328', 'Supported', 'Not Supported'],
42 [
43 'seed-1-8-251228 Retiring\n(Recommended replacement: seed-2-0-lite-260428)',
44 'Supported',
45 'Supported',
46 ],
47 ]),
48 )
49 expect([...support]).toEqual([
50 ['dola-seed-2-1-turbo-260628', true],
51 ['seed-2-0-code-preview-260328', false],
52 ['seed-1-8-251228', true],
53 ])
54 })
55
56 it('reads the Yes / No wording past a Provider column', () => {
57 // The Tool use table as served on 2026-10-23, cut down.
58 const support = parseByteplusMcpSupport(
59 doc([
60 ['Provider', 'Model ID', 'Function calling', 'MCP'],
61 ['ByteDance', 'dola-seed-2-1-turbo-260628', 'Yes', 'Yes'],
62 ['', 'seed-2-0-code-preview-260328', 'Yes', 'No'],
63 ['Z.ai', 'glm-5-2-260617', 'Yes', 'Yes'],
64 ]),
65 )
66 expect([...support]).toEqual([
67 ['dola-seed-2-1-turbo-260628', true],
68 ['seed-2-0-code-preview-260328', false],
69 ['glm-5-2-260617', true],
70 ])
71 })
72
73 it('throws on a missing table or a cell it cannot read', () => {
74 expect(() =>
75 parseByteplusMcpSupport(doc([['Model ID', 'Capabilities']])),
76 ).toThrow('no Tool use table')
77 expect(() =>
78 parseByteplusMcpSupport(doc([HEADER, ['m-1', 'Supported', 'Beta']])),
79 ).toThrow('unread Tool use row')
80 })
81})
82
83describe('byteplusServerTools', () => {
84 afterEach(() => {
85 vi.unstubAllGlobals()
86 })
87
88 it('is source-silent only for a model the table marks Not Supported (#707)', async () => {
89 const content = JSON.stringify(
90 doc([
91 HEADER,
92 ['dola-seed-2-1-turbo-260628', 'Supported', 'Supported'],
93 ['seed-2-0-code-preview-260328', 'Supported', 'Not Supported'],
94 ]),
95 )
96 const html = `<script>window._ROUTER_DATA = ${JSON.stringify({
97 loaderData: { page: { curDoc: { Content: content } } },
98 })}</script>`
99 vi.stubGlobal(
100 'fetch',
101 vi.fn(() => Promise.resolve(new Response(html, { status: 200 }))),
102 )
103 const tools = await byteplusServerTools(docsRun())
104 expect(tools('dola-seed-2-1-turbo-260628').serverTools).toEqual(['mcp'])
105 const silent = {
106 factSources: {
107 serverTools: {
108 derivation: 'source-silent',
109 sourceUrl: BYTEPLUS_MODEL_LIST_URL,
110 },
111 },
112 }
113 expect(tools('seed-2-0-code-preview-260328')).toEqual(silent)
114 // Not in the table: the page states nothing for it.
115 expect(tools('seed-1-6-250615')).toEqual({})
116 })
117
118 it('keeps stored tools when the table fails to load', async () => {
119 vi.stubGlobal(
120 'fetch',
121 vi.fn(() => Promise.resolve(new Response('down', { status: 503 }))),
122 )
123 const tools = await byteplusServerTools(docsRun())
124 expect(tools('seed-1-6-250615')).toEqual({
125 absent: { serverTools: 'unavailable' },
126 })
127 })
128})