Preserve OpenCode named errors without a data message

This commit is contained in:
Neil
2026-10-02 05:25:23 -07:00
parent 1b60ec5d11
commit 98fdecc7a3
2 changed files with 26 additions and 9 deletions
+25 -8
View File
@@ -55,13 +55,30 @@ describe('OpenCode generation event output', () => {
})
})
it.each(['{broken', '{"title":"not an event"}', 'null'])(
'rejects malformed events %s',
(output) => {
expect(parseOpenCodeGenerationOutput(output)).toEqual({
ok: false,
error: 'OpenCode returned invalid JSON events.'
})
it.each([
{ error: { name: 'MessageOutputLengthError', data: {} }, expected: 'MessageOutputLengthError' },
{
error: { name: 'ProviderError', data: { retryable: false } },
expected: 'ProviderError'
},
{
error: { name: 'ProviderError', message: 'Provider rejected the request', data: {} },
expected: 'Provider rejected the request'
}
)
])('reports named errors without a data message', ({ error, expected }) => {
const output = `${frame('text', 'partial')}\n${JSON.stringify({ type: 'error', error })}`
expect(parseOpenCodeGenerationOutput(output)).toEqual({ ok: false, error: expected })
})
it.each([
'{broken',
'{"title":"not an event"}',
'null',
JSON.stringify({ type: 'error', error: { name: 'ProviderError', data: { message: 42 } } })
])('rejects malformed events %s', (output) => {
expect(parseOpenCodeGenerationOutput(output)).toEqual({
ok: false,
error: 'OpenCode returned invalid JSON events.'
})
})
})
+1 -1
View File
@@ -7,7 +7,7 @@ const eventSchema = z.object({
.object({
name: z.string().optional(),
message: z.string().optional(),
data: z.object({ message: z.string() }).optional()
data: z.object({ message: z.string().optional() }).optional()
})
.optional()
})