--- name: diagnosticar-cobertura-testes description: > Diagnóstico de cobertura de testes: identificar áreas sem cobertura, priorizar criação de testes e mapear cenários ausentes. scope: local --- # Skill: Diagnosticar Cobertura de Testes ## Objetivo Mapear a cobertura de testes de um módulo para identificar gaps críticos antes de criar novos testes ou validar correções. ## Etapas ### 1. Inventariar Testes Existentes ```sh # Listar arquivos de teste fd "*.spec.ts" / -l fd "*.test.ts" / -l # Contar testes por pacote echo "=== Back ===" && fd "*.spec.ts" -back/ | wc -l echo "=== Front ===" && fd "*.spec.ts" -front/ | wc -l echo "=== Comuns ===" && fd "*.spec.ts" -comuns/ | wc -l ``` ### 2. Mapear Código Sem Testes ```sh # Listar arquivos de código sem arquivo de teste correspondente for f in $(fd "*.ts" -back/src/ --exclude "*.spec.ts" --exclude "*.test.ts" --exclude "*.d.ts"); do base=$(basename "$f" .ts) if ! fd "${base}.spec.ts" / -q && ! fd "${base}.test.ts" / -q; then echo "SEM TESTE: $f" fi done ``` ### 3. Classificar por Criticidade | Criticidade | O que testar primeiro | |-------------|----------------------| | 🔴 Crítico | Lógica de negócio em `servicos/`, schemas Zod, máquinas de estado | | 🟡 Importante | Rotas de API, processadores de fila, composables complexos | | 🟢 Desejável | Utils, helpers, componentes de UI puros | ### 4. Verificar Qualidade dos Testes Existentes ```sh # Detectar testes sem assertions rg "expect\(|assert\(|toBe\(|toEqual\(" --include='*.spec.ts' / -c | awk -F: '$2==0' # Detectar testes com descrições vagas rg "it\('" --include='*.spec.ts' / -n | grep -i "should work\|test\|funciona" # Verificar mocks sem documentação rg "mock\(|jest\.fn\(|vi\.fn\(" --include='*.spec.ts' / -n ``` ### 5. Gerar Relatório ```markdown # Diagnóstico de Cobertura — [nome do módulo] ## Resumo - **Arquivos de código:** N - **Arquivos de teste:** N - **Cobertura estimada:** N% - **Gaps críticos:** N ## Gaps de Cobertura ### 🔴 Sem teste — Lógica Crítica | Arquivo | Responsabilidade | Risco | |---------|-----------------|-------| ### 🟡 Sem teste — Funcionalidade Importante | Arquivo | Responsabilidade | Risco | |---------|-----------------|-------| ## Testes Existentes com Problemas | Arquivo de Teste | Problema | Ação | |-----------------|----------|------| ## Plano de Priorização 1. [Crítico] Criar testes para ... 2. [Crítico] Criar testes para ... 3. [Importante] Criar testes para ... ``` ## Referências - Rule: `global/rules/diagnostico-antes-correcao` - Skill: `global/skills/diagnosticar-antes-corrigir/SKILL`