Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """Enforce explicit branch-coverage floors for execution-critical modules.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import sys | |
| from pathlib import Path | |
| THRESHOLDS = { | |
| "hermes_overlay/trading/config_validation.py": 85.0, | |
| "hermes_overlay/trading/plan_integrity.py": 70.0, | |
| "hermes_overlay/trading/risk.py": 80.0, | |
| "hermes_overlay/trading/domain/execution_service.py": 50.0, | |
| "hermes_overlay/trading/futures_execution.py": 50.0, | |
| "hermes_overlay/trading/provider_contracts.py": 50.0, | |
| } | |
| def validate(report: dict) -> list[str]: | |
| errors: list[str] = [] | |
| files = report.get("files") or {} | |
| for path, threshold in THRESHOLDS.items(): | |
| entry = files.get(path) | |
| if not isinstance(entry, dict): | |
| errors.append(f"critical coverage module missing: {path}") | |
| continue | |
| summary = entry.get("summary") or {} | |
| percent = summary.get("percent_covered") | |
| if not isinstance(percent, (int, float)): | |
| errors.append(f"critical coverage percentage missing: {path}") | |
| continue | |
| if float(percent) + 1e-9 < threshold: | |
| errors.append(f"critical coverage below threshold: {path} {percent:.2f}% < {threshold:.2f}%") | |
| return errors | |
| def main(argv: list[str] | None = None) -> int: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("report", nargs="?", default="coverage.json") | |
| args = parser.parse_args(argv) | |
| try: | |
| report = json.loads(Path(args.report).read_text(encoding="utf-8")) | |
| except (OSError, json.JSONDecodeError) as exc: | |
| print(f"ERROR: unable to read coverage report: {exc}") | |
| return 1 | |
| errors = validate(report) | |
| for error in errors: | |
| print(f"ERROR: {error}") | |
| print(f"critical_coverage={'PASS' if not errors else 'FAIL'} modules={len(THRESHOLDS)}") | |
| return 1 if errors else 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |