@mark1russell7/rigor-mutation 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -2
- package/build/cli.js +1 -1
- package/build/collect.js +29 -10
- package/build/collect.js.map +1 -1
- package/build/index.d.ts +44 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -3
- package/build/reporter-BS3LIodv.d.ts +219 -0
- package/build/reporter-BS3LIodv.d.ts.map +1 -0
- package/build/reporter-BYC384h-.js +257 -0
- package/build/reporter-BYC384h-.js.map +1 -0
- package/build/reporter.d.ts +2 -2
- package/build/reporter.js +1 -1
- package/build/{run-DSF8ITXj.js → run-DcH6lUvo.js} +307 -39
- package/build/run-DcH6lUvo.js.map +1 -0
- package/package.json +1 -1
- package/build/reporter-CkdX8IPx.d.ts +0 -63
- package/build/reporter-CkdX8IPx.d.ts.map +0 -1
- package/build/reporter-Cypwcaj9.js +0 -66
- package/build/reporter-Cypwcaj9.js.map +0 -1
- package/build/run-DSF8ITXj.js.map +0 -1
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { dirname, join, relative, sep } from "node:path";
|
|
2
|
+
import { appendFileSync, mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
// src/plan.ts
|
|
4
|
+
/**
|
|
5
|
+
* The cost plan of a selection. Stryker makes a plan of the mutants after the run of the tests without mutants. The
|
|
6
|
+
* reporter `rigor-partial` writes the plan of each file and each line into `plan.json`. `plan-check` reads the file and
|
|
7
|
+
* gives the estimate of the clock of the selection. It warns of a selection over its target. It fails a selection over
|
|
8
|
+
* its stop, and a file over its limit of static runs. The cut of the parts can then follow the cost of the lines, and
|
|
9
|
+
* not the size of the files.
|
|
10
|
+
*/
|
|
11
|
+
/** The name of the file of the plan, in the folder of the JSON report. */
|
|
12
|
+
const PLAN_FILE = "plan.json";
|
|
13
|
+
/**
|
|
14
|
+
* The default planned net time of one minute of the clock. In a nightly run of Vex (GitHub Actions, 2 test processes),
|
|
15
|
+
* the mutants that ended had 9.8 to 11.7 times the planned time of their clock. The lower value gives the longer estimate.
|
|
16
|
+
*/
|
|
17
|
+
const PLAN_PER_CLOCK = 9.8;
|
|
18
|
+
/** The default target of the estimate of a selection, in minutes. A slow runner then ends a job of 150 minutes. */
|
|
19
|
+
const TARGET_MINUTES = 100;
|
|
20
|
+
/**
|
|
21
|
+
* The default stop of the estimate of a selection, in minutes. A selection over it does not end before the limit of the
|
|
22
|
+
* job, so it cannot give a full score. The estimate has an error of 28 minutes in the mean, so the target only warns.
|
|
23
|
+
*/
|
|
24
|
+
const STOP_MINUTES = 140;
|
|
25
|
+
/** This function gives the planned times of each mutant that Stryker starts, by the id of the mutant. */
|
|
26
|
+
function plannedRuns(plans, path = (f) => f) {
|
|
27
|
+
const runs = /* @__PURE__ */ new Map();
|
|
28
|
+
for (const { plan, mutant, netTime, runOptions } of plans) {
|
|
29
|
+
if (plan !== "Run") continue;
|
|
30
|
+
const line = mutant.location === void 0 ? 0 : mutant.location.start.line + 1;
|
|
31
|
+
runs.set(mutant.id, {
|
|
32
|
+
file: path(mutant.fileName),
|
|
33
|
+
line,
|
|
34
|
+
static: mutant.static === true,
|
|
35
|
+
netMs: Math.round(netTime ?? 0),
|
|
36
|
+
limitMs: Math.round(runOptions?.timeout ?? 0)
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return runs;
|
|
40
|
+
}
|
|
41
|
+
/** This function gives the plan of each file: its mutants, the mutants that Stryker starts, and their planned times. */
|
|
42
|
+
function filePlans(plans, path = (f) => f) {
|
|
43
|
+
const runs = plannedRuns(plans, path);
|
|
44
|
+
const files = /* @__PURE__ */ new Map();
|
|
45
|
+
for (const { mutant } of plans) {
|
|
46
|
+
const file = path(mutant.fileName);
|
|
47
|
+
const row = files.get(file) ?? {
|
|
48
|
+
mutants: 0,
|
|
49
|
+
runs: 0,
|
|
50
|
+
static: 0,
|
|
51
|
+
netMs: 0,
|
|
52
|
+
limitMs: 0,
|
|
53
|
+
byLine: /* @__PURE__ */ new Map()
|
|
54
|
+
};
|
|
55
|
+
files.set(file, row);
|
|
56
|
+
row.mutants += 1;
|
|
57
|
+
const run = runs.get(mutant.id);
|
|
58
|
+
if (run === void 0) continue;
|
|
59
|
+
row.runs += 1;
|
|
60
|
+
row.static += run.static ? 1 : 0;
|
|
61
|
+
row.netMs += run.netMs;
|
|
62
|
+
row.limitMs += run.limitMs;
|
|
63
|
+
const line = row.byLine.get(run.line) ?? [
|
|
64
|
+
run.line,
|
|
65
|
+
0,
|
|
66
|
+
0,
|
|
67
|
+
0
|
|
68
|
+
];
|
|
69
|
+
line[1] += 1;
|
|
70
|
+
line[2] += run.static ? 1 : 0;
|
|
71
|
+
line[3] += run.netMs;
|
|
72
|
+
row.byLine.set(run.line, line);
|
|
73
|
+
}
|
|
74
|
+
const plan = ({ byLine, ...row }) => ({
|
|
75
|
+
...row,
|
|
76
|
+
lines: [...byLine.values()].toSorted((a, b) => a[0] - b[0])
|
|
77
|
+
});
|
|
78
|
+
return Object.fromEntries([...files].toSorted(([a], [b]) => a.localeCompare(b)).map(([file, row]) => [file, plan(row)]));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* This function gives the tests of the largest planned cost, the largest first. The cost of a test is its time without
|
|
82
|
+
* mutants, times the runs that start it. A test with a large cost is the first place to make the selection faster.
|
|
83
|
+
*/
|
|
84
|
+
function testPlans(plans, tests, path = (f) => f, top = 40) {
|
|
85
|
+
const runs = new Map(tests.map((test) => [test.id, 0]));
|
|
86
|
+
let all = 0;
|
|
87
|
+
for (const { plan, runOptions } of plans) {
|
|
88
|
+
if (plan !== "Run") continue;
|
|
89
|
+
if (runOptions?.testFilter === void 0) all += 1;
|
|
90
|
+
else for (const id of runOptions.testFilter) runs.set(id, (runs.get(id) ?? 0) + 1);
|
|
91
|
+
}
|
|
92
|
+
return tests.map((test) => {
|
|
93
|
+
const count = (runs.get(test.id) ?? 0) + all;
|
|
94
|
+
return [
|
|
95
|
+
test.name,
|
|
96
|
+
test.fileName === void 0 ? "" : path(test.fileName),
|
|
97
|
+
Math.round(test.timeSpentMs),
|
|
98
|
+
count,
|
|
99
|
+
Math.round(count * test.timeSpentMs)
|
|
100
|
+
];
|
|
101
|
+
}).toSorted((a, b) => b[4] - a[4] || a[0].localeCompare(b[0])).slice(0, top);
|
|
102
|
+
}
|
|
103
|
+
/** This function gives the estimate of the minutes of the clock of a planned net time. */
|
|
104
|
+
function clockMinutes(netMs, planPerClock = PLAN_PER_CLOCK) {
|
|
105
|
+
return netMs / planPerClock / 6e4;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* This function gives the faults of the static runs of a plan. A static run starts each test, so it costs the time of
|
|
109
|
+
* all tests. Code outside a function gives a static mutant.
|
|
110
|
+
*/
|
|
111
|
+
function staticFaults(files, limits = {}) {
|
|
112
|
+
return Object.entries(files).flatMap(([file, plan]) => {
|
|
113
|
+
const limit = limits[file] ?? limits["*"];
|
|
114
|
+
if (limit === void 0 || plan.static <= limit) return [];
|
|
115
|
+
return [`${file}: the plan has ${String(plan.static)} static runs, and the limit is ${String(limit)}. Each static run starts each test. Move the code outside a function into a function.`];
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/** This function reads the plan of a selection: its estimate of the clock, against the target and the stop, and its static runs. */
|
|
119
|
+
function readPlan(name, plan, limits = {}) {
|
|
120
|
+
const rows = Object.values(plan.files);
|
|
121
|
+
const sum = (key) => rows.reduce((n, row) => n + row[key], 0);
|
|
122
|
+
const minutes = clockMinutes(sum("netMs"), limits.planPerClock);
|
|
123
|
+
const target = limits.targetMinutes ?? 100;
|
|
124
|
+
const stop = limits.stopMinutes ?? 140;
|
|
125
|
+
const estimate = `${name}: the estimate of ${minutes.toFixed(0)} minutes`;
|
|
126
|
+
const line = `${`${name}: ${String(sum("runs"))} runs, ${String(sum("static"))} of them static, with a planned net time of ${(sum("netMs") / 36e5).toFixed(1)} h.`} The estimate is ${minutes.toFixed(0)} minutes of the clock, the target is ${String(target)} and the stop is ${String(stop)}.`;
|
|
127
|
+
const overStop = minutes > stop ? [`${estimate} is over the stop of ${String(stop)}. The run cannot end before the stop, so it cannot give a full score. Cut the selection into more parts.`] : [];
|
|
128
|
+
const warnings = minutes > target && minutes <= stop ? [`${estimate} is over the target of ${String(target)}. Cut the selection into more parts.`] : [];
|
|
129
|
+
return {
|
|
130
|
+
runs: sum("runs"),
|
|
131
|
+
static: sum("static"),
|
|
132
|
+
netMs: sum("netMs"),
|
|
133
|
+
minutes,
|
|
134
|
+
faults: [...overStop, ...staticFaults(plan.files, limits.staticLimits)],
|
|
135
|
+
warnings,
|
|
136
|
+
line
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* This function reads the JSON of `plan.json`.
|
|
141
|
+
*
|
|
142
|
+
* @throws Error when the JSON has no object `files` or no list `tests`
|
|
143
|
+
*/
|
|
144
|
+
function parsePlan(json) {
|
|
145
|
+
const plan = json;
|
|
146
|
+
if (typeof plan !== "object" || plan === null || typeof plan.files !== "object" || plan.files === null || !Array.isArray(plan.tests)) throw new Error(`the plan has no object "files" or no list "tests"`);
|
|
147
|
+
return plan;
|
|
148
|
+
}
|
|
149
|
+
// src/reporter.ts
|
|
150
|
+
/**
|
|
151
|
+
* The Stryker reporter `rigor-partial`. It appends the plan and each tested mutant to `partial.jsonl`, next to the JSON
|
|
152
|
+
* report, at the time of each event. When a time limit stops Stryker, `scores` reads this file for a partial score. It
|
|
153
|
+
* also writes the cost plan into `plan.json`, and with `rigorPartial.stopAfterPlan` it stops Stryker after the plan.
|
|
154
|
+
*/
|
|
155
|
+
/** The name of the file of the reporter, in the folder of the JSON report. */
|
|
156
|
+
const PARTIAL_FILE = "partial.jsonl";
|
|
157
|
+
/** The reporter. Stryker gives it its options, and `now`, `cwd` and `exit` are for the tests. */
|
|
158
|
+
var PartialReporter = class {
|
|
159
|
+
static inject = ["options"];
|
|
160
|
+
file;
|
|
161
|
+
/** The file of the cost plan, in the folder of the JSON report. */
|
|
162
|
+
planFile;
|
|
163
|
+
now;
|
|
164
|
+
cwd;
|
|
165
|
+
exit;
|
|
166
|
+
stopAfterPlan;
|
|
167
|
+
tests = [];
|
|
168
|
+
runs = /* @__PURE__ */ new Map();
|
|
169
|
+
constructor(options, now = Date.now, cwd = process.cwd(), exit = (code) => process.exit(code)) {
|
|
170
|
+
this.now = now;
|
|
171
|
+
this.cwd = cwd;
|
|
172
|
+
this.exit = exit;
|
|
173
|
+
this.stopAfterPlan = options.rigorPartial?.stopAfterPlan === true;
|
|
174
|
+
const dir = join(cwd, dirname(options.jsonReporter?.fileName ?? "reports/mutation/mutation.json"));
|
|
175
|
+
this.file = join(dir, PARTIAL_FILE);
|
|
176
|
+
this.planFile = join(dir, PLAN_FILE);
|
|
177
|
+
mkdirSync(dir, { recursive: true });
|
|
178
|
+
writeFileSync(this.file, "");
|
|
179
|
+
this.write({
|
|
180
|
+
event: "start",
|
|
181
|
+
at: this.now()
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
onDryRunCompleted(event) {
|
|
185
|
+
this.tests = event.result.tests;
|
|
186
|
+
}
|
|
187
|
+
onMutationTestingPlanReady(event) {
|
|
188
|
+
const plans = event.mutantPlans;
|
|
189
|
+
this.write({
|
|
190
|
+
event: "plan",
|
|
191
|
+
at: this.now(),
|
|
192
|
+
mutants: plans.length,
|
|
193
|
+
run: plans.filter((p) => p.plan === "Run").length
|
|
194
|
+
});
|
|
195
|
+
this.runs = plannedRuns(plans, this.path);
|
|
196
|
+
writeFileSync(this.planFile, `${JSON.stringify({
|
|
197
|
+
files: filePlans(plans, this.path),
|
|
198
|
+
tests: testPlans(plans, this.tests, this.path)
|
|
199
|
+
}, null, 2)}\n`);
|
|
200
|
+
if (this.stopAfterPlan) this.exit(0);
|
|
201
|
+
}
|
|
202
|
+
onMutantTested(result) {
|
|
203
|
+
const reason = result.statusReason === void 0 ? {} : { statusReason: result.statusReason };
|
|
204
|
+
const run = result.id === void 0 ? void 0 : this.runs.get(result.id);
|
|
205
|
+
const planned = run === void 0 ? {} : {
|
|
206
|
+
netMs: run.netMs,
|
|
207
|
+
limitMs: run.limitMs,
|
|
208
|
+
static: run.static
|
|
209
|
+
};
|
|
210
|
+
this.write({
|
|
211
|
+
event: "mutant",
|
|
212
|
+
at: this.now(),
|
|
213
|
+
file: this.path(result.fileName),
|
|
214
|
+
status: result.status,
|
|
215
|
+
...reason,
|
|
216
|
+
mutatorName: result.mutatorName,
|
|
217
|
+
line: result.location.start.line,
|
|
218
|
+
...planned
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
onMutationTestReportReady() {
|
|
222
|
+
this.write({
|
|
223
|
+
event: "done",
|
|
224
|
+
at: this.now()
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/** This function gives the path of a file from the folder where Stryker starts, with `/`. */
|
|
228
|
+
path = (fileName) => relative(this.cwd, fileName).split(sep).join("/");
|
|
229
|
+
write(line) {
|
|
230
|
+
appendFileSync(this.file, `${JSON.stringify(line)}\n`);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
/** The schema of the option of the reporter. Stryker adds it to its own schema, so the option gives no warning. */
|
|
234
|
+
const strykerValidationSchema = {
|
|
235
|
+
$schema: "http://json-schema.org/draft-07/schema",
|
|
236
|
+
type: "object",
|
|
237
|
+
properties: { rigorPartial: {
|
|
238
|
+
description: "The options of the reporter rigor-partial.",
|
|
239
|
+
type: "object",
|
|
240
|
+
properties: { stopAfterPlan: {
|
|
241
|
+
description: "Stop Stryker after the reporter writes the plan.",
|
|
242
|
+
type: "boolean",
|
|
243
|
+
default: false
|
|
244
|
+
} },
|
|
245
|
+
additionalProperties: false,
|
|
246
|
+
default: {}
|
|
247
|
+
} }
|
|
248
|
+
};
|
|
249
|
+
/** The plugins of this module, in the form of `declareClassPlugin` of `@stryker-mutator/api/plugin`. */
|
|
250
|
+
const strykerPlugins = [{
|
|
251
|
+
kind: "Reporter",
|
|
252
|
+
name: "rigor-partial",
|
|
253
|
+
injectableClass: PartialReporter
|
|
254
|
+
}];
|
|
255
|
+
export { PLAN_FILE as a, TARGET_MINUTES as c, parsePlan as d, readPlan as f, strykerValidationSchema as i, clockMinutes as l, testPlans as m, PartialReporter as n, PLAN_PER_CLOCK as o, staticFaults as p, strykerPlugins as r, STOP_MINUTES as s, PARTIAL_FILE as t, filePlans as u };
|
|
256
|
+
|
|
257
|
+
//# sourceMappingURL=reporter-BYC384h-.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reporter-BYC384h-.js","names":[],"sources":["../src/plan.ts","../src/reporter.ts"],"sourcesContent":["/**\n * The cost plan of a selection. Stryker makes a plan of the mutants after the run of the tests without mutants. The\n * reporter `rigor-partial` writes the plan of each file and each line into `plan.json`. `plan-check` reads the file and\n * gives the estimate of the clock of the selection. It warns of a selection over its target. It fails a selection over\n * its stop, and a file over its limit of static runs. The cut of the parts can then follow the cost of the lines, and\n * not the size of the files.\n */\n\n/** The name of the file of the plan, in the folder of the JSON report. */\nexport const PLAN_FILE = \"plan.json\";\n\n/**\n * The default planned net time of one minute of the clock. In a nightly run of Vex (GitHub Actions, 2 test processes),\n * the mutants that ended had 9.8 to 11.7 times the planned time of their clock. The lower value gives the longer estimate.\n */\nexport const PLAN_PER_CLOCK = 9.8;\n\n/** The default target of the estimate of a selection, in minutes. A slow runner then ends a job of 150 minutes. */\nexport const TARGET_MINUTES = 100;\n\n/**\n * The default stop of the estimate of a selection, in minutes. A selection over it does not end before the limit of the\n * job, so it cannot give a full score. The estimate has an error of 28 minutes in the mean, so the target only warns.\n */\nexport const STOP_MINUTES = 140;\n\n/** The count of the tests of the largest cost that the plan keeps. */\nexport const TOP_TESTS = 40;\n\n/** The parts of a plan of Stryker for one mutant that the reporter reads. */\nexport interface PlanOfMutant {\n readonly plan: string;\n readonly mutant: {\n readonly id: string;\n readonly fileName: string;\n readonly static?: boolean;\n /** The start of the mutant. In a plan, Stryker counts the lines from 0. */\n readonly location?: { readonly start: { readonly line: number } };\n };\n readonly netTime?: number;\n /** The tests that Stryker starts for the mutant. With no filter, Stryker starts all tests, as for a static mutant. */\n readonly runOptions?: { readonly timeout?: number; readonly testFilter?: readonly string[] };\n}\n\n/** The parts of a test of the run without mutants that the reporter reads. */\nexport interface TestOfDryRun {\n readonly id: string;\n readonly name: string;\n readonly fileName?: string;\n readonly timeSpentMs: number;\n}\n\n/** The planned times of one mutant that Stryker starts. */\nexport interface PlannedRun {\n readonly file: string;\n /** The line of the start of the mutant, counted from 1. The value 0 is a mutant with no location. */\n readonly line: number;\n readonly static: boolean;\n readonly netMs: number;\n readonly limitMs: number;\n}\n\n/** The plan of one line: the line from 1, the runs that start on it, the static runs of them, and their planned net time. */\nexport type LinePlan = readonly [line: number, runs: number, staticRuns: number, netMs: number];\n\n/** The plan of one file of a selection. */\nexport interface FilePlan {\n /** The mutants of the file, with the mutants that have an early result. */\n readonly mutants: number;\n readonly runs: number;\n readonly static: number;\n readonly netMs: number;\n readonly limitMs: number;\n /** The plan of each line with a run, in the order of the lines. */\n readonly lines: readonly LinePlan[];\n}\n\n/** The plan of one test: its name, its file, its time without mutants, the runs that start it, and their product. */\nexport type TestPlan = readonly [name: string, file: string, ms: number, runs: number, costMs: number];\n\n/** The content of `plan.json`. The paths of the files are from the folder where Stryker starts. */\nexport interface SelectionPlan {\n readonly files: Readonly<Record<string, FilePlan>>;\n readonly tests: readonly TestPlan[];\n}\n\n/** This function gives the planned times of each mutant that Stryker starts, by the id of the mutant. */\nexport function plannedRuns(plans: readonly PlanOfMutant[], path: (fileName: string) => string = (f) => f): Map<string, PlannedRun> {\n const runs = new Map<string, PlannedRun>();\n for (const { plan, mutant, netTime, runOptions } of plans) {\n if (plan !== \"Run\") continue;\n const line = mutant.location === undefined ? 0 : mutant.location.start.line + 1;\n runs.set(mutant.id, { file: path(mutant.fileName), line, static: mutant.static === true, netMs: Math.round(netTime ?? 0), limitMs: Math.round(runOptions?.timeout ?? 0) });\n }\n return runs;\n}\n\n/** This function gives the plan of each file: its mutants, the mutants that Stryker starts, and their planned times. */\nexport function filePlans(plans: readonly PlanOfMutant[], path: (fileName: string) => string = (f) => f): Record<string, FilePlan> {\n const runs = plannedRuns(plans, path);\n type Row = { mutants: number; runs: number; static: number; netMs: number; limitMs: number; byLine: Map<number, [number, number, number, number]> };\n const files = new Map<string, Row>();\n for (const { mutant } of plans) {\n const file = path(mutant.fileName);\n const row = files.get(file) ?? { mutants: 0, runs: 0, static: 0, netMs: 0, limitMs: 0, byLine: new Map() };\n files.set(file, row);\n row.mutants += 1;\n const run = runs.get(mutant.id);\n if (run === undefined) continue;\n row.runs += 1;\n row.static += run.static ? 1 : 0;\n row.netMs += run.netMs;\n row.limitMs += run.limitMs;\n const line = row.byLine.get(run.line) ?? [run.line, 0, 0, 0];\n line[1] += 1;\n line[2] += run.static ? 1 : 0;\n line[3] += run.netMs;\n row.byLine.set(run.line, line);\n }\n const plan = ({ byLine, ...row }: Row): FilePlan => ({ ...row, lines: [...byLine.values()].toSorted((a, b) => a[0] - b[0]) });\n return Object.fromEntries([...files].toSorted(([a], [b]) => a.localeCompare(b)).map(([file, row]) => [file, plan(row)]));\n}\n\n/**\n * This function gives the tests of the largest planned cost, the largest first. The cost of a test is its time without\n * mutants, times the runs that start it. A test with a large cost is the first place to make the selection faster.\n */\nexport function testPlans(plans: readonly PlanOfMutant[], tests: readonly TestOfDryRun[], path: (fileName: string) => string = (f) => f, top: number = TOP_TESTS): TestPlan[] {\n const runs = new Map<string, number>(tests.map((test) => [test.id, 0]));\n let all = 0;\n for (const { plan, runOptions } of plans) {\n if (plan !== \"Run\") continue;\n if (runOptions?.testFilter === undefined) all += 1;\n else for (const id of runOptions.testFilter) runs.set(id, (runs.get(id) ?? 0) + 1);\n }\n const rows = tests.map((test): TestPlan => {\n const count = (runs.get(test.id) ?? 0) + all;\n return [test.name, test.fileName === undefined ? \"\" : path(test.fileName), Math.round(test.timeSpentMs), count, Math.round(count * test.timeSpentMs)];\n });\n return rows.toSorted((a, b) => b[4] - a[4] || a[0].localeCompare(b[0])).slice(0, top);\n}\n\n/** This function gives the estimate of the minutes of the clock of a planned net time. */\nexport function clockMinutes(netMs: number, planPerClock: number = PLAN_PER_CLOCK): number {\n return netMs / planPerClock / 60_000;\n}\n\n/** The read of the plan of a selection. */\nexport interface PlanRead {\n readonly runs: number;\n readonly static: number;\n readonly netMs: number;\n /** The estimate of the clock of the selection, in minutes. */\n readonly minutes: number;\n /** One line for a selection over its stop, and one for each file over its limit of static runs. */\n readonly faults: readonly string[];\n /** One line for a selection over its target and under its stop. */\n readonly warnings: readonly string[];\n /** The line of the plan of the selection, with its estimate. */\n readonly line: string;\n}\n\n/** The limits of the read of a plan. */\nexport interface PlanLimits {\n readonly planPerClock?: number;\n readonly targetMinutes?: number;\n readonly stopMinutes?: number;\n /** The most static runs of each file. The key `*` gives the limit of each file that the field does not name. */\n readonly staticLimits?: Readonly<Record<string, number>>;\n}\n\n/**\n * This function gives the faults of the static runs of a plan. A static run starts each test, so it costs the time of\n * all tests. Code outside a function gives a static mutant.\n */\nexport function staticFaults(files: Readonly<Record<string, FilePlan>>, limits: Readonly<Record<string, number>> = {}): string[] {\n return Object.entries(files).flatMap(([file, plan]) => {\n const limit = limits[file] ?? limits[\"*\"];\n if (limit === undefined || plan.static <= limit) return [];\n return [`${file}: the plan has ${String(plan.static)} static runs, and the limit is ${String(limit)}. Each static run starts each test. Move the code outside a function into a function.`];\n });\n}\n\n/** This function reads the plan of a selection: its estimate of the clock, against the target and the stop, and its static runs. */\nexport function readPlan(name: string, plan: SelectionPlan, limits: PlanLimits = {}): PlanRead {\n const rows = Object.values(plan.files);\n const sum = (key: \"runs\" | \"static\" | \"netMs\"): number => rows.reduce((n, row) => n + row[key], 0);\n const minutes = clockMinutes(sum(\"netMs\"), limits.planPerClock);\n const target = limits.targetMinutes ?? TARGET_MINUTES;\n const stop = limits.stopMinutes ?? STOP_MINUTES;\n const estimate = `${name}: the estimate of ${minutes.toFixed(0)} minutes`;\n const head = `${name}: ${String(sum(\"runs\"))} runs, ${String(sum(\"static\"))} of them static, with a planned net time of ${(sum(\"netMs\") / 3_600_000).toFixed(1)} h.`;\n const line = `${head} The estimate is ${minutes.toFixed(0)} minutes of the clock, the target is ${String(target)} and the stop is ${String(stop)}.`;\n const overStop = minutes > stop ? [`${estimate} is over the stop of ${String(stop)}. The run cannot end before the stop, so it cannot give a full score. Cut the selection into more parts.`] : [];\n const warnings = minutes > target && minutes <= stop ? [`${estimate} is over the target of ${String(target)}. Cut the selection into more parts.`] : [];\n return { runs: sum(\"runs\"), static: sum(\"static\"), netMs: sum(\"netMs\"), minutes, faults: [...overStop, ...staticFaults(plan.files, limits.staticLimits)], warnings, line };\n}\n\n/**\n * This function reads the JSON of `plan.json`.\n *\n * @throws Error when the JSON has no object `files` or no list `tests`\n */\nexport function parsePlan(json: unknown): SelectionPlan {\n const plan = json as Partial<SelectionPlan> | null;\n if (typeof plan !== \"object\" || plan === null || typeof plan.files !== \"object\" || plan.files === null || !Array.isArray(plan.tests)) {\n throw new Error(`the plan has no object \"files\" or no list \"tests\"`);\n }\n return plan as SelectionPlan;\n}\n","/**\n * The Stryker reporter `rigor-partial`. It appends the plan and each tested mutant to `partial.jsonl`, next to the JSON\n * report, at the time of each event. When a time limit stops Stryker, `scores` reads this file for a partial score. It\n * also writes the cost plan into `plan.json`, and with `rigorPartial.stopAfterPlan` it stops Stryker after the plan.\n */\nimport { appendFileSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative, sep } from \"node:path\";\nimport { filePlans, PLAN_FILE, plannedRuns, testPlans, type PlannedRun, type PlanOfMutant, type TestOfDryRun } from \"./plan.ts\";\n\n/** The name of the file of the reporter, in the folder of the JSON report. */\nexport const PARTIAL_FILE = \"partial.jsonl\";\n\n/** A line of `partial.jsonl`. The field `at` gives the time in milliseconds since 1970. */\nexport type PartialLine =\n | { readonly event: \"start\"; readonly at: number }\n | { readonly event: \"plan\"; readonly at: number; readonly mutants: number; readonly run: number }\n | {\n readonly event: \"mutant\";\n readonly at: number;\n readonly file: string;\n readonly status: string;\n readonly statusReason?: string;\n readonly mutatorName: string;\n readonly line: number;\n /** The planned net time of the mutant in milliseconds. A mutant with an early result has none. */\n readonly netMs?: number;\n /** The time limit of the mutant in milliseconds. A mutant that the clock stops costs this time. */\n readonly limitMs?: number;\n readonly static?: boolean;\n }\n | { readonly event: \"done\"; readonly at: number };\n\n/** The parts of a Stryker mutant result that the reporter reads. */\ninterface TestedMutant {\n readonly id?: string;\n readonly fileName: string;\n readonly status: string;\n readonly statusReason?: string;\n readonly mutatorName: string;\n readonly location: { readonly start: { readonly line: number } };\n}\n\n/** The options of Stryker that the reporter reads. */\nexport interface ReporterOptions {\n readonly jsonReporter?: { readonly fileName?: string };\n /** With `stopAfterPlan` at true, the reporter stops Stryker after it writes the plan, before the first mutant. */\n readonly rigorPartial?: { readonly stopAfterPlan?: boolean };\n}\n\n/** The reporter. Stryker gives it its options, and `now`, `cwd` and `exit` are for the tests. */\nexport class PartialReporter {\n static readonly inject = [\"options\"] as const;\n readonly file: string;\n /** The file of the cost plan, in the folder of the JSON report. */\n readonly planFile: string;\n private readonly now: () => number;\n private readonly cwd: string;\n private readonly exit: (code: number) => void;\n private readonly stopAfterPlan: boolean;\n private tests: readonly TestOfDryRun[] = [];\n private runs = new Map<string, PlannedRun>();\n\n constructor(options: ReporterOptions, now: () => number = Date.now, cwd: string = process.cwd(), exit: (code: number) => void = (code) => process.exit(code)) {\n this.now = now;\n this.cwd = cwd;\n this.exit = exit;\n this.stopAfterPlan = options.rigorPartial?.stopAfterPlan === true;\n const dir = join(cwd, dirname(options.jsonReporter?.fileName ?? \"reports/mutation/mutation.json\"));\n this.file = join(dir, PARTIAL_FILE);\n this.planFile = join(dir, PLAN_FILE);\n mkdirSync(dir, { recursive: true });\n writeFileSync(this.file, \"\");\n this.write({ event: \"start\", at: this.now() });\n }\n\n onDryRunCompleted(event: { readonly result: { readonly tests: readonly TestOfDryRun[] } }): void {\n this.tests = event.result.tests;\n }\n\n onMutationTestingPlanReady(event: { readonly mutantPlans: readonly PlanOfMutant[] }): void {\n const plans = event.mutantPlans;\n this.write({ event: \"plan\", at: this.now(), mutants: plans.length, run: plans.filter((p) => p.plan === \"Run\").length });\n this.runs = plannedRuns(plans, this.path);\n writeFileSync(this.planFile, `${JSON.stringify({ files: filePlans(plans, this.path), tests: testPlans(plans, this.tests, this.path) }, null, 2)}\\n`);\n // The test processes of Stryker stop with this process.\n if (this.stopAfterPlan) this.exit(0);\n }\n\n onMutantTested(result: TestedMutant): void {\n const reason = result.statusReason === undefined ? {} : { statusReason: result.statusReason };\n const run = result.id === undefined ? undefined : this.runs.get(result.id);\n const planned = run === undefined ? {} : { netMs: run.netMs, limitMs: run.limitMs, static: run.static };\n this.write({ event: \"mutant\", at: this.now(), file: this.path(result.fileName), status: result.status, ...reason, mutatorName: result.mutatorName, line: result.location.start.line, ...planned });\n }\n\n onMutationTestReportReady(): void {\n this.write({ event: \"done\", at: this.now() });\n }\n\n /** This function gives the path of a file from the folder where Stryker starts, with `/`. */\n private readonly path = (fileName: string): string => relative(this.cwd, fileName).split(sep).join(\"/\");\n\n // A synchronous append: a stop of the process loses no line of a mutant that was tested.\n private write(line: PartialLine): void {\n appendFileSync(this.file, `${JSON.stringify(line)}\\n`);\n }\n}\n\n/** The schema of the option of the reporter. Stryker adds it to its own schema, so the option gives no warning. */\nexport const strykerValidationSchema = {\n $schema: \"http://json-schema.org/draft-07/schema\",\n type: \"object\",\n properties: {\n rigorPartial: {\n description: \"The options of the reporter rigor-partial.\",\n type: \"object\",\n properties: { stopAfterPlan: { description: \"Stop Stryker after the reporter writes the plan.\", type: \"boolean\", default: false } },\n additionalProperties: false,\n default: {},\n },\n },\n} as const;\n\n/** The plugins of this module, in the form of `declareClassPlugin` of `@stryker-mutator/api/plugin`. */\nexport const strykerPlugins: readonly { readonly kind: \"Reporter\"; readonly name: string; readonly injectableClass: typeof Partial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c;EACZ,aAAa;EACb,MAAM;EACN,YAAY,EAAE,eAAe;GAAE,aAAa;GAAoD,MAAM;GAAW,SAAS;EAAM,EAAE;EAClI,sBAAsB;EACtB,SAAS,CAAC;CACZ,EACF;AACF;;AAGA,MAAa,iBAAoI,CAC/I;CAAE,MAAM;CAAY,MAAM;CAAiB,iBAAiB;AAAgB,CAC9E"}
|
package/build/reporter.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { PARTIAL_FILE, PartialLine, PartialReporter, strykerPlugins };
|
|
1
|
+
import { a as strykerPlugins, i as ReporterOptions, n as PartialLine, o as strykerValidationSchema, r as PartialReporter, t as PARTIAL_FILE } from "./reporter-BS3LIodv.js";
|
|
2
|
+
export { PARTIAL_FILE, PartialLine, PartialReporter, ReporterOptions, strykerPlugins, strykerValidationSchema };
|
package/build/reporter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as PARTIAL_FILE, n as PartialReporter, r as strykerPlugins } from "./reporter-
|
|
1
|
+
export { t as PARTIAL_FILE, n as PartialReporter, r as strykerPlugins, i as strykerValidationSchema } from "./reporter-BYC384h-.js";
|