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

opencode-go-facts.test.ts

187 lines5.8 KB

1import { describe, expect, it } from 'vitest'
2​
3import {
4 goListingRoutes,
5 goTrainsOnRequestData,
6 openCodeGoFacts,
7} from './opencode-go-facts.ts'
8​
9describe('openCodeGoFacts', () => {
10 it('requires the session header and User-Agent on every Go row', () => {
11 const facts = openCodeGoFacts('opencode-go', 'glm-5.2')
12 expect(facts.requiredRequestHeaders?.map((header) => header.name)).toEqual([
13 'x-opencode-session',
14 'User-Agent',
15 ])
16 expect(facts.trainsOnRequestData).toBeNull()
17 expect(facts.factSources.requiredRequestHeaders).toMatchObject({
18 derivation: 'docs-derived',
19 sourceUrl: 'https://opencode.ai/docs/console/go/',
20 })
21 expect(facts.factSources.trainsOnRequestData).toBeUndefined()
22 })
23​
24 it('sets training only on the id whose probe stated it', () => {
25 const argon = openCodeGoFacts('opencode-go', 'gemini-4-argon-contributor')
26 expect(argon.trainsOnRequestData).toBe(true)
27 expect(argon.factSources.trainsOnRequestData).toMatchObject({
28 derivation: 'probe-verified',
29 verifiedAt: '2026-10-23',
30 })
31 expect(
32 openCodeGoFacts('opencode-go', 'muse-spark-1.3-contributor')
33 .trainsOnRequestData,
34 ).toBeNull()
35 expect(openCodeGoFacts('opencode', 'gemini-4-argon-contributor')).toEqual({
36 requiredRequestHeaders: null,
37 trainsOnRequestData: null,
38 factSources: {},
39 })
40 })
41})
42​
43describe('goTrainsOnRequestData', () => {
44 it('reads the listing boolean and does not treat false as missing', () => {
45 const training = goTrainsOnRequestData({
46 object: 'list',
47 data: [
48 { id: 'muse-spark-1.3-contributor', go: { training: true } },
49 { id: 'grok-4.7', go: { training: false } },
50 ],
51 })
52 expect(training.get('muse-spark-1.3-contributor')).toBe(true)
53 expect(training.get('grok-4.7')).toBe(false)
54 })
55​
56 it('throws when go.training is missing or not a boolean', () => {
57 expect(() =>
58 goTrainsOnRequestData({
59 object: 'list',
60 data: [{ id: 'grok-4.7', go: { training: '30 days' } }],
61 }),
62 ).toThrow(/grok-4\.7/)
63 })
64})
65​
66describe('goListingRoutes', () => {
67 it('reads routes from api.protocol.base_url and ignores other listing facts', () => {
68 const routes = goListingRoutes({
69 object: 'list',
70 data: [
71 {
72 id: 'deepseek-v4.1-flash',
73 cost: { input: 0.3, output: 1.2 },
74 limit: { context: 128000, output: 8192 },
75 capabilities: { tools: true },
76 api: {
77 'chat-completions': {
78 base_url: 'https://opencode.ai/inference/go/openai/v1',
79 sdk: {
80 aisdk: '@ai-sdk/openai-compatible',
81 opencodeai: '@opencode/ai/providers/openai-compatible',
82 },
83 },
84 },
85 },
86 {
87 id: 'grok-4.7',
88 api: {
89 responses: {
90 base_url: 'https://opencode.ai/inference/go/openai/v1/',
91 sdk: { aisdk: '@ai-sdk/openai' },
92 },
93 },
94 },
95 {
96 id: 'gemini-4-argon',
97 api: {
98 'generate-content': {
99 base_url: 'https://opencode.ai/inference/go/google/v1beta',
100 sdk: { aisdk: '@ai-sdk/google' },
101 capabilities: { tools: { choice: ['auto'] } },
102 },
103 },
104 },
105 ],
106 })
107 expect(routes).toEqual([
108 '/inference/go/google/v1beta/models/gemini-4-argon:generateContent',
109 '/inference/go/openai/v1/chat/completions',
110 '/inference/go/openai/v1/responses',
111 ])
112 })
113​
114 it('reads the live gemini-4-argon interactions route with the model out of the path', () => {
115 // gemini-4-argon is GET https://opencode.ai/inference/go/v1/models on
116 // 2026-11-20. The contributor row is only here to show a shared base
117 // collapses to one interactions path.
118 const routes = goListingRoutes({
119 object: 'list',
120 data: [
121 {
122 id: 'gemini-4-argon',
123 api: {
124 'generate-content': {
125 base_url: 'https://opencode.ai/inference/go/google/v1beta',
126 sdk: {
127 aisdk: '@ai-sdk/google',
128 opencodeai: '@opencode/ai/providers/google',
129 },
130 capabilities: {
131 tools: { choice: ['auto', 'none', 'required', 'tool'] },
132 },
133 },
134 interactions: {
135 base_url: 'https://opencode.ai/inference/go/google/v1beta/',
136 sdk: {
137 aisdk: '@ai-sdk/google',
138 opencodeai: '@opencode/ai/providers/google/interactions',
139 },
140 },
141 },
142 cost: { input: 1, output: 2 },
143 limit: { context: 1000000 },
144 },
145 {
146 id: 'gemini-4-argon-contributor',
147 api: {
148 interactions: {
149 base_url: 'https://opencode.ai/inference/go/google/v1beta',
150 sdk: {
151 opencodeai: '@opencode/ai/providers/google/interactions',
152 },
153 },
154 },
155 },
156 ],
157 })
158 expect(routes).toEqual([
159 '/inference/go/google/v1beta/interactions',
160 '/inference/go/google/v1beta/models/gemini-4-argon:generateContent',
161 ])
162 })
163​
164 it('throws when api is missing or the protocol key is unknown', () => {
165 expect(() =>
166 goListingRoutes({
167 object: 'list',
168 data: [{ id: 'grok-4.7', go: { training: false } }],
169 }),
170 ).toThrow('opencode-go: grok-4.7 has no api entry')
171 expect(() =>
172 goListingRoutes({
173 object: 'list',
174 data: [
175 {
176 id: 'grok-4.7',
177 api: {
178 embeddings: {
179 base_url: 'https://opencode.ai/inference/go/openai/v1',
180 },
181 },
182 },
183 ],
184 }),
185 ).toThrow('opencode-go: grok-4.7 has unknown api protocol embeddings')
186 })
187})