// tools/create-spec-hu/ai-testing-governance-adapter.ts — SPEC-049 TD-P14-02
// Adds AI-generated test lifecycle ownership criterion when CI is established
// or when AI testing tools (Keploy, Qodo, Diffblue) are detected in the stack.
/** AI testing tools that trigger the lifecycle ownership criterion */
const AI_TESTING_TOOLS = ['keploy', 'qodo', 'diffblue', 'testim', 'mabl', 'functionize'];
/**
 * Returns true when the project uses AI-generated test tools in its stack.
 */
function hasAiTestingTools(knowledge) {
    if (!knowledge) {
        return false;
    }
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    const stackItems = (knowledge.stack ?? []).map((s) => s.toLowerCase());
    return stackItems.some((s) => AI_TESTING_TOOLS.some((tool) => s.includes(tool)));
}
/**
 * Returns true when the project has established CI workflows.
 */
function hasCiEstablished(knowledge) {
    if (!knowledge) {
        return false;
    }
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    const conventions = knowledge.conventions ?? {};
    const allConventions = Object.values(conventions).map((v) => v.toLowerCase());
    if (allConventions.some((v) => v.includes('ci') || v.includes('github-actions'))) {
        return true;
    }
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    const hasCiInStack = (knowledge.stack ?? []).some((s) => {
        const lower = s.toLowerCase();
        return (lower.includes('github-actions') ||
            lower.includes('gitlab-ci') ||
            lower.includes('circleci') ||
            lower.includes('jenkins'));
    });
    if (hasCiInStack) {
        return true;
    }
    // Check tooling for CI indicators
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    const tooling = knowledge.tooling ?? {};
    const toolingValues = Object.values(tooling).map((v) => v.toLowerCase());
    return toolingValues.some((v) => v.includes('ci') || v.includes('github') || v.includes('pipeline'));
}
/**
 * Build the AI testing governance section for HU.md.
 * Emits an AI test lifecycle ownership criterion when CI is established
 * or when AI testing tools (Keploy, Qodo, Diffblue) are detected in the stack.
 */
export function buildAiTestingGovernanceSection(knowledge) {
    const triggeredByCi = hasCiEstablished(knowledge);
    const triggeredByAiTools = hasAiTestingTools(knowledge);
    if (!triggeredByCi && !triggeredByAiTools) {
        return [];
    }
    const lines = [
        '',
        '## AI Testing Governance',
        '',
        '- [ ] Los tests generados por IA tienen ownership de lifecycle definido: ' +
            'la política documenta si los tests generados se revisan manualmente antes de merge ' +
            'o se auto-confían — esta política está documentada, no es implícita',
        '- [ ] Cada test AI-generado debe tener un owner humano asignado que lo revisa y mantiene',
        '',
    ];
    return lines;
}
//# sourceMappingURL=ai-testing-governance-adapter.js.map