Files
Stirling-PDF/engine/scripts/check_coverage.py
T
Ludy87 06c6bec7ce CI: add engine coverage & linting/style fixes
Add AI engine coverage reporting to CI (run tests with coverage, show in step summary, and upload artifact). Relax and align engine pre-commit package specifiers and update uv.lock. Increase ruff line-length and add per-file ignores; update Taskfile and pre-commit Taskfile to use engine ruff config. Add coverage entries to engine/.gitignore. Apply numerous non-functional Python style and formatting fixes across scripts and cucumber test steps (imports, f-strings, line breaks, noqa markers, single-line asserts) to satisfy linters—no behavioral changes intended.
2026-08-12 10:41:42 +02:00

36 lines
1.0 KiB
Python

"""Fail when any measured source file falls below the required coverage."""
from __future__ import annotations
import argparse
import json
import sys
from pathlib import Path
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("report", type=Path)
parser.add_argument("--minimum", type=float, default=90.0)
args = parser.parse_args()
data = json.loads(args.report.read_text(encoding="utf-8"))
failures: list[tuple[str, float]] = []
for filename, details in data["files"].items():
coverage = float(details["summary"]["percent_covered"])
if coverage < args.minimum:
failures.append((filename, coverage))
if failures:
print(f"Per-file coverage below {args.minimum:.1f}%:", file=sys.stderr)
for filename, coverage in sorted(failures):
print(f" {coverage:.1f}% {filename}", file=sys.stderr)
return 1
print(f"Per-file coverage: every file is at least {args.minimum:.1f}%.")
return 0
if __name__ == "__main__":
raise SystemExit(main())