|
22 | 22 | * compared exactly in integers, so 89.96% fails rather than rounding up. |
23 | 23 | * - A dimension with nothing to measure (no statements, or no branches) |
24 | 24 | * counts as 100%: there is nothing in it left untested. |
25 | | - * - A report that is missing, unreadable, or measured no files at all is a |
26 | | - * failure, never a vacuous pass. |
| 25 | + * - A report that is missing, unreadable, measured no files at all, or was |
| 26 | + * measured without branch coverage (`meta.branch_coverage` not true, where |
| 27 | + * every file's branch count is 0) is a failure, never a vacuous pass. |
27 | 28 | * |
28 | 29 | * Pure apart from `readCoverageReport`, so `node --test` covers it without |
29 | 30 | * `uv` or Python. |
@@ -86,6 +87,16 @@ export function checkReport(report, threshold = THRESHOLD) { |
86 | 87 | if (!files || typeof files !== "object" || Array.isArray(files)) { |
87 | 88 | return { error: "not a coverage.py JSON report (no `files` object)" }; |
88 | 89 | } |
| 90 | + // Without branch measurement coverage.py still writes `num_branches: 0` for |
| 91 | + // every file, which would read as 100% below. Refuse the report instead. |
| 92 | + const meta = /** @type {{ meta?: { branch_coverage?: unknown } }} */ (report) |
| 93 | + .meta; |
| 94 | + if (meta?.branch_coverage !== true) { |
| 95 | + return { |
| 96 | + error: |
| 97 | + "the report was not measured with branch coverage (meta.branch_coverage is not true); set [tool.coverage.run] branch = true in pyproject.toml", |
| 98 | + }; |
| 99 | + } |
89 | 100 | const names = Object.keys(files).sort(); |
90 | 101 | if (names.length === 0) { |
91 | 102 | return { |
|
0 commit comments