test(coverage): ratchet autogen branch coverage gate #46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ci-${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| test: | |
| name: Python ${{ matrix.python-version }} / ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| timeout-minutes: 20 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, windows-latest] | |
| python-version: ['3.12'] | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: pip | |
| - name: Install dependencies | |
| run: python -m pip install -r requirements.txt | |
| - name: Verify dependency consistency | |
| run: python -m pip check | |
| - name: Contract compatibility (pinned cas-contracts v1.1) | |
| # Consumer-side gate: fails red if autogen's pinned CAS contract version | |
| # or the vendored v1.1 schema release drifts. See | |
| # tests/test_contract_compatibility.py for the validated contract surface. | |
| run: python -m pytest tests/test_contract_compatibility.py -q --tb=short | |
| - name: Run full test suite | |
| run: | | |
| python -m pytest -q --tb=short --cov --cov-branch --cov-report=xml --cov-fail-under=73 | |
| - name: Emit branch coverage telemetry | |
| if: always() | |
| run: | | |
| python - <<'PY' | |
| import json | |
| import sys | |
| import xml.etree.ElementTree as ET | |
| from pathlib import Path | |
| required = 54.6 | |
| coverage_file = Path("coverage.xml") | |
| if not coverage_file.exists(): | |
| print(json.dumps({ | |
| "event": "ci_failure", | |
| "metric": "branch-rate", | |
| "coverage_percent": None, | |
| "required": required, | |
| "reason": "coverage.xml missing", | |
| })) | |
| sys.exit(1) | |
| branch_rate = float(ET.parse(coverage_file).getroot().attrib["branch-rate"]) * 100.0 | |
| passed = branch_rate >= required | |
| print(json.dumps({ | |
| "event": "ci_pass" if passed else "ci_failure", | |
| "metric": "branch-rate", | |
| "coverage_percent": round(branch_rate, 2), | |
| "required": required, | |
| })) | |
| sys.exit(0 if passed else 1) | |
| PY | |
| - name: Compile Python sources | |
| run: python -m compileall autogen_starter autogen_dashboard maf_starter main.py -q | |
| - name: Validate dashboard JavaScript | |
| run: node --check autogen_dashboard/static/app.js |