fix(core): handle unhandled promise rejection in mcp-client-manager (#14701)

This commit is contained in:
HyeongHo Jun
2026-01-03 01:06:56 +09:00
committed by GitHub
parent c29a8c12b3
commit 8a0190ca3b
2 changed files with 59 additions and 15 deletions
@@ -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();
});
});
});