pmat 3.15.0

PMAT - Zero-config AI context generation and code quality toolkit (CLI, MCP, HTTP)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# GitHub Actions CI/CD Integration for PMAT Mutation Testing

This guide demonstrates how to integrate PMAT mutation testing into GitHub Actions workflows for continuous quality assurance.

## Overview

GitHub Actions provides automated CI/CD pipelines that can run mutation testing on every push, pull request, or scheduled basis. This ensures code quality is continuously monitored and mutation scores are tracked over time.

## Table of Contents

1. [Basic Setup]#basic-setup
2. [Multi-Language Support]#multi-language-support
3. [Quality Gates]#quality-gates
4. [Advanced Patterns]#advanced-patterns
5. [Caching Strategies]#caching-strategies
6. [Artifacts and Reporting]#artifacts-and-reporting
7. [Troubleshooting]#troubleshooting

## Basic Setup

### Minimal Workflow

Create `.github/workflows/mutation-testing.yml`:

```yaml
name: Mutation Testing

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main ]

jobs:
  mutation-test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          profile: minimal

      - name: Install PMAT
        run: cargo install pmat

      - name: Run mutation tests
        run: pmat mutate --target src/ --failures-only
```

### With Threshold Enforcement

Add quality gates with mutation score thresholds:

```yaml
      - name: Run mutation tests with threshold
        run: |
          pmat mutate \
            --target src/ \
            --threshold 80 \
            --failures-only \
            --output-format json > mutation-results.json

      - name: Check mutation score
        run: |
          SCORE=$(jq '.mutation_score' mutation-results.json)
          echo "Mutation Score: ${SCORE}%"
          if (( $(echo "$SCORE < 80" | bc -l) )); then
            echo "❌ Mutation score ${SCORE}% is below threshold 80%"
            exit 1
          fi
          echo "✅ Mutation score ${SCORE}% meets threshold"
```

## Multi-Language Support

### Rust Project

```yaml
name: Rust Mutation Testing

on: [push, pull_request]

jobs:
  test-and-mutate:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Setup Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          components: rustfmt, clippy

      - name: Cache cargo registry
        uses: actions/cache@v3
        with:
          path: ~/.cargo/registry
          key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

      - name: Cache cargo index
        uses: actions/cache@v3
        with:
          path: ~/.cargo/git
          key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

      - name: Cache cargo build
        uses: actions/cache@v3
        with:
          path: target
          key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

      - name: Run tests
        run: cargo test --all-features

      - name: Install PMAT
        run: cargo install pmat

      - name: Run mutation tests
        run: |
          pmat mutate \
            --target src/ \
            --threshold 85 \
            --jobs 4 \
            --timeout 10 \
            --output-format markdown > mutation-report.md

      - name: Upload mutation report
        uses: actions/upload-artifact@v3
        if: always()
        with:
          name: mutation-report
          path: mutation-report.md
```

### Python Project

```yaml
name: Python Mutation Testing

on: [push, pull_request]

jobs:
  test-and-mutate:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.9', '3.10', '3.11']

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}

      - name: Cache pip packages
        uses: actions/cache@v3
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
          restore-keys: |
            ${{ runner.os }}-pip-

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          pip install pytest pytest-cov

      - name: Run tests with coverage
        run: pytest tests/ --cov=src --cov-report=xml

      - name: Install Rust and PMAT
        run: |
          curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
          source $HOME/.cargo/env
          cargo install pmat

      - name: Run mutation tests
        run: |
          source $HOME/.cargo/env
          pmat mutate \
            --target src/ \
            --threshold 80 \
            --failures-only \
            --output-format json > mutation-results.json

      - name: Upload results
        uses: actions/upload-artifact@v3
        if: always()
        with:
          name: mutation-results-py${{ matrix.python-version }}
          path: mutation-results.json
```

### TypeScript/Node.js Project

```yaml
name: TypeScript Mutation Testing

on: [push, pull_request]

jobs:
  test-and-mutate:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [16, 18, 20]

    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run linter
        run: npm run lint

      - name: Run tests
        run: npm test -- --coverage

      - name: Install Rust and PMAT
        run: |
          curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
          source $HOME/.cargo/env
          cargo install pmat

      - name: Run mutation tests
        run: |
          source $HOME/.cargo/env
          pmat mutate \
            --target src/ \
            --threshold 85 \
            --jobs 4 \
            --output-format markdown > mutation-report.md

      - name: Comment PR with results
        if: github.event_name == 'pull_request'
        uses: actions/github-script@v6
        with:
          script: |
            const fs = require('fs');
            const report = fs.readFileSync('mutation-report.md', 'utf8');
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.name,
              body: report
            });
```

## Quality Gates

### Fail on Low Mutation Score

```yaml
      - name: Enforce mutation score threshold
        run: |
          SCORE=$(pmat mutate --target src/ --output-format json | jq '.mutation_score')
          echo "::notice ::Mutation Score: ${SCORE}%"

          if (( $(echo "$SCORE < 80" | bc -l) )); then
            echo "::error ::Mutation score ${SCORE}% is below required 80%"
            exit 1
          fi
```

### Progressive Thresholds

Different thresholds for different branches:

```yaml
      - name: Run mutation tests with branch-specific thresholds
        run: |
          if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
            THRESHOLD=90
          elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
            THRESHOLD=85
          else
            THRESHOLD=80
          fi

          echo "Using mutation score threshold: ${THRESHOLD}%"
          pmat mutate --target src/ --threshold $THRESHOLD
```

### Comment on PR with Results

```yaml
      - name: Run mutation tests
        id: mutation
        run: |
          pmat mutate \
            --target src/ \
            --output-format markdown > mutation-report.md

          SCORE=$(pmat mutate --target src/ --output-format json | jq '.mutation_score')
          echo "score=$SCORE" >> $GITHUB_OUTPUT

      - name: Comment PR
        if: github.event_name == 'pull_request'
        uses: actions/github-script@v6
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const fs = require('fs');
            const report = fs.readFileSync('mutation-report.md', 'utf8');
            const score = '${{ steps.mutation.outputs.score }}';

            const emoji = score >= 90 ? '🟢' : score >= 80 ? '🟡' : '🔴';
            const body = `## ${emoji} Mutation Testing Report\n\n**Score: ${score}%**\n\n${report}`;

            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.name,
              body: body
            });
```

## Advanced Patterns

### Matrix Testing (Multiple Languages)

```yaml
name: Multi-Language Mutation Testing

on: [push, pull_request]

jobs:
  mutation-test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        language: [rust, python, typescript]
        include:
          - language: rust
            target: src/
            threshold: 90
          - language: python
            target: python/src/
            threshold: 85
          - language: typescript
            target: ts/src/
            threshold: 85

    steps:
      - uses: actions/checkout@v4

      - name: Setup environment for ${{ matrix.language }}
        run: |
          case "${{ matrix.language }}" in
            rust)
              curl https://sh.rustup.rs -sSf | sh -s -- -y
              ;;
            python)
              sudo apt-get install -y python3 python3-pip
              ;;
            typescript)
              curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
              sudo apt-get install -y nodejs
              ;;
          esac

      - name: Install PMAT
        run: cargo install pmat

      - name: Run mutation tests for ${{ matrix.language }}
        run: |
          pmat mutate \
            --target ${{ matrix.target }} \
            --threshold ${{ matrix.threshold }} \
            --output-format json > mutation-${{ matrix.language }}.json

      - name: Upload results
        uses: actions/upload-artifact@v3
        with:
          name: mutation-results-${{ matrix.language }}
          path: mutation-${{ matrix.language }}.json
```

### Scheduled Mutation Testing

Run comprehensive mutation testing on a schedule:

```yaml
name: Scheduled Mutation Testing

on:
  schedule:
    # Run every night at 2 AM UTC
    - cron: '0 2 * * *'
  workflow_dispatch:  # Allow manual triggers

jobs:
  comprehensive-mutation-test:
    runs-on: ubuntu-latest
    timeout-minutes: 120  # 2 hours max

    steps:
      - uses: actions/checkout@v4

      - name: Install PMAT
        run: cargo install pmat

      - name: Run comprehensive mutation tests
        run: |
          pmat mutate \
            --target src/ \
            --jobs 8 \
            --timeout 30 \
            --output-format json > full-mutation-report.json

      - name: Generate historical trend
        run: |
          mkdir -p mutation-history
          cp full-mutation-report.json mutation-history/$(date +%Y-%m-%d).json

      - name: Commit history
        run: |
          git config user.name "Mutation Bot"
          git config user.email "bot@example.com"
          git add mutation-history/
          git commit -m "chore: Add mutation testing report for $(date +%Y-%m-%d)" || true
          git push
```

### Differential Mutation Testing

Test only changed files:

```yaml
      - name: Get changed files
        id: changed-files
        uses: tj-actions/changed-files@v39
        with:
          files: |
            src/**/*.rs
            src/**/*.py
            src/**/*.ts

      - name: Run mutation tests on changed files only
        if: steps.changed-files.outputs.any_changed == 'true'
        run: |
          for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
            echo "Testing mutations in: $file"
            pmat mutate --target "$file" --failures-only
          done
```

## Caching Strategies

### Cache PMAT Binary

```yaml
      - name: Cache PMAT binary
        id: cache-pmat
        uses: actions/cache@v3
        with:
          path: ~/.cargo/bin/pmat
          key: ${{ runner.os }}-pmat-${{ hashFiles('**/Cargo.lock') }}

      - name: Install PMAT
        if: steps.cache-pmat.outputs.cache-hit != 'true'
        run: cargo install pmat
```

### Cache Build Artifacts

```yaml
      - name: Cache build artifacts
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-
```

## Artifacts and Reporting

### Upload Multiple Reports

```yaml
      - name: Generate multiple report formats
        run: |
          pmat mutate --target src/ --output-format text > mutation-report.txt
          pmat mutate --target src/ --output-format json > mutation-report.json
          pmat mutate --target src/ --output-format markdown > mutation-report.md

      - name: Upload all reports
        uses: actions/upload-artifact@v3
        if: always()
        with:
          name: mutation-reports
          path: |
            mutation-report.txt
            mutation-report.json
            mutation-report.md
```

### Create GitHub Release with Report

```yaml
      - name: Create release with mutation report
        if: startsWith(github.ref, 'refs/tags/')
        uses: softprops/action-gh-release@v1
        with:
          files: |
            mutation-report.md
            mutation-report.json
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

## Troubleshooting

### Timeout Issues

If mutation testing takes too long:

```yaml
      - name: Run mutation tests with timeout
        timeout-minutes: 30
        run: |
          pmat mutate \
            --target src/ \
            --timeout 10 \
            --jobs 4
```

### Memory Issues

For large projects:

```yaml
      - name: Run mutation tests in batches
        run: |
          find src -name "*.rs" | xargs -n 10 -P 2 pmat mutate --target
```

### Debug Output

Enable verbose logging:

```yaml
      - name: Run mutation tests with debug output
        run: |
          RUST_LOG=debug pmat mutate --target src/ --verbose
```

## Best Practices

1. **Start with `--failures-only`** to reduce noise
2. **Use caching** to speed up builds
3. **Set reasonable timeouts** (5-10 seconds per mutant)
4. **Run comprehensive tests nightly**, lightweight on PRs
5. **Use matrix strategy** for multi-language projects
6. **Cache PMAT binary** to avoid rebuilding
7. **Set mutation score thresholds** as quality gates
8. **Upload artifacts** for historical tracking
9. **Comment on PRs** with mutation scores
10. **Use differential testing** on PRs to save time

## Example: Complete Production Workflow

```yaml
name: Production Mutation Testing

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
  schedule:
    - cron: '0 2 * * 0'  # Weekly on Sunday

jobs:
  mutation-test:
    runs-on: ubuntu-latest
    timeout-minutes: 60

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0  # Full history for trend analysis

      - name: Setup Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          profile: minimal

      - name: Cache dependencies
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
            ~/.cargo/bin/pmat
          key: ${{ runner.os }}-mutation-${{ hashFiles('**/Cargo.lock') }}

      - name: Install PMAT
        run: cargo install pmat || true

      - name: Run tests first
        run: cargo test --all-features

      - name: Run mutation tests
        id: mutation
        run: |
          if [[ "${{ github.event_name }}" == "pull_request" ]]; then
            MODE="--failures-only"
            THRESHOLD=80
          else
            MODE=""
            THRESHOLD=85
          fi

          pmat mutate \
            --target src/ \
            --threshold $THRESHOLD \
            $MODE \
            --jobs 4 \
            --timeout 10 \
            --output-format json > mutation-results.json

          SCORE=$(jq '.mutation_score' mutation-results.json)
          echo "score=$SCORE" >> $GITHUB_OUTPUT

      - name: Generate markdown report
        run: |
          pmat mutate \
            --target src/ \
            --output-format markdown > mutation-report.md

      - name: Upload artifacts
        uses: actions/upload-artifact@v3
        if: always()
        with:
          name: mutation-reports-${{ github.sha }}
          path: |
            mutation-results.json
            mutation-report.md

      - name: Comment on PR
        if: github.event_name == 'pull_request'
        uses: actions/github-script@v6
        with:
          script: |
            const fs = require('fs');
            const report = fs.readFileSync('mutation-report.md', 'utf8');
            const score = '${{ steps.mutation.outputs.score }}';
            const threshold = 80;

            const emoji = score >= 90 ? '🟢' : score >= threshold ? '🟡' : '🔴';
            const status = score >= threshold ? 'PASSED' : 'FAILED';

            const body = `## ${emoji} Mutation Testing Report - ${status}

**Mutation Score: ${score}%** (Threshold: ${threshold}%)

${report}

---
*Mutation testing powered by PMAT*
            `;

            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.name,
              body: body
            });
```

## Resources

- [PMAT GitHub Repository]https://github.com/paiml/paiml-mcp-agent-toolkit
- [GitHub Actions Documentation]https://docs.github.com/en/actions
- [Rust Example Project]../../examples/rust-mutation-testing/
- [Python Example Project]../../examples/python-mutation-testing/
- [TypeScript Example Project]../../examples/typescript-mutation-testing/