|
| 1 | +name: Mutation Testing |
| 2 | + |
| 3 | +# Mutation testing is slow (it re-runs the test suite per mutant), so it runs |
| 4 | +# nightly and on demand — never on pull requests — to avoid PR latency. It is |
| 5 | +# informational/non-blocking: the score is reported to the run summary and the |
| 6 | +# HTML report is uploaded as an artifact. |
| 7 | + |
| 8 | +on: |
| 9 | + schedule: |
| 10 | + - cron: "0 4 * * *" # nightly, 04:00 UTC |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + mutate: |
| 14 | + description: "Optional glob to scope mutation (e.g. src/tokens/**/*.ts)" |
| 15 | + required: false |
| 16 | + type: string |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: mutation-${{ github.ref }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + stryker: |
| 24 | + name: Stryker (packages/pipeline) |
| 25 | + runs-on: ubuntu-latest |
| 26 | + timeout-minutes: 90 |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Setup Node.js |
| 31 | + uses: actions/setup-node@v4 |
| 32 | + with: |
| 33 | + node-version: "20" |
| 34 | + |
| 35 | + - name: Install pnpm |
| 36 | + uses: pnpm/action-setup@v4 |
| 37 | + with: |
| 38 | + version: 9 |
| 39 | + |
| 40 | + - name: Install dependencies |
| 41 | + run: pnpm install --frozen-lockfile |
| 42 | + |
| 43 | + - name: Run Stryker mutation testing |
| 44 | + working-directory: packages/pipeline |
| 45 | + run: | |
| 46 | + # Run from packages/pipeline so the pnpm-linked node_modules resolve in |
| 47 | + # the Stryker sandbox; the config lives at the repo root. |
| 48 | + if [ -n "${{ github.event.inputs.mutate }}" ]; then |
| 49 | + npx stryker run ../../stryker.conf.json --mutate "${{ github.event.inputs.mutate }}" |
| 50 | + else |
| 51 | + npx stryker run ../../stryker.conf.json |
| 52 | + fi |
| 53 | +
|
| 54 | + - name: Mutation score summary |
| 55 | + if: always() |
| 56 | + working-directory: packages/pipeline |
| 57 | + run: | |
| 58 | + node -e ' |
| 59 | + const fs = require("fs"); |
| 60 | + const path = "reports/mutation/mutation-report.json"; |
| 61 | + if (!fs.existsSync(path)) { console.log("No mutation report produced."); process.exit(0); } |
| 62 | + const report = JSON.parse(fs.readFileSync(path, "utf-8")); |
| 63 | + const counts = { Killed: 0, Survived: 0, Timeout: 0, NoCoverage: 0, RuntimeError: 0, CompileError: 0, Ignored: 0 }; |
| 64 | + for (const file of Object.values(report.files || {})) { |
| 65 | + for (const m of file.mutants || []) counts[m.status] = (counts[m.status] || 0) + 1; |
| 66 | + } |
| 67 | + const detected = counts.Killed + counts.Timeout; |
| 68 | + const valid = detected + counts.Survived + counts.NoCoverage; |
| 69 | + const score = valid ? ((detected / valid) * 100).toFixed(2) : "n/a"; |
| 70 | + const out = [ |
| 71 | + "## Mutation testing (packages/pipeline)", |
| 72 | + "", |
| 73 | + `**Mutation score: ${score}%**` + (score === "n/a" ? "" : ` (target 80%, opt-in)`), |
| 74 | + "", |
| 75 | + "| Status | Count |", |
| 76 | + "| --- | --- |", |
| 77 | + ...Object.entries(counts).map(([k, v]) => `| ${k} | ${v} |`), |
| 78 | + ].join("\n"); |
| 79 | + fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY || "/dev/stdout", out + "\n"); |
| 80 | + console.log(`Mutation score: ${score}%`); |
| 81 | + ' |
| 82 | +
|
| 83 | + - name: Upload mutation report |
| 84 | + if: always() |
| 85 | + uses: actions/upload-artifact@v4 |
| 86 | + with: |
| 87 | + name: mutation-report |
| 88 | + path: packages/pipeline/reports/mutation/ |
| 89 | + if-no-files-found: ignore |
| 90 | + retention-days: 14 |
0 commit comments