/** * QA360 Flakiness Detection Engine * * Detects and scores test flakiness using consecutive runs and pattern analysis. * This is the core differentiator of QA360 - measuring test reliability. * * Scoring Categories: * - Legendary (100): Never flaky - 100% reliable * - Solid (90-99): Rarely flaky * - Good (75-89): Occasionally flaky * - Shaky (50-74): Often flaky - attention needed * - Unstable (0-49): Very flaky - quarantine recommended * * @module flakiness */ /** * Flakiness score category */ export declare enum FlakinessCategory { LEGENDARY = "legendary",// 100 SOLID = "solid",// 90-99 GOOD = "good",// 75-89 SHAKY = "shaky",// 50-74 UNSTABLE = "unstable" } /** * Flakiness category metadata */ export declare const FLAKINESS_CATEGORIES: Record; /** * Test result from a single run */ export interface TestResult { /** Test identifier (unique per test) */ testId: string; /** Test name/title */ testName: string; /** File path */ filePath: string; /** Gate name */ gate: string; /** Whether the test passed */ success: boolean; /** Duration in milliseconds */ durationMs: number; /** Error type if failed */ errorType?: string; /** Error message if failed */ errorMessage?: string; /** Timestamp of run */ timestamp: number; /** Environment (local, ci, staging) */ environment: string; /** Git branch */ branch?: string; /** Commit hash */ commitHash?: string; /** CI run ID */ ciRunId?: string; /** Tags (team, repo, etc.) */ tags?: Record; } /** * Flakiness detection result for a single test */ export interface FlakinessResult { /** Test identifier */ testId: string; /** Test name */ testName: string; /** File path */ filePath: string; /** Gate name */ gate: string; /** Flakiness score (0-100) */ score: number; /** Flakiness category */ category: FlakinessCategory; /** Total number of runs analyzed */ totalRuns: number; /** Number of successful runs */ successfulRuns: number; /** Average duration in ms */ avgDurationMs: number; /** Detected pattern type (if any) */ patternType?: string; /** Suggested fix */ suggestedFix?: string; /** Confidence in pattern detection (0-1) */ confidence?: number; /** First seen timestamp */ firstSeen?: number; /** Last seen timestamp */ lastSeen?: number; /** Current streak (consecutive passes or failures) */ currentStreak?: number; /** Streak type */ streakType?: 'pass' | 'fail'; } /** * Flakiness detection options */ export interface FlakinessDetectionOptions { /** Minimum runs before calculating score */ minRuns?: number; /** Number of consecutive runs for detection */ consecutiveRuns?: number; /** Time window in days (only consider runs within this window) */ timeWindowDays?: number; /** Enable pattern detection */ enablePatternDetection?: boolean; } /** * Default flakiness detection options */ export declare const DEFAULT_FLAKINESS_OPTIONS: Required; /** * Flakiness pattern types */ export declare enum FlakinessPattern { TIMING = "timing", RACE_CONDITION = "race_condition", EXTERNAL_DEPENDENCY = "external_dependency", ENVIRONMENT_SPECIFIC = "environment_specific", SELECTOR_ISSUE = "selector_issue", UNKNOWN = "unknown" } /** * Pattern detection result */ export interface PatternDetection { /** Pattern type */ patternType: FlakinessPattern; /** Pattern description */ description: string; /** Suggested fix */ suggestedFix: string; /** Confidence (0-1) */ confidence: number; /** Whether auto-fix is possible */ autoFixPossible: boolean; } /** * Calculate flakiness score from test results * @param results Array of test results * @returns Flakiness score (0-100) */ export declare function calculateFlakinessScore(results: TestResult[]): number; /** * Get flakiness category from score * @param score Flakiness score (0-100) * @returns Flakiness category */ export declare function getFlakinessCategory(score: number): FlakinessCategory; /** * Generate a unique test ID * @param testName Test name * @param filePath File path * @returns Unique test ID */ export declare function generateTestId(testName: string, filePath: string): string; /** * Analyze test results for flakiness patterns * @param results Array of test results for the same test * @returns Pattern detection result or undefined */ export declare function detectFlakinessPattern(results: TestResult[]): PatternDetection | undefined; /** * Calculate consecutive streak (passes or failures) * @param results Array of test results sorted by timestamp * @returns Current streak info */ export declare function calculateStreak(results: TestResult[]): { currentStreak: number; streakType: 'pass' | 'fail'; }; /** * Format flakiness score for display * @param score Flakiness score (0-100) * @returns Formatted string with emoji */ export declare function formatFlakinessScore(score: number): string; /** * Flakiness Detection Engine * * Main class for detecting and scoring test flakiness */ export declare class FlakinessDetector { private options; constructor(options?: FlakinessDetectionOptions); /** * Analyze a single test's flakiness from its run history * @param testId Test identifier * @param results Array of test results (must be from the same test) * @returns Flakiness result */ analyzeTest(testId: string, results: TestResult[]): FlakinessResult; /** * Analyze multiple tests and return flakiness results * @param testResults Map of testId to array of results * @returns Array of flakiness results */ analyzeAll(testResults: Map): FlakinessResult[]; /** * Check if a test should be quarantined based on flakiness * @param result Flakiness result * @returns Whether to quarantine */ shouldQuarantine(result: FlakinessResult): boolean; /** * Get quarantine recommendation message * @param result Flakiness result * @returns Recommendation message */ getQuarantineRecommendation(result: FlakinessResult): string; /** * Calculate average duration */ private averageDuration; }