# 🎯 Testing-Autonomous: 蚊子项目专用配置
# 基于1210个测试经验的优化方案

---

# 1. 目标设定
targets:
  # 覆盖率目标（生产级标准）
  coverage:
    instruction: 85%    # 指令覆盖率
    branch: 60%         # 分支覆盖率
    method: 85%         # 方法覆盖率
    class: 95%          # 类覆盖率
    
  # 质量目标
  quality:
    min_tests_per_class: 5
    max_tests_per_class: 50
    avg_test_execution_time: 100ms  # 毫秒
    
  # 缺陷发现目标
  defects:
    min_boundary_tests: 10
    min_exception_tests: 5
    min_concurrency_tests: 3
    
  # 迭代限制
  iteration:
    max_rounds: 10
    coverage_gain_threshold: 2%  # 每轮至少提升2%

---

# 2. 自动恢复配置
recovery:
  # 超时设置
  timeout_threshold: 300s  # 5分钟无响应视为卡住
  
  # 恢复策略（基于蚊子项目经验）
  strategies:
    # 策略1: DTO默认构造函数缺失
    dto_noargs_constructor:
      trigger: "Cannot construct instance.*no Creators.*exist"
      action: "auto_fix_dto"
      fix_steps:
        - "分析DTO类结构"
        - "添加@NoArgsConstructor注解"
        - "重新编译验证"
        - "重新生成JSON测试"
      max_retry: 3
      
    # 策略2: 文件过大拆分
    file_too_large:
      trigger: "test_file_lines > 500"
      action: "split_to_nested"
      split_rules:
        - "按功能分组(Constructor/Getter/Boundary)"
        - "每类最多100个测试"
        - "使用@Nested注解"
      max_retry: 2
      
    # 策略3: 覆盖率停滞突破
    coverage_stalled:
      trigger: "coverage_gain < 1% after 100 tests"
      action: "switch_strategy"
      alternatives:
        - name: "focus_branches"
          description: "专注分支覆盖"
          target: "if/else/switch语句"
          
        - name: "focus_dtos"
          description: "专注DTO测试"
          target: "com.mosquito.project.dto.*"
          
        - name: "focus_integration"
          description: "专注集成测试"
          target: "API端到端流程"
          
        - name: "use_testcontainers"
          description: "使用真实数据库"
          target: "Repository层"
          
    # 策略4: 内存溢出处理
    out_of_memory:
      trigger: "heap_usage > 90% OR OutOfMemoryError"
      action: "reduce_batch_size"
      batch_sizes: [100, 50, 25, 10]
      cleanup:
        - "强制GC"
        - "清理临时文件"
        - "减少并发线程"

---

# 3. 质量门禁配置
gates:
  # 门禁1: 基础检查（必须全部通过）
  level1_basic:
    compile_check:
      command: "mvn compile -q"
      must_pass: true
      error_message: "编译失败，请检查代码语法"
      
    test_execution:
      command: "mvn test -q"
      must_pass: true
      error_message: "测试执行失败"
      
  # 门禁2: 覆盖率检查
  level2_coverage:
    instruction_coverage:
      metric: "instruction_coverage"
      threshold: 85%
      must_pass: true
      auto_fix: true  # 未达标自动触发优化
      
    branch_coverage:
      metric: "branch_coverage"
      threshold: 60%
      must_pass: false  # 警告但不阻止
      warning_message: "分支覆盖率未达标，建议加强条件测试"
      
    method_coverage:
      metric: "method_coverage"
      threshold: 85%
      must_pass: true
      
  # 门禁3: 质量检查
  level3_quality:
    test_quality_score:
      metric: "test_quality_score"
      threshold: 0.7  # 70分
      must_pass: true
      evaluation_criteria:
        - "代码覆盖贡献 > 0.5"
        - "分支覆盖贡献 > 0.3"
        - "断言数量 >= 2"
        - "复杂度适中"
        
    duplicate_test_ratio:
      metric: "duplicate_test_ratio"
      threshold: 5%  # 重复率<5%
      must_pass: true
      auto_deduplicate: true  # 自动去重
      
    low_value_test_ratio:
      metric: "low_value_test_ratio"
      threshold: 20%  # 低价值测试<20%
      must_pass: false
      warning_message: "低价值测试过多(getter/setter)，建议使用参数化测试"

  # 门禁4: 缺陷检查（建议性质）
  level4_defects:
    boundary_test_coverage:
      metric: "boundary_test_count"
      threshold: 10
      must_pass: false
      suggestion: "增加边界条件测试(null/空值/极大值/负数)"
      
    exception_test_coverage:
      metric: "exception_test_count"
      threshold: 5
      must_pass: false
      suggestion: "增加异常处理测试"
      
    concurrency_test_coverage:
      metric: "concurrency_test_count"
      threshold: 3
      must_pass: false
      suggestion: "增加并发安全测试"

---

# 4. 缺口分析配置
gap_analysis:
  # 未覆盖代码优先级
  priority_rules:
    - condition: "class_name contains 'Config'"
      priority: 10  # 最高
      reason: "配置类影响系统启动"
      
    - condition: "class_name contains 'Service'"
      priority: 9
      reason: "核心业务逻辑"
      
    - condition: "class_name contains 'Controller'"
      priority: 8
      reason: "API入口"
      
    - condition: "class_name contains 'Security'"
      priority: 10
      reason: "安全相关"
      
    - condition: "class_name contains 'Dto' OR class_name contains 'DTO'"
      priority: 7
      reason: "数据传输对象"
      
    - condition: "complexity > 10"
      priority: 9
      reason: "复杂度高，风险大"
      
    - condition: "branch_count > 5"
      priority: 8
      reason: "分支多，测试价值高"
  
  # 忽略规则
  ignore_patterns:
    - "com.mosquito.project.config.Test*"  # 测试配置
    - "*.class"  # 已编译类
    - "target/**"  # 构建目录

---

# 5. 蚊子项目特定优化
mosquito_optimizations:
  # DTO优化（基于发现的问题）
  dto_optimization:
    enabled: true
    actions:
      - "检查并添加@NoArgsConstructor"
      - "验证Jackson兼容性"
      - "生成JSON序列化/反序列化测试"
      - "测试边界值(null/空字符串/极大值)"
    
  # 分支覆盖优化
  branch_optimization:
    enabled: true
    target_classes:
      - "com.mosquito.project.service.*"
      - "com.mosquito.project.web.*"
    focus_areas:
      - "if/else条件分支"
      - "switch语句"
      - "三元运算符"
      - "异常处理路径"
      
  # 配置类优化
  config_optimization:
    enabled: true
    target_classes:
      - "com.mosquito.project.config.AppConfig"
      - "com.mosquito.project.config.CacheConfig"
      - "com.mosquito.project.config.WebMvcConfig"
    test_focus:
      - "默认值验证"
      - "配置加载"
      - "边界条件(0/负数/极大值)"
      - "异常处理(无效配置)"

---

# 6. 监控和日志
monitoring:
  # 进度记录
  progress_log: ".testing-autonomous/progress.log"
  
  # 失败模式记录
  failure_log: ".testing-autonomous/failures.log"
  
  # 覆盖率历史
  coverage_history: ".testing-autonomous/coverage-history.csv"
  
  # 告警设置
  alerts:
    - condition: "coverage < 50% after 3 rounds"
      level: "warning"
      message: "覆盖率提升缓慢，建议检查测试策略"
      
    - condition: "test_execution_time > 2 minutes"
      level: "warning"
      message: "测试执行时间过长，建议优化测试性能"
      
    - condition: "recovery_triggered > 5 times"
      level: "error"
      message: "多次触发恢复机制，建议人工介入检查"

---

# 7. 预设命令
commands:
  # 快速开始
  quick_start: |
    @skill testing-autonomous
    analyze-and-optimize --target 85% --auto-recovery --max-rounds 10
    
  # 仅缺口分析
  gap_analysis_only: |
    @skill testing-autonomous
    analyze-gaps --output report.html
    
  # 质量检查
  quality_check: |
    @skill testing-autonomous
    check-quality --gates all
    
  # 持续优化（适合CI/CD）
  continuous_optimization: |
    @skill testing-autonomous
    optimize --incremental --coverage-threshold 85% --fail-on-miss

---

# 使用说明
# 1. 复制此文件到项目根目录: .testing-autonomous/config.yml
# 2. 根据项目实际情况调整阈值
# 3. 运行: @skill testing-autonomous
# 4. 执行: optimize-project --config .testing-autonomous/config.yml