// engine/validator/gates/index.ts — gate runner aggregator
import { readFile } from 'node:fs/promises';
import { join, dirname } from 'node:path';
import { runTypecheckGate, runTodoGate } from './code-gates.js';
import { runTestFilesGate, runTestRunnerGate } from './test-gates.js';
import { runConventionsGate, runLintBaselineGate } from './convention-gates.js';
/**
 * Read progress.md content for a spec. Returns null if not found.
 */
async function readProgressContent(spec) {
    if (spec.progressPath) {
        try {
            return await readFile(spec.progressPath, 'utf-8');
        }
        catch {
            return null;
        }
    }
    if (spec.specPath) {
        try {
            const progressPath = join(dirname(spec.specPath), 'progress.md');
            return await readFile(progressPath, 'utf-8');
        }
        catch {
            return null;
        }
    }
    return null;
}
/**
 * Build a plain-text summary for text scanning.
 * Uses spec title and tags as a proxy for acceptance criteria when no spec.md content is available.
 */
function buildCriteriaText(spec) {
    const parts = [spec.title];
    if (spec.tags.length > 0) {
        parts.push(spec.tags.join(' '));
    }
    return parts.join('\n');
}
/**
 * Run all DoD gates for a spec and aggregate results.
 * A gate failure means status === 'failed' on a required (non-skipped) gate.
 * Skipped gates never block.
 */
export async function runAllGates(spec, projectPath) {
    const progressContent = await readProgressContent(spec);
    const criteriaText = buildCriteriaText(spec);
    const results = await Promise.all([
        runTypecheckGate(projectPath),
        runTodoGate(projectPath, progressContent),
        runTestFilesGate(projectPath, criteriaText, progressContent),
        runTestRunnerGate(projectPath),
        runConventionsGate(projectPath, progressContent),
        runLintBaselineGate(projectPath),
    ]);
    const failedCount = results.filter((r) => r.status === 'failed').length;
    const skippedCount = results.filter((r) => r.status === 'skipped').length;
    const passed = failedCount === 0;
    return { passed, results, failedCount, skippedCount };
}
//# sourceMappingURL=index.js.map