1- /// <reference types="bun-types" />
21import { test , expect , describe , mock } from 'bun:test'
32import { ResiliencePipeline } from './pipeline'
43import type { McpExecutionContext , McpMiddleware , McpMiddlewareNext } from './types'
@@ -85,12 +84,12 @@ describe('TelemetryMiddleware', () => {
8584 await telemetry . execute ( mockContext , finalHandler )
8685
8786 expect ( infoInfo ) . toHaveBeenCalled ( )
88- const logMsg = infoInfo . mock . calls [ 0 ] [ 0 ]
89- const logCtx = infoInfo . mock . calls [ 0 ] [ 1 ]
90- expect ( logMsg ) . toBe ( 'MCP Tool Execution Completed' )
91- expect ( logCtx . toolName ) . toBe ( 'telemetry_tool' )
92- expect ( logCtx . latency_ms ) . toBeGreaterThanOrEqual ( 10 )
93- expect ( logCtx . success ) . toBe ( true )
87+ const msg = infoInfo . mock . calls [ 0 ] [ 0 ]
88+ const logCall = infoInfo . mock . calls [ 0 ] [ 1 ]
89+ expect ( msg ) . toBe ( 'MCP Tool Execution Completed' )
90+ expect ( logCall . toolName ) . toBe ( 'telemetry_tool' )
91+ expect ( logCall . latency_ms ) . toBeGreaterThanOrEqual ( 10 )
92+ expect ( logCall . success ) . toBe ( true )
9493 } )
9594
9695 test ( 'should log TOOL_ERROR when tool result has isError: true' , async ( ) => {
@@ -105,9 +104,11 @@ describe('TelemetryMiddleware', () => {
105104 await telemetry . execute ( mockContext , finalHandler )
106105
107106 expect ( infoInfo ) . toHaveBeenCalled ( )
108- const logCtx = infoInfo . mock . calls [ 0 ] [ 1 ]
109- expect ( logCtx . success ) . toBe ( false )
110- expect ( logCtx . failure_reason ) . toBe ( 'TOOL_ERROR' )
107+ const msg = infoInfo . mock . calls [ 0 ] [ 0 ]
108+ const logCall = infoInfo . mock . calls [ 0 ] [ 1 ]
109+ expect ( msg ) . toBe ( 'MCP Tool Execution Completed' )
110+ expect ( logCall . success ) . toBe ( false )
111+ expect ( logCall . failure_reason ) . toBe ( 'TOOL_ERROR' )
111112 } )
112113
113114 test ( 'should log exception and rethrow with TIMEOUT explanation' , async ( ) => {
@@ -128,9 +129,9 @@ describe('TelemetryMiddleware', () => {
128129
129130 expect ( caughtError ) . toBeDefined ( )
130131 expect ( errorError ) . toHaveBeenCalled ( )
131- const logMsg = errorError . mock . calls [ 0 ] [ 0 ]
132- const logCtx = errorError . mock . calls [ 0 ] [ 1 ]
133- expect ( logMsg ) . toBe ( 'MCP Tool Execution Failed' )
134- expect ( logCtx . failure_reason ) . toBe ( 'TIMEOUT' )
132+ const msg = errorError . mock . calls [ 0 ] [ 0 ]
133+ const logCall = errorError . mock . calls [ 0 ] [ 1 ]
134+ expect ( msg ) . toBe ( 'MCP Tool Execution Failed' )
135+ expect ( logCall . failure_reason ) . toBe ( 'TIMEOUT' )
135136 } )
136137} )
0 commit comments