diff --git a/src/shared/opencode-generation-output.test.ts b/src/shared/opencode-generation-output.test.ts index f53afed85e1..1d0e8c4d9ce 100644 --- a/src/shared/opencode-generation-output.test.ts +++ b/src/shared/opencode-generation-output.test.ts @@ -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.' + }) + }) }) diff --git a/src/shared/opencode-generation-output.ts b/src/shared/opencode-generation-output.ts index 1bc3b73d576..8a3ba24e494 100644 --- a/src/shared/opencode-generation-output.ts +++ b/src/shared/opencode-generation-output.ts @@ -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() })