mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-27 05:24:34 -07:00
fix(core): handle unhandled promise rejection in mcp-client-manager (#14701)
This commit is contained in:
@@ -238,4 +238,40 @@ describe('McpClientManager', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Promise rejection handling', () => {
|
||||
it('should handle errors thrown during client initialization', async () => {
|
||||
vi.mocked(McpClient).mockImplementation(() => {
|
||||
throw new Error('Client initialization failed');
|
||||
});
|
||||
|
||||
mockConfig.getMcpServers.mockReturnValue({
|
||||
'test-server': {},
|
||||
});
|
||||
|
||||
const manager = new McpClientManager({} as ToolRegistry, mockConfig);
|
||||
|
||||
await expect(manager.startConfiguredMcpServers()).resolves.not.toThrow();
|
||||
});
|
||||
|
||||
it('should handle errors thrown in the async IIFE before try block', async () => {
|
||||
let disconnectCallCount = 0;
|
||||
mockedMcpClient.disconnect.mockImplementation(async () => {
|
||||
disconnectCallCount++;
|
||||
if (disconnectCallCount === 1) {
|
||||
throw new Error('Disconnect failed unexpectedly');
|
||||
}
|
||||
});
|
||||
mockedMcpClient.getServerConfig.mockReturnValue({});
|
||||
|
||||
mockConfig.getMcpServers.mockReturnValue({
|
||||
'test-server': {},
|
||||
});
|
||||
|
||||
const manager = new McpClientManager({} as ToolRegistry, mockConfig);
|
||||
await manager.startConfiguredMcpServers();
|
||||
|
||||
await expect(manager.restartServer('test-server')).resolves.not.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user