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

opencode-go.test.ts

218 lines7.9 KB

1import { OPENCODE_CATALOG_URL } from '../opencode-catalog.ts'
2​
3import { afterEach, describe, expect, it } from 'vitest'
4​
5import {
6 OPENCODE_GO_DOCS_MARKDOWN,
7 OPENCODE_GO_DOCS_URL,
8 OPENCODE_GO_MODELS_URL,
9 parseGoDocs,
10 provider,
11} from './opencode-go.ts'
12​
13/** Excerpt of https://opencode.ai/zen/go/v1/models (2026-10-07). */
14const LISTING = {
15 object: 'list',
16 data: ['minimax-m3', 'kimi-k3', 'gpt-6-luna', 'deepseek-v4-pro', 'glm-5'].map(
17 (id) => ({
18 id,
19 object: 'model',
20 created: 1791316362,
21 owned_by: 'opencode',
22 }),
23 ),
25​
26/** Excerpt of https://opencode.ai/docs/go.md (2026-10-07), rows verbatim. */
27const DOCS = `OpenCode Go gives you reliable access to popular open coding models, with two monthly plans:
28​
29| Plan | Price | Included usage |
30| ----------- | ------------- | ------------------------------------------- |
31| **Go** | **$10/month** | Lower-cost access to the models below |
32| **Go Plus** | **$40/month** | Higher usage limits across the models below |
33​
34---
35​
36## Usage limits
37​
38Usage limits are defined as monthly dollar amounts. The table below shows the
39monthly limit for each plan and the token costs for each model. Token pricing is
40the same for Go and Go Plus.
41​
42Token prices are per 1M tokens.
43​
44<Tabs syncKey="go-plan">
45 <TabItem label="Go">
46​
47 | Model | Input | Output | Cached Read | Cached Write | Monthly limit |
48 | --------------------------------------- | ------ | ------ | ----------- | ------------ | ---------------------------------------------- |
49 | Kimi K3 | $3.00 | $15.00 | $0.30 | - | **$15** |
50 | MiniMax M3 | $0.30 | $1.20 | $0.06 | - | **$60** |
51 | DeepSeek V4 Pro (Off-Peak) | $0.66 | $1.98 | $0.022 | - | **$15** |
52 | DeepSeek V4 Pro (Peak) | $1.32 | $3.96 | $0.044 | - | **$15** |
53 | GPT 6 Luna (≤ 272K tokens) | $0.10 | $0.50 | $0.01 | $0.125 | **$15** |
54 | GPT 6 Luna (> 272K tokens) | $0.20 | $0.75 | $0.02 | $0.25 | **$15** |
55​
56 </TabItem>
57</Tabs>
58​
59---
60​
61## Endpoints
62​
63You can also access Go models through the following API endpoints.
64​
65| Model | Model ID | Endpoint | AI SDK Package |
66| ---------------------------- | ---------------------------- | ------------------------------------------------ | --------------------------- |
67| GPT 6 Luna | gpt-6-luna | \`https://opencode.ai/zen/go/v1/responses\` | \`@ai-sdk/openai\` |
68| Kimi K3 | kimi-k3 | \`https://opencode.ai/zen/go/v1/chat/completions\` | \`@ai-sdk/openai-compatible\` |
69| DeepSeek V4 Pro | deepseek-v4-pro | \`https://opencode.ai/zen/go/v1/chat/completions\` | \`@ai-sdk/openai-compatible\` |
70| MiniMax M3 | minimax-m3 | \`https://opencode.ai/zen/go/v1/messages\` | \`@ai-sdk/anthropic\` |
71​
72The [model id](/docs/config/#models) in your OpenCode config
73uses the format \`opencode-go/<model-id>\`.
74​
75---
76​
77## Privacy
78​
79| Model | Model training | Data retention |
80| ---------------------------- | -------------- | -------------- |
81| Kimi K3 | Not used | 0 days |
83​
84const originalFetch = globalThis.fetch
85​
86afterEach(() => {
87 globalThis.fetch = originalFetch
88})
89​
90function stubFetch(docs: string | Response) {
91 const urls: Array<string> = []
92 globalThis.fetch = ((url: string) => {
93 urls.push(String(url))
94 if (String(url) === OPENCODE_GO_MODELS_URL) {
95 return Promise.resolve(new Response(JSON.stringify(LISTING)))
96 }
97 if (String(url) === OPENCODE_CATALOG_URL) {
98 return Promise.resolve(
99 new Response(
100 JSON.stringify({
101 'opencode-go': { models: { synthetic: { id: 'synthetic' } } },
102 }),
103 ),
104 )
105 }
106 if (String(url) === OPENCODE_GO_DOCS_MARKDOWN) {
107 return Promise.resolve(
108 typeof docs === 'string' ? new Response(docs) : docs,
109 )
110 }
111 if (
112 String(url).startsWith(
113 'https://raw.githubusercontent.com/anomalyco/opencode/dev/',
114 )
115 )
116 return Promise.resolve(
117 new Response('export function POST(input: APIEvent) {}'),
118 )
119 return Promise.reject(new Error(`unexpected fetch: ${String(url)}`))
120 }) as typeof fetch
121 return urls
123​
124describe('opencode-go', () => {
125 it('classifies rows by their documented route and leaves prices null', async () => {
126 const urls = stubFetch(DOCS)
127​
128 const listed = await provider.listModels({})
129 const spec = await provider.fetchSpec({})
130​
131 const row = (rawId: string, displayName: string) => ({
132 rawId,
133 releasedAt: null,
134 absent: { releasedAt: 'cleared' },
135 pricing: null,
136 displayName,
137 activity: 'chat',
138 factSources: {
139 schemaEndpointId: {
140 derivation: 'docs-derived',
141 sourceUrl: OPENCODE_GO_DOCS_URL,
142 path: 'Endpoints',
143 },
144 },
145 schemaEndpointId:
146 rawId === 'minimax-m3'
147 ? 'v1/messages'
148 : rawId === 'gpt-6-luna'
149 ? 'v1/responses'
150 : 'v1/chat/completions',
151 })
152 expect(listed.models).toEqual([
153 row('minimax-m3', 'MiniMax M3'),
154 row('kimi-k3', 'Kimi K3'),
155 row('gpt-6-luna', 'GPT 6 Luna'),
156 row('deepseek-v4-pro', 'DeepSeek V4 Pro'),
157 // Listed, absent from the Endpoints table: stays unclassified.
158 {
159 rawId: 'glm-5',
160 releasedAt: null,
161 pricing: null,
162 absent: { releasedAt: 'cleared' },
163 },
164 ])
165 expect(provider.bindSyncedRoutesOnly).toBe(true)
166 expect(spec.skipped).toBeUndefined()
167 expect(spec.specs[0]?.paths?.['/v1/messages']?.post).toMatchObject({
168 'x-modelschemas-route-only': true,
169 })
170 expect(urls.slice(0, 3)).toEqual([
171 OPENCODE_GO_MODELS_URL,
172 OPENCODE_GO_DOCS_MARKDOWN,
173 OPENCODE_CATALOG_URL,
174 ])
175 })
176​
177 it('leaves a row on an unknown route unclassified', () => {
178 const docs = DOCS.replace(
179 'go/v1/messages` ',
180 'go/v1/systemone` ',
181 )
182 const byId = parseGoDocs(docs)
183 expect(byId['minimax-m3']).toEqual({
184 displayName: 'MiniMax M3',
185 activity: null,
186 schemaEndpointId: null,
187 })
188 expect(byId['kimi-k3']?.activity).toBe('chat')
189 })
190​
191 it.each([
192 ['a renamed header', DOCS.replace('| Model ID ', '| Identifier')],
193 [
194 'an extra column',
195 DOCS.replace(
196 '| AI SDK Package |\n',
197 '| AI SDK Package | Notes |\n',
198 ),
199 ],
200 ['a missing section', DOCS.replace('## Endpoints', '## Routes')],
201 // The Zen page's routes: a Go row must sit under `/zen/go/`.
202 ['a route outside the Go base', DOCS.replaceAll('/zen/go/v1/', '/zen/v1/')],
203 ['a duplicate id', DOCS.replace('| kimi-k3 ', '| gpt-6-luna ')],
204 ['no chat route at all', DOCS.replaceAll(/go\/v1\/[a-z/]+`/g, 'go/v1/x`')],
205 ['an HTML page', '<!DOCTYPE html><html><body>Not Found</body></html>'],
206 ])('throws on %s', (_name, docs) => {
207 expect(docs).not.toBe(DOCS)
208 expect(() => parseGoDocs(docs)).toThrow(/^opencode-go: /)
209 })
210​
211 it('throws rather than list unclassified rows when the docs page fails', async () => {
212 stubFetch(new Response('gone', { status: 404 }))
213 await expect(provider.listModels({})).rejects.toThrow()
214​
215 stubFetch('<!DOCTYPE html><html><body>Not Found</body></html>')
216 await expect(provider.listModels({})).rejects.toThrow(/returned HTML/)
217 })
218})