/**
 * 测试策略契约 — 问题三十四 (Test Strategy Contract)。
 *
 * 核心规则:
 * - enforced contract 必须有 lifecycle test
 * - safety guard 必须有 must_fail case
 * - 测试数量不得作为质量 KPI
 * - skipped 不得计入 coverage
 * - 不得以测试数量作为清理目标
 */
/**
 * 评估契约测试覆盖。
 */
export function evaluateTestCoverage(contractId, existingTests) {
    const requiredTypes = ["unit", "contract"];
    const satisfiedTypes = [];
    const testFiles = [];
    let hasLifecycle = false;
    let hasMustFail = false;
    for (const test of existingTests) {
        testFiles.push(test.file);
        if (!satisfiedTypes.includes(test.type)) {
            satisfiedTypes.push(test.type);
        }
        if (test.is_lifecycle)
            hasLifecycle = true;
        if (test.is_must_fail)
            hasMustFail = true;
    }
    // lifecycle test 对 enforced 是必须的
    if (hasLifecycle && !satisfiedTypes.includes("lifecycle")) {
        satisfiedTypes.push("lifecycle");
    }
    const missingTypes = requiredTypes.filter((t) => !satisfiedTypes.includes(t));
    let status;
    if (missingTypes.length === 0 && hasLifecycle) {
        status = "satisfied";
    }
    else if (satisfiedTypes.length > 0) {
        status = "partial";
    }
    else {
        status = "missing";
    }
    return {
        contract_id: contractId,
        required_test_types: requiredTypes,
        coverage_status: status,
        satisfied_types: satisfiedTypes,
        missing_types: missingTypes,
        test_files: testFiles,
        has_lifecycle_test: hasLifecycle,
        has_must_fail_case: hasMustFail,
    };
}
/**
 * 评估测试清理候选。
 * 不得以数量作为清理目标；必须有独有断言迁移证明。
 */
export function evaluateTestPrune(targetFiles, uniqueAssertions, riskCoverage) {
    const canPrune = uniqueAssertions === 0 && riskCoverage.length === 0;
    return {
        target_files: targetFiles,
        unique_assertions: uniqueAssertions,
        risk_coverage: riskCoverage,
        can_prune: canPrune,
        prune_reason: canPrune
            ? undefined
            : uniqueAssertions > 0
                ? "测试包含独有断言，不可清理"
                : "测试覆盖独有风险，不可清理",
    };
}
/**
 * 验证测试策略规则。
 */
export function validateTestStrategy(contractId, isEnforced, coverage) {
    const errors = [];
    if (isEnforced && !coverage.has_lifecycle_test) {
        errors.push({
            error: `enforced 契约 ${contractId} 缺少 lifecycle test`,
            severity: "hard_fail",
        });
    }
    if (coverage.coverage_status === "missing") {
        errors.push({
            error: `契约 ${contractId} 测试覆盖为 missing`,
            severity: isEnforced ? "hard_fail" : "warning",
        });
    }
    return errors;
}
//# sourceMappingURL=test_strategy.js.map