"use strict";
/**
 * 测试配置文件
 * 统一管理所有测试相关的配置参数
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAdjustedConfig = exports.CIConfig = exports.getPlatformValidation = exports.isFeatureSupported = exports.getPlatformTimeout = exports.getCurrentPlatformConfig = exports.PlatformConfigs = exports.TestGlobalConfig = void 0;
const os = __importStar(require("os"));
/**
 * 全局测试配置
 */
exports.TestGlobalConfig = {
    // 基础超时设置
    timeouts: {
        default: 10000, // 默认测试超时 (10秒)
        long: 30000, // 长时间测试超时 (30秒)
        performance: 5000, // 性能测试最大执行时间 (5秒)
        quick: 2000 // 快速测试超时 (2秒)
    },
    // 性能基准
    performance: {
        maxMemoryIncreaseMB: 10, // 最大内存增长 (10MB)
        maxExecutionTimeMs: 5000, // 最大执行时间 (5秒)
        maxSyncOperationMs: 100, // 同步操作最大时间 (100ms)
        maxAsyncOperationMs: 10000, // 异步操作最大时间 (10秒)
        iterationCount: {
            quick: 10, // 快速迭代测试
            standard: 50, // 标准迭代测试
            stress: 100 // 压力测试迭代
        }
    },
    // 数据验证阈值
    validation: {
        percentageRange: { min: 0, max: 100 }, // 百分比范围
        memoryToleranceMB: 100, // 内存值容差 (100MB)
        diskToleranceGB: 1, // 磁盘空间容差 (1GB)
        percentageTolerance: 0.1, // 百分比容差 (0.1%)
        networkStatsMinFields: ['interface', 'inputBytes', 'outputBytes']
    },
    // 重试配置
    retry: {
        maxAttempts: 3, // 最大重试次数
        delayMs: 1000, // 重试延迟 (1秒)
        backoffMultiplier: 2 // 延迟倍增因子
    }
};
/**
 * 平台特定配置
 */
exports.PlatformConfigs = {
    linux: {
        timeouts: {
            memory: 8000, // Linux内存测试超时
            disk: 6000, // Linux磁盘测试超时
            network: 8000, // Linux网络测试超时
            cpu: 5000 // Linux CPU测试超时
        },
        features: {
            procFilesystem: true, // 支持/proc文件系统
            loadavg: true, // 支持负载平均值
            networkInterfaces: ['lo', 'eth0', 'wlan0', 'enp', 'wlp'],
            expectedCommands: ['free', 'df', 'vmstat', 'netstat', 'ps', 'top', 'lscpu']
        },
        paths: {
            procMeminfo: '/proc/meminfo',
            procCpuinfo: '/proc/cpuinfo',
            procStat: '/proc/stat',
            procLoadavg: '/proc/loadavg',
            procNetDev: '/proc/net/dev'
        },
        validation: {
            memoryMinMB: 512, // 最小内存要求 (512MB)
            diskMinGB: 1, // 最小磁盘空间 (1GB)
            cpuMinCount: 1 // 最小CPU核心数
        }
    },
    darwin: {
        timeouts: {
            memory: 10000, // macOS内存测试超时
            disk: 12000, // macOS磁盘测试超时
            network: 10000, // macOS网络测试超时
            cpu: 6000 // macOS CPU测试超时
        },
        features: {
            procFilesystem: false, // 不支持/proc文件系统
            loadavg: true, // 支持负载平均值
            networkInterfaces: ['lo0', 'en0', 'en1', 'wi0', 'awdl0', 'utun'],
            expectedCommands: ['vm_stat', 'top', 'df', 'netstat', 'system_profiler', 'sysctl'],
            applesilicon: process.arch === 'arm64' // Apple Silicon检测
        },
        paths: {
            mountPoint: '/',
            systemVolumesData: '/System/Volumes/Data',
            privatePath: '/private'
        },
        validation: {
            memoryMinMB: 4000, // 最小内存要求 (4GB，macOS典型配置)
            diskMinGB: 10, // 最小磁盘空间 (10GB)
            cpuMinCount: 2, // 最小CPU核心数
            cpuModelPatterns: /(Apple|Intel|M[0-9]+|Core)/i
        }
    },
    win32: {
        timeouts: {
            memory: 15000, // Windows内存测试超时
            disk: 15000, // Windows磁盘测试超时
            network: 12000, // Windows网络测试超时
            cpu: 8000 // Windows CPU测试超时
        },
        features: {
            procFilesystem: false, // 不支持/proc文件系统
            loadavg: false, // 不完全支持负载平均值
            networkInterfaces: ['Ethernet', 'Wi-Fi', 'Wireless', 'Local Area Connection', 'loopback'],
            expectedCommands: ['wmic', 'tasklist', 'systeminfo', 'netstat', 'powershell'],
            unsupportedFeatures: ['loadavg', 'uptime']
        },
        paths: {
            systemDrive: 'C:',
            commonDrives: ['C:', 'D:', 'E:', 'F:']
        },
        validation: {
            memoryMinMB: 2000, // 最小内存要求 (2GB)
            diskMinGB: 5, // 最小磁盘空间 (5GB)
            cpuMinCount: 1, // 最小CPU核心数
            cpuModelPatterns: /(Intel|AMD|Ryzen|Core)/i
        }
    }
};
/**
 * 获取当前平台的配置
 */
function getCurrentPlatformConfig() {
    const platform = os.platform();
    return exports.PlatformConfigs[platform] || exports.PlatformConfigs.linux; // 默认使用Linux配置
}
exports.getCurrentPlatformConfig = getCurrentPlatformConfig;
/**
 * 获取平台特定的超时时间
 */
function getPlatformTimeout(category) {
    const config = getCurrentPlatformConfig();
    const timeoutKey = category;
    return config.timeouts[timeoutKey] || exports.TestGlobalConfig.timeouts.default;
}
exports.getPlatformTimeout = getPlatformTimeout;
/**
 * 检查功能是否在当前平台上支持
 */
function isFeatureSupported(feature) {
    const config = getCurrentPlatformConfig();
    if ('unsupportedFeatures' in config && config.unsupportedFeatures && Array.isArray(config.unsupportedFeatures)) {
        return !config.unsupportedFeatures.includes(feature);
    }
    // 默认支持所有功能
    return true;
}
exports.isFeatureSupported = isFeatureSupported;
/**
 * 获取平台特定的验证阈值
 */
function getPlatformValidation() {
    const config = getCurrentPlatformConfig();
    return {
        ...exports.TestGlobalConfig.validation,
        ...config.validation
    };
}
exports.getPlatformValidation = getPlatformValidation;
/**
 * CI/CD 环境检测和配置
 */
exports.CIConfig = {
    isCI: !!(process.env.CI ||
        process.env.CONTINUOUS_INTEGRATION ||
        process.env.GITHUB_ACTIONS ||
        process.env.TRAVIS ||
        process.env.JENKINS_URL),
    // CI环境下的特殊配置
    adjustments: {
        timeoutMultiplier: 2, // CI环境超时时间加倍
        maxMemoryIncreaseMB: 20, // CI环境允许更大内存增长
        retryAttempts: 5, // CI环境增加重试次数
        skipPerformanceTests: true // CI环境可能跳过性能测试
    }
};
/**
 * 应用CI环境调整
 */
function getAdjustedConfig() {
    if (!exports.CIConfig.isCI) {
        return exports.TestGlobalConfig;
    }
    return {
        ...exports.TestGlobalConfig,
        timeouts: {
            ...exports.TestGlobalConfig.timeouts,
            default: exports.TestGlobalConfig.timeouts.default * exports.CIConfig.adjustments.timeoutMultiplier,
            long: exports.TestGlobalConfig.timeouts.long * exports.CIConfig.adjustments.timeoutMultiplier,
            performance: exports.TestGlobalConfig.timeouts.performance * exports.CIConfig.adjustments.timeoutMultiplier
        },
        performance: {
            ...exports.TestGlobalConfig.performance,
            maxMemoryIncreaseMB: exports.CIConfig.adjustments.maxMemoryIncreaseMB
        },
        retry: {
            ...exports.TestGlobalConfig.retry,
            maxAttempts: exports.CIConfig.adjustments.retryAttempts
        }
    };
}
exports.getAdjustedConfig = getAdjustedConfig;
//# sourceMappingURL=test-config.js.map