From 3e5654979ac1e4ef9922c16dc85c0d7535201905 Mon Sep 17 00:00:00 2001 From: James Phillip Sanders Date: Sat, 21 Nov 2026 17:59:00 +0000 Subject: [PATCH] Review every pull request with ruru, in CI and in make checks ruru (github.com/jpsanders/ruru-review) audits the tests for tampering, checks that new tests fail without the change, and runs mutants on the changed lines. ruru.yml runs it with a read only token, safe for forks; ruru-post.yml comments from its report without checking out pull request code. make ruru runs the same review locally and is part of make checks; make checks RURU=: skips it. --- .github/workflows/ruru-post.yml | 41 ++++++++++++++++++++++++++++++++ .github/workflows/ruru.yml | 42 +++++++++++++++++++++++++++++++++ AGENTS.md | 1 + Makefile | 15 +++++++++++- 4 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ruru-post.yml create mode 100644 .github/workflows/ruru.yml diff --git a/.github/workflows/ruru-post.yml b/.github/workflows/ruru-post.yml new file mode 100644 index 0000000..85a55d3 --- /dev/null +++ b/.github/workflows/ruru-post.yml @@ -0,0 +1,41 @@ +# Template B: comments on the pull request from the report Template A uploaded. +# It runs in the base repository's context with a write token, so it NEVER checks out pull request code: it +# downloads the report and hands it to `ruru post`, which checks the schema, checks that the pull request's head is +# the commit this trusted event names, and escapes every string. +name: ruru post + +on: + workflow_run: + workflows: [ruru] + types: [completed] + +permissions: + pull-requests: write + actions: read + +jobs: + post: + if: github.event.workflow_run.event == 'pull_request' + runs-on: ubuntu-latest + steps: + - name: "Download the report (data only)" + uses: actions/download-artifact@v4 + with: + name: ruru-report + path: ruru + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ github.token }} + + - name: "Read the pull request number from the artifact" + id: pr + run: | + n=$(python3 -c 'import json; n = json.load(open("ruru/ruru-pr.json")).get("number") + print(n if isinstance(n, int) and n > 0 else "")') + echo "number=$n" >> "$GITHUB_OUTPUT" + + - name: "ruru post" + uses: jpsanders/ruru-review@main + with: + run: post + report: ruru/ruru-report.json + pr: ${{ steps.pr.outputs.number }} diff --git a/.github/workflows/ruru.yml b/.github/workflows/ruru.yml new file mode 100644 index 0000000..6faf838 --- /dev/null +++ b/.github/workflows/ruru.yml @@ -0,0 +1,42 @@ +# ruru reviews each pull request: a tamper audit of the tests, fail first for new tests, and mutants on the changed +# lines (https://github.com/jpsanders/ruru-review). This job runs the pull request's code with a read only token, so +# it is safe for forks; ruru-post.yml comments from its report. +name: ruru + +on: + pull_request: + +permissions: + contents: read + +jobs: + ruru: + runs-on: ubuntu-latest + steps: + - name: "Checkout code with history" + uses: actions/checkout@v7 + with: + fetch-depth: 0 + persist-credentials: false + + - name: "Set up Python" + uses: actions/setup-python@v7 + with: + python-version: "3.15" + + - name: "Install the package and its test tools" + run: python -m pip install -e ".[dev]" + + - name: "ruru" + uses: jpsanders/ruru-review@main + with: + mode: gate + report: ruru/ruru-report.json + + - name: "Upload the report for the posting workflow" + if: always() + uses: actions/upload-artifact@v4 + with: + name: ruru-report + path: ruru/ + if-no-files-found: ignore diff --git a/AGENTS.md b/AGENTS.md index e174f72..eaa20be 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,6 +9,7 @@ Instructions for AI coding agents working on usbuntu itself. To use the tool, re make init-dev # install the package and the development tools into the active environment make format # apply black and isort make checks # every check CI runs, in CI's order; run it before you say a change is done +make ruru # ruru reviews your branch against main: tamper audit, fail first, mutants (in checks) make man # rebuild the man page and the packaged manual after editing docs/MANUAL.md ``` diff --git a/Makefile b/Makefile index 8451f9c..d077926 100644 --- a/Makefile +++ b/Makefile @@ -113,4 +113,17 @@ clean: # Run all checking tools .PHONY: checks -checks: isort-check black-check ec docstyle lint mypy bandit man-check pytest +checks: isort-check black-check ec docstyle lint mypy bandit man-check pytest ruru + +# ruru reviews the change on this branch against main: a tamper audit of the tests, fail first for new tests, and +# mutants on the changed lines (https://github.com/jpsanders/ruru-review). On main with nothing changed it passes at +# once. `make checks RURU=:` skips it; RURU_BASE and RURU_MODE override the defaults. +RURU ?= uvx --python 3.14 --from git+https://github.com/jpsanders/ruru-review@main ruru +RURU_BASE ?= origin/main +RURU_MODE ?= gate + +.PHONY: ruru +ruru: + @echo + @echo --- ruru: tamper audit, fail first and mutants on the change --- + $(RURU) check --base $(RURU_BASE) --mode $(RURU_MODE)