diff --git a/.github/scripts/mutants-scope.py b/.github/scripts/mutants-scope.py new file mode 100644 index 0000000..cd2ea4b --- /dev/null +++ b/.github/scripts/mutants-scope.py @@ -0,0 +1,10 @@ +import fnmatch +import sys +import tomllib + +with open(sys.argv[1], "rb") as f: + globs = tomllib.load(f).get("examine_globs", []) + +for path in sys.stdin.read().splitlines(): + if any(fnmatch.fnmatchcase(path, glob) for glob in globs): + print(path) diff --git a/.github/scripts/mutants-summary.sh b/.github/scripts/mutants-summary.sh index 1d8b4a7..c183cd7 100755 --- a/.github/scripts/mutants-summary.sh +++ b/.github/scripts/mutants-summary.sh @@ -3,6 +3,7 @@ set -euo pipefail shards_dir=$1 out=$2 +mode=${3:-nightly} mkdir -p "$out" for kind in caught missed timeout unviable; do @@ -12,9 +13,15 @@ done count() { grep -c . "$1" || true; } { - echo "## Mutation grading" - echo - echo "cargo-mutants over the files in \`.cargo/mutants.toml\`, graded by the \`pr_chaos\` tests." + if [[ $mode == diff ]]; then + echo "## Diff mutation grading" + echo + echo "cargo-mutants over the lines this PR changes in the files in \`.cargo/mutants.toml\`, graded by the \`pr_chaos\` tests. Advisory: a missed mutant does not block the merge." + else + echo "## Mutation grading" + echo + echo "cargo-mutants over the files in \`.cargo/mutants.toml\`, graded by the \`pr_chaos\` tests." + fi echo echo "| file | caught | missed | timeout | unviable |" echo "| --- | ---: | ---: | ---: | ---: |" @@ -28,5 +35,21 @@ count() { grep -c . "$1" || true; } done echo "| **total** | $(count "$out/caught.txt") | $(count "$out/missed.txt") | $(count "$out/timeout.txt") | $(count "$out/unviable.txt") |" echo - echo "Survivors are listed in \`missed.txt\` and \`timeout.txt\` in the \`mutants-survivors\` artifact." + if [[ $mode == diff ]]; then + if ! grep -q . "$out"/{caught,missed,timeout,unviable}.txt; then + echo "The changed lines hold no mutants." + echo + fi + for kind in missed timeout; do + [[ -s $out/$kind.txt ]] || continue + echo "### ${kind^}" + echo + echo '```text' + cat "$out/$kind.txt" + echo '```' + echo + done + else + echo "Survivors are listed in \`missed.txt\` and \`timeout.txt\` in the \`mutants-survivors\` artifact." + fi } >"$out/summary.md" diff --git a/.github/workflows/mutants-diff.yml b/.github/workflows/mutants-diff.yml new file mode 100644 index 0000000..d956478 --- /dev/null +++ b/.github/workflows/mutants-diff.yml @@ -0,0 +1,92 @@ +name: mutants-diff + +on: + pull_request: + paths: + - "src/**.rs" + - .cargo/mutants.toml + - .github/workflows/mutants-diff.yml + - .github/scripts/mutants-scope.py + - .github/scripts/mutants-summary.sh + +permissions: + contents: read + +concurrency: + group: mutants-diff-${{ github.event.pull_request.number }} + cancel-in-progress: true + +defaults: + run: + shell: bash + +env: + CARGO_TERM_COLOR: always + RUSTFLAGS: -C link-arg=-fuse-ld=mold + +jobs: + mutants: + name: mutants (diff, advisory) + runs-on: ubuntu-latest + timeout-minutes: 120 + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + fetch-depth: 2 + - name: Diff against the PR base + id: scope + run: | + git diff --no-ext-diff --no-color --src-prefix=a/ --dst-prefix=b/ HEAD^1 HEAD >pr.diff + files=$(git diff --name-only --no-renames HEAD^1 HEAD | python3 .github/scripts/mutants-scope.py .cargo/mutants.toml) + if [ -z "$files" ]; then + echo "run=false" >>"$GITHUB_OUTPUT" + { + echo "## Diff mutation grading" + echo + echo "No file in \`.cargo/mutants.toml\` changed, so no mutants ran." + } >>"$GITHUB_STEP_SUMMARY" + exit 0 + fi + printf '%s\n' "$files" + echo "run=true" >>"$GITHUB_OUTPUT" + - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # stable as of 2026-10-16 + if: steps.scope.outputs.run == 'true' + with: + toolchain: stable + - name: Install mold + if: steps.scope.outputs.run == 'true' + run: sudo apt-get update && sudo apt-get install -y mold + - uses: taiki-e/install-action@3a3daafd3b7f23b8f65d9f5ba2db203fb59b79e2 # v2.90.2 + if: steps.scope.outputs.run == 'true' + with: + tool: cargo-mutants@27.1.0,cargo-nextest@0.9.151 + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + if: steps.scope.outputs.run == 'true' + with: + key: chaos-mutants-diff + - name: Grade the mutants in the diff + id: grade + if: steps.scope.outputs.run == 'true' + run: | + mkdir -p mutants-diff + set +e + cargo mutants --in-place --in-diff pr.diff --output mutants-diff + code=$? + set -e + case $code in + 0|2|3) ;; + *) echo "cargo-mutants exited $code"; exit "$code" ;; + esac + - name: Job summary + if: steps.grade.outcome == 'success' + run: | + .github/scripts/mutants-summary.sh mutants-diff mutants-diff-summary diff + cat mutants-diff-summary/summary.md >>"$GITHUB_STEP_SUMMARY" + - uses: actions/upload-artifact@v7 + if: steps.grade.outcome == 'success' + with: + name: mutants-diff + path: mutants-diff-summary/ + if-no-files-found: ignore + retention-days: 14 diff --git a/docs/src/contributing.md b/docs/src/contributing.md index f9e389a..3de2759 100644 --- a/docs/src/contributing.md +++ b/docs/src/contributing.md @@ -114,6 +114,28 @@ The workflow does not file issues. A later job could read the hashes from the `chaos-failures` artifact and open or comment on one tracking issue per hash, with `issues: write` granted to that job alone. +### Diff mutation check + +`.github/workflows/mutants-diff.yml` runs the same mutation grading on a pull +request, limited to the lines the PR changes. It starts only when the PR +touches a Rust file under `src/`, `.cargo/mutants.toml`, or the workflow and +its scripts, and its first step skips the rest when none of the changed files +is in `.cargo/mutants.toml`'s `examine_globs`. Otherwise it diffs the merge +commit against the base it was merged onto, runs +`cargo mutants --in-diff` with the `mutants` profile and the `pr_chaos` tests, +and writes the caught, missed, timeout and unviable counts per file to the job +summary, with each missed and timed-out mutant listed below the table. The +`mutants-diff` artifact holds the same files. + +The check is advisory. It runs in its own workflow, outside the required +`check` job in `ci.yml`, and passes when mutants survive: it fails only when +cargo-mutants itself fails, such as when the unmutated tree does not build. +Expect survivors in `src/board.rs` rendering code, which the chaos tests do not +reach. A survivor in code your PR adds is worth a look: either a `pr_chaos` +invariant should notice the change, or the line is outside what the chaos +oracle checks. It needs no secrets and runs with `contents: read`, so it works +the same on pull requests from forks. + ## This site `docs/build.sh` generates the [API reference](api.md) page from `t3cm types`, diff --git a/src/wf.rs b/src/wf.rs index 5f54523..60d8db7 100644 --- a/src/wf.rs +++ b/src/wf.rs @@ -294,7 +294,11 @@ const BLOCKER_GATE: &str = "relay:blocker"; fn relays(kind: &str, gate: Option<&str>) -> bool { let ticket_owned = |g: &str| g == "merge" || g.starts_with("delivery:"); - kind == "blocker" || (kind == "gate" && !gate.is_some_and(ticket_owned)) + match kind { + "blocker" => true, + "gate" => !gate.is_some_and(ticket_owned), + _ => false, + } } fn release_hold(ln: &mut Link) {