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

opencode-go.test.ts

287 lines9.3 KB

1import { OPENCODE_CATALOG_URL } from '../opencode-catalog.ts'
2import { OPENCODE_GO_ROUTE_DOCS_URL } from '../opencode-routes.ts'
3​
4import { afterEach, describe, expect, it } from 'vitest'
5​
6import { OPENCODE_GO_MODELS_URL, provider } from './opencode-go.ts'
7​
8const LISTING = {
9 object: 'list',
10 data: ['mini', 'kimi', 'gpt', 'deepseek', 'absent'].map((id) => ({
11 id,
12 object: 'model',
13 owned_by: 'opencode',
14 })),
16​
17const CATALOG = {
18 'opencode-go': {
19 npm: '@ai-sdk/openai-compatible',
20 api: 'https://opencode.ai/inference/go/openai/v1',
21 models: {
22 mini: {
23 id: 'mini',
24 name: 'Mini',
25 provider: {
26 npm: '@ai-sdk/anthropic',
27 api: 'https://opencode.ai/inference/go/anthropic/v1',
28 },
29 cost: { input: 0.3, output: 1.2, cache_read: 0.06 },
30 },
31 kimi: { id: 'kimi', name: 'Kimi', cost: { input: 3, output: 15 } },
32 gpt: {
33 id: 'gpt',
34 name: 'GPT',
35 provider: { npm: '@ai-sdk/openai' },
36 cost: { input: 0.1, output: 0.5 },
37 },
38 deepseek: {
39 id: 'deepseek',
40 name: 'DeepSeek',
41 cost: { input: 1, output: 2 },
42 },
43 },
44 },
46​
47/** go.mdx Endpoints table excerpt (2026-10-21), Gemini row included. */
48const ROUTE_DOCS = `# Go
49​
50## Endpoints
51​
52| Model | Model ID | Endpoint |
53| ------ | -------- | -------------------------------------------------------------- |
54| GPT | gpt | \`https://opencode.ai/inference/go/openai/v1/responses\` |
55| Mini | mini | \`https://opencode.ai/inference/go/anthropic/v1/messages\` |
56| Gemini | gemini | \`https://opencode.ai/inference/go/google/v1beta/models/gemini\` |
57| Kimi | kimi | \`https://opencode.ai/inference/go/openai/v1/chat/completions\` |
58​
59## Privacy
60​
61| Model | Model training | Data retention |
62| ------ | -------------- | -------------- |
63| Mini | Yes | Not ZDR |
64| GPT | Not used | 30 days |
65| Gemini | Not used | 0 days |
66| Kimi | Not used | 0 days |
68​
69const originalFetch = globalThis.fetch
70​
71afterEach(() => {
72 globalThis.fetch = originalFetch
73})
74​
75function stubFetch() {
76 const urls: Array<string> = []
77 globalThis.fetch = ((url: string) => {
78 urls.push(String(url))
79 if (String(url) === OPENCODE_GO_MODELS_URL) {
80 return Promise.resolve(new Response(JSON.stringify(LISTING)))
81 }
82 if (String(url) === OPENCODE_CATALOG_URL) {
83 return Promise.resolve(new Response(JSON.stringify(CATALOG)))
84 }
85 if (String(url) === OPENCODE_GO_ROUTE_DOCS_URL) {
86 return Promise.resolve(new Response(ROUTE_DOCS))
87 }
88 return Promise.reject(new Error(`unexpected fetch: ${String(url)}`))
89 }) as typeof fetch
90 return urls
92​
93describe('opencode-go', () => {
94 it('classifies rows by package and leaves prices null', async () => {
95 const urls = stubFetch()
96 const listed = await provider.listModels({})
97 const spec = await provider.fetchSpec({})
98​
99 const byId = Object.fromEntries(
100 listed.models.map((model) => [model.rawId, model]),
101 )
102 expect(listed.models.map((model) => model.rawId)).toEqual([
103 'mini',
104 'kimi',
105 'gpt',
106 'deepseek',
107 'absent',
108 ])
109 expect(byId.mini).toMatchObject({
110 displayName: 'Mini',
111 activity: 'chat',
112 pricing: null,
113 trainsOnRequestData: true,
114 schemaEndpointId: 'inference/go/anthropic/v1/messages',
115 })
116 expect(byId.mini?.factSources?.trainsOnRequestData).toMatchObject({
117 derivation: 'docs-derived',
118 sourceUrl: 'https://opencode.ai/docs/console/go/',
119 path: 'Privacy',
120 })
121 expect(byId.kimi?.trainsOnRequestData).toBeNull()
122 expect(byId.gpt?.trainsOnRequestData).toBeNull()
123 expect(byId.mini?.factSources?.schemaEndpointId).toMatchObject({
124 derivation: 'listing',
125 sourceUrl: OPENCODE_CATALOG_URL,
126 path: 'opencode-go.models.mini.provider',
127 })
128 expect(byId.kimi).toMatchObject({
129 schemaEndpointId: 'inference/go/openai/v1/chat/completions',
130 pricing: null,
131 })
132 expect(byId.kimi?.factSources?.schemaEndpointId?.path).toBe(
133 'opencode-go.npm',
134 )
135 expect(byId.gpt).toMatchObject({
136 schemaEndpointId: 'inference/go/openai/v1/responses',
137 pricing: null,
138 })
139 expect(byId.deepseek).toMatchObject({
140 schemaEndpointId: 'inference/go/openai/v1/chat/completions',
141 pricing: null,
142 })
143 expect(byId.absent).toEqual({
144 rawId: 'absent',
145 releasedAt: null,
146 pricing: null,
147 trainsOnRequestData: null,
148 absent: { releasedAt: 'cleared' },
149 })
150 expect(
151 provider.connect?.requiredHeaders?.map((header) => header.name),
152 ).toEqual(['x-opencode-session', 'User-Agent'])
153 expect(provider.modelsEndpoint).toBe(OPENCODE_GO_MODELS_URL)
154 expect(
155 spec.specs[0]?.paths?.['/inference/go/anthropic/v1/messages']?.post,
156 ).toMatchObject({
157 'x-modelschemas-route-only': true,
158 })
159 expect(
160 spec.specs[0]?.paths?.[
161 '/inference/go/google/v1beta/models/gemini-4-argon-contributor:generateContent'
162 ]?.post,
163 ).toMatchObject({
164 'x-modelschemas-route-only': true,
165 'x-modelschemas-provenance': {
166 derivation: 'probe-verified',
167 verifiedAt: '2026-10-23',
168 },
169 })
170 expect(spec.specs[0]?.paths?.['/v1/messages']).toBeUndefined()
171 expect(urls.filter((url) => url.includes('/docs/'))).toEqual([
172 OPENCODE_GO_ROUTE_DOCS_URL,
173 OPENCODE_GO_ROUTE_DOCS_URL,
174 ])
175 expect(urls).toContain(OPENCODE_GO_MODELS_URL)
176 expect(urls).toContain(OPENCODE_CATALOG_URL)
177 })
178​
179 it('binds a Go Gemini row only when that exact id has a probe record', async () => {
180 const catalog = {
181 'opencode-go': {
182 ...CATALOG['opencode-go'],
183 models: {
184 ...CATALOG['opencode-go'].models,
185 gemini: {
186 id: 'gemini',
187 name: 'Gemini',
188 provider: {
189 npm: '@ai-sdk/google',
190 api: 'https://opencode.ai/inference/go/google/v1beta',
191 },
192 },
193 'gemini-4-argon-contributor': {
194 id: 'gemini-4-argon-contributor',
195 name: 'Argon',
196 provider: {
197 npm: '@ai-sdk/google',
198 api: 'https://opencode.ai/inference/go/google/v1beta',
199 },
200 },
201 },
202 },
203 }
204 globalThis.fetch = ((url: string) => {
205 if (String(url) === OPENCODE_GO_MODELS_URL) {
206 return Promise.resolve(
207 new Response(
208 JSON.stringify({
209 object: 'list',
210 data: [
211 { id: 'gemini', object: 'model', owned_by: 'opencode' },
212 {
213 id: 'gemini-4-argon-contributor',
214 object: 'model',
215 owned_by: 'opencode',
216 },
217 ],
218 }),
219 ),
220 )
221 }
222 if (String(url) === OPENCODE_CATALOG_URL) {
223 return Promise.resolve(new Response(JSON.stringify(catalog)))
224 }
225 if (String(url) === OPENCODE_GO_ROUTE_DOCS_URL) {
226 return Promise.resolve(new Response(ROUTE_DOCS))
227 }
228 return Promise.resolve(new Response('404: Not Found', { status: 404 }))
229 }) as typeof fetch
230​
231 const spec = await provider.fetchSpec({})
232 expect(Object.keys(spec.specs[0]?.paths ?? {}).sort()).toEqual([
233 '/inference/go/anthropic/v1/messages',
234 '/inference/go/google/v1beta/models/gemini-4-argon-contributor:generateContent',
235 '/inference/go/google/v1beta/models/gemini-4-argon-contributor:streamGenerateContent',
236 '/inference/go/openai/v1/chat/completions',
237 '/inference/go/openai/v1/responses',
238 ])
239 const listed = await provider.listModels({})
240 const gemini = listed.models.find((model) => model.rawId === 'gemini')
241 const argon = listed.models.find(
242 (model) => model.rawId === 'gemini-4-argon-contributor',
243 )
244 expect(gemini).toMatchObject({ rawId: 'gemini', activity: 'chat' })
245 expect(gemini?.schemaEndpointId).toBeUndefined()
246 expect(gemini?.factSources?.schemaEndpointId).toBeUndefined()
247 expect(argon?.schemaEndpointId).toBe(
248 'inference/go/google/v1beta/models/gemini-4-argon-contributor:generateContent',
249 )
250 expect(argon?.factSources?.schemaEndpointId).toEqual({
251 derivation: 'probe-verified',
252 verifiedAt: '2026-10-23',
253 sourceUrl:
254 'src/server/providers/probes/opencode-go.ts#gemini-4-argon-contributor-generate',
255 })
256 expect(
257 spec.specs[0]?.paths?.[
258 '/inference/go/google/v1beta/models/gemini-4-argon-contributor:generateContent'
259 ]?.post,
260 ).not.toHaveProperty('requestBody')
261 })
262​
263 it('throws when the catalog classifies no listed row', async () => {
264 stubFetch()
265 const fetchCatalog = globalThis.fetch
266 globalThis.fetch = ((url: string, init?: RequestInit) => {
267 if (String(url) !== OPENCODE_CATALOG_URL) return fetchCatalog(url, init)
268 return Promise.resolve(
269 new Response(
270 JSON.stringify({
271 'opencode-go': {
272 npm: '@ai-sdk/openai-compatible',
273 api: 'https://opencode.ai/inference/go/openai/v1',
274 models: {
275 mini: {
276 id: 'mini',
277 provider: { npm: '@ai-sdk/mistral' },
278 },
279 },
280 },
281 }),
282 ),
283 )
284 }) as typeof fetch
285 await expect(provider.listModels({})).rejects.toThrow(/classified 0/)
286 })
287})