wpnav_test_metrics
Monitor test execution metrics and generate reports to track progress, measure automation success rates, and capture detailed statistics for WordPress management testing.
Instructions
Track test execution metrics and generate reports. Use this to monitor test progress, measure automation success rate, and capture detailed execution statistics.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action to perform: start (begin test), phase_complete (mark phase done), tool_result (record tool call), finish (end test), report (get metrics), reset (clear metrics) | |
| phase | No | Phase name (required for phase_complete) | |
| tool | No | Tool name (required for tool_result) | |
| success | No | Whether tool call succeeded (required for tool_result) | |
| duration_ms | No | Tool execution duration in milliseconds (optional for tool_result) | |
| error | No | Error message if tool call failed (optional for tool_result) |
Implementation Reference
- src/tools/testing/index.ts:56-244 (handler)The main execution handler for wpnav_test_metrics tool. Processes actions such as 'start', 'phase_complete', 'tool_result', 'finish', 'report', and 'reset' to track test metrics, update phases, record tool results, generate reports, etc. Uses in-memory testMetrics storage.handler: async (args, context) => { validateRequired(args, ['action']); try { switch (args.action) { case 'start': // Reset and start new test testMetrics.startTime = Date.now(); testMetrics.endTime = undefined; testMetrics.phases = {}; testMetrics.tools = {}; return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ action: 'start', timestamp: testMetrics.startTime, message: 'Test metrics tracking started', }, null, 2)), }], }; case 'phase_complete': if (!args.phase) { throw new Error('phase parameter required for phase_complete action'); } testMetrics.phases[args.phase] = { completed: true, timestamp: Date.now(), }; const phasesCompleted = Object.keys(testMetrics.phases).length; return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ action: 'phase_complete', phase: args.phase, timestamp: Date.now(), phases_completed: phasesCompleted, message: `Phase "${args.phase}" marked as complete`, }, null, 2)), }], }; case 'tool_result': if (!args.tool) { throw new Error('tool parameter required for tool_result action'); } if (args.success === undefined) { throw new Error('success parameter required for tool_result action'); } // Initialize tool metrics if not exists if (!testMetrics.tools[args.tool]) { testMetrics.tools[args.tool] = { success: 0, failure: 0, errors: [], }; } // Update metrics if (args.success) { testMetrics.tools[args.tool].success++; } else { testMetrics.tools[args.tool].failure++; if (args.error) { testMetrics.tools[args.tool].errors.push(args.error); } } return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ action: 'tool_result', tool: args.tool, success: args.success, duration_ms: args.duration_ms, message: `Tool "${args.tool}" result recorded`, }, null, 2)), }], }; case 'finish': testMetrics.endTime = Date.now(); return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ action: 'finish', timestamp: testMetrics.endTime, message: 'Test metrics tracking finished', }, null, 2)), }], }; case 'report': // Calculate metrics const duration = testMetrics.endTime ? testMetrics.endTime - (testMetrics.startTime || 0) : Date.now() - (testMetrics.startTime || 0); const durationMinutes = (duration / 1000 / 60).toFixed(2); let totalToolCalls = 0; let successfulToolCalls = 0; const toolErrors: Array<{ tool: string; error: string }> = []; Object.entries(testMetrics.tools).forEach(([tool, metrics]) => { totalToolCalls += metrics.success + metrics.failure; successfulToolCalls += metrics.success; metrics.errors.forEach(error => { toolErrors.push({ tool, error }); }); }); const successRate = totalToolCalls > 0 ? ((successfulToolCalls / totalToolCalls) * 100).toFixed(2) : '0.00'; const automationPercentage = totalToolCalls > 0 ? ((successfulToolCalls / totalToolCalls) * 100).toFixed(1) : '0.0'; const report = { test_started: testMetrics.startTime ? new Date(testMetrics.startTime).toISOString() : null, test_ended: testMetrics.endTime ? new Date(testMetrics.endTime).toISOString() : 'In progress', test_duration_ms: duration, test_duration_minutes: parseFloat(durationMinutes), phases_completed: Object.keys(testMetrics.phases).length, phases: Object.keys(testMetrics.phases), tool_success_rate: `${successRate}%`, total_tools_called: totalToolCalls, successful_tool_calls: successfulToolCalls, failed_tool_calls: totalToolCalls - successfulToolCalls, tools_used: Object.keys(testMetrics.tools).length, tool_breakdown: testMetrics.tools, errors: toolErrors.length > 0 ? toolErrors : 'No errors', automation_percentage: `${automationPercentage}%`, }; return { content: [{ type: 'text', text: context.clampText(JSON.stringify(report, null, 2)), }], }; case 'reset': // Clear all metrics testMetrics.startTime = undefined; testMetrics.endTime = undefined; testMetrics.phases = {}; testMetrics.tools = {}; return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ action: 'reset', message: 'Test metrics cleared', }, null, 2)), }], }; default: throw new Error(`Unknown action: ${args.action}`); } } catch (error: any) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'Test metrics operation failed', message: error.message || 'Unknown error', action: args.action, }, null, 2)), }], isError: true, }; } },
- src/tools/testing/index.ts:39-54 (schema)Input schema for wpnav_test_metrics defining the expected parameters: action (required, enum of operations), phase, tool, success, duration_ms, error.inputSchema: { type: 'object', properties: { action: { type: 'string', enum: ['start', 'phase_complete', 'tool_result', 'finish', 'report', 'reset'], description: 'Action to perform: start (begin test), phase_complete (mark phase done), tool_result (record tool call), finish (end test), report (get metrics), reset (clear metrics)', }, phase: { type: 'string', description: 'Phase name (required for phase_complete)' }, tool: { type: 'string', description: 'Tool name (required for tool_result)' }, success: { type: 'boolean', description: 'Whether tool call succeeded (required for tool_result)' }, duration_ms: { type: 'integer', description: 'Tool execution duration in milliseconds (optional for tool_result)' }, error: { type: 'string', description: 'Error message if tool call failed (optional for tool_result)' }, }, required: ['action'], },
- src/tools/testing/index.ts:35-246 (registration)Direct registration of the wpnav_test_metrics tool via toolRegistry.register within registerTestingTools() function.toolRegistry.register({ definition: { name: 'wpnav_test_metrics', description: 'Track test execution metrics and generate reports. Use this to monitor test progress, measure automation success rate, and capture detailed execution statistics.', inputSchema: { type: 'object', properties: { action: { type: 'string', enum: ['start', 'phase_complete', 'tool_result', 'finish', 'report', 'reset'], description: 'Action to perform: start (begin test), phase_complete (mark phase done), tool_result (record tool call), finish (end test), report (get metrics), reset (clear metrics)', }, phase: { type: 'string', description: 'Phase name (required for phase_complete)' }, tool: { type: 'string', description: 'Tool name (required for tool_result)' }, success: { type: 'boolean', description: 'Whether tool call succeeded (required for tool_result)' }, duration_ms: { type: 'integer', description: 'Tool execution duration in milliseconds (optional for tool_result)' }, error: { type: 'string', description: 'Error message if tool call failed (optional for tool_result)' }, }, required: ['action'], }, }, handler: async (args, context) => { validateRequired(args, ['action']); try { switch (args.action) { case 'start': // Reset and start new test testMetrics.startTime = Date.now(); testMetrics.endTime = undefined; testMetrics.phases = {}; testMetrics.tools = {}; return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ action: 'start', timestamp: testMetrics.startTime, message: 'Test metrics tracking started', }, null, 2)), }], }; case 'phase_complete': if (!args.phase) { throw new Error('phase parameter required for phase_complete action'); } testMetrics.phases[args.phase] = { completed: true, timestamp: Date.now(), }; const phasesCompleted = Object.keys(testMetrics.phases).length; return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ action: 'phase_complete', phase: args.phase, timestamp: Date.now(), phases_completed: phasesCompleted, message: `Phase "${args.phase}" marked as complete`, }, null, 2)), }], }; case 'tool_result': if (!args.tool) { throw new Error('tool parameter required for tool_result action'); } if (args.success === undefined) { throw new Error('success parameter required for tool_result action'); } // Initialize tool metrics if not exists if (!testMetrics.tools[args.tool]) { testMetrics.tools[args.tool] = { success: 0, failure: 0, errors: [], }; } // Update metrics if (args.success) { testMetrics.tools[args.tool].success++; } else { testMetrics.tools[args.tool].failure++; if (args.error) { testMetrics.tools[args.tool].errors.push(args.error); } } return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ action: 'tool_result', tool: args.tool, success: args.success, duration_ms: args.duration_ms, message: `Tool "${args.tool}" result recorded`, }, null, 2)), }], }; case 'finish': testMetrics.endTime = Date.now(); return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ action: 'finish', timestamp: testMetrics.endTime, message: 'Test metrics tracking finished', }, null, 2)), }], }; case 'report': // Calculate metrics const duration = testMetrics.endTime ? testMetrics.endTime - (testMetrics.startTime || 0) : Date.now() - (testMetrics.startTime || 0); const durationMinutes = (duration / 1000 / 60).toFixed(2); let totalToolCalls = 0; let successfulToolCalls = 0; const toolErrors: Array<{ tool: string; error: string }> = []; Object.entries(testMetrics.tools).forEach(([tool, metrics]) => { totalToolCalls += metrics.success + metrics.failure; successfulToolCalls += metrics.success; metrics.errors.forEach(error => { toolErrors.push({ tool, error }); }); }); const successRate = totalToolCalls > 0 ? ((successfulToolCalls / totalToolCalls) * 100).toFixed(2) : '0.00'; const automationPercentage = totalToolCalls > 0 ? ((successfulToolCalls / totalToolCalls) * 100).toFixed(1) : '0.0'; const report = { test_started: testMetrics.startTime ? new Date(testMetrics.startTime).toISOString() : null, test_ended: testMetrics.endTime ? new Date(testMetrics.endTime).toISOString() : 'In progress', test_duration_ms: duration, test_duration_minutes: parseFloat(durationMinutes), phases_completed: Object.keys(testMetrics.phases).length, phases: Object.keys(testMetrics.phases), tool_success_rate: `${successRate}%`, total_tools_called: totalToolCalls, successful_tool_calls: successfulToolCalls, failed_tool_calls: totalToolCalls - successfulToolCalls, tools_used: Object.keys(testMetrics.tools).length, tool_breakdown: testMetrics.tools, errors: toolErrors.length > 0 ? toolErrors : 'No errors', automation_percentage: `${automationPercentage}%`, }; return { content: [{ type: 'text', text: context.clampText(JSON.stringify(report, null, 2)), }], }; case 'reset': // Clear all metrics testMetrics.startTime = undefined; testMetrics.endTime = undefined; testMetrics.phases = {}; testMetrics.tools = {}; return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ action: 'reset', message: 'Test metrics cleared', }, null, 2)), }], }; default: throw new Error(`Unknown action: ${args.action}`); } } catch (error: any) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'Test metrics operation failed', message: error.message || 'Unknown error', action: args.action, }, null, 2)), }], isError: true, }; } }, category: ToolCategory.CONTENT, // Using CONTENT category since there's no TESTING category });
- src/tools/index.ts:31-31 (registration)Call to registerTestingTools() inside registerAllTools(), which triggers the registration of testing tools including wpnav_test_metrics.registerTestingTools();
- src/tools/testing/index.ts:23-26 (helper)In-memory storage for test metrics used by the handler (testMetrics object tracking phases, tools, timings).const testMetrics: TestMetrics = { phases: {}, tools: {}, };