Skip to content
Merged
Prev Previous commit
Next Next commit
Fix coverage gate to check per-class regressions, not just overall
The previous gate only checked overall line/branch/method coverage,
which allowed per-class regressions to pass when offset by improvements
elsewhere. Now fails on any class regressing any metric by >0.05%.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
  • Loading branch information
andimarek and claude committed Mar 6, 2026
commit 069d64a4fdbc5aa3d37ffdc4b3805b82c4dbdc33
27 changes: 11 additions & 16 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -391,25 +391,20 @@ jobs:
});
}

// --- Coverage gate: fail if any metric drops ---
if (covLine || covBranch || covMethod) {
const drops = [];
for (const { name, curr, baseKey } of [
{ name: 'Line', curr: covLine, baseKey: 'line' },
{ name: 'Branch', curr: covBranch, baseKey: 'branch' },
{ name: 'Method', curr: covMethod, baseKey: 'method' },
]) {
if (!curr) continue;
const b = baseCov[baseKey] || zeroCov;
const currPct = pct(curr.covered, curr.missed);
const basePct = pct(b.covered, b.missed);
// --- Coverage gate: fail if any class regresses on any metric ---
const regressions = [];
for (const [cls, curr] of Object.entries(classCounters)) {
const base = baseClasses[cls] || { line: zeroCov, branch: zeroCov, method: zeroCov };
for (const [metric, key] of [['Line', 'line'], ['Branch', 'branch'], ['Method', 'method']]) {
const currPct = pct(curr[key].covered, curr[key].missed);
const basePct = pct(base[key].covered, base[key].missed);
if (currPct < basePct - 0.05) {
drops.push(`${name}: ${currPct.toFixed(1)}% (was ${basePct.toFixed(1)}%, delta ${(currPct - basePct).toFixed(1)}%)`);
regressions.push(` ${cls} ${metric}: ${currPct.toFixed(1)}% (was ${basePct.toFixed(1)}%, delta ${(currPct - basePct).toFixed(1)}%)`);
}
}
if (drops.length > 0) {
core.setFailed(`Coverage decreased:\n${drops.join('\n')}`);
}
}
if (regressions.length > 0) {
core.setFailed(`Per-class coverage regressions detected:\n${regressions.join('\n')}\n\nUpdate test-baseline.json if these changes are intentional.`);
}
javadoc:
runs-on: ubuntu-latest
Expand Down
Loading