mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-30 15:04:16 -07:00
Add tests for newly added fields in tool_call_update struct
This commit is contained in:
@@ -894,6 +894,9 @@ describe('Session', () => {
|
|||||||
update: expect.objectContaining({
|
update: expect.objectContaining({
|
||||||
sessionUpdate: 'tool_call_update',
|
sessionUpdate: 'tool_call_update',
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
|
title: 'Test Tool',
|
||||||
|
locations: [],
|
||||||
|
kind: 'read',
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -1306,6 +1309,18 @@ describe('Session', () => {
|
|||||||
expect(path.resolve).toHaveBeenCalled();
|
expect(path.resolve).toHaveBeenCalled();
|
||||||
expect(fs.stat).toHaveBeenCalled();
|
expect(fs.stat).toHaveBeenCalled();
|
||||||
|
|
||||||
|
expect(mockConnection.sessionUpdate).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
update: expect.objectContaining({
|
||||||
|
sessionUpdate: 'tool_call_update',
|
||||||
|
status: 'completed',
|
||||||
|
title: 'Read files',
|
||||||
|
locations: [],
|
||||||
|
kind: 'read',
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
// Verify ReadManyFilesTool was used (implicitly by checking if sendMessageStream was called with resolved content)
|
// Verify ReadManyFilesTool was used (implicitly by checking if sendMessageStream was called with resolved content)
|
||||||
// Since we mocked ReadManyFilesTool to return specific content, we can check the args passed to sendMessageStream
|
// Since we mocked ReadManyFilesTool to return specific content, we can check the args passed to sendMessageStream
|
||||||
expect(mockChat.sendMessageStream).toHaveBeenCalledWith(
|
expect(mockChat.sendMessageStream).toHaveBeenCalledWith(
|
||||||
@@ -1321,6 +1336,65 @@ describe('Session', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle @path resolution error', async () => {
|
||||||
|
(path.resolve as unknown as Mock).mockReturnValue('/tmp/error.txt');
|
||||||
|
(fs.stat as unknown as Mock).mockResolvedValue({
|
||||||
|
isDirectory: () => false,
|
||||||
|
});
|
||||||
|
(isWithinRoot as unknown as Mock).mockReturnValue(true);
|
||||||
|
|
||||||
|
const MockReadManyFilesTool = ReadManyFilesTool as unknown as Mock;
|
||||||
|
MockReadManyFilesTool.mockImplementationOnce(() => ({
|
||||||
|
name: 'read_many_files',
|
||||||
|
kind: 'read',
|
||||||
|
build: vi.fn().mockReturnValue({
|
||||||
|
getDescription: () => 'Read files',
|
||||||
|
toolLocations: () => [],
|
||||||
|
execute: vi.fn().mockRejectedValue(new Error('File read failed')),
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const stream = createMockStream([
|
||||||
|
{
|
||||||
|
type: StreamEventType.CHUNK,
|
||||||
|
value: { candidates: [] },
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
mockChat.sendMessageStream.mockResolvedValue(stream);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
session.prompt({
|
||||||
|
sessionId: 'session-1',
|
||||||
|
prompt: [
|
||||||
|
{ type: 'text', text: 'Read' },
|
||||||
|
{
|
||||||
|
type: 'resource_link',
|
||||||
|
uri: 'file://error.txt',
|
||||||
|
mimeType: 'text/plain',
|
||||||
|
name: 'error.txt',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
).rejects.toThrow('File read failed');
|
||||||
|
|
||||||
|
expect(mockConnection.sessionUpdate).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
update: expect.objectContaining({
|
||||||
|
sessionUpdate: 'tool_call_update',
|
||||||
|
status: 'failed',
|
||||||
|
content: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
content: expect.objectContaining({
|
||||||
|
text: expect.stringMatching(/File read failed/),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
kind: 'read',
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle cancellation during prompt', async () => {
|
it('should handle cancellation during prompt', async () => {
|
||||||
let streamController: ReadableStreamDefaultController<unknown>;
|
let streamController: ReadableStreamDefaultController<unknown>;
|
||||||
const stream = new ReadableStream({
|
const stream = new ReadableStream({
|
||||||
@@ -1434,6 +1508,7 @@ describe('Session', () => {
|
|||||||
content: expect.objectContaining({ text: 'Tool failed' }),
|
content: expect.objectContaining({ text: 'Tool failed' }),
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
|
kind: 'read',
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user