/** * Agentic QE v3 - Flaky Test Detector Service * Identifies and analyzes flaky tests from execution history */ import { Result } from '../../../shared/types'; import { FlakyDetectionRequest, FlakyTestReport } from '../interfaces'; import { MemoryBackend } from '../../../kernel/interfaces'; /** * Configuration for the flaky detector service */ export interface FlakyDetectorConfig { /** * When true, simulates test execution with random outcomes (for unit testing). * When false (default), actually executes tests using the configured test runner. */ simulateForTesting: boolean; /** * Base flakiness probability (0-1) when simulateForTesting is true. * Defaults to 0.3 (30% of tests are flaky in simulation). */ simulatedFlakinessRate: number; /** * Simulated pass rate for flaky tests (0-1) when simulateForTesting is true. * Defaults to 0.7 (70% pass rate for flaky tests). */ simulatedFlakyPassRate: number; /** * Number of tests per file in simulation mode. * Defaults to 2. */ simulatedTestsPerFile: number; /** * Test runner command to use. Defaults to 'npx vitest'. * Examples: 'npx vitest', 'npm test --', 'npx jest', 'npx mocha' */ testRunner: string; /** * Additional arguments to pass to the test runner. */ testRunnerArgs: string[]; /** * Working directory for test execution. */ cwd?: string; /** * Timeout in milliseconds for each test run. * Defaults to 60000 (60 seconds). */ runTimeout: number; /** * Environment variables to pass to the test runner. */ env?: Record; } export interface IFlakyTestDetector { /** Detect flaky tests by running multiple times */ detectFlaky(request: FlakyDetectionRequest): Promise>; /** Analyze failure patterns from history */ analyzePattern(testId: string): Promise>; /** Suggest remediation for a flaky test */ suggestFix(testId: string): Promise>; /** Record test execution result for analysis */ recordExecution(testId: string, result: TestExecutionRecord): Promise; /** Get flakiness score for a test */ getFlakinessScore(testId: string): Promise; } export interface FlakyAnalysis { testId: string; pattern: 'timing' | 'ordering' | 'resource' | 'async' | 'unknown'; confidence: number; factors: string[]; correlations: CorrelationFactor[]; } export interface CorrelationFactor { factor: string; correlation: number; description: string; } export interface FlakySuggestion { testId: string; pattern: string; recommendations: Recommendation[]; priority: 'high' | 'medium' | 'low'; } export interface Recommendation { action: string; description: string; codeSnippet?: string; effort: 'low' | 'medium' | 'high'; } export interface TestExecutionRecord { runId: string; passed: boolean; duration: number; error?: string; timestamp: Date; context?: ExecutionContext; } export interface ExecutionContext { workerIndex?: number; parallelRuns?: number; environment?: Record; precedingTests?: string[]; } export declare class FlakyDetectorService implements IFlakyTestDetector { private readonly memory; private readonly testHistory; private readonly analysisCache; private readonly config; constructor(memory: MemoryBackend, config?: Partial); /** * Detect flaky tests by running them multiple times */ detectFlaky(request: FlakyDetectionRequest): Promise>; /** * Analyze failure patterns for a specific test */ analyzePattern(testId: string): Promise>; /** * Suggest fixes for a flaky test */ suggestFix(testId: string): Promise>; /** * Record a test execution for future analysis */ recordExecution(testId: string, result: TestExecutionRecord): Promise; /** * Calculate flakiness score (0-1, where 1 is most flaky) */ getFlakinessScore(testId: string): Promise; private runMultipleTimes; /** * Execute a single test file and parse the results */ private executeTestFile; /** * Parse test runner output to extract individual test results */ private parseTestOutput; /** * Extract JSON from mixed output */ private extractJson; /** * Parse Vitest JSON output */ private parseVitestJson; /** * Parse Jest JSON output */ private parseJestJson; /** * Parse TAP output format */ private parseTapOutput; /** * Parse Mocha-style console output */ private parseMochaOutput; /** * Generate a deterministic test ID from file and test name */ private generateTestId; /** * Get recorded execution history for tests in a file */ private getHistoryForFile; /** * Simulate multiple test runs with random outcomes (for unit testing only) */ private simulateMultipleRuns; private identifyFlakyTests; private detectPattern; private getQuickRecommendation; private getTestHistory; private performPatternAnalysis; private identifyFactors; private calculateCorrelations; private correlateWithFailure; private pearsonCorrelation; private calculateConfidence; private generateRecommendations; private determinePriority; private hasDurationSpikes; private average; private standardDeviation; private storeReport; } //# sourceMappingURL=flaky-detector.d.ts.map