Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/test_coverage_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ def test_load_baseline_enforces_minimum_recovery_days(tmp_path: Path) -> None:
assert baseline.recovery_days == 3


def test_coverage_breach_requires_drop_beyond_warn_threshold() -> None:
assert not coverage_guard.is_coverage_breach(84.0, 85.0, 1.0)
assert coverage_guard.is_coverage_breach(83.99, 85.0, 1.0)


def test_compute_top_files_prioritises_missing_lines() -> None:
coverage = {
"files": {
Expand Down
14 changes: 13 additions & 1 deletion tools/coverage_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ def load_baseline(path: Path) -> BaselineConfig:
)


def is_coverage_breach(current: float, baseline: float, warn_drop: float) -> bool:
"""Return whether coverage exceeds the configured drop allowance."""
return current < baseline - warn_drop


def compute_top_files(coverage_data: dict[str, Any], limit: int = 15) -> list[FileCoverage]:
"""Return the most useful file-level coverage rows for issue comments."""
files = coverage_data.get("files", {})
Expand Down Expand Up @@ -680,6 +685,7 @@ def main(args: list[str] | None = None) -> int:
)
return 0
delta = current - baseline
warn_drop = load_baseline(parsed.baseline_path).warn_drop
Comment thread
stranske marked this conversation as resolved.
configured_recovery_window = max(
1,
_to_int(
Expand Down Expand Up @@ -714,7 +720,7 @@ def main(args: list[str] | None = None) -> int:
return 0

# Create or update issue
if current < baseline:
if is_coverage_breach(current, baseline, warn_drop):
try:
_find_or_create_issue(
repo=parsed.repo,
Expand All @@ -726,6 +732,12 @@ def main(args: list[str] | None = None) -> int:
print(f"Failed to create or update coverage issue: {exc}", file=sys.stderr)
return 1
else:
if current < baseline:
print(
f"Coverage {current:.2f}% is within the configured {warn_drop:.2f}-point "
f"drop allowance below baseline {baseline:.2f}% - no new issue needed"
)
return 0
print(f"Coverage {current:.2f}% meets baseline {baseline:.2f}% - no open issue needed")
if not _recovery_window_satisfied(
trend_data,
Expand Down
Loading