From 39937e2f22dbd5533b76a167161cce2feb2a5fc6 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Tue, 29 Sep 2026 14:24:33 -0400 Subject: [PATCH 1/2] ci: enforce patch coverage of changed lines; drop COMPOSER_ROOT_VERSION Adds tests/bin/patch-coverage.php and an "Enforce coverage of changed lines" CI step (pull_request only) that fails when production PHP lines a PR changes are left uncovered, mirroring plugin_thold. Whole-file coverage is not meaningful for a Cacti plugin (most code only runs inside a live Cacti), so the gate measures only the lines a change adds. Also sets fetch-depth: 0 on the plugin checkout so the gate can diff against the PR base, and removes the inert COMPOSER_ROOT_VERSION env from the Pest step (it only affects composer root-version detection, which does not run in that step). --- .github/workflows/plugin-ci-workflow.yml | 16 +- CHANGELOG.md | 1 + tests/bin/patch-coverage.php | 198 +++++++++++++++++++++++ 3 files changed, 213 insertions(+), 2 deletions(-) create mode 100644 tests/bin/patch-coverage.php diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index edadadc..03352a3 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -62,6 +62,8 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: path: cacti/plugins/flowview + # patch-coverage.php diffs against the base branch below. + fetch-depth: 0 - name: Install PHP ${{ matrix.php }} uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 @@ -179,13 +181,23 @@ jobs: run: echo -n "${{ env.CACTI }}" | sudo tee ${{ github.workspace }}/cacti/plugins/flowview/tests/.cacti-version > /dev/null - name: Run Pest Unit Tests - env: - COMPOSER_ROOT_VERSION: 1.3.0-dev run: | cd ${{ github.workspace }}/cacti include/vendor/bin/pest --configuration=plugins/flowview/phpunit.xml \ --coverage-clover=plugins/flowview/coverage/clover.xml + # Whole-file coverage is meaningless here: most of the plugin only runs + # inside a live Cacti. What is enforceable is that a change covers the + # lines it adds. + - name: Enforce coverage of changed lines + if: github.event_name == 'pull_request' + env: + BASE_REF: ${{ github.event.pull_request.base.sha }} + run: | + cd ${{ github.workspace }}/cacti/plugins/flowview + git config --global --add safe.directory ${{ github.workspace }}/cacti/plugins/flowview + php tests/bin/patch-coverage.php coverage/clover.xml "$BASE_REF" 100 + - name: Upload coverage report if: always() uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 99432e9..6ce8b55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ --- develop --- +* dev: Enforce patch coverage of changed lines in CI and remove the inert COMPOSER_ROOT_VERSION env from the Pest step * issue#110: Add NAT (postNAT source/destination IP and port) support to the core raw flow schema, filters, and DNS resolution; see flowview_upgrade_nat_columns.php to backfill existing partitions * security: Add a version-safe CSP nonce (`plugin_flowview_csp_nonce()`) to every inline `