/** * QA360 Watch Mode * * Continuous testing mode that monitors file changes and re-runs tests. * Features: * - File watching with debounce * - Smart test selection based on changed files * - Benchmark mode for performance comparison * - Statistics aggregation across runs * * @example * ```typescript * const watcher = new WatchMode({ * workingDir: process.cwd(), * debounceMs: 300, * onRunStart: () => console.log('Running tests...'), * onRunComplete: (result) => console.log('Done:', result) * }); * * await watcher.start(); * ``` */ import { type Phase3RunResult } from '../runner/phase3-runner.js'; /** * Watch mode configuration options */ export interface WatchModeOptions { /** Working directory for tests */ workingDir: string; /** Path to pack.yml file */ packPath?: string; /** Debounce delay in milliseconds (default: 300) */ debounceMs?: number; /** Patterns to ignore (default: node_modules, .git, dist) */ ignore?: string[]; /** Whether to run initial test on start (default: true) */ runOnStart?: boolean; /** Whether to clear screen between runs (default: true) */ clearScreen?: boolean; /** Callback when a run starts */ onRunStart?: (runNumber: number) => void; /** Callback when a run completes */ onRunComplete?: (result: WatchRunResult) => void; /** Callback when a file changes */ onFileChange?: (path: string) => void; /** Callback on error */ onError?: (error: Error) => void; } /** * Result of a single watch run */ export interface WatchRunResult { /** Run number (incrementing) */ runNumber: number; /** Timestamp when run started */ startedAt: Date; /** Timestamp when run completed */ completedAt: Date; /** Duration in milliseconds */ duration: number; /** Phase3Runner result */ result: Phase3RunResult; /** Files that triggered this run */ changedFiles: string[]; /** Whether this run was successful */ success: boolean; } /** * Aggregated statistics across watch runs */ export interface WatchStats { /** Total number of runs */ totalRuns: number; /** Number of successful runs */ successfulRuns: number; /** Number of failed runs */ failedRuns: number; /** Average duration in milliseconds */ avgDuration: number; /** Fastest run duration */ fastestRun: number; /** Slowest run duration */ slowestRun: number; /** Total duration of all runs */ totalDuration: number; /** Trust score average */ avgTrustScore: number; /** Total tests executed */ totalTests: number; /** Total passed tests */ totalPassed: number; /** Total failed tests */ totalFailed: number; } /** * Benchmark configuration */ export interface BenchmarkConfig { /** Number of iterations to run */ iterations: number; /** Warm-up iterations (not counted in stats) */ warmupIterations: number; /** Whether to run with cache enabled */ withCache: boolean; /** Whether to run in parallel */ parallel?: boolean; } /** * Benchmark result */ export interface BenchmarkResult { /** Average duration across iterations */ avgDuration: number; /** Minimum duration */ minDuration: number; /** Maximum duration */ maxDuration: number; /** Standard deviation */ stdDev: number; /** Median duration */ median: number; /** P95 duration */ p95: number; /** P99 duration */ p99: number; /** Number of successful runs */ successfulRuns: number; /** Total iterations */ totalIterations: number; /** Throughput (runs per second) */ throughput: number; } /** * Watch Mode Manager * * Monitors file changes and runs tests automatically. */ export declare class WatchMode { private options; private watchers; private runNumber; private isRunning; private debounceTimer?; private pendingChanges; private runResults; private stats; private packConfig?; constructor(options: WatchModeOptions); /** * Start watching files and running tests */ start(): Promise; /** * Stop watching files */ stop(): Promise; /** * Get current statistics */ getStats(): WatchStats; /** * Get run history */ getRunHistory(): WatchRunResult[]; /** * Run benchmark tests */ benchmark(config: BenchmarkConfig): Promise; /** * Load pack configuration */ private loadPackConfig; /** * Setup file watcher using native Node.js fs.watch */ private setupWatcher; /** * Check if a path should be ignored */ private shouldIgnore; /** * Handle file change with debouncing */ private handleFileChange; /** * Run tests and update statistics */ private runTests; /** * Update aggregated statistics */ private updateStats; /** * Calculate benchmark statistics */ private calculateBenchmarkStats; /** * Log formatted run result */ private logRunResult; /** * Format statistics for display */ private formatStats; /** * Log message */ private log; } /** * Factory function to create a watch mode instance */ export declare function createWatchMode(options: WatchModeOptions): WatchMode;