mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 09:17:53 +00:00
Sync upstream Gemini-CLI v0.8.2 (#838)
This commit is contained in:
@@ -26,7 +26,14 @@ import {
|
||||
|
||||
vi.mock('node:fs');
|
||||
vi.mock('node:path');
|
||||
vi.mock('node:crypto');
|
||||
vi.mock('node:crypto', () => ({
|
||||
randomUUID: vi.fn(),
|
||||
createHash: vi.fn(() => ({
|
||||
update: vi.fn(() => ({
|
||||
digest: vi.fn(() => 'mocked-hash'),
|
||||
})),
|
||||
})),
|
||||
}));
|
||||
vi.mock('../utils/paths.js');
|
||||
|
||||
describe('ChatRecordingService', () => {
|
||||
@@ -47,6 +54,13 @@ describe('ChatRecordingService', () => {
|
||||
},
|
||||
getModel: vi.fn().mockReturnValue('gemini-pro'),
|
||||
getDebugMode: vi.fn().mockReturnValue(false),
|
||||
getToolRegistry: vi.fn().mockReturnValue({
|
||||
getTool: vi.fn().mockReturnValue({
|
||||
displayName: 'Test Tool',
|
||||
description: 'A test tool',
|
||||
isOutputMarkdown: false,
|
||||
}),
|
||||
}),
|
||||
} as unknown as Config;
|
||||
|
||||
vi.mocked(getProjectHash).mockReturnValue('test-project-hash');
|
||||
@@ -120,7 +134,11 @@ describe('ChatRecordingService', () => {
|
||||
const writeFileSyncSpy = vi
|
||||
.spyOn(fs, 'writeFileSync')
|
||||
.mockImplementation(() => undefined);
|
||||
chatRecordingService.recordMessage({ type: 'user', content: 'Hello' });
|
||||
chatRecordingService.recordMessage({
|
||||
type: 'user',
|
||||
content: 'Hello',
|
||||
model: 'gemini-pro',
|
||||
});
|
||||
expect(mkdirSyncSpy).toHaveBeenCalled();
|
||||
expect(writeFileSyncSpy).toHaveBeenCalled();
|
||||
const conversation = JSON.parse(
|
||||
@@ -131,7 +149,7 @@ describe('ChatRecordingService', () => {
|
||||
expect(conversation.messages[0].type).toBe('user');
|
||||
});
|
||||
|
||||
it('should append to the last message if append is true and types match', () => {
|
||||
it('should create separate messages when recording multiple messages', () => {
|
||||
const writeFileSyncSpy = vi
|
||||
.spyOn(fs, 'writeFileSync')
|
||||
.mockImplementation(() => undefined);
|
||||
@@ -153,8 +171,8 @@ describe('ChatRecordingService', () => {
|
||||
|
||||
chatRecordingService.recordMessage({
|
||||
type: 'user',
|
||||
content: ' World',
|
||||
append: true,
|
||||
content: 'World',
|
||||
model: 'gemini-pro',
|
||||
});
|
||||
|
||||
expect(mkdirSyncSpy).toHaveBeenCalled();
|
||||
@@ -162,8 +180,9 @@ describe('ChatRecordingService', () => {
|
||||
const conversation = JSON.parse(
|
||||
writeFileSyncSpy.mock.calls[0][1] as string,
|
||||
) as ConversationRecord;
|
||||
expect(conversation.messages).toHaveLength(1);
|
||||
expect(conversation.messages[0].content).toBe('Hello World');
|
||||
expect(conversation.messages).toHaveLength(2);
|
||||
expect(conversation.messages[0].content).toBe('Hello');
|
||||
expect(conversation.messages[1].content).toBe('World');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -200,7 +219,7 @@ describe('ChatRecordingService', () => {
|
||||
messages: [
|
||||
{
|
||||
id: '1',
|
||||
type: 'gemini',
|
||||
type: 'qwen',
|
||||
content: 'Response',
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
@@ -211,10 +230,10 @@ describe('ChatRecordingService', () => {
|
||||
);
|
||||
|
||||
chatRecordingService.recordMessageTokens({
|
||||
input: 1,
|
||||
output: 2,
|
||||
total: 3,
|
||||
cached: 0,
|
||||
promptTokenCount: 1,
|
||||
candidatesTokenCount: 2,
|
||||
totalTokenCount: 3,
|
||||
cachedContentTokenCount: 0,
|
||||
});
|
||||
|
||||
expect(mkdirSyncSpy).toHaveBeenCalled();
|
||||
@@ -224,7 +243,14 @@ describe('ChatRecordingService', () => {
|
||||
) as ConversationRecord;
|
||||
expect(conversation.messages[0]).toEqual({
|
||||
...initialConversation.messages[0],
|
||||
tokens: { input: 1, output: 2, total: 3, cached: 0 },
|
||||
tokens: {
|
||||
input: 1,
|
||||
output: 2,
|
||||
total: 3,
|
||||
cached: 0,
|
||||
thoughts: 0,
|
||||
tool: 0,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -235,7 +261,7 @@ describe('ChatRecordingService', () => {
|
||||
messages: [
|
||||
{
|
||||
id: '1',
|
||||
type: 'gemini',
|
||||
type: 'qwen',
|
||||
content: 'Response',
|
||||
timestamp: new Date().toISOString(),
|
||||
tokens: { input: 1, output: 1, total: 2, cached: 0 },
|
||||
@@ -247,10 +273,10 @@ describe('ChatRecordingService', () => {
|
||||
);
|
||||
|
||||
chatRecordingService.recordMessageTokens({
|
||||
input: 2,
|
||||
output: 2,
|
||||
total: 4,
|
||||
cached: 0,
|
||||
promptTokenCount: 2,
|
||||
candidatesTokenCount: 2,
|
||||
totalTokenCount: 4,
|
||||
cachedContentTokenCount: 0,
|
||||
});
|
||||
|
||||
// @ts-expect-error private property
|
||||
@@ -259,6 +285,8 @@ describe('ChatRecordingService', () => {
|
||||
output: 2,
|
||||
total: 4,
|
||||
cached: 0,
|
||||
thoughts: 0,
|
||||
tool: 0,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -278,7 +306,7 @@ describe('ChatRecordingService', () => {
|
||||
messages: [
|
||||
{
|
||||
id: '1',
|
||||
type: 'gemini',
|
||||
type: 'qwen',
|
||||
content: '',
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
@@ -295,7 +323,7 @@ describe('ChatRecordingService', () => {
|
||||
status: 'awaiting_approval',
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
chatRecordingService.recordToolCalls([toolCall]);
|
||||
chatRecordingService.recordToolCalls('gemini-pro', [toolCall]);
|
||||
|
||||
expect(mkdirSyncSpy).toHaveBeenCalled();
|
||||
expect(writeFileSyncSpy).toHaveBeenCalled();
|
||||
@@ -304,7 +332,14 @@ describe('ChatRecordingService', () => {
|
||||
) as ConversationRecord;
|
||||
expect(conversation.messages[0]).toEqual({
|
||||
...initialConversation.messages[0],
|
||||
toolCalls: [toolCall],
|
||||
toolCalls: [
|
||||
{
|
||||
...toolCall,
|
||||
displayName: 'Test Tool',
|
||||
description: 'A test tool',
|
||||
renderOutputAsMarkdown: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
@@ -335,7 +370,7 @@ describe('ChatRecordingService', () => {
|
||||
status: 'awaiting_approval',
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
chatRecordingService.recordToolCalls([toolCall]);
|
||||
chatRecordingService.recordToolCalls('gemini-pro', [toolCall]);
|
||||
|
||||
expect(mkdirSyncSpy).toHaveBeenCalled();
|
||||
expect(writeFileSyncSpy).toHaveBeenCalled();
|
||||
@@ -347,10 +382,17 @@ describe('ChatRecordingService', () => {
|
||||
...conversation.messages[1],
|
||||
id: 'this-is-a-test-uuid',
|
||||
model: 'gemini-pro',
|
||||
type: 'gemini',
|
||||
type: 'qwen',
|
||||
thoughts: [],
|
||||
content: '',
|
||||
toolCalls: [toolCall],
|
||||
toolCalls: [
|
||||
{
|
||||
...toolCall,
|
||||
displayName: 'Test Tool',
|
||||
description: 'A test tool',
|
||||
renderOutputAsMarkdown: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user