mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
fix(acp): handle all InvalidStreamError types gracefully in prompt (#24540)
This commit is contained in:
@@ -875,6 +875,32 @@ describe('Session', () => {
|
|||||||
expect(result).toMatchObject({ stopReason: 'end_turn' });
|
expect(result).toMatchObject({ stopReason: 'end_turn' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle prompt with no finish reason (InvalidStreamError)', async () => {
|
||||||
|
mockChat.sendMessageStream.mockRejectedValue(
|
||||||
|
new InvalidStreamError('No finish reason', 'NO_FINISH_REASON'),
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = await session.prompt({
|
||||||
|
sessionId: 'session-1',
|
||||||
|
prompt: [{ type: 'text', text: 'Hi' }],
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockChat.sendMessageStream).toHaveBeenCalled();
|
||||||
|
expect(result).toMatchObject({ stopReason: 'end_turn' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle prompt with no finish reason (NO_FINISH_REASON anomaly)', async () => {
|
||||||
|
mockChat.sendMessageStream.mockRejectedValue({ type: 'NO_FINISH_REASON' });
|
||||||
|
|
||||||
|
const result = await session.prompt({
|
||||||
|
sessionId: 'session-1',
|
||||||
|
prompt: [{ type: 'text', text: 'Hi' }],
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockChat.sendMessageStream).toHaveBeenCalled();
|
||||||
|
expect(result).toMatchObject({ stopReason: 'end_turn' });
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle /memory command', async () => {
|
it('should handle /memory command', async () => {
|
||||||
const handleCommandSpy = vi
|
const handleCommandSpy = vi
|
||||||
.spyOn(
|
.spyOn(
|
||||||
|
|||||||
@@ -863,7 +863,10 @@ export class Session {
|
|||||||
(error &&
|
(error &&
|
||||||
typeof error === 'object' &&
|
typeof error === 'object' &&
|
||||||
'type' in error &&
|
'type' in error &&
|
||||||
error.type === 'NO_RESPONSE_TEXT')
|
(error.type === 'NO_RESPONSE_TEXT' ||
|
||||||
|
error.type === 'NO_FINISH_REASON' ||
|
||||||
|
error.type === 'MALFORMED_FUNCTION_CALL' ||
|
||||||
|
error.type === 'UNEXPECTED_TOOL_CALL'))
|
||||||
) {
|
) {
|
||||||
// The stream ended with an empty response or malformed tool call.
|
// The stream ended with an empty response or malformed tool call.
|
||||||
// Treat this as a graceful end to the model's turn rather than a crash.
|
// Treat this as a graceful end to the model's turn rather than a crash.
|
||||||
|
|||||||
Reference in New Issue
Block a user