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

opencode-catalog.test.ts

156 lines4.6 KB

1import { describe, expect, it } from 'vitest'
2import {
3 OPENCODE_CATALOG_URL,
4 parseOpenCodeCatalog,
5} from './opencode-catalog.ts'
6​
7// Synthetic fixtures exercise catalog fields, never production model data.
8function payload(extra: Record<string, unknown> = {}) {
9 return {
10 opencode: {
11 models: {
12 synthetic: {
13 id: 'synthetic',
14 limit: { context: 1234, output: 234 },
15 modalities: { input: ['text', 'image'], output: ['text'] },
16 tool_call: true,
17 structured_output: false,
18 reasoning: true,
19 reasoning_options: [{ type: 'effort', values: ['none', 'high'] }],
20 interleaved: { field: 'reasoning_content' },
21 ...extra,
22 },
23 },
24 },
25 }
27describe('OpenCode native catalog', () => {
28 it('extracts only stated facts and records first-party provenance', () => {
29 const model = parseOpenCodeCatalog(
30 payload(),
31 'opencode',
32 'digest',
33 ).synthetic
34 expect(model).toMatchObject({
35 contextWindow: 1234,
36 maxOutput: 234,
37 modalities: { input: ['text', 'image'], output: ['text'] },
38 capabilities: {
39 tools: true,
40 structured_outputs: false,
41 reasoning: true,
42 vision: true,
43 },
44 reasoning: {
45 mode: 'effort',
46 mandatory: false,
47 efforts: ['none', 'high'],
48 },
49 requestMap: {
50 replayReasoningContent: true,
51 thinking: null,
52 developerRole: null,
53 },
54 })
55 expect(model?.factSources?.contextWindow).toEqual({
56 derivation: 'listing',
57 sourceUrl: OPENCODE_CATALOG_URL,
58 sourceHash: 'digest',
59 path: 'opencode.models.synthetic.limit.context',
60 })
61 })
62 it('does not infer mandatory thinking from an effort list without off', () => {
63 expect(
64 parseOpenCodeCatalog(
65 payload({ reasoning_options: [{ type: 'effort', values: ['high'] }] }),
66 'opencode',
67 'h',
68 ).synthetic?.reasoning?.mandatory,
69 ).toBeNull()
70 })
71 it('recognizes budget plus toggle and leaves absent replay unknown', () => {
72 const model = parseOpenCodeCatalog(
73 payload({
74 reasoning_options: [{ type: 'toggle' }, { type: 'budget_tokens' }],
75 interleaved: undefined,
76 }),
77 'opencode',
78 'h',
79 ).synthetic
80 expect(model?.reasoning).toEqual({ mode: 'budget', mandatory: false })
81 expect(model?.requestMap).toBeNull()
82 })
83 it('leaves missing facts null rather than borrowing another provider', () => {
84 const data = {
85 opencode: { models: { synthetic: { id: 'synthetic' } } },
86 unrelated: { models: payload().opencode.models },
87 }
88 expect(parseOpenCodeCatalog(data, 'opencode', 'h').synthetic).toMatchObject(
89 {
90 contextWindow: null,
91 maxOutput: null,
92 capabilities: null,
93 modalities: null,
94 reasoning: null,
95 requestMap: null,
96 },
97 )
98 expect(() => parseOpenCodeCatalog(data, 'opencode-go', 'h')).toThrow(
99 /no provider/,
100 )
101 })
102 it.each([
103 { limit: { context: 'unknown' } },
104 { modalities: { input: 'text', output: [] } },
105 { tool_call: 'yes' },
106 { reasoning_options: [{ type: 'effort', values: null }] },
107 { interleaved: {} },
108 ])('rejects malformed catalog facts %j', (fields) => {
109 expect(() =>
110 parseOpenCodeCatalog(payload(fields), 'opencode', 'h'),
111 ).toThrow(/unreadable/)
112 })
113})
114​
115it('uses explicit catalog dates and weights with field provenance', () => {
116 const model = parseOpenCodeCatalog(
117 payload({
118 release_date: '2026-09-22',
119 knowledge: '2026-04',
120 open_weights: false,
121 }),
122 'opencode',
123 'hash',
124 ).synthetic
125 expect(model).toMatchObject({
126 releasedAt: Date.UTC(2026, 8, 22) / 1000,
127 knowledgeCutoff: '2026-04',
128 openWeights: false,
129 })
130 expect(model?.providerMetadata?.release_date).toBe('2026-09-22')
131 expect(model?.factSources?.knowledgeCutoff?.path).toBe(
132 'opencode.models.synthetic.knowledge',
133 )
134 expect(model?.factSources?.openWeights?.path).toBe(
135 'opencode.models.synthetic.open_weights',
136 )
137 const unknown = parseOpenCodeCatalog(payload(), 'opencode', 'hash').synthetic
138 expect(unknown).toMatchObject({
139 releasedAt: null,
140 knowledgeCutoff: null,
141 openWeights: null,
142 })
143})
144it.each([
145 { release_date: '2026-02-30' },
146 { release_date: '2026-13-01' },
147 { release_date: 123 },
148 { knowledge: '2026-00' },
149 { knowledge: '2026-02-30' },
150 { knowledge: 'unknown' },
151 { open_weights: 'true' },
152])('rejects malformed sourced dates or weights %j', (fields) => {
153 expect(() =>
154 parseOpenCodeCatalog(payload(fields), 'opencode', 'hash'),
155 ).toThrow(/unreadable/)
156})