// engine/advanced-testing/mutation-advisor.ts — SPEC-049
// Recommends mutation testing configuration based on project language and coverage.
/** Minimum coverage required before recommending mutation testing. */
const MIN_COVERAGE_FOR_MUTATION = 90;
/**
 * Determine if mutation testing should be recommended.
 * Only recommended when line/branch coverage is already >= 90%.
 */
export function shouldRecommendMutation(coverage) {
    return coverage >= MIN_COVERAGE_FOR_MUTATION;
}
/** Map a language to its primary mutation testing tool. */
export function getMutationTool(language) {
    const lang = language.toLowerCase();
    if (lang === 'typescript' || lang === 'javascript') {
        return 'stryker';
    }
    if (lang === 'python') {
        return 'mutmut';
    }
    if (lang === 'java' || lang === 'kotlin') {
        return 'pitest';
    }
    if (lang === 'rust') {
        return 'cargo-mutants';
    }
    if (lang === 'go') {
        return 'gremlins';
    }
    if (lang === 'scala') {
        return 'stryker4s';
    }
    if (lang === 'csharp' || lang === 'fsharp') {
        return 'stryker-dotnet';
    }
    return 'stryker';
}
/** Generate the Stryker config file content for JS/TS with Vitest. */
function buildStrykerVitestConfig(thresholdScore) {
    return `// stryker.config.mjs
/** @type {import('@stryker-mutator/api/core').PartialStrykerOptions} */
const config = {
  testRunner: 'vitest',
  plugins: ['@stryker-mutator/vitest-runner'],
  coverageAnalysis: 'perTest',
  thresholds: {
    high: ${thresholdScore},
    low: ${Math.max(thresholdScore - 10, 60)},
    break: ${Math.max(thresholdScore - 20, 50)},
  },
  mutate: [
    'src/**/*.ts',
    '!src/**/*.test.ts',
    '!src/**/*.spec.ts',
    '!src/**/index.ts',
    '!src/config/**',
  ],
  reporters: ['html', 'json', 'progress'],
  htmlReporter: { fileName: 'reports/mutation/index.html' },
  jsonReporter: { fileName: 'reports/mutation/mutation.json' },
  concurrency: 4,
  timeoutMS: 60000,
};

export default config;
`;
}
/** Generate the mutmut config for Python projects. */
function buildMutmutConfig() {
    return `# setup.cfg — mutmut configuration
[mutmut]
paths_to_mutate=src/
backup=False
runner=python -m pytest -x --timeout=10
tests_dir=tests/
dict_synonyms=
`;
}
/** Generate the PIT (Pitest) Maven plugin config for Java. */
function buildPitestConfig(thresholdScore) {
    return `<!-- pom.xml — PIT mutation testing plugin -->
<plugin>
  <groupId>org.pitest</groupId>
  <artifactId>pitest-maven</artifactId>
  <version>1.15.0</version>
  <configuration>
    <targetClasses>
      <param>com.yourcompany.*</param>
    </targetClasses>
    <targetTests>
      <param>com.yourcompany.*Test</param>
    </targetTests>
    <mutationThreshold>${thresholdScore}</mutationThreshold>
    <coverageThreshold>90</coverageThreshold>
    <outputFormats>
      <outputFormat>HTML</outputFormat>
      <outputFormat>XML</outputFormat>
    </outputFormats>
    <timestampedReports>false</timestampedReports>
    <threads>4</threads>
  </configuration>
</plugin>
`;
}
/** Generate the cargo-mutants config for Rust projects. */
function buildCargoMutantsConfig() {
    return `# .cargo-mutants.toml
timeout_multiplier = 3.0
in_place = false
jobs = 4

# Exclude generated or external code
exclude_globs = [
  "src/generated/**",
  "src/vendor/**",
]
`;
}
/** Generate the gremlins config for Go projects. */
function buildGremlinsConfig(thresholdScore) {
    return `# .gremlins.yaml
threshold:
  mutant_coverage: ${thresholdScore}
  efficiency: 100

mutants:
  arithmetic_base:
    enabled: true
  conditional_boundary:
    enabled: true
  negate_conditionals:
    enabled: true
  remove_negation:
    enabled: true

output:
  go_module: true
`;
}
/** Generate the Stryker4s config for Scala projects. */
function buildStryker4sConfig(thresholdScore) {
    return `// stryker4s.conf
stryker4s {
  mutate = ["src/main/scala/**/*.scala"]
  thresholds {
    high = ${thresholdScore}
    low = ${Math.max(thresholdScore - 10, 60)}
    break = ${Math.max(thresholdScore - 20, 50)}
  }
  reporters = ["html", "json"]
  base-dir = .
}
`;
}
/** Generate the Stryker .NET config. */
function buildStrykerDotnetConfig(thresholdScore) {
    return `// stryker-config.json
{
  "stryker-config": {
    "project": "YourProject.csproj",
    "test-projects": ["YourProject.Tests/YourProject.Tests.csproj"],
    "threshold-high": ${thresholdScore},
    "threshold-low": ${Math.max(thresholdScore - 10, 60)},
    "threshold-break": ${Math.max(thresholdScore - 20, 50)},
    "reporters": ["html", "json"],
    "concurrency": 4
  }
}
`;
}
/**
 * Generate a mutation testing configuration for the given tool and language.
 * Returns the full MutationConfig with config file content and threshold.
 */
export function generateMutationConfig(tool, language) {
    const thresholdScore = 80;
    let configFileContent = buildStrykerVitestConfig(thresholdScore);
    switch (tool) {
        case 'stryker':
            configFileContent = buildStrykerVitestConfig(thresholdScore);
            break;
        case 'mutmut':
        case 'cosmic-ray':
            configFileContent = buildMutmutConfig();
            break;
        case 'pitest':
            configFileContent = buildPitestConfig(thresholdScore);
            break;
        case 'cargo-mutants':
            configFileContent = buildCargoMutantsConfig();
            break;
        case 'gremlins':
            configFileContent = buildGremlinsConfig(thresholdScore);
            break;
        case 'stryker4s':
            configFileContent = buildStryker4sConfig(thresholdScore);
            break;
        case 'stryker-dotnet':
            configFileContent = buildStrykerDotnetConfig(thresholdScore);
            break;
    }
    const excludePatterns = getDefaultExcludePatterns(language);
    const includeReporters = ['html', 'json', 'progress'];
    return {
        tool,
        thresholdScore,
        configFile: configFileContent,
        excludePatterns,
        includeReporters,
    };
}
/** Return sensible default exclude patterns for a language. */
function getDefaultExcludePatterns(language) {
    const lang = language.toLowerCase();
    if (lang === 'typescript' || lang === 'javascript') {
        return ['**/*.test.ts', '**/*.spec.ts', '**/index.ts', 'src/config/**', 'src/types/**'];
    }
    if (lang === 'python') {
        return ['tests/**', 'setup.py', 'conftest.py'];
    }
    if (lang === 'java' || lang === 'kotlin') {
        return ['**/*Test*.java', '**/*Spec*.java'];
    }
    return ['**/*.test.*', '**/*.spec.*'];
}
//# sourceMappingURL=mutation-advisor.js.map