// tools/compliance-test-handler.ts — SPEC-390: Compliance Test Suite Generator handlers
import { generateComplianceTests } from '../engine/compliance-test-generator/index.js';
import { getControlsForFrameworks } from '../engine/compliance-test-generator/control-mapper.js';
import { specStore } from '../storage/index.js';
import { hashProjectPath } from '../storage/base-store.js';
export async function handleGenerateComplianceTests(input) {
    const projectId = hashProjectPath(input.projectPath);
    const spec = await specStore.getSpec(projectId, input.specId);
    if (!spec) {
        return {
            content: [
                {
                    type: 'text',
                    text: `Spec "${input.specId}" not found in project at "${input.projectPath}". ` +
                        `Run list_specs to see available specs.`,
                },
            ],
        };
    }
    const outputFormat = input.outputFormat ?? 'jest';
    const result = await generateComplianceTests(spec.specPath, input.specId, input.frameworks, outputFormat);
    const fileLines = result.generatedFiles.map((f) => `  ${f.path} (${f.content.split('\n').length} lines)`);
    const coveredCount = result.coverageReport.filter((r) => r.covered).length;
    const totalCount = result.coverageReport.length;
    const lines = [
        result.message,
        ``,
        `Mapped tests: ${result.mappedTests.length}`,
        `Control coverage: ${coveredCount}/${totalCount}`,
        ``,
        `Generated files:`,
        ...fileLines,
    ];
    if (result.mappedTests.length > 0) {
        lines.push(``, `Preview (first test):`, ``, result.mappedTests[0]?.testCode ?? '');
    }
    return {
        content: [{ type: 'text', text: lines.join('\n') }],
    };
}
export function handleComplianceCoverageReport(input) {
    const controls = getControlsForFrameworks(input.frameworks);
    if (controls.length === 0) {
        return {
            content: [
                {
                    type: 'text',
                    text: `No built-in controls found for frameworks: ${input.frameworks.join(', ')}. ` +
                        `Supported: soc2, pci-dss, iso-42001.`,
                },
            ],
        };
    }
    const controlLines = controls.map((c) => `• [${c.id}] ${c.title}\n  ${c.description}\n  Keywords: ${c.keywords.join(', ')}`);
    const lines = [
        `Compliance controls for ${input.frameworks.join(', ')} (${controls.length} total):`,
        ``,
        ...controlLines,
        ``,
        `Run generate_compliance_tests with a specId to map spec criteria to these controls.`,
    ];
    return {
        content: [{ type: 'text', text: lines.join('\n') }],
    };
}
//# sourceMappingURL=compliance-test-handler.js.map