export const RELEASE_GATE_NODE_SCHEMA = 'sks.release-gates.v2';
export const RELEASE_GATE_RESOURCE_CLASSES = [
    'cpu-light',
    'cpu-heavy',
    'io-light',
    'io-heavy',
    'git',
    'git-worktree',
    'zellij-real',
    'local-llm-real',
    'remote-model-real',
    'python',
    'network',
    'global-config',
    'publish',
    'fs-read'
];
export function validateReleaseGateManifest(input) {
    const errors = [];
    if (input?.schema !== RELEASE_GATE_NODE_SCHEMA)
        errors.push('schema_mismatch');
    if (!Array.isArray(input?.gates))
        errors.push('gates_missing');
    const ids = new Set();
    const resources = new Set(RELEASE_GATE_RESOURCE_CLASSES);
    for (const gate of Array.isArray(input?.gates) ? input.gates : []) {
        if (!gate?.id)
            errors.push('gate_id_missing');
        if (gate?.id && ids.has(gate.id))
            errors.push(`gate_duplicate:${gate.id}`);
        if (gate?.id)
            ids.add(gate.id);
        if (!gate?.command)
            errors.push(`gate_command_missing:${gate?.id || 'unknown'}`);
        if (!Array.isArray(gate?.deps))
            errors.push(`gate_deps_missing:${gate?.id || 'unknown'}`);
        if (!Array.isArray(gate?.resource) || !gate.resource.length)
            errors.push(`gate_resource_missing:${gate?.id || 'unknown'}`);
        for (const resource of Array.isArray(gate?.resource) ? gate.resource : []) {
            if (!resources.has(resource))
                errors.push(`gate_unknown_resource:${gate?.id || 'unknown'}:${resource}`);
        }
        if (gate?.side_effect !== 'hermetic' && gate?.side_effect !== 'real-env')
            errors.push(`gate_side_effect_invalid:${gate?.id || 'unknown'}`);
        if (!Number.isFinite(Number(gate?.timeout_ms)) || Number(gate.timeout_ms) <= 0)
            errors.push(`gate_timeout_missing:${gate?.id || 'unknown'}`);
        if (!gate?.cache || typeof gate.cache.enabled !== 'boolean' || !Array.isArray(gate.cache.inputs))
            errors.push(`gate_cache_missing:${gate?.id || 'unknown'}`);
        if (!gate?.isolation || gate.isolation.report_dir !== 'per-gate')
            errors.push(`gate_isolation_missing:${gate?.id || 'unknown'}`);
        if (!Array.isArray(gate?.preset))
            errors.push(`gate_preset_missing:${gate?.id || 'unknown'}`);
    }
    for (const gate of Array.isArray(input?.gates) ? input.gates : []) {
        for (const dep of Array.isArray(gate?.deps) ? gate.deps : []) {
            if (!ids.has(dep))
                errors.push(`gate_unknown_dep:${gate.id}:${dep}`);
        }
    }
    return errors.length ? { ok: false, errors } : { ok: true, manifest: input, errors };
}
//# sourceMappingURL=release-gate-node.js.map