ci(ananke): separate test and gate metrics

This commit is contained in:
codex 2026-04-21 16:10:14 -03:00
parent 7284eaf5a2
commit 70680ea2eb

View File

@ -169,12 +169,27 @@ def _count_source_files_over_limit(repo_root: Path, max_lines: int = 500) -> int
continue continue
if path.suffix not in SOURCE_EXTENSIONS: if path.suffix not in SOURCE_EXTENSIONS:
continue continue
if path.name.endswith("_test.go") or path.name.endswith(".test.py"):
continue
lines = len(path.read_text(encoding="utf-8", errors="ignore").splitlines()) lines = len(path.read_text(encoding="utf-8", errors="ignore").splitlines())
if lines > max_lines: if lines > max_lines:
count += 1 count += 1
return count return count
def _unit_tests_failed(output_path: Path, coverage_percent: float) -> bool:
if coverage_percent <= 0 or not output_path.exists():
return True
text = output_path.read_text(encoding="utf-8", errors="ignore")
start_marker = "[quality] unit tests + workspace coverage profile"
end_marker = "[quality] hygiene: doc contracts"
if start_marker in text:
text = text.split(start_marker, 1)[1]
if end_marker in text:
text = text.split(end_marker, 1)[0]
return bool(re.search(r"^(--- FAIL:|FAIL\\b)", text, flags=re.M))
def _parse_go_test_counts(output_path: Path) -> dict[str, int]: def _parse_go_test_counts(output_path: Path) -> dict[str, int]:
if not output_path.exists(): if not output_path.exists():
return {"passed": 0, "failed": 0, "errors": 0, "skipped": 0} return {"passed": 0, "failed": 0, "errors": 0, "skipped": 0}
@ -361,9 +376,9 @@ def main(argv: list[str] | None = None) -> int:
test_cases = _parse_go_test_cases(quality_output) test_cases = _parse_go_test_cases(quality_output)
gate_rc = _read_exit_code(Path(os.getenv("ANANKE_QUALITY_EXIT_CODE_PATH", str(build_dir / "quality-gate.rc")))) gate_rc = _read_exit_code(Path(os.getenv("ANANKE_QUALITY_EXIT_CODE_PATH", str(build_dir / "quality-gate.rc"))))
docs_status = _read_status(Path(os.getenv("ANANKE_QUALITY_DOCS_STATUS_PATH", str(build_dir / "docs-naming.status")))) docs_status = _read_status(Path(os.getenv("ANANKE_QUALITY_DOCS_STATUS_PATH", str(build_dir / "docs-naming.status"))))
gate_failed = gate_rc != 0 unit_tests_failed = _unit_tests_failed(quality_output, coverage_percent)
checks = { checks = {
"tests": "failed" if gate_failed or tests["failed"] > 0 else "ok", "tests": "failed" if unit_tests_failed or tests["failed"] > 0 or tests["errors"] > 0 else "ok",
"coverage": "ok" if coverage_percent >= 95.0 else "failed", "coverage": "ok" if coverage_percent >= 95.0 else "failed",
"loc": "ok" if source_lines_over_500 == 0 else "failed", "loc": "ok" if source_lines_over_500 == 0 else "failed",
"docs_naming": docs_status, "docs_naming": docs_status,