Skip to content

Fail the PR when its changed files aren't fully covered - #286

Closed
pnzrfst wants to merge 1 commit into
report-coverage-on-prfrom
enforce-coverage-gate
Closed

pnzrfst wants to merge 1 commit into
report-coverage-on-prfrom
enforce-coverage-gate

Conversation

@pnzrfst

@pnzrfst pnzrfst commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Resumo

Terceira PR da série de migração qlty → couve (empilhada sobre #285). Liga o gate couve --fail-on-low-coverage: a partir desta PR, qualquer PR cujo diff toque uma linha não coberta reprova o CI, com o comentário de cobertura mostrando exatamente qual arquivo/linha.

O que muda

  • .github/workflows/config.yml:
    • --fail-on-low-coverage no couve, que é o que de fato liga o gate (sem ele, o couve sempre sai com 0 independente da cobertura).
    • a chamada do couve deixa de rodar direto — é envolvida num if/then/else que captura sucesso/falha em COVERAGE_OK via $GITHUB_ENV. Necessário porque um step que falha aborta na hora (o shell da Action já roda com set -e), o que puxaria o step de comentário junto e o dev veria um X vermelho sem saber por quê.
    • novo último step, que só faz exit 1 quando COVERAGE_OK == 'false' — assim o comentário de cobertura sempre posta antes do job ficar vermelho.
  • spec/spec_helper.rb — exclui spec/support/ do SimpleCov (add_filter '/spec/support/'). Código de suporte de teste (matchers, helpers) é exercitado pelas specs que o usam, não coberto por si só; sem essa exclusão, spec/support/have_same_content_of.rb (hoje em 44%) reprovaria a próxima PR que só tocasse esse helper por motivo nenhum relacionado à mudança real. Mesmo raciocínio documentado em docs/padroes-de-programacao/testes-automatizados/o-que-nao-cobrir.md do facil123.

O que NÃO muda

  • Não mexe nos 5 arquivos de produto que hoje têm gaps reais de cobertura (document.rb ×3 com fallback de method_missing/respond_to_missing?, nfce_lib/header.rb com uma branch real de layout, e lib/prawn/font_metric_cache.rb, um monkey-patch interno do Prawn). Backfill dessas specs é escopo de uma quarta PR, separada.
  • Esta PR passa no próprio gate porque só toca config.yml e spec_helper.rb, nenhum dos dois rastreado por cobertura — confirmado localmente simulando o diff desta PR contra o coverage.json real.
  • Não configura branch protection no GitHub — hoje master não tem nenhuma regra de proteção (protected: false), então um check vermelho não impede tecnicamente o merge, só sinaliza. Configurar isso é uma decisão separada, fora do escopo desta PR.

Plano de teste

  • bundle exec rspec local: suíte verde, spec/support/ confirmado fora do coverage.json
  • bundle exec rubocop --display-cop-names --parallel local: sem ofensas
  • Simulado localmente: diff desta PR (config.yml + spec_helper.rb) rodado através de cc-test-reporter + couve --fail-on-low-coverage → passa limpo (nenhum arquivo coberto alterado)
  • Simulado localmente com um arquivo novo e não coberto: couve --fail-on-low-coverage reprova corretamente (couve: coverage below 100% in ...), e o relatório continua sendo escrito mesmo com a falha
  • CI verde nesta PR (rodando de verdade no Actions)

🤖 Generated with Claude Code

@pnzrfst pnzrfst self-assigned this Aug 18, 2026
@github-actions

Copy link
Copy Markdown

Nenhum arquivo coberto por testes foi alterado nesta PR.

@pnzrfst pnzrfst linked an issue Aug 18, 2026 that may be closed by this pull request
@pnzrfst pnzrfst mentioned this pull request Aug 18, 2026
5 tasks done
@pnzrfst

pnzrfst commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Verificação ao vivo do gate

O gate ligado aqui (--fail-on-low-coverage) foi verificado de propósito em CI real na #288 — dois experimentos: um mostrando que o gate fica cego pra regressão de cobertura em arquivos que a PR não toca (só a spec foi tocada, CI passou), e outro mostrando que ele reprova corretamente quando o arquivo de produto também entra no diff, apontando a linha exata no comentário. Detalhes e links dos runs: #288 (comment)

Turns on couve's --fail-on-low-coverage gate. The couve call is
wrapped instead of run directly, because a failing step aborts
immediately and would skip the comment-posting step — the result is
captured into COVERAGE_OK and the actual exit 1 is deferred to a
final step, so the coverage comment (showing exactly which lines are
uncovered) always posts before the job goes red.

Also excludes spec/support/ from SimpleCov tracking: test-support code
(matchers, helpers) is exercised by the specs that use it, not covered
on its own, and gating on it would incentivize test-for-a-test specs
that verify nothing about br_danfe's actual behavior. Same reasoning
facil123 documents in docs/padroes-de-programacao/testes-automatizados/o-que-nao-cobrir.md.

This PR's own diff only touches this workflow file and spec_helper.rb,
neither tracked by coverage, so it passes its own gate cleanly.
Backfilling specs for the 5 pre-existing product-code gaps is separate
follow-up work.

Refs #283

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
gabrieldeespindula pushed a commit that referenced this pull request Aug 20, 2026
…nally disabled)

Removes header.rb's width_box, dead since PR #159 (2021) replaced its
only bounding_box call site with individual text_box/move_down calls
without removing the method itself.

Adds specs for the method_missing/respond_to_missing? delegation
fallback in the 3 Document wrapper classes (nfce_lib, cce_lib,
nfe_lib) - each mutation-tested locally to confirm it fails when the
real `super` fallback is broken.

Excludes lib/prawn/ from SimpleCov, alongside the existing
spec/support/ exclusion: it's a Prawn-internals monkey-patch, not
br_danfe's own product logic.

The nfe_lib delegation spec is deliberately commented out in this
commit to prove the coverage gate (PR #286) actually catches a real
gap on live CI, not just locally. Follow-up commit re-enables it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@gabrieldeespindula

Copy link
Copy Markdown
Member

Closing together with #285 in favor of #289 — full reasoning over there.

On the gate specifically: with octocov it becomes one line (coverage.acceptable: current >= prev), checked against the master baseline. That model also covers the blind spot your own experiment here documented — killing a test without touching the product file passes a changed-files gate, but it drops the project total, which a baseline comparison catches.

We're starting #289 without a gate on purpose; turning it on later is config, not a new flow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remover integração com qlty do CI (projeto pausado no Qlty Cloud)

2 participants