From d5a02bd748d26350f5634ee9e580d0d33583e4fd Mon Sep 17 00:00:00 2001 From: Joseph Magly <1159087+jmagly@users.noreply.github.com> Date: Fri, 14 Aug 2026 11:40:58 -0400 Subject: [PATCH] test: reject malformed coverage metrics --- scripts/check_coverage_thresholds.py | 7 ++++++- tests/test_coverage_thresholds.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/check_coverage_thresholds.py b/scripts/check_coverage_thresholds.py index cdb8f6e..5fbd745 100644 --- a/scripts/check_coverage_thresholds.py +++ b/scripts/check_coverage_thresholds.py @@ -4,6 +4,7 @@ from __future__ import annotations import argparse import json +import math from pathlib import Path from typing import Any @@ -23,7 +24,11 @@ def validate_coverage( ) for label, key, minimum in metrics: value = totals.get(key) - if not isinstance(value, (int, float)): + if ( + isinstance(value, bool) + or not isinstance(value, (int, float)) + or not math.isfinite(value) + ): failures.append(f"coverage report is missing numeric {key}") elif value < minimum: failures.append( diff --git a/tests/test_coverage_thresholds.py b/tests/test_coverage_thresholds.py index 5e44751..8754421 100644 --- a/tests/test_coverage_thresholds.py +++ b/tests/test_coverage_thresholds.py @@ -43,3 +43,16 @@ def test_validate_coverage_rejects_malformed_totals(): assert MODULE.validate_coverage( {}, min_line=49.0, min_branch=36.0, ) == ["coverage report is missing the totals object"] + + +def test_validate_coverage_rejects_non_numeric_metrics(): + report = _report() + report["totals"]["percent_statements_covered"] = True + report["totals"]["percent_branches_covered"] = float("nan") + + assert MODULE.validate_coverage( + report, min_line=49.0, min_branch=36.0, + ) == [ + "coverage report is missing numeric percent_statements_covered", + "coverage report is missing numeric percent_branches_covered", + ]