From 7b6a8603a9c09a6d5ed71343b0e557024c37b194 Mon Sep 17 00:00:00 2001 From: Michael Duncan McArthur Date: Thu, 3 Dec 2026 02:39:28 -0500 Subject: [PATCH] CI: executed-test floor of 443 passed tests per leg, in ci.yml and release.yml (row 1.236) Co-Authored-By: Claude Sonnet 5.5 AI-Use: L3 made undo unread (Claude Sonnet 5.5) AI-Use-Standing: https://github.com/gorfednet/ai-use-levels/blob/main/docs/delegation.md 2026-11-18 --- .github/workflows/ci.yml | 7 ++++ .github/workflows/release.yml | 7 +++- .gitignore | 1 + scripts/assert_tests_executed.py | 58 ++++++++++++++++++++++++++ tests/test_assert_tests_executed.py | 64 +++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 scripts/assert_tests_executed.py create mode 100644 tests/test_assert_tests_executed.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6655abe..69935a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,13 @@ jobs: python -m pytest -q --cov=acid2reaper --cov-report=term-missing --cov-fail-under=75 + --junitxml=pytest-junit.xml + + # Floor: passed tests only, skips excluded. Lowest leg (Windows) runs 467 passed + # (459 on main plus the 8 floor-script tests); 443 is about 5 percent under. + - name: Assert executed-test floor + if: ${{ !cancelled() }} + run: python scripts/assert_tests_executed.py pytest-junit.xml --min 443 - name: Check golden projects are up to date run: python scripts/update_goldens.py --check diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7319c3c..82fe6f7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,7 +34,12 @@ jobs: run: python scripts/verify_changelog.py - name: Run tests - run: python -m pytest -q + run: python -m pytest -q --junitxml=pytest-junit.xml + + # Same floor as CI's lowest leg. Linux runs 468 passed here. + - name: Assert executed-test floor + if: ${{ !cancelled() }} + run: python scripts/assert_tests_executed.py pytest-junit.xml --min 443 - name: Build sdist and wheel run: python -m build diff --git a/.gitignore b/.gitignore index 04bc18e..4901e87 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ id_ed25519.pub .coverage.* coverage.xml htmlcov/ +pytest-junit.xml diff --git a/scripts/assert_tests_executed.py b/scripts/assert_tests_executed.py new file mode 100644 index 0000000..11a0b4e --- /dev/null +++ b/scripts/assert_tests_executed.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +""" +Fail unless pytest's junit report shows at least N tests that really ran. + +A skipped test is not an executed test: env-gated skips (see tests/conftest.py) and a +mis-selected run both exit 0 with fewer tests than intended. Passed testcases only; +skipped, failed and errored ones don't count. A missing, unreadable or empty report +fails too. + +Usage: python scripts/assert_tests_executed.py REPORT.xml --min N +""" +from __future__ import annotations + +import argparse +import sys +import xml.etree.ElementTree as ET +from pathlib import Path + +NOT_PASSED = ("skipped", "failure", "error") + + +def count_passed(report: Path) -> int: + """Count testcases in a junit xml file that carry no skipped/failure/error child.""" + try: + root = ET.parse(report).getroot() + except (OSError, ET.ParseError) as exc: + raise ValueError(f"cannot read junit report {report}: {exc}") from exc + cases = list(root.iter("testcase")) + if not cases: + raise ValueError(f"junit report {report} has no testcases") + return sum(1 for case in cases if not any(case.find(tag) is not None for tag in NOT_PASSED)) + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("report", type=Path) + parser.add_argument("--min", type=int, required=True, dest="minimum") + args = parser.parse_args(argv) + if args.minimum < 1: + print("assert_tests_executed: --min must be at least 1", file=sys.stderr) + return 1 + try: + passed = count_passed(args.report) + except ValueError as exc: + print(f"assert_tests_executed: {exc}", file=sys.stderr) + return 1 + if passed < args.minimum: + print( + f"assert_tests_executed: {passed} tests passed, floor is {args.minimum}", + file=sys.stderr, + ) + return 1 + print(f"assert_tests_executed: {passed} tests passed, floor {args.minimum}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/test_assert_tests_executed.py b/tests/test_assert_tests_executed.py new file mode 100644 index 0000000..5a48d4e --- /dev/null +++ b/tests/test_assert_tests_executed.py @@ -0,0 +1,64 @@ +"""Tests for scripts/assert_tests_executed.py, the CI executed-test floor.""" +from __future__ import annotations + +import importlib.util +from pathlib import Path + +import pytest + +_SCRIPT = Path(__file__).resolve().parent.parent / "scripts" / "assert_tests_executed.py" +_spec = importlib.util.spec_from_file_location("assert_tests_executed", _SCRIPT) +floor = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(floor) + + +def _report(tmp_path: Path, body: str) -> Path: + path = tmp_path / "junit.xml" + path.write_text(f'{body}') + return path + + +def test_counts_only_passed_cases(tmp_path): + report = _report( + tmp_path, + '' + '' + '' + '', + ) + assert floor.count_passed(report) == 2 + + +def test_meets_floor_exactly(tmp_path): + report = _report(tmp_path, '') + assert floor.main([str(report), "--min", "2"]) == 0 + + +def test_below_floor_fails(tmp_path, capsys): + report = _report(tmp_path, '') + assert floor.main([str(report), "--min", "2"]) == 1 + assert "1 tests passed, floor is 2" in capsys.readouterr().err + + +def test_missing_report_fails(tmp_path): + assert floor.main([str(tmp_path / "nope.xml"), "--min", "1"]) == 1 + + +def test_empty_report_fails(tmp_path): + assert floor.main([str(_report(tmp_path, "")), "--min", "1"]) == 1 + + +def test_malformed_report_fails(tmp_path): + path = tmp_path / "junit.xml" + path.write_text("") + assert floor.main([str(path), "--min", "1"]) == 1 + + +def test_zero_floor_rejected(tmp_path): + report = _report(tmp_path, '') + assert floor.main([str(report), "--min", "0"]) == 1 + + +def test_count_raises_on_empty(tmp_path): + with pytest.raises(ValueError): + floor.count_passed(_report(tmp_path, ""))