/** * Agentic QE v3 - Retry Handler Service * Implements intelligent retry logic for failed tests */ import { Result } from '../../../shared/types'; import { RetryResult, FailedTest } from '../interfaces'; import { MemoryBackend } from '../../../kernel/interfaces'; /** * Supported test runners for retry execution */ export type TestRunner = 'vitest' | 'jest' | 'mocha' | 'auto'; /** * Configuration for the retry handler service */ export interface RetryHandlerConfig { /** * When true, simulates test execution with random outcomes (for unit testing). * When false (default), executes actual tests using the configured test runner. */ simulateForTesting: boolean; /** * Success rate for simulated retries (0-1) when simulateForTesting is true. * Defaults to 0.7 (70% chance of passing on retry). */ simulatedRetrySuccessRate: number; /** * When true, adds random jitter to backoff delays. * When false (default), backoff delays are deterministic. */ enableJitter: boolean; /** * Maximum jitter percentage (0-1) when enableJitter is true. * Defaults to 0.1 (10% variation). */ maxJitterPercent: number; /** * Test runner to use for executing retries. * 'auto' will detect the runner based on project configuration. * Defaults to 'auto'. */ testRunner: TestRunner; /** * Timeout for individual test execution in milliseconds. * Defaults to 60000 (60 seconds). */ testTimeout: number; /** * Working directory for test execution. * Defaults to process.cwd(). */ cwd?: string; /** * Path to npx binary. Defaults to 'npx'. */ npxPath: string; } export interface IRetryHandler { /** Determine if a test should be retried */ shouldRetry(testId: string, attempt: number, error: string): Promise; /** Execute a test with retry logic */ executeWithRetry(request: RetryExecutionRequest): Promise>; /** Get retry statistics */ getRetryStats(runId?: string): Promise>; /** Configure retry policy for a test */ setRetryPolicy(testId: string, policy: RetryPolicy): Promise; /** Get retry policy for a test */ getRetryPolicy(testId: string): Promise; } export interface RetryExecutionRequest { runId: string; failedTests: FailedTest[]; maxRetries: number; backoff: 'linear' | 'exponential' | 'constant'; baseDelay?: number; maxDelay?: number; onRetry?: (testId: string, attempt: number) => void; } export interface RetryStatistics { totalRetries: number; successfulRetries: number; failedRetries: number; averageAttemptsToPass: number; retryRate: number; testStats: Map; } export interface TestRetryStats { testId: string; attempts: number; lastResult: 'passed' | 'failed'; errorPatterns: string[]; } export interface RetryPolicy { maxRetries: number; backoff: 'linear' | 'exponential' | 'constant'; baseDelay: number; maxDelay: number; retryOn: RetryCondition[]; noRetryOn: RetryCondition[]; } export type RetryCondition = { type: 'error_pattern'; pattern: string; } | { type: 'exit_code'; code: number; } | { type: 'flakiness_score'; threshold: number; } | { type: 'custom'; predicate: string; }; export declare class RetryHandlerService implements IRetryHandler { private readonly memory; private readonly retryHistory; private readonly retryPolicies; private readonly runStats; private readonly config; private readonly defaultPolicy; constructor(memory: MemoryBackend, config?: Partial); /** * Determine if a test should be retried based on policy and history */ shouldRetry(testId: string, attempt: number, error: string): Promise; /** * Execute failed tests with retry logic */ executeWithRetry(request: RetryExecutionRequest): Promise>; /** * Get retry statistics for a run or overall */ getRetryStats(runId?: string): Promise>; /** * Set retry policy for a specific test */ setRetryPolicy(testId: string, policy: RetryPolicy): Promise; /** * Get retry policy for a test (or default) */ getRetryPolicy(testId: string): Promise; private matchesCondition; private retryTest; private executeTest; /** * Execute a real test using the configured test runner */ private executeRealTest; /** * Detect which test runner is available in the project */ private detectTestRunner; /** * Build the command and arguments for the test runner */ private buildTestCommand; /** * Spawn a test process and parse the result */ private spawnTestProcess; /** * Parse test runner output to determine pass/fail status */ private parseTestResult; private calculateDelay; private sleep; private recordRetry; private convertToRetryStatistics; } //# sourceMappingURL=retry-handler.d.ts.map