mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 08:47:44 +00:00
chore: sync gemini-cli v0.1.19
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
||||
EditorType,
|
||||
AuthType,
|
||||
GeminiEventType as ServerGeminiEventType,
|
||||
AnyToolInvocation,
|
||||
} from '@qwen-code/qwen-code-core';
|
||||
import { Part, PartListUnion } from '@google/genai';
|
||||
import { UseHistoryManagerReturn } from './useHistoryManager.js';
|
||||
@@ -405,6 +406,8 @@ describe('useGeminiStream', () => {
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
);
|
||||
},
|
||||
{
|
||||
@@ -453,9 +456,13 @@ describe('useGeminiStream', () => {
|
||||
},
|
||||
tool: {
|
||||
name: 'tool1',
|
||||
displayName: 'tool1',
|
||||
description: 'desc1',
|
||||
getDescription: vi.fn(),
|
||||
build: vi.fn(),
|
||||
} as any,
|
||||
invocation: {
|
||||
getDescription: () => `Mock description`,
|
||||
} as unknown as AnyToolInvocation,
|
||||
startTime: Date.now(),
|
||||
endTime: Date.now(),
|
||||
} as TrackedCompletedToolCall,
|
||||
@@ -470,9 +477,13 @@ describe('useGeminiStream', () => {
|
||||
responseSubmittedToGemini: false,
|
||||
tool: {
|
||||
name: 'tool2',
|
||||
displayName: 'tool2',
|
||||
description: 'desc2',
|
||||
getDescription: vi.fn(),
|
||||
build: vi.fn(),
|
||||
} as any,
|
||||
invocation: {
|
||||
getDescription: () => `Mock description`,
|
||||
} as unknown as AnyToolInvocation,
|
||||
startTime: Date.now(),
|
||||
liveOutput: '...',
|
||||
} as TrackedExecutingToolCall,
|
||||
@@ -507,6 +518,12 @@ describe('useGeminiStream', () => {
|
||||
status: 'success',
|
||||
responseSubmittedToGemini: false,
|
||||
response: { callId: 'call1', responseParts: toolCall1ResponseParts },
|
||||
tool: {
|
||||
displayName: 'MockTool',
|
||||
},
|
||||
invocation: {
|
||||
getDescription: () => `Mock description`,
|
||||
} as unknown as AnyToolInvocation,
|
||||
} as TrackedCompletedToolCall,
|
||||
{
|
||||
request: {
|
||||
@@ -546,6 +563,8 @@ describe('useGeminiStream', () => {
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -585,6 +604,12 @@ describe('useGeminiStream', () => {
|
||||
status: 'cancelled',
|
||||
response: { callId: '1', responseParts: [{ text: 'cancelled' }] },
|
||||
responseSubmittedToGemini: false,
|
||||
tool: {
|
||||
displayName: 'mock tool',
|
||||
},
|
||||
invocation: {
|
||||
getDescription: () => `Mock description`,
|
||||
} as unknown as AnyToolInvocation,
|
||||
} as TrackedCancelledToolCall,
|
||||
];
|
||||
const client = new MockedGeminiClientClass(mockConfig);
|
||||
@@ -613,6 +638,8 @@ describe('useGeminiStream', () => {
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -645,9 +672,13 @@ describe('useGeminiStream', () => {
|
||||
},
|
||||
tool: {
|
||||
name: 'toolA',
|
||||
displayName: 'toolA',
|
||||
description: 'descA',
|
||||
getDescription: vi.fn(),
|
||||
build: vi.fn(),
|
||||
} as any,
|
||||
invocation: {
|
||||
getDescription: () => `Mock description`,
|
||||
} as unknown as AnyToolInvocation,
|
||||
status: 'cancelled',
|
||||
response: {
|
||||
callId: 'cancel-1',
|
||||
@@ -670,9 +701,13 @@ describe('useGeminiStream', () => {
|
||||
},
|
||||
tool: {
|
||||
name: 'toolB',
|
||||
displayName: 'toolB',
|
||||
description: 'descB',
|
||||
getDescription: vi.fn(),
|
||||
build: vi.fn(),
|
||||
} as any,
|
||||
invocation: {
|
||||
getDescription: () => `Mock description`,
|
||||
} as unknown as AnyToolInvocation,
|
||||
status: 'cancelled',
|
||||
response: {
|
||||
callId: 'cancel-2',
|
||||
@@ -711,6 +746,8 @@ describe('useGeminiStream', () => {
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -763,9 +800,13 @@ describe('useGeminiStream', () => {
|
||||
responseSubmittedToGemini: false,
|
||||
tool: {
|
||||
name: 'tool1',
|
||||
displayName: 'tool1',
|
||||
description: 'desc',
|
||||
getDescription: vi.fn(),
|
||||
build: vi.fn(),
|
||||
} as any,
|
||||
invocation: {
|
||||
getDescription: () => `Mock description`,
|
||||
} as unknown as AnyToolInvocation,
|
||||
startTime: Date.now(),
|
||||
} as TrackedExecutingToolCall,
|
||||
];
|
||||
@@ -814,6 +855,8 @@ describe('useGeminiStream', () => {
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -914,6 +957,44 @@ describe('useGeminiStream', () => {
|
||||
expect(result.current.streamingState).toBe(StreamingState.Idle);
|
||||
});
|
||||
|
||||
it('should call onCancelSubmit handler when escape is pressed', async () => {
|
||||
const cancelSubmitSpy = vi.fn();
|
||||
const mockStream = (async function* () {
|
||||
yield { type: 'content', value: 'Part 1' };
|
||||
// Keep the stream open
|
||||
await new Promise(() => {});
|
||||
})();
|
||||
mockSendMessageStream.mockReturnValue(mockStream);
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useGeminiStream(
|
||||
mockConfig.getGeminiClient(),
|
||||
[],
|
||||
mockAddItem,
|
||||
mockConfig,
|
||||
mockOnDebugMessage,
|
||||
mockHandleSlashCommand,
|
||||
false,
|
||||
() => 'vscode' as EditorType,
|
||||
() => {},
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
cancelSubmitSpy,
|
||||
),
|
||||
);
|
||||
|
||||
// Start a query
|
||||
await act(async () => {
|
||||
result.current.submitQuery('test query');
|
||||
});
|
||||
|
||||
simulateEscapeKeyPress();
|
||||
|
||||
expect(cancelSubmitSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not do anything if escape is pressed when not responding', () => {
|
||||
const { result } = renderTestHook();
|
||||
|
||||
@@ -984,8 +1065,13 @@ describe('useGeminiStream', () => {
|
||||
tool: {
|
||||
name: 'tool1',
|
||||
description: 'desc1',
|
||||
getDescription: vi.fn(),
|
||||
build: vi.fn().mockImplementation((_) => ({
|
||||
getDescription: () => `Mock description`,
|
||||
})),
|
||||
} as any,
|
||||
invocation: {
|
||||
getDescription: () => `Mock description`,
|
||||
},
|
||||
startTime: Date.now(),
|
||||
liveOutput: '...',
|
||||
} as TrackedExecutingToolCall,
|
||||
@@ -1136,9 +1222,13 @@ describe('useGeminiStream', () => {
|
||||
},
|
||||
tool: {
|
||||
name: 'save_memory',
|
||||
displayName: 'save_memory',
|
||||
description: 'Saves memory',
|
||||
getDescription: vi.fn(),
|
||||
build: vi.fn(),
|
||||
} as any,
|
||||
invocation: {
|
||||
getDescription: () => `Mock description`,
|
||||
} as unknown as AnyToolInvocation,
|
||||
};
|
||||
|
||||
// Capture the onComplete callback
|
||||
@@ -1165,6 +1255,8 @@ describe('useGeminiStream', () => {
|
||||
mockPerformMemoryRefresh,
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1216,6 +1308,8 @@ describe('useGeminiStream', () => {
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1264,6 +1358,8 @@ describe('useGeminiStream', () => {
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1310,6 +1406,8 @@ describe('useGeminiStream', () => {
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1357,6 +1455,8 @@ describe('useGeminiStream', () => {
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1444,6 +1544,8 @@ describe('useGeminiStream', () => {
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1498,6 +1600,8 @@ describe('useGeminiStream', () => {
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1574,6 +1678,8 @@ describe('useGeminiStream', () => {
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1626,6 +1732,8 @@ describe('useGeminiStream', () => {
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user