diff --git a/src/cli-agent.ts b/src/cli-agent.ts index ac96664b..fc3fec03 100644 --- a/src/cli-agent.ts +++ b/src/cli-agent.ts @@ -573,7 +573,7 @@ export async function agentSpawn(deps: AgentDeps, options: SpawnOptions): Promis ready = !dead && Boolean(result?.matched); } } catch (error) { - readinessError = getErrorMessage(error); + readinessError = getErrorMessage(error) || 'Readiness request failed'; } } diff --git a/test/cli-agent.test.ts b/test/cli-agent.test.ts index 60454991..ff41f7ce 100644 --- a/test/cli-agent.test.ts +++ b/test/cli-agent.test.ts @@ -577,6 +577,21 @@ describe('agent spawn', () => { { method: 'GET', path: `/api/v1/sessions/${OTHER}/wait-output` }, ]); }); + + it.each([ + { error: new Error(''), kind: 'Error' }, + { error: '', kind: 'string' }, + ])('reports a readiness failure when the thrown $kind has no message', async ({ error }) => { + const deps = fakeDeps((options) => { + if (options.path === '/api/v1/quick-start') return ok({ sessionId: OTHER }); + throw error; + }, true); + + expect(await agentSpawn(deps, { caseName: 'c', mode: 'claude', ready: true, timeoutMs: 1000 })).toBe(EXIT.error); + expect(deps.out).toHaveLength(1); + expect(JSON.parse(deps.out[0])).toEqual({ sessionId: OTHER, readinessError: 'Readiness request failed' }); + expect(deps.calls).toHaveLength(2); + }); }); describe('session id prefixes', () => {