UNPKG

ai-debug-local-mcp

Version:

🎯 ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh

216 lines • 8.58 kB
import { SmartTestMaintenance } from '../smart-test-maintenance.js'; export const smartTestMaintenanceTools = [ { name: 'analyze_test_health', description: 'Analyze the health of your test suite and identify issues', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'The debug session ID' }, testCode: { type: 'string', description: 'The test code to analyze' } }, required: ['sessionId', 'testCode'] } }, { name: 'detect_stale_tests', description: 'Detect stale selectors and outdated test code', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'The debug session ID' }, testCode: { type: 'string', description: 'The test code to check for staleness' } }, required: ['sessionId', 'testCode'] } }, { name: 'auto_fix_tests', description: 'Automatically fix simple test issues like outdated selectors', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'The debug session ID' }, testCode: { type: 'string', description: 'The test code to fix' } }, required: ['sessionId', 'testCode'] } }, { name: 'find_test_coverage_gaps', description: 'Find UI elements that are not covered by tests', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'The debug session ID' }, testSelectors: { type: 'array', items: { type: 'string' }, description: 'List of selectors used in current tests' } }, required: ['sessionId', 'testSelectors'] } }, { name: 'generate_test_maintenance_report', description: 'Generate a comprehensive test maintenance report', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'The debug session ID' }, testSuiteId: { type: 'string', description: 'Identifier for the test suite' } }, required: ['sessionId', 'testSuiteId'] } } ]; export async function handleSmartTestMaintenanceTool(toolName, args, sessions) { const session = sessions.get(args.sessionId); if (!session) { throw new Error(`Session not found: ${args.sessionId}`); } // Initialize test maintenance engine if not already present if (!session.state.testMaintenance) { session.state.testMaintenance = new SmartTestMaintenance(); } const maintenance = session.state.testMaintenance; switch (toolName) { case 'analyze_test_health': { const staleSelectors = await maintenance.detectStaleSelectors(args.testCode, session.page); const elementChanges = await maintenance.detectElementChanges(args.testCode, session.page); const removedFeatures = await maintenance.detectRemovedFeatures(args.testCode, session.page); const allIssues = [...staleSelectors, ...elementChanges, ...removedFeatures]; const health = await maintenance.calculateTestHealth({ totalTests: (args.testCode.match(/test\(/g) || []).length, staleSelectors: staleSelectors.length, duplicateTests: 0, // Would need more context flakyTests: 0, // Would need historical data coverageGaps: 0 // Would need full test suite }); return { success: true, health, issues: allIssues, summary: { staleSelectors: staleSelectors.length, elementChanges: elementChanges.length, removedFeatures: removedFeatures.length } }; } case 'detect_stale_tests': { const staleSelectors = await maintenance.detectStaleSelectors(args.testCode, session.page); const suggestions = []; for (const issue of staleSelectors) { if (issue.selector) { const selectorSuggestions = await maintenance.suggestSelectorUpdate(issue.selector, session.page); suggestions.push(...selectorSuggestions); } } return { success: true, staleSelectors, suggestions, message: `Found ${staleSelectors.length} stale selectors` }; } case 'auto_fix_tests': { const issues = await maintenance.detectStaleSelectors(args.testCode, session.page); // Get suggestions for fixes const issuesWithFixes = await Promise.all(issues.map(async (issue) => { if (issue.selector) { const suggestions = await maintenance.suggestSelectorUpdate(issue.selector, session.page); if (suggestions.length > 0) { return { ...issue, suggestedFix: suggestions[0].newSelector }; } } return issue; })); const updatedCode = await maintenance.autoFixTests(args.testCode, issuesWithFixes); return { success: true, originalCode: args.testCode, updatedCode, fixesApplied: issuesWithFixes.filter(i => i.suggestedFix).length, totalIssues: issues.length }; } case 'find_test_coverage_gaps': { const gaps = await maintenance.findCoverageGaps(args.testSelectors, session.page); // Get element details for gaps const gapDetails = await session.page.evaluate((selectors) => { return selectors.map((selector) => { const el = document.querySelector(selector); if (el) { return { selector, type: el.tagName.toLowerCase(), text: el.textContent?.trim(), placeholder: el.placeholder }; } return { selector, type: 'unknown' }; }); }, gaps); const suggestions = await maintenance.generateTestSuggestions(gapDetails); return { success: true, coverageGaps: gaps, gapDetails, suggestions, message: `Found ${gaps.length} untested UI elements` }; } case 'generate_test_maintenance_report': { const report = await maintenance.generateMaintenanceReport(args.testSuiteId, session.page); // Add session-specific insights if (session.events.length > 0) { await maintenance.learnFromDebugSession({ interactions: session.events.filter((e) => e.type === 'user-action'), errors: session.events.filter((e) => e.type === 'error') }); const learningSuggestions = await maintenance.getSuggestionsFromLearning(); report.suggestions.push(...learningSuggestions); } return { success: true, report, maintenanceHistory: await maintenance.getMaintenanceHistory() }; } default: throw new Error(`Unknown smart test maintenance tool: ${toolName}`); } } //# sourceMappingURL=smart-test-maintenance-tool.js.map