mutant-cafe 0.1.3 → 0.1.4
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 +66 -0
- package/dist/bin.js +267 -112
- package/dist/bin.js.map +4 -4
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -133,7 +133,22 @@ var NotMutated = Schema3.Struct({
|
|
|
133
133
|
functionName: Schema3.String,
|
|
134
134
|
reason: Schema3.String
|
|
135
135
|
});
|
|
136
|
+
var SelectionCounts = Schema3.Struct({
|
|
137
|
+
selected: Schema3.Int,
|
|
138
|
+
run: Schema3.Int,
|
|
139
|
+
budgetSkipped: Schema3.Int
|
|
140
|
+
});
|
|
141
|
+
var MutantList = Schema3.Struct({
|
|
142
|
+
schemaVersion: Schema3.Literal(2),
|
|
143
|
+
tool: Schema3.Literal("mutant.cafe"),
|
|
144
|
+
mutants: Schema3.Array(Mutant),
|
|
145
|
+
notMutated: Schema3.Array(NotMutated),
|
|
146
|
+
counts: SelectionCounts
|
|
147
|
+
});
|
|
136
148
|
var RunReport = Schema3.Struct({
|
|
149
|
+
selected: Schema3.optional(Schema3.Int),
|
|
150
|
+
run: Schema3.optional(Schema3.Int),
|
|
151
|
+
budgetSkipped: Schema3.optional(Schema3.Int),
|
|
137
152
|
schemaVersion: Schema3.Literal(2),
|
|
138
153
|
tool: Schema3.Literal("mutant.cafe"),
|
|
139
154
|
root: Schema3.String,
|
|
@@ -162,33 +177,33 @@ import * as Schema4 from "effect/Schema";
|
|
|
162
177
|
|
|
163
178
|
// packages/engine/src/Generate.ts
|
|
164
179
|
import { createHash } from "node:crypto";
|
|
165
|
-
function* generateFunction(
|
|
166
|
-
const api =
|
|
180
|
+
function* generateFunction(fn9) {
|
|
181
|
+
const api = fn9.api;
|
|
167
182
|
const candidate = (genre, expression, value = { text: "", synthetic: false }, description = expression) => {
|
|
168
|
-
const pinned = `((): ${
|
|
169
|
-
const text =
|
|
170
|
-
return makeMutant(
|
|
183
|
+
const pinned = `((): ${fn9.returnType} => (${expression}))()`;
|
|
184
|
+
const text = fn9.block ? `{ return ${fn9.generator ? "yield* " : ""}${pinned}; }` : `(${pinned})`;
|
|
185
|
+
return makeMutant(fn9, genre, text, value.synthetic, description);
|
|
171
186
|
};
|
|
172
|
-
const shape =
|
|
187
|
+
const shape = fn9.shape;
|
|
173
188
|
switch (shape.kind) {
|
|
174
189
|
case "Effect": {
|
|
175
|
-
const
|
|
176
|
-
if (
|
|
190
|
+
const succeed4 = api("Effect", "succeed");
|
|
191
|
+
if (succeed4) {
|
|
177
192
|
for (const value of shape.values) {
|
|
178
|
-
if (!
|
|
193
|
+
if (!fn9.equivalentValues.includes(value.text)) yield candidate("EffectSucceed", `${succeed4}(${value.text})`, value);
|
|
179
194
|
}
|
|
180
195
|
}
|
|
181
196
|
const fail3 = api("Effect", "fail");
|
|
182
|
-
const
|
|
183
|
-
for (const
|
|
184
|
-
if (fail3) yield candidate("EffectFail", `${fail3}(${
|
|
197
|
+
const catchTag3 = api("Effect", "catchTag");
|
|
198
|
+
for (const error3 of shape.errors) {
|
|
199
|
+
if (fail3) yield candidate("EffectFail", `${fail3}(${error3.text})`, error3, `${fail3}(${error3.text}) [${error3.synthetic ? "synthetic tag cast" : "constructed error"}]`);
|
|
185
200
|
const value = shape.values[0];
|
|
186
201
|
const die3 = api("Effect", "die");
|
|
187
|
-
const recovery = value &&
|
|
188
|
-
if (
|
|
189
|
-
const
|
|
190
|
-
const original =
|
|
191
|
-
if (original) yield candidate(value ? "SwallowTag" : "TagToDefect", `${original}.pipe(${
|
|
202
|
+
const recovery = value && succeed4 ? `${succeed4}(${value.text})` : die3 ? `${die3}(${JSON.stringify(`mutant.cafe: swallowed ${error3.tag}`)})` : void 0;
|
|
203
|
+
if (catchTag3 && recovery) {
|
|
204
|
+
const gen9 = api("Effect", "gen");
|
|
205
|
+
const original = fn9.generator ? gen9 && `((): ${fn9.returnType} => ${gen9}(function* () ${fn9.original}))()` : fn9.block ? `((): ${fn9.returnType} => ${fn9.original})()` : `((): ${fn9.returnType} => (${fn9.original}))()`;
|
|
206
|
+
if (original) yield candidate(value ? "SwallowTag" : "TagToDefect", `${original}.pipe(${catchTag3}(${JSON.stringify(error3.tag)}, () => ${recovery}))`, value, value ? `body.pipe(${catchTag3}(${JSON.stringify(error3.tag)}, () => ${recovery}))` : `turn ${error3.tag} into a defect`);
|
|
192
207
|
}
|
|
193
208
|
}
|
|
194
209
|
const die2 = api("Effect", "die");
|
|
@@ -206,11 +221,11 @@ function* generateFunction(fn8) {
|
|
|
206
221
|
}
|
|
207
222
|
case "Stream": {
|
|
208
223
|
const empty = api("Stream", "empty");
|
|
209
|
-
const
|
|
224
|
+
const make9 = api("Stream", "make");
|
|
210
225
|
const fail3 = api("Stream", "fail");
|
|
211
226
|
if (empty) yield candidate("StreamEmpty", empty);
|
|
212
|
-
if (
|
|
213
|
-
if (fail3) for (const
|
|
227
|
+
if (make9) for (const value of shape.values) yield candidate("StreamOne", `${make9}(${value.text})`, value);
|
|
228
|
+
if (fail3) for (const error3 of shape.errors) yield candidate("StreamFail", `${fail3}(${error3.text})`, error3);
|
|
214
229
|
break;
|
|
215
230
|
}
|
|
216
231
|
case "Layer": {
|
|
@@ -219,37 +234,37 @@ function* generateFunction(fn8) {
|
|
|
219
234
|
const die2 = api("Effect", "die");
|
|
220
235
|
if (layer2 && die2) yield candidate("LayerDie", `${layer2}(${die2}("mutant.cafe"))`);
|
|
221
236
|
if (layer2 && fail3) {
|
|
222
|
-
for (const
|
|
237
|
+
for (const error3 of shape.errors) yield candidate("LayerFail", `${layer2}(${fail3}(${error3.text}))`, error3);
|
|
223
238
|
}
|
|
224
239
|
break;
|
|
225
240
|
}
|
|
226
241
|
case "Void":
|
|
227
|
-
yield makeMutant(
|
|
242
|
+
yield makeMutant(fn9, "FnValue", "{}", false, "an empty body");
|
|
228
243
|
break;
|
|
229
244
|
default: {
|
|
230
245
|
const genre = shape.kind === "Boolean" ? "BooleanFlip" : shape.kind === "Literal" ? "LiteralCycle" : "FnValue";
|
|
231
246
|
for (const value of shape.values) {
|
|
232
|
-
if (shape.kind === "Literal" && value.text ===
|
|
247
|
+
if (shape.kind === "Literal" && value.text === fn9.literal) continue;
|
|
233
248
|
yield candidate(genre, value.text, value);
|
|
234
249
|
}
|
|
235
250
|
}
|
|
236
251
|
}
|
|
237
252
|
}
|
|
238
|
-
function makeMutant(
|
|
239
|
-
const additions =
|
|
240
|
-
const prefix =
|
|
241
|
-
const insertion =
|
|
242
|
-
const replacement = additions.length &&
|
|
243
|
-
const id = createHash("sha256").update(JSON.stringify([
|
|
253
|
+
function makeMutant(fn9, genre, text, synthetic, description) {
|
|
254
|
+
const additions = fn9.extraImports?.filter((item) => text.includes(`${item.namespace}.`)) ?? [];
|
|
255
|
+
const prefix = fn9.sourcePrefix ?? "";
|
|
256
|
+
const insertion = fn9.importInsertionOffset ?? 0;
|
|
257
|
+
const replacement = additions.length && fn9.sourcePrefix !== void 0 ? { startOffset: 0, endOffset: fn9.endOffset, text: prefix.slice(0, insertion) + (insertion ? "\n" : "") + additions.map((item) => item.statement).join("\n") + "\n" + prefix.slice(insertion) + text } : { startOffset: fn9.startOffset, endOffset: fn9.endOffset, text };
|
|
258
|
+
const id = createHash("sha256").update(JSON.stringify([fn9.identityFile ?? fn9.file, fn9.name, fn9.identityOrdinal ?? 0, fn9.logicalSpan, genre, text, additions.map((item) => item.statement)])).digest("hex").slice(0, 24);
|
|
244
259
|
return {
|
|
245
260
|
id,
|
|
246
|
-
file:
|
|
247
|
-
functionName:
|
|
248
|
-
returnType:
|
|
249
|
-
displayReturnType:
|
|
261
|
+
file: fn9.file,
|
|
262
|
+
functionName: fn9.name,
|
|
263
|
+
returnType: fn9.returnType,
|
|
264
|
+
displayReturnType: fn9.displayReturnType,
|
|
250
265
|
genre,
|
|
251
|
-
description: `replace ${
|
|
252
|
-
span:
|
|
266
|
+
description: `replace ${fn9.name} -> ${fn9.returnType} with ${description}`,
|
|
267
|
+
span: fn9.span,
|
|
253
268
|
replacement,
|
|
254
269
|
synthetic
|
|
255
270
|
};
|
|
@@ -424,10 +439,10 @@ function makeTypeScriptOracle() {
|
|
|
424
439
|
const found = [];
|
|
425
440
|
visit(source);
|
|
426
441
|
const occurrences = /* @__PURE__ */ new Map();
|
|
427
|
-
for (const
|
|
428
|
-
const ordinal = occurrences.get(
|
|
429
|
-
occurrences.set(
|
|
430
|
-
functions.push({ ...
|
|
442
|
+
for (const fn9 of found) {
|
|
443
|
+
const ordinal = occurrences.get(fn9.name) ?? 0;
|
|
444
|
+
occurrences.set(fn9.name, ordinal + 1);
|
|
445
|
+
functions.push({ ...fn9, identityOrdinal: ordinal });
|
|
431
446
|
}
|
|
432
447
|
}
|
|
433
448
|
const unmatched = config.include.filter((glob) => !matched.has(glob));
|
|
@@ -731,7 +746,7 @@ function shapeOf(type, checker, node, body) {
|
|
|
731
746
|
return {
|
|
732
747
|
kind: "Effect",
|
|
733
748
|
values: [...new Map(values2.map((value) => [value.text, value])).values()].sort((a, b) => a.text.localeCompare(b.text, "en")),
|
|
734
|
-
errors: [...new Map(errors.map((
|
|
749
|
+
errors: [...new Map(errors.map((error3) => [error3.tag, error3])).values()].sort((a, b) => a.tag.localeCompare(b.tag, "en"))
|
|
735
750
|
};
|
|
736
751
|
}
|
|
737
752
|
const detected = family(type, checker);
|
|
@@ -926,28 +941,28 @@ function makeMutantSource(oracle) {
|
|
|
926
941
|
const discovered = oracle.discover(config);
|
|
927
942
|
const notMutated = [...discovered.notMutated];
|
|
928
943
|
const mutants = [];
|
|
929
|
-
for (const
|
|
930
|
-
const generated = [...generateFunction(
|
|
931
|
-
if (!generated.length) notMutated.push({ file:
|
|
944
|
+
for (const fn9 of discovered.functions) {
|
|
945
|
+
const generated = [...generateFunction(fn9)];
|
|
946
|
+
if (!generated.length) notMutated.push({ file: fn9.file, functionName: fn9.name, reason: fn9.skipReason ?? `opaque return or no synthesizable value: ${fn9.displayReturnType}` });
|
|
932
947
|
mutants.push(...generated);
|
|
933
948
|
}
|
|
934
949
|
return { mutants, notMutated };
|
|
935
950
|
},
|
|
936
|
-
catch: (
|
|
951
|
+
catch: (error3) => loadError(config.tsconfig, error3)
|
|
937
952
|
});
|
|
938
953
|
return {
|
|
939
954
|
notMutated: (config) => discover(config).pipe(Effect.map((result2) => result2.notMutated)),
|
|
940
955
|
generate: (config) => Stream.unwrap(discover(config).pipe(Effect.map((result2) => Stream.fromIterable(result2.mutants)))),
|
|
941
956
|
checkViable: (mutant) => Effect.try({
|
|
942
957
|
try: () => oracle.checkViable(mutant),
|
|
943
|
-
catch: (
|
|
958
|
+
catch: (error3) => loadError("", error3)
|
|
944
959
|
})
|
|
945
960
|
};
|
|
946
961
|
}
|
|
947
|
-
function loadError(tsconfig,
|
|
948
|
-
return Schema4.is(ProgramLoadError)(
|
|
962
|
+
function loadError(tsconfig, error3) {
|
|
963
|
+
return Schema4.is(ProgramLoadError)(error3) ? error3 : new ProgramLoadError({
|
|
949
964
|
tsconfig,
|
|
950
|
-
diagnostics: [
|
|
965
|
+
diagnostics: [error3 instanceof Error ? error3.message : String(error3)]
|
|
951
966
|
});
|
|
952
967
|
}
|
|
953
968
|
|
|
@@ -959,7 +974,7 @@ import * as Path from "effect/Path";
|
|
|
959
974
|
var ScratchLive = Layer2.effect(Scratch, Effect2.gen(function* () {
|
|
960
975
|
const fs = yield* FileSystem.FileSystem;
|
|
961
976
|
const path = yield* Path.Path;
|
|
962
|
-
const failure = (operation, location,
|
|
977
|
+
const failure = (operation, location, error3) => new ScratchError({ operation, path: location, message: error3.message });
|
|
963
978
|
return Scratch.of({
|
|
964
979
|
acquire: Effect2.fn("Scratch.acquire")(function* (root) {
|
|
965
980
|
const source = path.resolve(root);
|
|
@@ -976,7 +991,7 @@ var ScratchLive = Layer2.effect(Scratch, Effect2.gen(function* () {
|
|
|
976
991
|
}
|
|
977
992
|
const temp = yield* Effect2.acquireRelease(
|
|
978
993
|
fs.makeTempDirectory({ prefix: "mutant-cafe-" }).pipe(
|
|
979
|
-
Effect2.mapError((
|
|
994
|
+
Effect2.mapError((error3) => failure("create", source, error3))
|
|
980
995
|
),
|
|
981
996
|
(dir2) => fs.remove(dir2, { recursive: true }).pipe(Effect2.orDie)
|
|
982
997
|
);
|
|
@@ -1018,10 +1033,10 @@ var ScratchLive = Layer2.effect(Scratch, Effect2.gen(function* () {
|
|
|
1018
1033
|
} else if (info.type === "File") {
|
|
1019
1034
|
yield* fs.copyFile(from, to);
|
|
1020
1035
|
}
|
|
1021
|
-
}).pipe(Effect2.mapError((
|
|
1036
|
+
}).pipe(Effect2.mapError((error3) => failure("copy", from, error3)));
|
|
1022
1037
|
yield* copy(copyRoot, temp, []);
|
|
1023
1038
|
const packageRoot = yield* fs.realPath(path.join(temp, path.relative(copyRoot, source))).pipe(
|
|
1024
|
-
Effect2.mapError((
|
|
1039
|
+
Effect2.mapError((error3) => failure("resolve", source, error3))
|
|
1025
1040
|
);
|
|
1026
1041
|
const originals = /* @__PURE__ */ new Map();
|
|
1027
1042
|
const target = (mutant) => Effect2.gen(function* () {
|
|
@@ -1031,7 +1046,7 @@ var ScratchLive = Layer2.effect(Scratch, Effect2.gen(function* () {
|
|
|
1031
1046
|
if (rel === "" || rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel) || rel.split(path.sep).includes("node_modules")) {
|
|
1032
1047
|
return yield* Effect2.fail(new ScratchError({ operation: "resolve", path: mutant.file, message: "Mutant file must be inside the copied source tree" }));
|
|
1033
1048
|
}
|
|
1034
|
-
const real = yield* fs.realPath(location).pipe(Effect2.mapError((
|
|
1049
|
+
const real = yield* fs.realPath(location).pipe(Effect2.mapError((error3) => failure("resolve", location, error3)));
|
|
1035
1050
|
const realRelative = path.relative(packageRoot, real);
|
|
1036
1051
|
if (realRelative === ".." || realRelative.startsWith(`..${path.sep}`) || path.isAbsolute(realRelative)) {
|
|
1037
1052
|
return yield* Effect2.fail(new ScratchError({ operation: "resolve", path: mutant.file, message: "Mutant file resolves outside the scratch package" }));
|
|
@@ -1050,7 +1065,7 @@ var ScratchLive = Layer2.effect(Scratch, Effect2.gen(function* () {
|
|
|
1050
1065
|
return yield* Effect2.fail(new ScratchError({ operation: "apply", path: location, message: "Replacement offsets are outside the file" }));
|
|
1051
1066
|
}
|
|
1052
1067
|
yield* fs.writeFileString(location, original.slice(0, startOffset) + text + original.slice(endOffset));
|
|
1053
|
-
}, (effect5, mutant) => effect5.pipe(Effect2.mapError((
|
|
1068
|
+
}, (effect5, mutant) => effect5.pipe(Effect2.mapError((error3) => failure("apply", mutant.file, error3)))),
|
|
1054
1069
|
revert: Effect2.fn("Scratch.revert")(function* (mutant) {
|
|
1055
1070
|
const location = yield* target(mutant);
|
|
1056
1071
|
const bytes = originals.get(location);
|
|
@@ -1058,10 +1073,10 @@ var ScratchLive = Layer2.effect(Scratch, Effect2.gen(function* () {
|
|
|
1058
1073
|
yield* fs.writeFile(location, bytes);
|
|
1059
1074
|
originals.delete(location);
|
|
1060
1075
|
}
|
|
1061
|
-
}, (effect5, mutant) => effect5.pipe(Effect2.mapError((
|
|
1076
|
+
}, (effect5, mutant) => effect5.pipe(Effect2.mapError((error3) => failure("revert", mutant.file, error3))))
|
|
1062
1077
|
};
|
|
1063
1078
|
return dir;
|
|
1064
|
-
}, (effect5, root) => effect5.pipe(Effect2.mapError((
|
|
1079
|
+
}, (effect5, root) => effect5.pipe(Effect2.mapError((error3) => error3._tag === "ScratchError" ? error3 : failure("acquire", root, error3))))
|
|
1065
1080
|
});
|
|
1066
1081
|
}));
|
|
1067
1082
|
|
|
@@ -1253,7 +1268,7 @@ var TestRunnerLive = Layer3.effect(TestRunner, Effect4.gen(function* () {
|
|
|
1253
1268
|
const path = yield* Path3.Path;
|
|
1254
1269
|
const execute = Effect4.fn("TestRunner.execute")(function* (dir, args, timeoutMs) {
|
|
1255
1270
|
const reporterDir = yield* fs.makeTempDirectoryScoped({ prefix: "mutant-vitest-" }).pipe(
|
|
1256
|
-
Effect4.mapError((
|
|
1271
|
+
Effect4.mapError((error3) => new TestSpawnError({ command: ["vitest"], message: String(error3) }))
|
|
1257
1272
|
);
|
|
1258
1273
|
const reporter = path.join(reporterDir, "reporter.mjs");
|
|
1259
1274
|
const marker = `mutant-cafe:${path.basename(reporterDir)}:`;
|
|
@@ -1264,7 +1279,7 @@ var TestRunnerLive = Layer3.effect(TestRunner, Effect4.gen(function* () {
|
|
|
1264
1279
|
onTestModuleCollected() { console.log(${JSON.stringify(marker + "collected")}); }
|
|
1265
1280
|
onTestCaseResult(test) { if (test.result().state === "failed") console.log(${JSON.stringify(marker + "failed")}); }
|
|
1266
1281
|
onTestRunEnd() { if (this.files === 0) console.log(${JSON.stringify(marker + "empty")}); }
|
|
1267
|
-
}`).pipe(Effect4.mapError((
|
|
1282
|
+
}`).pipe(Effect4.mapError((error3) => new TestSpawnError({ command: ["vitest"], message: String(error3) })));
|
|
1268
1283
|
const command = [
|
|
1269
1284
|
"npx",
|
|
1270
1285
|
"--no",
|
|
@@ -1278,7 +1293,7 @@ var TestRunnerLive = Layer3.effect(TestRunner, Effect4.gen(function* () {
|
|
|
1278
1293
|
"--no-cache",
|
|
1279
1294
|
"--no-fsModuleCache"
|
|
1280
1295
|
];
|
|
1281
|
-
if (timeoutMs === void 0) yield* Console.
|
|
1296
|
+
if (timeoutMs === void 0) yield* Console.error(`Baseline command: ${command.join(" ")} (cwd: ${dir.path})`);
|
|
1282
1297
|
const started = yield* Clock.currentTimeMillis;
|
|
1283
1298
|
const chunks = [];
|
|
1284
1299
|
let exitCode = 1;
|
|
@@ -1301,13 +1316,13 @@ var TestRunnerLive = Layer3.effect(TestRunner, Effect4.gen(function* () {
|
|
|
1301
1316
|
const status = yield* (timeoutMs === void 0 ? child : child.pipe(
|
|
1302
1317
|
Effect4.timeout(timeoutMs),
|
|
1303
1318
|
Effect4.catchTag("TimeoutError", () => Effect4.succeed("timedOut"))
|
|
1304
|
-
)).pipe(Effect4.mapError((
|
|
1319
|
+
)).pipe(Effect4.mapError((error3) => new TestSpawnError({ command, message: error3.message })));
|
|
1305
1320
|
const ended = yield* Clock.currentTimeMillis;
|
|
1306
1321
|
const output = chunks.join("");
|
|
1307
1322
|
const failed = output.includes(marker + "failed");
|
|
1308
1323
|
const selection = output.split("\n").find((line) => line.includes(marker + "selected:"))?.split(marker + "selected:")[1];
|
|
1309
1324
|
const selected = selection === void 0 ? [] : yield* Schema6.decodeEffect(Schema6.fromJsonString(Schema6.Array(Schema6.String)))(selection).pipe(
|
|
1310
|
-
Effect4.mapError((
|
|
1325
|
+
Effect4.mapError((error3) => new TestSpawnError({ command, message: `Cannot decode Vitest selected files: ${String(error3)}` }))
|
|
1311
1326
|
);
|
|
1312
1327
|
const run2 = {
|
|
1313
1328
|
status: failed ? "failed" : status === "passed" && output.includes(marker + "empty") ? "untested" : status,
|
|
@@ -1321,7 +1336,7 @@ var TestRunnerLive = Layer3.effect(TestRunner, Effect4.gen(function* () {
|
|
|
1321
1336
|
}, Effect4.scoped);
|
|
1322
1337
|
return TestRunner.of({
|
|
1323
1338
|
baseline: Effect4.fn("TestRunner.baseline")(function* (dir, tsconfig) {
|
|
1324
|
-
const unreliable = yield* preflight(dir.path, tsconfig).pipe(Effect4.provideService(ChildProcessSpawner3.ChildProcessSpawner, spawner), Effect4.catch((
|
|
1339
|
+
const unreliable = yield* preflight(dir.path, tsconfig).pipe(Effect4.provideService(ChildProcessSpawner3.ChildProcessSpawner, spawner), Effect4.catch((error3) => Effect4.succeed([{ kind: "warning", reason: `Cannot verify runner selection: ${String(error3)}` }])));
|
|
1325
1340
|
for (const issue of unreliable) yield* Console.warn(`Warning (${issue.kind}): ${issue.reason}`);
|
|
1326
1341
|
if (unreliable.some((issue) => issue.kind === "runner")) {
|
|
1327
1342
|
const command = ["npx", "--no", "vitest", "run", "--passWithNoTests"];
|
|
@@ -1539,19 +1554,19 @@ ${state2.failure.output.slice(-8e3)}` : String(state2.failure) }
|
|
|
1539
1554
|
}, Effect5.scoped);
|
|
1540
1555
|
|
|
1541
1556
|
// packages/cli/src/bin.ts
|
|
1542
|
-
import * as
|
|
1557
|
+
import * as Effect10 from "effect/Effect";
|
|
1543
1558
|
import * as Layer5 from "effect/Layer";
|
|
1544
|
-
import * as
|
|
1559
|
+
import * as Stream7 from "effect/Stream";
|
|
1545
1560
|
|
|
1546
1561
|
// packages/cli/src/Command.ts
|
|
1547
1562
|
import * as Console3 from "effect/Console";
|
|
1548
|
-
import * as
|
|
1549
|
-
import * as
|
|
1563
|
+
import * as Effect9 from "effect/Effect";
|
|
1564
|
+
import * as FileSystem11 from "effect/FileSystem";
|
|
1550
1565
|
import * as Option from "effect/Option";
|
|
1551
|
-
import * as
|
|
1566
|
+
import * as Path13 from "effect/Path";
|
|
1552
1567
|
import * as Ref from "effect/Ref";
|
|
1553
|
-
import * as
|
|
1554
|
-
import * as
|
|
1568
|
+
import * as Schema11 from "effect/Schema";
|
|
1569
|
+
import * as Stream6 from "effect/Stream";
|
|
1555
1570
|
import * as Command from "effect/cli/Command";
|
|
1556
1571
|
import * as Flag from "effect/cli/Flag";
|
|
1557
1572
|
|
|
@@ -1643,13 +1658,13 @@ var parseDiff = (text, path) => Effect6.try({
|
|
|
1643
1658
|
if (!sawFile) fail3("No unified diff found");
|
|
1644
1659
|
return patches;
|
|
1645
1660
|
},
|
|
1646
|
-
catch: (
|
|
1661
|
+
catch: (error3) => Schema8.is(DiffParseError)(error3) ? error3 : new DiffParseError({ path, message: String(error3) })
|
|
1647
1662
|
});
|
|
1648
1663
|
var selectDiffScope = Effect6.fn("selectDiffScope")(function* (options) {
|
|
1649
1664
|
const fs = yield* FileSystem5.FileSystem;
|
|
1650
1665
|
const path = yield* Path7.Path;
|
|
1651
1666
|
const diffPath = path.resolve(options.root, options.diffPath);
|
|
1652
|
-
const text = yield* fs.readFileString(diffPath).pipe(Effect6.mapError((
|
|
1667
|
+
const text = options.diffText ?? (yield* fs.readFileString(diffPath).pipe(Effect6.mapError((error3) => new DiffParseError({ path: diffPath, message: String(error3) }))));
|
|
1653
1668
|
const patches = yield* parseDiff(text, diffPath);
|
|
1654
1669
|
const gitRoot = yield* Effect6.scoped(Effect6.gen(function* () {
|
|
1655
1670
|
const handle = yield* ChildProcess3.make("git", ["rev-parse", "--show-toplevel"], { cwd: options.root, stderr: "ignore" });
|
|
@@ -1669,7 +1684,7 @@ var selectDiffScope = Effect6.fn("selectDiffScope")(function* (options) {
|
|
|
1669
1684
|
return yield* new DiffParseError({ path: diffPath, message: "Diff path escapes repository root" });
|
|
1670
1685
|
}
|
|
1671
1686
|
if (!(yield* fs.exists(candidate))) continue;
|
|
1672
|
-
const current = yield* fs.readFileString(candidate).pipe(Effect6.mapError((
|
|
1687
|
+
const current = yield* fs.readFileString(candidate).pipe(Effect6.mapError((error3) => new DiffMismatch({ path: patch.file, message: String(error3) })));
|
|
1673
1688
|
const lines2 = current.split("\n");
|
|
1674
1689
|
const finalLine = current.endsWith("\n") ? lines2.length - 1 : lines2.length;
|
|
1675
1690
|
if (patch.lines.every((line) => {
|
|
@@ -1697,8 +1712,8 @@ var selectDiffScope = Effect6.fn("selectDiffScope")(function* (options) {
|
|
|
1697
1712
|
|
|
1698
1713
|
// packages/cli/src/ExitCode.ts
|
|
1699
1714
|
var reportExitCode = (report) => report.results.some((result2) => result2.outcome === "missed") ? 2 : report.results.some((result2) => result2.outcome === "unreliable") ? 7 : report.results.some((result2) => result2.outcome === "untested") ? 2 : report.results.some((result2) => result2.outcome === "timeout") ? 3 : 0;
|
|
1700
|
-
var errorExitCode = (
|
|
1701
|
-
switch (
|
|
1715
|
+
var errorExitCode = (error3) => {
|
|
1716
|
+
switch (error3._tag) {
|
|
1702
1717
|
case "BaselineFailed":
|
|
1703
1718
|
return 4;
|
|
1704
1719
|
case "DiffMismatch":
|
|
@@ -1815,6 +1830,29 @@ var unifiedDiff = (original, modified, file) => {
|
|
|
1815
1830
|
return [...output, ""].join("\n");
|
|
1816
1831
|
};
|
|
1817
1832
|
|
|
1833
|
+
// packages/cli/src/Summary.ts
|
|
1834
|
+
var outcomeNames = ["caught", "missed", "timeout", "unviable", "untested", "unreliable"];
|
|
1835
|
+
var countsLine = (report, notMutated) => `${report.selected ?? report.results.length} selected, ${report.run ?? report.results.length} run, ${report.budgetSkipped ?? 0} budget-skipped; ` + outcomeNames.map((outcome) => `${report.results.filter((result2) => result2.outcome === outcome).length} ${outcome}`).join(", ") + `; ${notMutated} not mutated`;
|
|
1836
|
+
var cell = (text) => text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\\", "\\\\").replaceAll("|", "\\|").replaceAll("`", "`").replace(/[\r\n]+/g, " ");
|
|
1837
|
+
var markdownSummary = (options) => {
|
|
1838
|
+
const { report, path } = options;
|
|
1839
|
+
const rows = report.results.filter((result2) => result2.outcome === "missed" || result2.outcome === "timeout" || result2.outcome === "untested" || result2.outcome === "unreliable");
|
|
1840
|
+
const exit = report.failure?.startsWith("BaselineFailed") ? 4 : reportExitCode(report);
|
|
1841
|
+
return [
|
|
1842
|
+
options.marker,
|
|
1843
|
+
countsLine(report, options.notMutated),
|
|
1844
|
+
"",
|
|
1845
|
+
...report.failure === void 0 ? [] : [`Failure: ${cell(report.failure)}`, ""],
|
|
1846
|
+
options.advisory ? `Advisory: would exit ${exit} without --advisory.` : `Exit code: ${exit}.`,
|
|
1847
|
+
"",
|
|
1848
|
+
"| File:line | Function | Description | Outcome |",
|
|
1849
|
+
"| --- | --- | --- | --- |",
|
|
1850
|
+
...rows.slice(0, 50).map(({ mutant, outcome }) => `| ${cell(path.relative(options.gitRoot, path.resolve(options.root, mutant.file)).replaceAll("\\", "/"))}:${mutant.span.start.line} | ${cell(mutant.functionName)} | ${cell(mutant.description)} | ${outcome} |`),
|
|
1851
|
+
...rows.length > 50 ? ["", `and ${rows.length - 50} more`] : [],
|
|
1852
|
+
""
|
|
1853
|
+
].join("\n");
|
|
1854
|
+
};
|
|
1855
|
+
|
|
1818
1856
|
// packages/cli/src/Reporter.ts
|
|
1819
1857
|
var mutantLine = (mutant, root, path) => `${path.relative(root, path.resolve(root, mutant.file))}:${mutant.span.start.line}:${mutant.span.start.column}: ${mutant.description.replace(mutant.returnType, shortType(mutant.displayReturnType ?? mutant.returnType))} [${mutant.id}]`;
|
|
1820
1858
|
var shortType = (text) => {
|
|
@@ -1836,7 +1874,7 @@ var makeReporter = Effect7.fn("makeReporter")(function* (options) {
|
|
|
1836
1874
|
const results = [];
|
|
1837
1875
|
let pendingError;
|
|
1838
1876
|
let summarized = false;
|
|
1839
|
-
const writeError = (
|
|
1877
|
+
const writeError = (error3) => new ReportWriteError({ path: dir, message: String(error3) });
|
|
1840
1878
|
const ids = /* @__PURE__ */ new Set();
|
|
1841
1879
|
for (const mutant of options.mutants) {
|
|
1842
1880
|
if (!/^[A-Za-z0-9_-]+$/.test(mutant.id) || ids.has(mutant.id)) return yield* writeError("Mutant ids must be unique safe filenames");
|
|
@@ -1874,21 +1912,27 @@ var makeReporter = Effect7.fn("makeReporter")(function* (options) {
|
|
|
1874
1912
|
const service = Reporter.of({
|
|
1875
1913
|
progress: (result2) => semaphore.withPermit(Effect7.gen(function* () {
|
|
1876
1914
|
results.push(result2);
|
|
1877
|
-
yield* Console2.log(`${result2.outcome} ${mutantLine(result2.mutant, options.root, path)} (${result2.durationMs}ms)`);
|
|
1915
|
+
if (!options.markdown?.stdout) yield* Console2.log(`${result2.outcome} ${mutantLine(result2.mutant, options.root, path)} (${result2.durationMs}ms)`);
|
|
1878
1916
|
yield* Effect7.gen(function* () {
|
|
1879
1917
|
if (!ids.has(result2.mutant.id)) return yield* writeError("Progress result does not belong to this report");
|
|
1880
1918
|
yield* writeLists(results);
|
|
1881
1919
|
yield* fs.writeFileString(path.join(dir, "logs", `${result2.mutant.id}.log`), logText(result2));
|
|
1882
|
-
}).pipe(Effect7.catch((
|
|
1920
|
+
}).pipe(Effect7.catch((error3) => Effect7.gen(function* () {
|
|
1883
1921
|
if (pendingError === void 0) {
|
|
1884
|
-
pendingError = writeError(
|
|
1922
|
+
pendingError = writeError(error3);
|
|
1885
1923
|
yield* Console2.warn(`Report write failed: ${pendingError.message}`);
|
|
1886
1924
|
}
|
|
1887
1925
|
})));
|
|
1888
1926
|
})),
|
|
1889
1927
|
write: (report) => semaphore.withPermit(Effect7.gen(function* () {
|
|
1890
1928
|
if (pendingError !== void 0) return yield* pendingError;
|
|
1891
|
-
const
|
|
1929
|
+
const counted = {
|
|
1930
|
+
...report,
|
|
1931
|
+
selected: options.selected ?? options.mutants.length,
|
|
1932
|
+
run: report.results.length,
|
|
1933
|
+
budgetSkipped: options.budgetSkipped ?? 0
|
|
1934
|
+
};
|
|
1935
|
+
const encoded = yield* jsonReport(counted).pipe(Effect7.mapError(writeError));
|
|
1892
1936
|
yield* fs.writeFileString(path.join(dir, "outcomes.json.tmp"), encoded).pipe(Effect7.mapError(writeError));
|
|
1893
1937
|
yield* fs.rename(path.join(dir, "outcomes.json.tmp"), path.join(dir, "outcomes.json")).pipe(Effect7.mapError(writeError));
|
|
1894
1938
|
yield* writeLists(report.results).pipe(Effect7.mapError(writeError));
|
|
@@ -1896,22 +1940,65 @@ var makeReporter = Effect7.fn("makeReporter")(function* (options) {
|
|
|
1896
1940
|
if (!ids.has(result2.mutant.id)) return yield* writeError("Final result does not belong to this report");
|
|
1897
1941
|
yield* fs.writeFileString(path.join(dir, "logs", `${result2.mutant.id}.log`), logText(result2)).pipe(Effect7.mapError(writeError));
|
|
1898
1942
|
}
|
|
1943
|
+
if (options.markdown !== void 0) {
|
|
1944
|
+
const markdown = markdownSummary({ ...options.markdown, root: options.root, path, report: counted, notMutated: options.notMutated?.length ?? 0 });
|
|
1945
|
+
for (const file of new Set(options.markdown.files)) {
|
|
1946
|
+
yield* fs.writeFileString(file, markdown).pipe(Effect7.mapError((error3) => new ReportWriteError({ path: file, message: String(error3) })));
|
|
1947
|
+
}
|
|
1948
|
+
if (!summarized && options.markdown.stdout) yield* Console2.log(markdown);
|
|
1949
|
+
}
|
|
1899
1950
|
if (summarized) return;
|
|
1900
1951
|
summarized = true;
|
|
1901
1952
|
if (report.results.some((result2) => result2.outcome === "unreliable")) yield* Console2.warn("Unreliable: the configured Vitest run cannot see all tests. See unreliable.txt and per-mutant diagnostics; these are not missed mutants.");
|
|
1902
1953
|
const elapsed = (yield* Clock2.currentTimeMillis) - started;
|
|
1903
|
-
|
|
1954
|
+
if (!options.markdown?.stdout) yield* Console2.log(countsLine(counted, options.notMutated?.length ?? 0) + `; ${(elapsed / 1e3).toFixed(2)}s`);
|
|
1955
|
+
if (options.markdown === void 0 && report.failure !== void 0) yield* Console2.warn(report.failure);
|
|
1904
1956
|
}))
|
|
1905
1957
|
});
|
|
1906
1958
|
return service;
|
|
1907
1959
|
});
|
|
1908
1960
|
|
|
1909
|
-
// packages/cli/src/
|
|
1961
|
+
// packages/cli/src/Git.ts
|
|
1962
|
+
import * as Effect8 from "effect/Effect";
|
|
1963
|
+
import * as FileSystem9 from "effect/FileSystem";
|
|
1964
|
+
import * as Path11 from "effect/Path";
|
|
1965
|
+
import * as Schema10 from "effect/Schema";
|
|
1966
|
+
import * as Stream5 from "effect/Stream";
|
|
1967
|
+
import * as ChildProcess4 from "effect/process/ChildProcess";
|
|
1910
1968
|
var UsageError = class extends Schema10.TaggedError()("UsageError", { message: Schema10.String }) {
|
|
1911
1969
|
};
|
|
1970
|
+
var git = Effect8.fn("git")(function* (root, args) {
|
|
1971
|
+
const command = `git ${args.join(" ")}`;
|
|
1972
|
+
return yield* Effect8.scoped(Effect8.gen(function* () {
|
|
1973
|
+
const handle = yield* ChildProcess4.make("git", args, { cwd: root });
|
|
1974
|
+
const [stdout, stderr, code] = yield* Effect8.all([
|
|
1975
|
+
Stream5.mkString(Stream5.decodeText(handle.stdout)),
|
|
1976
|
+
Stream5.mkString(Stream5.decodeText(handle.stderr)),
|
|
1977
|
+
handle.exitCode
|
|
1978
|
+
], { concurrency: "unbounded" });
|
|
1979
|
+
if (Number(code) !== 0) return yield* new UsageError({ message: `${command}:
|
|
1980
|
+
${stderr}` });
|
|
1981
|
+
return stdout;
|
|
1982
|
+
})).pipe(Effect8.mapError((error3) => error3._tag === "UsageError" ? error3 : new UsageError({ message: `${command}: ${String(error3)}` })));
|
|
1983
|
+
});
|
|
1984
|
+
var repositoryRoot = Effect8.fn("repositoryRoot")(function* (root) {
|
|
1985
|
+
const path = yield* Path11.Path;
|
|
1986
|
+
const fs = yield* FileSystem9.FileSystem;
|
|
1987
|
+
const top = (yield* git(root, ["rev-parse", "--show-toplevel"])).trim();
|
|
1988
|
+
const physical = yield* fs.realPath(root).pipe(Effect8.mapError((error3) => new UsageError({ message: String(error3) })));
|
|
1989
|
+
return path.resolve(root, path.relative(physical, top));
|
|
1990
|
+
});
|
|
1991
|
+
|
|
1992
|
+
// packages/cli/src/Command.ts
|
|
1912
1993
|
var flags = {
|
|
1913
1994
|
list: Flag.Boolean("list").pipe(Flag.withDefault(false), Flag.withDescription("List mutants and skipped function count without running tests")),
|
|
1914
1995
|
inDiff: Flag.String("in-diff").pipe(Flag.optional, Flag.withDescription("Only mutate bodies overlapping this unified diff")),
|
|
1996
|
+
inDiffRange: Flag.String("in-diff-range").pipe(Flag.optional, Flag.withDescription("Only mutate bodies overlapping git diff A...B or A..B; exclusive with --in-diff")),
|
|
1997
|
+
maxMutants: Flag.Int("max-mutants").pipe(Flag.optional, Flag.withDescription("Keep first N selected mutants ordered by repository path, line, column, id; N >= 0")),
|
|
1998
|
+
format: Flag.String("format").pipe(Flag.withDefault("text"), Flag.withDescription("Output format: text (default), json (--list only), or github (Markdown and GITHUB_STEP_SUMMARY)")),
|
|
1999
|
+
summaryMd: Flag.String("summary-md").pipe(Flag.optional, Flag.withDescription("Write Markdown summary to this file")),
|
|
2000
|
+
summaryMarker: Flag.String("summary-marker").pipe(Flag.withDefault("<!-- mutant.cafe -->"), Flag.withDescription("Override the first-line sticky-comment marker")),
|
|
2001
|
+
advisory: Flag.Boolean("advisory").pipe(Flag.withDefault(false), Flag.withDescription("Exit 0 for outcomes and baseline failure; keep usage/internal errors")),
|
|
1915
2002
|
include: Flag.String("file").pipe(Flag.atLeast(0), Flag.withDescription("Include source glob relative to package root; repeatable")),
|
|
1916
2003
|
exclude: Flag.String("exclude").pipe(Flag.atLeast(0), Flag.withDescription("Exclude source glob; repeatable")),
|
|
1917
2004
|
exportedOnly: Flag.Boolean("exported-only").pipe(Flag.withDefault(false), Flag.withDescription("Only exported binding paths, returned curried functions and Layer service methods; exclude local helpers")),
|
|
@@ -1922,18 +2009,30 @@ var flags = {
|
|
|
1922
2009
|
output: Flag.String("output").pipe(Flag.withDefault("mutants.out"), Flag.withDescription("Report directory; default mutants.out")),
|
|
1923
2010
|
tsconfig: Flag.String("tsconfig").pipe(Flag.withDefault("tsconfig.json"), Flag.withDescription("TypeScript project path; default tsconfig.json"))
|
|
1924
2011
|
};
|
|
1925
|
-
var makeCommand = (options) => Command.make("mutant-cafe", flags, (input) =>
|
|
1926
|
-
const fs = yield*
|
|
1927
|
-
const path = yield*
|
|
2012
|
+
var makeCommand = (options) => Command.make("mutant-cafe", flags, (input) => Effect9.gen(function* () {
|
|
2013
|
+
const fs = yield* FileSystem11.FileSystem;
|
|
2014
|
+
const path = yield* Path13.Path;
|
|
1928
2015
|
const root = path.resolve(options.root);
|
|
2016
|
+
const range = Option.getOrUndefined(input.inDiffRange);
|
|
2017
|
+
const inDiff = Option.getOrUndefined(input.inDiff);
|
|
2018
|
+
const maxMutants = Option.getOrUndefined(input.maxMutants);
|
|
2019
|
+
const summaryMd = Option.getOrUndefined(input.summaryMd);
|
|
2020
|
+
if (range !== void 0 && inDiff !== void 0) return yield* new UsageError({ message: "--in-diff-range and --in-diff are mutually exclusive" });
|
|
2021
|
+
if (range !== void 0 && (!/^[^\s.][^\s]*\.{2,3}[^\s.][^\s]*$/.test(range) || range.startsWith("-") || range.includes("...."))) {
|
|
2022
|
+
return yield* new UsageError({ message: "--in-diff-range expects A...B or A..B" });
|
|
2023
|
+
}
|
|
2024
|
+
if (maxMutants !== void 0 && (!Number.isSafeInteger(maxMutants) || maxMutants < 0)) return yield* new UsageError({ message: "--max-mutants must be a nonnegative safe integer" });
|
|
2025
|
+
if (!["text", "json", "github"].includes(input.format) || input.format === "json" && !input.list) return yield* new UsageError({ message: "--format expects text, github, or json with --list" });
|
|
2026
|
+
if (/[\r\n]/.test(input.summaryMarker)) return yield* new UsageError({ message: "--summary-marker must be one line" });
|
|
2027
|
+
const gitRoot = range !== void 0 ? yield* repositoryRoot(root) : yield* repositoryRoot(root).pipe(Effect9.catch(() => Effect9.succeed(root)));
|
|
2028
|
+
const diffText = range === void 0 ? void 0 : yield* git(gitRoot, ["diff", "--no-ext-diff", "--no-color", range, "--"]);
|
|
1929
2029
|
const configPath = path.join(root, "mutants.config.json");
|
|
1930
2030
|
const fileConfig = (yield* fs.exists(configPath)) ? yield* fs.readFileString(configPath).pipe(
|
|
1931
|
-
|
|
1932
|
-
|
|
2031
|
+
Effect9.flatMap(Schema11.decodeEffect(Schema11.fromJsonString(ConfigFile))),
|
|
2032
|
+
Effect9.mapError((error3) => new UsageError({ message: `Invalid mutants.config.json: ${String(error3)}` }))
|
|
1933
2033
|
) : {};
|
|
1934
2034
|
const timeoutMs = Option.map(input.timeout, (seconds) => Math.ceil(seconds * 1e3));
|
|
1935
|
-
const
|
|
1936
|
-
const config = yield* Schema10.decodeEffect(RunConfig)({
|
|
2035
|
+
const config = yield* Schema11.decodeEffect(RunConfig)({
|
|
1937
2036
|
root,
|
|
1938
2037
|
tsconfig: input.tsconfig,
|
|
1939
2038
|
exportedOnly: input.exportedOnly,
|
|
@@ -1947,45 +2046,101 @@ var makeCommand = (options) => Command.make("mutant-cafe", flags, (input) => Eff
|
|
|
1947
2046
|
minimumTimeoutMs: Option.match(input.minimumTimeout, { onNone: () => fileConfig.minimumTimeoutMs ?? 2e4, onSome: (seconds) => Math.ceil(seconds * 1e3) }),
|
|
1948
2047
|
neverTimeoutMs: 1e3,
|
|
1949
2048
|
outDir: input.output
|
|
1950
|
-
}).pipe(
|
|
2049
|
+
}).pipe(Effect9.mapError((error3) => new UsageError({ message: String(error3) })));
|
|
1951
2050
|
if (config.jobs < 1 || config.timeoutMultiplier <= 0 || config.minimumTimeoutMs <= 0 || config.timeoutMs !== void 0 && config.timeoutMs <= 0) {
|
|
1952
2051
|
return yield* new UsageError({ message: "Jobs and timeout values must be positive" });
|
|
1953
2052
|
}
|
|
1954
2053
|
const source = yield* MutantSource;
|
|
1955
|
-
const generated = yield*
|
|
1956
|
-
|
|
2054
|
+
const generated = yield* Stream6.runCollect(source.generate(config)).pipe(
|
|
2055
|
+
Effect9.mapError((error3) => error3.reason === "selection" ? new UsageError({ message: error3.diagnostics.join("\n") }) : error3)
|
|
1957
2056
|
);
|
|
1958
2057
|
const skipped2 = yield* source.notMutated(config);
|
|
1959
|
-
const selected = inDiff === void 0 ? { mutants: generated, notMutated: skipped2 } : yield* selectDiffScope({ root, diffPath: inDiff, mutants: generated, notMutated: skipped2 });
|
|
1960
|
-
const
|
|
2058
|
+
const selected = inDiff === void 0 && diffText === void 0 ? { mutants: generated, notMutated: skipped2 } : yield* selectDiffScope({ root, diffPath: inDiff ?? `git diff ${range}`, ...diffText === void 0 ? {} : { diffText }, mutants: generated, notMutated: skipped2 });
|
|
2059
|
+
const relative2 = (mutant) => path.relative(gitRoot, path.resolve(root, mutant.file)).replaceAll("\\", "/");
|
|
2060
|
+
const compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
2061
|
+
const ordered = [...selected.mutants].sort((a, b) => compare(relative2(a), relative2(b)) || a.span.start.line - b.span.start.line || a.span.start.column - b.span.start.column || compare(a.id, b.id));
|
|
2062
|
+
const mutants = ordered.slice(0, maxMutants);
|
|
2063
|
+
const notMutated = selected.notMutated;
|
|
2064
|
+
const counts = { selected: ordered.length, run: 0, budgetSkipped: ordered.length - mutants.length };
|
|
2065
|
+
const markdown = input.format === "github" || summaryMd !== void 0 ? {
|
|
2066
|
+
gitRoot,
|
|
2067
|
+
marker: input.summaryMarker,
|
|
2068
|
+
advisory: input.advisory,
|
|
2069
|
+
stdout: input.format === "github",
|
|
2070
|
+
files: [
|
|
2071
|
+
...summaryMd === void 0 ? [] : [path.resolve(root, summaryMd)],
|
|
2072
|
+
...input.format === "github" && process.env.GITHUB_STEP_SUMMARY ? [process.env.GITHUB_STEP_SUMMARY] : []
|
|
2073
|
+
]
|
|
2074
|
+
} : void 0;
|
|
2075
|
+
if (input.list && markdown !== void 0) {
|
|
2076
|
+
const text = markdownSummary({
|
|
2077
|
+
...markdown,
|
|
2078
|
+
root,
|
|
2079
|
+
path,
|
|
2080
|
+
notMutated: notMutated.length,
|
|
2081
|
+
report: { schemaVersion: 2, tool: "mutant.cafe", root, baseline: { durationMs: 0, testCommand: [] }, timeoutMs: 0, results: [], ...counts }
|
|
2082
|
+
});
|
|
2083
|
+
for (const file of new Set(markdown.files)) yield* fs.writeFileString(file, text).pipe(
|
|
2084
|
+
Effect9.mapError((error3) => new ReportWriteError({ path: file, message: String(error3) }))
|
|
2085
|
+
);
|
|
2086
|
+
if (markdown.stdout) {
|
|
2087
|
+
yield* Console3.log(text);
|
|
2088
|
+
if (options.onExit !== void 0) yield* options.onExit(0);
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
if (input.list && input.format === "json") {
|
|
2093
|
+
yield* Console3.log(yield* Schema11.encodeEffect(Schema11.fromJsonString(MutantList))({ schemaVersion: 2, tool: "mutant.cafe", mutants, notMutated, counts }));
|
|
2094
|
+
if (options.onExit !== void 0) yield* options.onExit(0);
|
|
2095
|
+
return;
|
|
2096
|
+
}
|
|
1961
2097
|
if (input.list) {
|
|
1962
2098
|
for (const mutant of mutants) yield* Console3.log(mutantLine(mutant, config.root, path));
|
|
1963
|
-
const
|
|
2099
|
+
const perFile = /* @__PURE__ */ new Map();
|
|
1964
2100
|
for (const mutant of mutants) {
|
|
1965
2101
|
const file = path.relative(root, path.resolve(root, mutant.file));
|
|
1966
|
-
|
|
2102
|
+
perFile.set(file, (perFile.get(file) ?? 0) + 1);
|
|
1967
2103
|
}
|
|
1968
|
-
for (const [file, count] of [...
|
|
1969
|
-
yield* Console3.log(`${mutants.length} mutants total; ${notMutated.length} not mutated`);
|
|
2104
|
+
for (const [file, count] of [...perFile].sort(([a], [b]) => a.localeCompare(b))) yield* Console3.log(`${file}: ${count} mutants`);
|
|
2105
|
+
yield* Console3.log(`${mutants.length} mutants total; ${notMutated.length} not mutated; ${counts.selected} selected, 0 run, ${counts.budgetSkipped} budget-skipped`);
|
|
1970
2106
|
if (options.onExit !== void 0) yield* options.onExit(0);
|
|
1971
2107
|
return;
|
|
1972
2108
|
}
|
|
1973
|
-
const reporter = yield* makeReporter({ root, outDir: config.outDir, mutants, notMutated });
|
|
1974
|
-
const report = yield* options.run(config, mutants).pipe(
|
|
2109
|
+
const reporter = yield* makeReporter({ root, outDir: config.outDir, mutants, notMutated, selected: counts.selected, budgetSkipped: counts.budgetSkipped, ...markdown === void 0 ? {} : { markdown } });
|
|
2110
|
+
const report = yield* options.run(config, mutants).pipe(
|
|
2111
|
+
Effect9.provideService(Reporter, reporter),
|
|
2112
|
+
Effect9.catchTag("BaselineFailed", (error3) => Effect9.gen(function* () {
|
|
2113
|
+
const failed = {
|
|
2114
|
+
schemaVersion: 2,
|
|
2115
|
+
tool: "mutant.cafe",
|
|
2116
|
+
root,
|
|
2117
|
+
baseline: { durationMs: 0, testCommand: error3.command },
|
|
2118
|
+
timeoutMs: config.timeoutMs ?? config.minimumTimeoutMs,
|
|
2119
|
+
results: [],
|
|
2120
|
+
failure: `BaselineFailed: ${error3.command.join(" ")}
|
|
2121
|
+
${error3.output.slice(-8e3)}`
|
|
2122
|
+
};
|
|
2123
|
+
yield* reporter.write(failed);
|
|
2124
|
+
if (!input.advisory) return yield* error3;
|
|
2125
|
+
if (markdown === void 0) yield* Console3.log("Advisory: baseline failed; would exit 4 without --advisory.");
|
|
2126
|
+
return failed;
|
|
2127
|
+
}))
|
|
2128
|
+
);
|
|
2129
|
+
if (input.advisory && reportExitCode(report) !== 0 && markdown === void 0) yield* Console3.log(`Advisory: would exit ${reportExitCode(report)} without --advisory.`);
|
|
1975
2130
|
yield* reporter.write(report);
|
|
1976
|
-
if (options.onExit !== void 0) yield* options.onExit(reportExitCode(report));
|
|
2131
|
+
if (options.onExit !== void 0) yield* options.onExit(input.advisory ? 0 : reportExitCode(report));
|
|
1977
2132
|
}));
|
|
1978
|
-
var runCli =
|
|
2133
|
+
var runCli = Effect9.fn("runCli")(function* (options) {
|
|
1979
2134
|
const code = yield* Ref.make(0);
|
|
1980
2135
|
const command = makeCommand({ ...options, onExit: (value) => Ref.set(code, value) });
|
|
1981
|
-
yield* Command.runWith(command, { version: "0.1.
|
|
1982
|
-
|
|
1983
|
-
yield* Console3.error(
|
|
1984
|
-
${
|
|
1985
|
-
${
|
|
1986
|
-
yield* Ref.set(code, errorExitCode(
|
|
2136
|
+
yield* Command.runWith(command, { version: "0.1.4" })(options.args).pipe(
|
|
2137
|
+
Effect9.catch((error3) => Effect9.gen(function* () {
|
|
2138
|
+
yield* Console3.error(error3._tag === "ProgramLoadError" ? `${error3.tsconfig}:
|
|
2139
|
+
${error3.diagnostics.join("\n")}` : error3._tag === "BaselineFailed" ? `Baseline failed (${error3.exitCode}): ${error3.command.join(" ")}
|
|
2140
|
+
${error3.output.slice(-8e3)}` : String(error3));
|
|
2141
|
+
yield* Ref.set(code, errorExitCode(error3));
|
|
1987
2142
|
})),
|
|
1988
|
-
|
|
2143
|
+
Effect9.catchDefect((defect) => Effect9.gen(function* () {
|
|
1989
2144
|
yield* Console3.error(`Internal error: ${String(defect)}`);
|
|
1990
2145
|
yield* Ref.set(code, 70);
|
|
1991
2146
|
}))
|
|
@@ -1994,15 +2149,15 @@ ${error2.output.slice(-8e3)}` : String(error2));
|
|
|
1994
2149
|
});
|
|
1995
2150
|
|
|
1996
2151
|
// packages/cli/src/bin.ts
|
|
1997
|
-
var run = (config, mutants) => runMutants(config,
|
|
2152
|
+
var run = (config, mutants) => runMutants(config, Stream7.fromIterable(mutants));
|
|
1998
2153
|
var live = Layer5.mergeAll(MutantSourceLive, ScratchLive, TestRunnerLive).pipe(
|
|
1999
2154
|
Layer5.provideMerge(NodeServices.layer)
|
|
2000
2155
|
);
|
|
2001
|
-
var main =
|
|
2156
|
+
var main = Effect10.gen(function* () {
|
|
2002
2157
|
const code = yield* runCli({ root: process.cwd(), args: process.argv.slice(2), run });
|
|
2003
|
-
yield*
|
|
2158
|
+
yield* Effect10.sync(() => {
|
|
2004
2159
|
process.exitCode = code;
|
|
2005
2160
|
});
|
|
2006
|
-
}).pipe(
|
|
2161
|
+
}).pipe(Effect10.provide(live));
|
|
2007
2162
|
NodeRuntime.runMain(main);
|
|
2008
2163
|
//# sourceMappingURL=bin.js.map
|