/** * QA360 Test Sharding Module * * P0: Split test execution across multiple workers/machines * - Consistent hashing for test distribution * - Dynamic shard allocation * - Load balancing across workers * - CI-friendly shard configuration */ /** * Shard configuration */ export interface ShardConfig { /** Total number of shards */ totalShards: number; /** Current shard index (1-based) */ shardIndex: number; /** Optional shard seed for reproducibility */ seed?: string; } /** * Test metadata for sharding */ export interface TestMetadata { /** Unique test identifier */ testId: string; /** Test file path */ filePath: string; /** Test name */ testName: string; /** Optional test tags/categories */ tags?: string[]; /** Optional estimated duration (ms) */ duration?: number; } /** * Shard allocation result */ export interface ShardAllocation { /** Assigned shard index (1-based) */ shardIndex: number; /** Total number of shards */ totalShards: number; /** Tests assigned to this shard */ tests: TestMetadata[]; } /** * Test Sharding Manager */ export declare class TestSharding { private config; private seed; constructor(config: ShardConfig); /** * Determine which shard a test belongs to * Uses consistent hashing for reproducible distribution */ getShardForTest(test: TestMetadata): number; /** * Check if a test should run in current shard */ shouldRunTest(test: TestMetadata): boolean; /** * Filter tests to only those in current shard */ filterTests(tests: TestMetadata[]): TestMetadata[]; /** * Allocate tests across all shards * Returns distribution stats for all shards */ allocateTests(tests: TestMetadata[]): Map; /** * Get shard information for display/logging */ getShardInfo(): { shardIndex: number; totalShards: number; shardId: string; }; /** * Hash test metadata to a consistent number */ private hashTest; /** * Create shard configuration from environment variables * CI-friendly: reads SHARD_TOTAL and SHARD_INDEX */ static fromEnv(): ShardConfig | null; /** * Check if sharding is enabled via environment */ static isEnabled(): boolean; /** * Get environment variable with multiple possible names */ private static getEnvVar; /** * Parse shard config from string format "index/total" * Example: "1/4" -> shardIndex: 1, totalShards: 4 */ static parseShardString(shardStr: string): ShardConfig; /** * Get recommended shard count based on test count */ static getRecommendedShardCount(testCount: number, maxShards?: number): number; /** * Get optimal shard count based on CPU cores */ static getOptimalShardCount(): number; } /** * Create a test sharding manager */ export declare function createTestSharding(config: ShardConfig): TestSharding; /** * Create sharding from environment if enabled */ export declare function createShardingFromEnv(): TestSharding | null; /** * Vitest filter function for sharding * Usage: vitest.config.ts -> test.exclude = [..., createShardingExclude()] */ export declare function createShardingExclude(): RegExp[] | ((file: string) => boolean); /** * Setup sharding for Vitest * Returns a function that can be used to filter tests */ export declare function setupVitestSharding(): ((testId: string) => boolean) | null; /** * Get shard-specific suffix for output files * Prevents overwriting artifacts between shards */ export declare function getShardSuffix(): string; /** * Create shard-specific report filename */ export declare function getShardedFilename(baseName: string): string;