/** * xray Testing Best Practices MCP Server * * Knowledge skill for comprehensive testing strategies, TDD/BDD implementation, * test coverage optimization, and automated testing workflows */ import * as fs from "fs"; import { frameworkLogger } from "../../core/framework-logger.js"; import { XrayKnowledgeSkillBase } from "../shared/knowledge-skill-base.js"; interface TestStrategy { type: | "unit" | "integration" | "e2e" | "performance" | "security" | "accessibility"; framework: string; coverage: number; confidence: "low" | "medium" | "high"; automationLevel: number; // 0-100 } interface TestAnalysis { currentCoverage: number; targetCoverage: number; gaps: TestGap[]; recommendations: TestRecommendation[]; strategy: TestStrategy[]; automationPotential: number; } interface TestGap { area: string; currentCoverage: number; recommendedCoverage: number; priority: "high" | "medium" | "low"; effort: "low" | "medium" | "high"; } interface TestRecommendation { type: string; description: string; impact: "high" | "medium" | "low"; effort: "low" | "medium" | "high"; tools: string[]; } interface AnalyzeTestCoverageArgs { codePath: string; testFramework?: string; coverageThreshold?: number; } interface DesignTestStrategyArgs { projectType: string; techStack?: string[]; teamSize?: string; timeline?: string; } interface ImplementTDDWorkflowArgs { language?: string; framework?: string; existingTests?: boolean; } interface OptimizeTestPerformanceArgs { testResults: string; targetRuntime?: number; parallelExecution?: boolean; } interface SetupCICDTestingArgs { ciPlatform: string; testTypes: string[]; coverageReporting?: boolean; } interface TDDWorkflowStep { title: string; description: string; command: string; } interface TDDWorkflow { steps: TDDWorkflowStep[]; } interface PerformanceBottleneck { type: string; description: string; impact: number; difficulty: string; solution: string; } interface PerformanceRecommendation { title: string; improvement: number; effort: string; description: string; } interface TestPerformanceAnalysis { currentRuntime: number; bottlenecks: PerformanceBottleneck[]; recommendations: PerformanceRecommendation[]; } interface CIStage { name: string; description: string; estimatedDuration: number; tests: string[]; conditions: string[]; } interface CIConfigFile { filename: string; location: string; description: string; } interface CIDependency { name: string; version?: string; purpose: string; } interface CIPipeline { stages: CIStage[]; configFiles: CIConfigFile[]; dependencies: CIDependency[]; } interface CoverageImprovementPhase { name: string; duration: string; focus: string; tasks: string[]; } interface CoverageImprovementPlan { phases: CoverageImprovementPhase[]; } interface ImplementationMilestone { phase: string; week: number; deliverables: string[]; } interface ImplementationRoadmap { phases: string[]; timeline: string; milestones: ImplementationMilestone[]; } interface TDDExampleSet { language: string; framework: string; examples: Array<{ scenario: string; test: string; implementation: string; }>; } interface PerformanceOptimizationPlan { immediate: PerformanceRecommendation[]; shortTerm: PerformanceRecommendation[]; longTerm: PerformanceRecommendation[]; totalImprovement: number; } interface PerformanceMonitoringStrategy { metrics: string[]; alerts: string[]; dashboards: string[]; } interface CIConfigTemplates { platform: string; templates: Record; } interface CITroubleshootingGuide { commonIssues: Array<{ issue: string; solution: string }>; debuggingSteps: string[]; } interface McpToolResponse { content: Array<{ type: "text"; text: string }>; data?: Record; } class XrayTestingBestPracticesServer extends XrayKnowledgeSkillBase { constructor() { super("testing-best-practices", "3.1.0"); this.tools = [ { name: "analyze_test_coverage", description: "Analyze current test coverage and identify gaps", inputSchema: { type: "object", properties: { codePath: { type: "string", description: "Path to codebase to analyze" }, testFramework: { type: "string", description: "Testing framework used (jest, vitest, mocha, etc.)", default: "auto-detect" }, coverageThreshold: { type: "number", description: "Minimum coverage threshold (0-100)", default: 80 } }, required: ["codePath"] } }, { name: "design_test_strategy", description: "Design comprehensive testing strategy for a project", inputSchema: { type: "object", properties: { projectType: { type: "string", enum: ["web-app", "api", "library", "mobile", "desktop"], description: "Type of project" }, techStack: { type: "array", items: { type: "string" }, description: "Technologies used (react, node, typescript, etc.)" }, teamSize: { type: "string", enum: ["solo", "small", "medium", "large"], description: "Development team size" }, timeline: { type: "string", enum: ["rapid", "balanced", "thorough"], description: "Development timeline priority" } }, required: ["projectType"] } }, { name: "implement_tdd_workflow", description: "Implement Test-Driven Development workflow and practices", inputSchema: { type: "object", properties: { language: { type: "string", description: "Programming language", default: "typescript" }, framework: { type: "string", description: "Preferred testing framework", default: "jest" }, existingTests: { type: "boolean", description: "Whether tests already exist", default: false } }, required: [] } }, { name: "optimize_test_performance", description: "Analyze and optimize test execution performance", inputSchema: { type: "object", properties: { testResults: { type: "string", description: "Path to test results or current execution time" }, targetRuntime: { type: "number", description: "Target test execution time in seconds", default: 300 }, parallelExecution: { type: "boolean", description: "Whether parallel execution is supported", default: true } }, required: ["testResults"] } }, { name: "setup_ci_cd_testing", description: "Set up comprehensive CI/CD testing pipeline", inputSchema: { type: "object", properties: { ciPlatform: { type: "string", enum: ["github-actions", "gitlab-ci", "jenkins", "circle-ci", "travis-ci"], description: "CI/CD platform" }, testTypes: { type: "array", items: { type: "string", enum: ["unit", "integration", "e2e", "performance", "security"] }, description: "Types of tests to include" }, coverageReporting: { type: "boolean", description: "Enable coverage reporting", default: true } }, required: ["ciPlatform", "testTypes"] } }, ]; this.handlers = { analyze_test_coverage: async (args) => this.analyzeTestCoverage(args as AnalyzeTestCoverageArgs), design_test_strategy: async (args) => this.designTestStrategy(args as DesignTestStrategyArgs), implement_tdd_workflow: async (args) => this.implementTDDWorkflow(args as ImplementTDDWorkflowArgs), optimize_test_performance: async (args) => this.optimizeTestPerformance(args as OptimizeTestPerformanceArgs), setup_ci_cd_testing: async (args) => this.setupCICDTesting(args as SetupCICDTestingArgs), }; this.setupToolHandlers(); } // setupToolHandlers removed โ€” handled by XrayKnowledgeSkillBase via this.tools + this.handlers private async analyzeTestCoverage(args: AnalyzeTestCoverageArgs): Promise { const { codePath, testFramework = "auto-detect", coverageThreshold = 80, } = args; try { const analysis = await this.performCoverageAnalysis( codePath, testFramework, ); const gaps = analysis.gaps.filter( (gap: TestGap) => gap.currentCoverage < coverageThreshold, ); const criticalGaps = gaps.filter((gap: TestGap) => gap.priority === "high"); return { content: [ { type: "text", text: `Test Coverage Analysis for ${codePath}:\n\n` + `๐Ÿ“Š COVERAGE METRICS\n` + `Current Coverage: ${analysis.currentCoverage}%\n` + `Target Coverage: ${analysis.targetCoverage}%\n` + `Coverage Gap: ${(analysis.targetCoverage - analysis.currentCoverage).toFixed(1)}%\n` + `Automation Potential: ${analysis.automationPotential}%\n\n` + `๐Ÿšจ COVERAGE GAPS (${gaps.length} total, ${criticalGaps.length} critical)\n${gaps .slice(0, 5) .map( (gap: TestGap) => `${this.getPriorityIcon(gap.priority)} ${gap.area}\n` + ` Current: ${gap.currentCoverage}% | Target: ${gap.recommendedCoverage}%\n` + ` Priority: ${gap.priority.toUpperCase()} | Effort: ${gap.effort.toUpperCase()}`, ) .join("\n\n")}\n\n` + `๐ŸŽฏ TEST STRATEGY RECOMMENDATIONS\n${analysis.recommendations .slice(0, 5) .map( (rec: TestRecommendation) => ` Impact: ${rec.impact.toUpperCase()} | Effort: ${rec.effort.toUpperCase()}\n` + ` Tools: ${rec.tools.join(", ")}`, ) .join("\n\n")}\n\n` + `โšก QUICK WINS\n` + `โ€ข Focus on high-impact, low-effort improvements first\n` + `โ€ข Automate repetitive testing tasks\n` + `โ€ข Implement test-driven development for new features\n` + `โ€ข Set up continuous integration with coverage gates`, }, ], data: { analysis, prioritizedGaps: this.prioritizeGaps(gaps), implementationPlan: this.createCoverageImprovementPlan(analysis), }, }; } catch (error) { return { content: [ { type: "text", text: `Error analyzing test coverage: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } private async designTestStrategy(args: DesignTestStrategyArgs): Promise { const { projectType, techStack = [], teamSize = "small", timeline = "balanced", } = args; try { const strategy = this.createTestStrategy( projectType, techStack, teamSize, timeline, ); return { content: [ { type: "text", text: `Testing Strategy for ${projectType.toUpperCase()} Project:\n\n` + `๐Ÿ‘ฅ TEAM CONTEXT\n` + `Team Size: ${teamSize.toUpperCase()}\n` + `Timeline Priority: ${timeline.toUpperCase()}\n` + `Tech Stack: ${techStack.join(", ") || "Not specified"}\n\n` + `๐Ÿงช RECOMMENDED TEST PYRAMID\n${strategy .map( (testType: TestStrategy) => `${this.getTestTypeIcon(testType.type)} ${testType.type.toUpperCase()} TESTS\n` + ` Framework: ${testType.framework}\n` + ` Target Coverage: ${testType.coverage}%\n` + ` Confidence Level: ${testType.confidence.toUpperCase()}\n` + ` Automation: ${testType.automationLevel}%`, ) .join("\n\n")}\n\n` + `๐Ÿ“ˆ IMPLEMENTATION ROADMAP\n` + `1. Set up unit testing framework and basic test structure\n` + `2. Implement integration tests for critical user journeys\n` + `3. Add end-to-end tests for complete workflows\n` + `4. Integrate performance and security testing\n` + `5. Set up automated test execution in CI/CD\n\n` + `๐ŸŽฏ SUCCESS METRICS\n` + `โ€ข 80%+ automated test coverage\n` + `โ€ข <5 minute test execution time\n` + `โ€ข 99% test reliability\n` + `โ€ข Zero production bugs from untested code`, }, ], data: { strategy, roadmap: this.createImplementationRoadmap(strategy, timeline), tools: this.recommendTestingTools(strategy), }, }; } catch (error) { return { content: [ { type: "text", text: `Error designing test strategy: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } private async implementTDDWorkflow(args: ImplementTDDWorkflowArgs): Promise { const { language = "typescript", framework = "jest", existingTests = false, } = args; try { const workflow = this.createTDDWorkflow( language, framework, existingTests, ); return { content: [ { type: "text", text: `Test-Driven Development Workflow for ${language.toUpperCase()}:\n\n` + `๐Ÿ”„ TDD CYCLE\n` + `1. ๐ŸŸฅ RED: Write failing test first\n` + `2. ๐ŸŸข GREEN: Make test pass with minimal code\n` + `3. ๐ŸŸก REFACTOR: Improve code while keeping tests green\n` + `4. ๐Ÿ”„ REPEAT: Continue with next requirement\n\n` + `๐Ÿ› ๏ธ SETUP & TOOLS\n` + `Framework: ${framework}\n` + `Language: ${language}\n` + `Existing Tests: ${existingTests ? "Yes" : "No"}\n\n` + `๐Ÿ“ PRACTICAL WORKFLOW\n${workflow.steps .map( (step: TDDWorkflowStep, i: number) => `${i + 1}. ${step.title}\n` + ` ${step.description}\n` + ` Command: ${step.command}`, ) .join("\n\n")}\n\n` + `๐Ÿ’ก TDD BEST PRACTICES\n` + `โ€ข Write test before implementation code\n` + `โ€ข Test one concept per test case\n` + `โ€ข Use descriptive test names (should/when/given)\n` + `โ€ข Keep tests fast and isolated\n` + `โ€ข Refactor code, not tests\n` + `โ€ข Maintain high test coverage (>90%)\n\n` + `๐Ÿš€ GETTING STARTED\n` + `${existingTests ? "Integrate TDD into existing test suite" : "Start with a simple feature and practice the cycle"}\n` + `Run tests continuously during development\n` + `Use test results to guide implementation`, }, ], data: { workflow, examples: this.provideTDDExamples(language, framework), resources: this.recommendTDDResources(language, framework), }, }; } catch (error) { return { content: [ { type: "text", text: `Error implementing TDD workflow: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } private async optimizeTestPerformance(args: OptimizeTestPerformanceArgs): Promise { const { testResults, targetRuntime = 300, parallelExecution = true } = args; try { const optimization = await this.analyzeTestPerformance( testResults, targetRuntime, parallelExecution, ); return { content: [ { type: "text", text: `Test Performance Optimization Analysis:\n\n` + `โฑ๏ธ CURRENT PERFORMANCE\n` + `Execution Time: ${optimization.currentRuntime}s\n` + `Target Time: ${targetRuntime}s\n` + `Performance Gap: ${(optimization.currentRuntime - targetRuntime).toFixed(1)}s\n` + `Parallel Execution: ${parallelExecution ? "Enabled" : "Disabled"}\n\n` + `๐ŸŒ PERFORMANCE BOTTLENECKS\n${optimization.bottlenecks .map( (bottleneck: PerformanceBottleneck, i: number) => `${i + 1}. ${bottleneck.type}: ${bottleneck.description}\n` + ` Impact: ${bottleneck.impact}s saved\n` + ` Difficulty: ${bottleneck.difficulty}\n` + ` Solution: ${bottleneck.solution}`, ) .join("\n\n")}\n\n` + `โšก OPTIMIZATION RECOMMENDATIONS\n${optimization.recommendations .map( (rec: PerformanceRecommendation, i: number) => ` Expected Improvement: ${rec.improvement}s\n` + ` Effort: ${rec.effort}\n` + ` ${rec.description}`, ) .join("\n\n")}\n\n` + `๐ŸŽฏ IMPLEMENTATION PRIORITY\n` + `1. Enable parallel test execution (if not already)\n` + `2. Optimize slow integration tests\n` + `3. Implement intelligent test skipping\n` + `4. Use test result caching\n` + `5. Optimize test data setup/cleanup`, }, ], data: { optimization, implementationPlan: this.createPerformanceOptimizationPlan(optimization), monitoringStrategy: this.setupPerformanceMonitoring(optimization), }, }; } catch (error) { return { content: [ { type: "text", text: `Error optimizing test performance: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } private async setupCICDTesting(args: SetupCICDTestingArgs): Promise { const { ciPlatform, testTypes, coverageReporting = true } = args; try { const pipeline = this.createCIPipeline( ciPlatform, testTypes, coverageReporting, ); return { content: [ { type: "text", text: `CI/CD Testing Pipeline for ${ciPlatform.toUpperCase()}:\n\n` + `๐Ÿ”ง CONFIGURATION OVERVIEW\n` + `Platform: ${ciPlatform}\n` + `Test Types: ${testTypes.join(", ")}\n` + `Coverage Reporting: ${coverageReporting ? "Enabled" : "Disabled"}\n\n` + `๐Ÿ“‹ PIPELINE STAGES\n${pipeline.stages .map( (stage: CIStage, i: number) => `Stage ${i + 1}: ${stage.name}\n` + ` Purpose: ${stage.description}\n` + ` Duration: ~${stage.estimatedDuration}min\n` + ` Tests: ${stage.tests.join(", ")}\n` + ` Conditions: ${stage.conditions.join(", ")}`, ) .join("\n\n")}\n\n` + `๐Ÿ“„ CONFIGURATION FILES\n${pipeline.configFiles .map( (file: CIConfigFile) => `${file.filename}\n` + ` Location: ${file.location}\n` + ` Purpose: ${file.description}`, ) .join("\n\n")}\n\n` + `๐Ÿ› ๏ธ REQUIRED TOOLS & DEPENDENCIES\n${pipeline.dependencies .map( (dep: CIDependency) => `โ€ข ${dep.name}: ${dep.version || "latest"} (${dep.purpose})`, ) .join("\n")}\n\n` + `โœ… QUALITY GATES\n` + `โ€ข All tests must pass\n` + `${coverageReporting ? "โ€ข Minimum coverage thresholds met\n" : ""}` + `โ€ข No critical security vulnerabilities\n` + `โ€ข Performance benchmarks achieved\n` + `โ€ข Linting and formatting checks pass`, }, ], data: { pipeline, configurationTemplates: this.generateCIConfigTemplates( ciPlatform, pipeline, ), troubleshootingGuide: this.createCITroubleshootingGuide(pipeline), }, }; } catch (error) { return { content: [ { type: "text", text: `Error setting up CI/CD testing: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } // Implementation methods private async performCoverageAnalysis( codePath: string, testFramework: string, ): Promise { // Simplified analysis - would be more comprehensive in production return { currentCoverage: 65, targetCoverage: 85, gaps: [ { area: "API endpoints", currentCoverage: 45, recommendedCoverage: 90, priority: "high", effort: "medium", }, { area: "Error handling", currentCoverage: 30, recommendedCoverage: 80, priority: "high", effort: "low", }, { area: "UI components", currentCoverage: 70, recommendedCoverage: 85, priority: "medium", effort: "high", }, ], recommendations: [ { type: "Unit Test Expansion", description: "Increase unit test coverage for business logic", impact: "high", effort: "medium", tools: ["Jest", "Vitest", "Testing Library"], }, { type: "Integration Testing", description: "Add integration tests for API endpoints", impact: "high", effort: "medium", tools: ["Supertest", "TestContainers"], }, ], strategy: [], automationPotential: 75, }; } private createTestStrategy( projectType: string, techStack: string[], teamSize: string, timeline: string, ): TestStrategy[] { const baseStrategy: TestStrategy[] = []; switch (projectType) { case "web-app": baseStrategy.push( { type: "unit", framework: "Jest + Testing Library", coverage: 85, confidence: "high", automationLevel: 95, }, { type: "integration", framework: "Cypress", coverage: 70, confidence: "medium", automationLevel: 80, }, { type: "e2e", framework: "Playwright", coverage: 60, confidence: "high", automationLevel: 85, }, ); break; case "api": baseStrategy.push( { type: "unit", framework: "Jest", coverage: 90, confidence: "high", automationLevel: 95, }, { type: "integration", framework: "Supertest", coverage: 80, confidence: "high", automationLevel: 90, }, ); break; default: baseStrategy.push({ type: "unit", framework: "Jest", coverage: 80, confidence: "high", automationLevel: 90, }); } return baseStrategy; } private createTDDWorkflow( language: string, framework: string, existingTests: boolean, ): TDDWorkflow { return { steps: [ { title: "Set up testing framework", description: "Install and configure testing framework with proper scripts", command: `npm install --save-dev ${framework}`, }, { title: "Create test file structure", description: "Set up __tests__ directories and test file naming conventions", command: "mkdir -p src/__tests__ && touch src/__tests__/example.test.ts", }, { title: "Write first failing test", description: "Start with a simple test case that will initially fail", command: "npm test -- --watch", }, { title: "Implement minimal code", description: "Write just enough code to make the test pass", command: "npm run build && npm test", }, { title: "Refactor and improve", description: "Clean up code while ensuring tests still pass", command: "npm test && npm run lint", }, ], }; } private async analyzeTestPerformance( testResults: string, targetRuntime: number, parallelExecution: boolean, ): Promise { return { currentRuntime: 450, bottlenecks: [ { type: "Slow integration tests", description: "Database setup and teardown taking too long", impact: 120, difficulty: "medium", solution: "Use test containers and parallel execution", }, { type: "Inefficient test data", description: "Large fixtures loaded for every test", impact: 80, difficulty: "low", solution: "Implement shared test data with factories", }, ], recommendations: [ { title: "Enable parallel test execution", improvement: 150, effort: "low", description: "Run tests in parallel to reduce total execution time", }, { title: "Optimize test database setup", improvement: 100, effort: "medium", description: "Use in-memory databases and efficient fixtures", }, ], }; } private createCIPipeline( ciPlatform: string, testTypes: string[], coverageReporting: boolean, ): CIPipeline { const stages: CIStage[] = []; if (testTypes.includes("unit")) { stages.push({ name: "Unit Tests", description: "Fast unit tests for individual components", estimatedDuration: 5, tests: ["Unit tests"], conditions: ["All unit tests pass"], }); } if (testTypes.includes("integration")) { stages.push({ name: "Integration Tests", description: "Test component interactions and APIs", estimatedDuration: 10, tests: ["Integration tests"], conditions: ["All integration tests pass", "API contracts validated"], }); } if (testTypes.includes("e2e")) { stages.push({ name: "E2E Tests", description: "End-to-end user journey testing", estimatedDuration: 15, tests: ["E2E tests"], conditions: ["All E2E tests pass", "UI interactions working"], }); } return { stages, configFiles: [ { filename: ".github/workflows/ci.yml", location: "Repository root", description: "GitHub Actions workflow configuration", }, { filename: "jest.config.js", location: "Repository root", description: "Jest testing framework configuration", }, ], dependencies: [ { name: "jest", version: "^29.0.0", purpose: "Unit testing framework" }, { name: "cypress", version: "^12.0.0", purpose: "E2E testing framework", }, { name: "@testing-library/react", purpose: "React component testing utilities", }, ], }; } // Helper methods private prioritizeGaps(gaps: TestGap[]): TestGap[] { return gaps.sort((a: TestGap, b: TestGap) => { const priorityScore = { high: 3, medium: 2, low: 1 }; const effortScore = { low: 3, medium: 2, high: 1 }; return ( priorityScore[b.priority as keyof typeof priorityScore] * effortScore[b.effort as keyof typeof effortScore] - priorityScore[a.priority as keyof typeof priorityScore] * effortScore[a.effort as keyof typeof effortScore] ); }); } private createCoverageImprovementPlan(analysis: TestAnalysis): CoverageImprovementPlan { return { phases: [ { name: "Quick Wins", duration: "1-2 weeks", focus: "High-impact, low-effort improvements", tasks: ["Add tests for error handling", "Cover critical user paths"], }, { name: "Systematic Coverage", duration: "2-4 weeks", focus: "Methodical coverage improvement", tasks: ["Test all public APIs", "Add integration tests"], }, { name: "Optimization", duration: "1-2 weeks", focus: "Performance and maintainability", tasks: ["Refactor test code", "Optimize test execution"], }, ], }; } private createImplementationRoadmap( strategy: TestStrategy[], timeline: string, ): ImplementationRoadmap { const phases = [ "Setup testing infrastructure", "Implement unit testing", "Add integration testing", "Set up E2E testing", "Continuous integration", "Test optimization", ]; return { phases, timeline: timeline === "rapid" ? "4 weeks" : timeline === "balanced" ? "8 weeks" : "12 weeks", milestones: phases.map((phase: string, index: number) => ({ phase, week: index + 1, deliverables: [`Complete ${phase.toLowerCase()}`], })), }; } private recommendTestingTools(strategy: TestStrategy[]): string[] { const tools = new Set(); strategy.forEach((testType: TestStrategy) => { tools.add(testType.framework); if (testType.type === "e2e") { tools.add("Selenium"); tools.add("WebDriver"); } if (testType.type === "performance") { tools.add("k6"); tools.add("Lighthouse"); } }); return Array.from(tools); } private provideTDDExamples(language: string, framework: string): TDDExampleSet { return { language, framework, examples: [ { scenario: "Simple calculator function", test: `describe('Calculator', () => {\n it('should add two numbers', () => {\n expect(add(2, 3)).toBe(5);\n });\n});`, implementation: `function add(a: number, b: number): number {\n return a + b;\n}`, }, ], }; } private recommendTDDResources(language: string, framework: string): string[] { return [ `Test-Driven Development: By Example by Kent Beck`, `${framework} Official Documentation`, `Testing ${language} Applications`, "Martin Fowler's Testing Articles", "Kent Beck's TDD Resources", ]; } private createPerformanceOptimizationPlan(optimization: TestPerformanceAnalysis): PerformanceOptimizationPlan { return { immediate: optimization.recommendations.filter( (rec: PerformanceRecommendation) => rec.effort === "low", ), shortTerm: optimization.recommendations.filter( (rec: PerformanceRecommendation) => rec.effort === "medium", ), longTerm: optimization.recommendations.filter( (rec: PerformanceRecommendation) => rec.effort === "high", ), totalImprovement: optimization.recommendations.reduce( (sum: number, rec: PerformanceRecommendation) => sum + rec.improvement, 0, ), }; } private setupPerformanceMonitoring(optimization: TestPerformanceAnalysis): PerformanceMonitoringStrategy { return { metrics: [ "Test execution time", "Test failure rate", "Coverage trends", "Flaky test detection", ], alerts: [ "Tests exceed 10 minute threshold", "Coverage drops below 80%", "Test failure rate > 5%", ], dashboards: [ "Test performance dashboard", "Coverage trend visualization", "CI/CD pipeline metrics", ], }; } private generateCIConfigTemplates(ciPlatform: string, pipeline: CIPipeline): CIConfigTemplates { return { platform: ciPlatform, templates: { "github-actions": `# .github/workflows/ci.yml\nname: CI\non: [push, pull_request]\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v3\n - uses: actions/setup-node@v3\n with:\n node-version: '24.22.1'\n - run: npm ci\n - run: npm run build\n - run: npm test`, "gitlab-ci": `# .gitlab-ci.yml\nstages:\n - test\ntest:\n stage: test\n image: node:24.22.1\n script:\n - npm ci\n - npm run build\n - npm test`, }, }; } private createCITroubleshootingGuide(pipeline: CIPipeline): CITroubleshootingGuide { return { commonIssues: [ { issue: "Tests failing in CI but passing locally", solution: "Check environment differences, use specific Node.js version, ensure dependencies are locked", }, { issue: "Slow CI builds", solution: "Enable caching, run tests in parallel, use faster runners", }, { issue: "Flaky tests", solution: "Identify and fix race conditions, improve test isolation, add retry logic", }, ], debuggingSteps: [ "Check CI logs for detailed error messages", "Run tests locally with same environment", "Use CI-specific debugging tools", "Review recent changes that might affect tests", ], }; } private getPriorityIcon(priority: string): string { const icons = { high: "๐Ÿ”ด", medium: "๐ŸŸก", low: "๐ŸŸข" }; return icons[priority as keyof typeof icons] || "โ“"; } private getImpactIcon(impact: string): string { const icons = { high: "๐Ÿš€", medium: "โšก", low: "๐ŸŒ" }; return icons[impact as keyof typeof icons] || "โ“"; } private getTestTypeIcon(type: string): string { const icons = { unit: "๐Ÿงฉ", integration: "๐Ÿ”—", e2e: "๐ŸŒ", performance: "โšก", security: "๐Ÿ”’", accessibility: "โ™ฟ", }; return icons[type as keyof typeof icons] || "๐Ÿงช"; } // run() removed โ€” handled by XrayKnowledgeSkillBase } // Run the server if this file is executed directly if (import.meta.url === `file://${fs.realpathSync(process.argv[1]!)}`) { const server = new XrayTestingBestPracticesServer(); server.run().catch(() => {}); } export { XrayTestingBestPracticesServer };