// tools/suggest-tooling/advanced-testing-catalog.ts — SPEC-049
// Builds advanced testing pattern tooling recommendation lines for suggest_tooling.
import { isWebProject, isKubernetesProject, hasPiiSignals, } from '../../engine/advanced-testing/index.js';
/**
 * Build advanced testing tooling recommendation lines.
 * Emits sections based on detected project characteristics.
 */
export function buildAdvancedTestingToolingLines(knowledge) {
    const lines = [];
    const lang = knowledge.language.toLowerCase();
    const stack = knowledge.stack;
    // Property-based testing — for any project with domain logic
    lines.push('', '## Advanced Testing Patterns', '');
    // S1 — Property-Based Testing
    lines.push('### Property-Based Testing (PBT)', '');
    if (lang === 'typescript' || lang === 'javascript') {
        lines.push('**fast-check** — Property-based testing for JS/TS (60K npm/week)');
        lines.push('- Install: `pnpm add -D fast-check`');
        lines.push('- Docs: https://fast-check.dev');
        lines.push('- Use for: invariants, idempotency, commutativity — detect edge cases unit tests miss');
    }
    else if (lang === 'python') {
        lines.push('**Hypothesis** — Property-based testing for Python (100K+ downloads/day)');
        lines.push('- Install: `pip install hypothesis`');
        lines.push('- Docs: https://hypothesis.readthedocs.io');
        lines.push('- CI config: `@settings(max_examples=100, deadline=None)` recommended');
    }
    else if (lang === 'rust') {
        lines.push('**proptest** — Property-based testing for Rust');
        lines.push('- Install: `cargo add --dev proptest`');
        lines.push('- Docs: https://proptest-rs.github.io/proptest');
    }
    else if (lang === 'java' || lang === 'kotlin') {
        lines.push('**jqwik** — Property-based testing for JVM (works with JUnit 5)');
        lines.push('- Install: `implementation("net.jqwik:jqwik:1.8.0")`');
        lines.push('- Docs: https://jqwik.net');
    }
    else if (lang === 'go') {
        lines.push('**gopter** — Property-based testing for Go');
        lines.push('- Install: `go get github.com/leanovate/gopter`');
        lines.push('- Docs: https://github.com/leanovate/gopter');
    }
    else {
        lines.push('**fast-check** (JS/TS), **Hypothesis** (Python), **proptest** (Rust)');
        lines.push('- Choose based on your language — all support invariant testing');
    }
    lines.push('');
    // S2 — Mutation Testing
    {
        lines.push('### Mutation Testing', '');
        lines.push('> Recommended when line/branch coverage is already ≥90%.');
        lines.push('');
        if (lang === 'typescript' || lang === 'javascript') {
            lines.push('**Stryker Mutator** — JS/TS mutation testing (5K+ GitHub stars)');
            lines.push('- Install: `pnpm add -D @stryker-mutator/core @stryker-mutator/vitest-runner`');
            lines.push('- Config: `testRunner: "vitest"` in stryker.config.mjs');
            lines.push('- Threshold: mutationScore ≥ 80% for critical modules');
            lines.push('- Docs: https://stryker-mutator.io');
        }
        else if (lang === 'python') {
            lines.push('**mutmut** — Python mutation testing');
            lines.push('- Install: `pip install mutmut`');
            lines.push('- Docs: https://mutmut.readthedocs.io');
        }
        else if (lang === 'java' || lang === 'kotlin') {
            lines.push('**PIT (Pitest)** — Java mutation testing');
            lines.push('- Maven plugin: `org.pitest:pitest-maven`');
            lines.push('- Docs: https://pitest.org');
        }
        else if (lang === 'rust') {
            lines.push('**cargo-mutants** — Rust mutation testing');
            lines.push('- Install: `cargo install cargo-mutants`');
            lines.push('- Docs: https://mutants.rs');
        }
        else if (lang === 'go') {
            lines.push('**gremlins** — Go mutation testing');
            lines.push('- Install: `go install github.com/go-gremlins/gremlins/cmd/gremlins@latest`');
            lines.push('- Docs: https://github.com/go-gremlins/gremlins');
        }
        lines.push('');
    }
    // S3 — Chaos Engineering (only when k8s detected)
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    const files = Object.keys(knowledge.tooling ?? {}).concat(stack);
    if (isKubernetesProject(files)) {
        lines.push('### Chaos Engineering (Kubernetes detected)', '');
        lines.push('**LitmusChaos** — CNCF chaos engineering platform (30M Docker pulls)');
        lines.push('- Install: `kubectl apply -f https://litmuschaos.github.io/litmus/litmus-operator-v3.0.0.yaml`');
        lines.push('- Experiments: pod-delete, network-latency, node-failure, cpu-stress');
        lines.push('- Docs: https://litmuschaos.io');
        lines.push('');
        lines.push('**Alternatives:**');
        lines.push('- AWS Fault Injection Simulator: https://docs.aws.amazon.com/fis/');
        lines.push('- Azure Chaos Studio: https://learn.microsoft.com/en-us/azure/chaos-studio/');
        lines.push('- Gremlin (enterprise SaaS): https://www.gremlin.com');
        lines.push('');
    }
    // S4 — Accessibility Testing (web projects only)
    if (isWebProject(stack)) {
        lines.push('### Accessibility Testing (WCAG 2.1 Level AA)', '');
        lines.push('**axe-core + Playwright** — 57% automatic WCAG violation detection (zero false positives)');
        lines.push('- Install: `pnpm add -D axe-playwright`');
        lines.push('- Docs: https://github.com/abhinaba-ghosh/axe-playwright');
        lines.push('');
        lines.push('**jest-axe** — For React component-level a11y tests');
        lines.push('- Install: `pnpm add -D jest-axe @types/jest-axe`');
        lines.push('- Docs: https://github.com/nickcolley/jest-axe');
        lines.push('');
        lines.push('**pa11y-ci** — Automated WCAG scanning in CI pipelines');
        lines.push('- Install: `pnpm add -D pa11y-ci`');
        lines.push('- Standard: WCAG2AA');
        lines.push('- Docs: https://github.com/pa11y/pa11y-ci');
        lines.push('');
        lines.push('> Note: axe-core covers 57% of WCAG violations automatically. Manual testing with real screen readers (NVDA/VoiceOver) is required for full coverage.');
        lines.push('');
    }
    // S5 — Synthetic Data (PII/PHI projects or any project)
    if (hasPiiSignals(stack)) {
        lines.push('### Synthetic Data Generation (PII/PHI detected)', '');
    }
    else {
        lines.push('### Test Data Management', '');
    }
    if (lang === 'typescript' || lang === 'javascript') {
        lines.push('**@faker-js/faker** — Fake data generation for JS/TS');
        lines.push('- Install: `pnpm add -D @faker-js/faker`');
        lines.push('- Docs: https://fakerjs.dev');
        lines.push('');
        lines.push('**fishery** — TypeScript factory library (factory_boy for TS)');
        lines.push('- Install: `pnpm add -D fishery`');
        lines.push('- Docs: https://github.com/thoughtbot/fishery');
    }
    else if (lang === 'python') {
        lines.push('**Faker** — Fake data generation for Python (100+ locales)');
        lines.push('- Install: `pip install faker`');
        lines.push('');
        lines.push('**factory_boy** — Factory library for Django/SQLAlchemy fixtures');
        lines.push('- Install: `pip install factory_boy`');
        if (hasPiiSignals(stack)) {
            lines.push('');
            lines.push('**Mimesis** — High-performance fake data — 100+ locales, faster than Faker');
            lines.push('- Install: `pip install mimesis`');
        }
    }
    lines.push('');
    // AI-assisted testing (always show as supplemental)
    lines.push('### AI-Assisted Test Generation (supplemental)', '');
    lines.push('**Keploy** — Captures real traffic → generates tests (Go/Java/Node/Python)');
    lines.push('- Install: `curl --silent --location "https://get.keploy.io" | bash`');
    lines.push('- Docs: https://keploy.io/docs');
    lines.push('- Note: Complement to manually-written tests, not a substitute');
    lines.push('');
    // SPEC-049 TD-P14-01: Autonomous testing agents section for mature projects
    if (hasMatureCiAndCoverage(knowledge)) {
        lines.push('### Autonomous Testing Agents (mature CI detected)', '');
        lines.push('> Your project shows signals of mature CI (≥90% coverage target, established pipeline).');
        lines.push('> Autonomous testing agents can amplify your test suite in 2026:');
        lines.push('');
        lines.push('**Keploy** — AI traffic-to-test recorder — auto-generates tests from real API calls');
        lines.push('- Install: `curl --silent --location "https://get.keploy.io" | bash`');
        lines.push('- Docs: https://keploy.io/docs');
        lines.push('');
        lines.push('**Qodo** — AI PR testing agent — reviews and generates tests for PRs automatically');
        lines.push('- Install: Qodo GitHub App → https://www.qodo.ai');
        lines.push('- Docs: https://docs.qodo.ai');
        lines.push('');
        lines.push('> **2026 caution:** Autonomous testing agents (81% adoption in teams using AI for testing)');
        lines.push('> still require human review to validate false positives before blocking merges.');
        lines.push('> Document your AI testing governance policy explicitly — never leave it implicit.');
        lines.push('');
    }
    return lines;
}
/**
 * Returns true when the project shows signals of mature CI and high coverage.
 * Uses conventions map, stack, and quality profile strictness as indicators.
 */
function hasMatureCiAndCoverage(knowledge) {
    const conventionsStr = JSON.stringify(knowledge.conventions).toLowerCase();
    const stackLower = knowledge.stack.map((s) => s.toLowerCase());
    // Explicit coverage convention signals
    const hasCoverageConvention = conventionsStr.includes('coverage') &&
        (conventionsStr.includes('90') ||
            conventionsStr.includes('95') ||
            conventionsStr.includes('100'));
    // CI tools in stack signal mature pipeline
    const hasCiTool = stackLower.some((s) => s.includes('codecov') ||
        s.includes('coveralls') ||
        s.includes('github-actions') ||
        s.includes('gitlab-ci') ||
        s.includes('circleci'));
    // Strict quality profile signals mature testing culture
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    const isStrictProfile = (knowledge.qualityProfile?.strictness ?? 'standard') === 'strict';
    return hasCoverageConvention || (hasCiTool && isStrictProfile);
}
//# sourceMappingURL=advanced-testing-catalog.js.map