test(mcp-client): preserve startup error cause

Strict startup intentionally wraps connection and synchronization failures with the server-qualified activation diagnostic while retaining the original error in Error.cause. The prior assertion checked only the wrapper text, so the causal chain could regress unnoticed and erase the actionable transport failure.

Assert the full wrapper message and object identity of the original connection error in cause. This keeps operator-facing context and the underlying SDK diagnostic independently stable without changing production behavior.
This commit is contained in:
Tianyi Cui
2026-08-11 00:02:13 +08:00
parent bdd0e6a709
commit 0e01036a2a

View File

@@ -254,11 +254,15 @@ describe('apply (plugin lifecycle)', () => {
})
it('rejects activation and still closes the client when startup failure is configured as fatal', async () => {
mockConnect.mockRejectedValue(new Error('connection refused'))
const cause = new Error('connection refused')
mockConnect.mockRejectedValue(cause)
await expect(apply(ctx, {
...stdioConfig,
failOnStartupError: true,
})).rejects.toThrow('initial connection or tool synchronization failed')
})).rejects.toMatchObject({
message: 'mcp-client(srv): initial connection or tool synchronization failed',
cause,
})
expect(mockListTools).not.toHaveBeenCalled()
expect(ctx.tools.get('mcp__srv__remote')).toBeUndefined()