Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Mutation

# Separate from build-and-test on purpose: release.yml waits only on build-and-test, so
# this never delays a release. It runs in parallel with build-and-test on the PR; making
# it block a merge is a branch-protection choice (mark the `mutation` check required).
#
# `dotnet stryker --since:origin/master` mutates only the changed diff (hermetic — E2E is
# filtered out in each stryker-config.json), then gate.sh --mutation fails on any new
# survivor. Only changed packages are mutated, so an unchanged package costs nothing.

on:
pull_request:
branches: [master]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
mutation:
runs-on: ubuntu-latest
# Ceiling, not the norm: Stryker.NET mutates everything if a non-C# file changed
# (stryker-net#3013), so the timeout bounds that worst case.
timeout-minutes: 30

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # --since and the gate's diff both need origin/master

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

- name: Install Stryker
run: dotnet tool install --global dotnet-stryker

- name: Mutate changed packages
run: |
git diff --name-only origin/master...HEAD -- 'packages/**/*.cs' \
| sed -E 's#(packages/[^/]+)/.*#\1#' | sort -u \
| while read -r pkg; do
cfg=$(ls "$pkg"/*.Tests/stryker-config.json 2>/dev/null) || continue
( cd "$(dirname "$cfg")" && dotnet stryker --since:origin/master )
done

- name: Evaluate mutation reports
run: ./scripts/quality-gate/gate.sh packages --mutation
3 changes: 2 additions & 1 deletion packages/Core/Core.Tests/stryker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"reporters": [
"json",
"progress"
]
],
"test-case-filter": "TestCategory!=E2E"
}
}
3 changes: 2 additions & 1 deletion packages/Functions/Functions.Tests/stryker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"reporters": [
"json",
"progress"
]
],
"test-case-filter": "TestCategory!=E2E"
}
}
3 changes: 2 additions & 1 deletion packages/Gotrue/Gotrue.Tests/stryker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"reporters": [
"json",
"progress"
]
],
"test-case-filter": "TestCategory!=E2E"
}
}
3 changes: 2 additions & 1 deletion packages/Postgrest/Postgrest.Tests/stryker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"reporters": [
"json",
"progress"
]
],
"test-case-filter": "TestCategory!=E2E"
}
}
3 changes: 2 additions & 1 deletion packages/Realtime/Realtime.Tests/stryker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"reporters": [
"json",
"progress"
]
],
"test-case-filter": "TestCategory!=E2E"
}
}
3 changes: 2 additions & 1 deletion packages/Storage/Storage.Tests/stryker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"reporters": [
"json",
"progress"
]
],
"test-case-filter": "TestCategory!=E2E"
}
}
3 changes: 2 additions & 1 deletion packages/Supabase/Supabase.Tests/stryker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"reporters": [
"json",
"progress"
]
],
"test-case-filter": "TestCategory!=E2E"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"stryker-config": {
"project": "Sample.csproj",
"test-projects": ["Sample.Tests.csproj"],
"test-case-filter": "TestCategory!=E2E"
}
}
9 changes: 9 additions & 0 deletions scripts/quality-gate/fixtures/mutation-clean/expect.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"description": "Every mutant in the changed file is killed — the tests actually assert on the new code. The mutation stage PASSes.",
"mode": "--mutation",
"exit": 0,
"verdict": "PASS",
"stages": [
{ "id": "3", "status": "PASS" }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Sample;

public class Calculator
{
public int Add(int a, int b) => a + b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"schemaVersion": "2",
"thresholds": {
"high": 80,
"low": 60
},
"files": {
"/repo/packages/Sample/Calculator.cs": {
"language": "cs",
"source": "namespace Sample;\n\npublic class Calculator\n{\n public int Add(int a, int b) => a + b;\n}\n",
"mutants": [
{
"id": "1",
"mutatorName": "Arithmetic",
"replacement": "a - b",
"location": {
"start": {
"line": 5,
"column": 41
},
"end": {
"line": 5,
"column": 46
}
},
"status": "Killed"
},
{
"id": "2",
"mutatorName": "Arithmetic",
"replacement": "a * b",
"location": {
"start": {
"line": 5,
"column": 41
},
"end": {
"line": 5,
"column": 46
}
},
"status": "Killed"
}
]
}
}
}
9 changes: 9 additions & 0 deletions scripts/quality-gate/fixtures/mutation-no-report/expect.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"description": "The diff changed a file but no Stryker report exists — 'couldn't check' must never read as 'no survivors'. The stage SKIPs and the run is INCOMPLETE (exit 2).",
"mode": "--mutation",
"exit": 2,
"verdict": "INCOMPLETE",
"stages": [
{ "id": "3", "status": "SKIP", "detailContains": "no usable mutation report" }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Sample;

public class Calculator
{
public int Add(int a, int b) => a + b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"description": "A survivor exists, but in Legacy.cs — a file this diff never touched. It's pre-existing debt, not this change's regression, so it's ignored; the changed file's mutants are all killed, so the stage PASSes.",
"mode": "--mutation",
"exit": 0,
"verdict": "PASS",
"stages": [
{ "id": "3", "status": "PASS" }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Sample;

public class Calculator
{
public int Add(int a, int b) => a + b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"schemaVersion": "2",
"thresholds": {
"high": 80,
"low": 60
},
"files": {
"/repo/packages/Sample/Calculator.cs": {
"language": "cs",
"source": "namespace Sample;\n\npublic class Calculator\n{\n public int Add(int a, int b) => a + b;\n}\n",
"mutants": [
{
"id": "1",
"mutatorName": "Arithmetic",
"replacement": "a - b",
"location": {
"start": {
"line": 5,
"column": 41
},
"end": {
"line": 5,
"column": 46
}
},
"status": "Killed"
}
]
},
"/repo/packages/Sample/Legacy.cs": {
"language": "cs",
"source": "namespace Sample;\n\npublic class Legacy\n{\n public int Twice(int n) => n * 2;\n}\n",
"mutants": [
{
"id": "2",
"mutatorName": "Arithmetic",
"replacement": "n / 2",
"location": {
"start": {
"line": 5,
"column": 32
},
"end": {
"line": 5,
"column": 37
}
},
"status": "Survived"
}
]
}
}
}
9 changes: 9 additions & 0 deletions scripts/quality-gate/fixtures/mutation-survivor/expect.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"description": "A surviving mutant lands on a line this diff added — a test executes the new code but asserts nothing, so line coverage is happy and the mutant lives. Only the mutation stage must FAIL.",
"mode": "--mutation",
"exit": 1,
"verdict": "FAIL",
"stages": [
{ "id": "3", "status": "FAIL", "detailContains": "new survivor" }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Sample;

public class Calculator
{
public int Add(int a, int b) => a + b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"schemaVersion": "2",
"thresholds": {
"high": 80,
"low": 60
},
"files": {
"/repo/packages/Sample/Calculator.cs": {
"language": "cs",
"source": "namespace Sample;\n\npublic class Calculator\n{\n public int Add(int a, int b) => a + b;\n}\n",
"mutants": [
{
"id": "1",
"mutatorName": "Arithmetic",
"replacement": "a - b",
"location": {
"start": {
"line": 5,
"column": 41
},
"end": {
"line": 5,
"column": 46
}
},
"status": "Survived"
},
{
"id": "2",
"mutatorName": "Arithmetic",
"replacement": "a * b",
"location": {
"start": {
"line": 5,
"column": 41
},
"end": {
"line": 5,
"column": 46
}
},
"status": "Killed"
}
]
}
}
}
Loading
Loading