-
Notifications
You must be signed in to change notification settings - Fork 0
184 lines (166 loc) · 7.19 KB
/
Copy pathmutation.yml
File metadata and controls
184 lines (166 loc) · 7.19 KB
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
name: Mutation Tests
on:
schedule:
- cron: "0 3 * * 0" # weekly, Sunday 3 AM UTC
workflow_dispatch:
inputs:
target:
description: >
Module to mutate — leave blank to run all.
Valid values: canonkeeper, resolver, npc-voice, scene-loop, story-loop,
resource-engine, world-architect, plot-hooks, delta-detection, contradiction
required: false
default: ""
jobs:
mutate:
name: "mutate / ${{ matrix.target.name }}"
runs-on: ubuntu-latest
# Canonkeeper's test suite runs ~1400 mutants × 8 test files (~2k LOC).
# The default 90-minute cap was too tight — modules were getting cancelled
# mid-execution and the aggregate computed on incomplete data. GitHub-hosted
# runners support up to 6h, so 240 leaves headroom without hitting limits.
timeout-minutes: 240
strategy:
fail-fast: false
matrix:
target:
- { name: canonkeeper, toml: cosmic-ray.toml }
- { name: resolver, toml: cosmic-ray-resolver.toml }
- { name: npc-voice, toml: cosmic-ray-npc-voice.toml }
- { name: scene-loop, toml: cosmic-ray-scene-loop.toml }
- { name: story-loop, toml: cosmic-ray-story-loop.toml }
- { name: resource-engine, toml: cosmic-ray-resource-engine.toml }
- { name: world-architect, toml: cosmic-ray-world-architect.toml }
- { name: plot-hooks, toml: cosmic-ray-plot-hooks.toml }
- { name: delta-detection, toml: cosmic-ray-delta-detection.toml }
- { name: contradiction, toml: cosmic-ray-contradiction.toml }
- { name: context-assembly, toml: cosmic-ray-context-assembly.toml }
- { name: narrator, toml: cosmic-ray-narrator.toml }
- { name: simulacrum, toml: cosmic-ray-simulacrum.toml }
# Environment variables cannot be evaluated in job-level ifs.
# We will just run the matrix unconditionally, or you can add a step to skip.
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
with:
python-version: "3.11"
- run: uv sync --frozen || uv sync
- name: Install cosmic-ray
run: uv pip install "cosmic-ray>=8.0"
- name: Initialize session
run: uv run cosmic-ray init ${{ matrix.target.toml }} session-${{ matrix.target.name }}.sqlite
- name: Run mutations
run: uv run cosmic-ray exec ${{ matrix.target.toml }} session-${{ matrix.target.name }}.sqlite
- name: Report + extract score
id: score
run: |
REPORT=$(uv run cr-report session-${{ matrix.target.name }}.sqlite) || exit 1
echo "$REPORT"
SCORE=$(echo "$REPORT" | python3 -c "
import sys, re
text = sys.stdin.read()
pct = re.search(r'kill rate[:\s]+(\d+\.?\d*)\s*%', text, re.IGNORECASE)
dec = re.search(r'score[:\s]+(\d+\.\d+)', text, re.IGNORECASE)
surv = re.search(r'surviving mutants: \d+ \(([\d\.]+)\%\)', text, re.IGNORECASE)
if pct:
print(round(float(pct.group(1))))
elif dec:
print(round(float(dec.group(1)) * 100))
elif surv:
survival_rate = float(surv.group(1))
print(round(100.0 - survival_rate))
else:
print('FAIL')
")
if [ "$SCORE" = "FAIL" ]; then
echo "Failed to parse mutation score from cr-report output."
exit 1
fi
echo "score=$SCORE" >> $GITHUB_OUTPUT
echo "$SCORE" > score-${{ matrix.target.name }}.txt
echo "Kill rate for ${{ matrix.target.name }}: $SCORE%"
- name: Upload score artifact
uses: actions/upload-artifact@v4
with:
name: mutation-score-${{ matrix.target.name }}
path: score-${{ matrix.target.name }}.txt
aggregate:
name: "mutate / aggregate + badge"
needs: mutate
runs-on: ubuntu-latest
if: always()
steps:
- name: Download all score artifacts
uses: actions/download-artifact@v4
with:
pattern: mutation-score-*
merge-multiple: true
path: scores/
- name: Compute aggregate kill rate and update badge
env:
GIST_TOKEN: ${{ secrets.GIST_TOKEN }}
MUTATION_GIST_ID: ${{ secrets.MUTATION_GIST_ID }}
EXPECTED_MODULES: "13"
run: |
python3 << 'PYEOF'
import glob, json, os, urllib.request
scores = {}
for path in glob.glob("scores/score-*.txt"):
name = os.path.basename(path).removeprefix("score-").removesuffix(".txt")
try:
scores[name] = int(open(path).read().strip())
except (ValueError, OSError):
pass
expected = int(os.environ.get("EXPECTED_MODULES", "0"))
if not scores:
print("No score artifacts found — all mutation jobs may have failed.")
raise SystemExit(1)
if expected and len(scores) < expected:
missing = expected - len(scores)
print(
f"⚠ Only {len(scores)}/{expected} modules produced a score — "
f"{missing} timed out or failed. Aggregate below may be misleading."
)
avg = round(sum(scores.values()) / len(scores))
count = len(scores)
print(f"\nPer-module kill rates:")
for name, score in sorted(scores.items()):
bar = "█" * (score // 5) + "░" * (20 - score // 5)
print(f" {name:<20} {bar} {score}%")
suffix = (
f" (incomplete: {count}/{expected})"
if expected and count < expected
else f" across {count} modules"
)
print(f"\nAggregate: {avg}%{suffix}\n")
token = os.environ.get("GIST_TOKEN", "")
gist_id = os.environ.get("MUTATION_GIST_ID", "")
if not token or not gist_id:
print("GIST_TOKEN or MUTATION_GIST_ID not configured — badge update skipped.")
print("See docs/contributing/BADGES.md for setup instructions.")
raise SystemExit(0)
color = "brightgreen" if avg >= 80 else "yellow" if avg >= 60 else "red"
# Mark incomplete aggregates so the badge doesn't claim a score that
# was computed on a subset of modules.
message = (
f"{avg}% ({count}/{expected})"
if expected and count < expected
else f"{avg}% ({count} modules)"
)
badge = {
"schemaVersion": 1,
"label": "mutation score",
"message": message,
"color": color,
}
payload = json.dumps({
"files": {"mutation-score.json": {"content": json.dumps(badge, indent=2)}}
}).encode()
req = urllib.request.Request(
f"https://api.github.com/gists/{gist_id}",
data=payload, method="PATCH",
headers={"Authorization": f"token {token}", "Content-Type": "application/json"},
)
with urllib.request.urlopen(req) as r:
print(f"Gist badge updated: {message} ({color})")
PYEOF