// tools/tdd-scaffold-handler.ts — SPEC-323
// Wraps tdd-scaffold-generator + coverage-gap-analyzer for MCP tool handlers.
import { generateTddScaffold } from '../engine/tdd-scaffold-generator.js';
import { analyzeCoverageGaps } from '../engine/coverage-gap-analyzer.js';
import { generateMutationConfig } from '../engine/mutation-config-generator.js';
import { generateTestSpec } from '../engine/test-spec-generator/index.js';
// ---------------------------------------------------------------------------
// tdd_scaffold handler
// ---------------------------------------------------------------------------
export async function handleTddScaffold(args) {
    const result = await generateTddScaffold(args.specPath, args.projectPath);
    const lines = [
        '## TDD Scaffold Generated',
        '',
        `**Framework detected:** ${result.framework}`,
        `**Stubs generated:** ${result.stubs.length}`,
        '',
        '### Test file',
        `\`${result.testFilePath}\``,
        '',
        '```',
        result.testContent,
        '```',
        '',
        '### Implementation skeleton',
        `\`${result.implFilePath}\``,
        '',
        '```',
        result.implContent,
        '```',
        '',
        '### Next steps',
        ...result.instructions.map((i) => `- ${i}`),
    ];
    // SPEC-627: Enrich output with scenario breakdown from criteria
    if (result.stubs.length > 0) {
        const testSpec = generateTestSpec('SPEC', 'SPEC', result.stubs.map((s) => s.criterion), 'en');
        if (testSpec.totalScenarios > 0) {
            lines.push('', '### Scenario breakdown (from test-spec-generator)', '');
            for (const entry of testSpec.scenarios) {
                lines.push(`**${entry.criterionId}**: ${entry.criterion}`);
                for (const s of entry.scenarios) {
                    lines.push(`  - ${s.type}: GIVEN ${s.given} WHEN ${s.when} THEN ${s.then}`);
                }
            }
        }
    }
    return {
        content: [{ type: 'text', text: lines.join('\n') }],
        structuredContent: result,
    };
}
// ---------------------------------------------------------------------------
// coverage_gap_analyzer handler
// ---------------------------------------------------------------------------
export async function handleCoverageGapAnalyzer(args) {
    const report = await analyzeCoverageGaps(args.specPath, args.projectPath);
    const gapLines = report.gaps.map((g) => `- [${g.riskLevel.toUpperCase()}] **${g.riskDomain}** — ${g.criterion}\n  → ${g.recommendation}`);
    const lines = [
        '## Coverage Gap Analysis',
        '',
        `**Coverage score:** ${report.coverageScore}% (${report.coveredCriteria}/${report.totalCriteria} ACs covered)`,
        `**Test files scanned:** ${report.testFilesScanned}`,
        `**Gaps found:** ${report.gaps.length}`,
        '',
    ];
    if (report.gaps.length === 0) {
        lines.push('All acceptance criteria appear to be covered by existing tests.');
    }
    else {
        lines.push('### Untested Acceptance Criteria (ranked by risk)', '');
        lines.push(...gapLines);
    }
    return {
        content: [{ type: 'text', text: lines.join('\n') }],
        structuredContent: report,
    };
}
// ---------------------------------------------------------------------------
// run_mutation_hints handler
// ---------------------------------------------------------------------------
export async function handleRunMutationHints(args) {
    const result = await generateMutationConfig(args.projectPath);
    const lines = [
        '## Mutation Testing Config',
        '',
        `**Tool:** ${result.tool}`,
        `**Framework:** ${result.framework}`,
        `**Config file:** \`${result.configFileName}\``,
        '',
        '### CI step',
        '```bash',
        result.ciStep,
        '```',
        '',
        '### Config content',
        '```',
        result.configContent,
        '```',
    ];
    return {
        content: [{ type: 'text', text: lines.join('\n') }],
        structuredContent: result,
    };
}
//# sourceMappingURL=tdd-scaffold-handler.js.map