mutant-cafe 0.1.6 → 0.1.8
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 +7 -4
- package/dist/bin.js +822 -498
- package/dist/bin.js.map +4 -4
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -43,7 +43,10 @@ var ProgramLoadError = class extends Schema2.TaggedError()("ProgramLoadError", {
|
|
|
43
43
|
diagnostics: Schema2.Array(Schema2.String)
|
|
44
44
|
}) {
|
|
45
45
|
};
|
|
46
|
-
var formatTestCommand = (command) =>
|
|
46
|
+
var formatTestCommand = (command) => {
|
|
47
|
+
const launcher = command.findIndex((arg) => !arg.startsWith("-") && /[\\/]mutant-vitest-[^\\/]+[\\/]launch\.mjs$/.test(arg));
|
|
48
|
+
return launcher > 0 ? `vitest ${command.slice(launcher + 1).filter((arg) => arg === "--reporter=default" || !arg.startsWith("--reporter=")).join(" ")} (via ${command.join(" ")})` : command.join(" ");
|
|
49
|
+
};
|
|
47
50
|
var BaselineFailed = class extends Schema2.TaggedError()("BaselineFailed", {
|
|
48
51
|
exitCode: Schema2.Int,
|
|
49
52
|
command: Schema2.Array(Schema2.String),
|
|
@@ -63,7 +66,7 @@ var ScratchError = class extends Schema2.TaggedError()("ScratchError", {
|
|
|
63
66
|
}) {
|
|
64
67
|
};
|
|
65
68
|
var TestSpawnError = class extends Schema2.TaggedError()("TestSpawnError", {
|
|
66
|
-
kind: Schema2.optional(Schema2.
|
|
69
|
+
kind: Schema2.optional(Schema2.Literals(["reporter", "vitest-version"])),
|
|
67
70
|
command: Schema2.Array(Schema2.String),
|
|
68
71
|
message: Schema2.String
|
|
69
72
|
}) {
|
|
@@ -265,24 +268,48 @@ function sanitizeReportTelemetry(report) {
|
|
|
265
268
|
return { report: { ...root.value, baseline: { ...baseline.value, ...warnings.length ? { telemetryWarnings: warnings } : {} }, results: results.map((result5) => result5.value) }, warnings };
|
|
266
269
|
}
|
|
267
270
|
|
|
268
|
-
// packages/
|
|
271
|
+
// packages/core/src/Selection.ts
|
|
269
272
|
import * as Effect from "effect/Effect";
|
|
273
|
+
import * as Path from "effect/Path";
|
|
274
|
+
var excludeLinkedCandidates = Effect.fn("Selection.excludeLinkedCandidates")(function* (root, candidates, linkedRoots) {
|
|
275
|
+
const path = yield* Path.Path;
|
|
276
|
+
const mutants = [];
|
|
277
|
+
const skipped2 = [];
|
|
278
|
+
for (const mutant of candidates) {
|
|
279
|
+
const file = path.isAbsolute(mutant.file) ? path.relative(root, mutant.file) : mutant.file;
|
|
280
|
+
const linked = linkedRoots.some((link) => {
|
|
281
|
+
const relative2 = path.relative(link, file);
|
|
282
|
+
return relative2 === "" || relative2 !== ".." && !relative2.startsWith(`..${path.sep}`) && !path.isAbsolute(relative2);
|
|
283
|
+
});
|
|
284
|
+
if (linked) skipped2.push({
|
|
285
|
+
file: path.resolve(root, file),
|
|
286
|
+
functionName: mutant.functionName,
|
|
287
|
+
span: mutant.span,
|
|
288
|
+
reason: "Source is in a linked ignored tree; original files are not mutation targets"
|
|
289
|
+
});
|
|
290
|
+
else mutants.push(mutant);
|
|
291
|
+
}
|
|
292
|
+
return { mutants, notMutated: [...new Map(skipped2.map((entry) => [JSON.stringify(entry), entry])).values()] };
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
// packages/engine/src/index.ts
|
|
296
|
+
import * as Effect2 from "effect/Effect";
|
|
270
297
|
import * as Layer from "effect/Layer";
|
|
271
298
|
import * as Stream from "effect/Stream";
|
|
272
299
|
import * as Schema4 from "effect/Schema";
|
|
273
300
|
|
|
274
301
|
// packages/engine/src/Generate.ts
|
|
275
302
|
import { createHash } from "node:crypto";
|
|
276
|
-
function* generateFunction(
|
|
277
|
-
const issue =
|
|
303
|
+
function* generateFunction(fn12) {
|
|
304
|
+
const issue = fn12.generationIssue?.();
|
|
278
305
|
if (issue) return issue;
|
|
279
|
-
const api =
|
|
306
|
+
const api = fn12.api;
|
|
280
307
|
const candidate = (genre, expression, value = { text: "", synthetic: false }, description = expression) => {
|
|
281
|
-
const pinned = `((): ${
|
|
282
|
-
const text =
|
|
283
|
-
return makeMutant(
|
|
308
|
+
const pinned = `((): ${fn12.returnType} => (${expression}))()`;
|
|
309
|
+
const text = fn12.block ? `{ return ${fn12.generator ? "yield* " : ""}${pinned}; }` : `(${pinned})`;
|
|
310
|
+
return makeMutant(fn12, genre, text, value.synthetic, description);
|
|
284
311
|
};
|
|
285
|
-
const shape =
|
|
312
|
+
const shape = fn12.shape;
|
|
286
313
|
const fits = (value) => new TextEncoder().encode(value.text).byteLength <= 2048;
|
|
287
314
|
const values = "values" in shape ? shape.values.filter(fits) : [];
|
|
288
315
|
switch (shape.kind) {
|
|
@@ -290,7 +317,7 @@ function* generateFunction(fn11) {
|
|
|
290
317
|
const succeed7 = api("Effect", "succeed");
|
|
291
318
|
if (succeed7) {
|
|
292
319
|
for (const value of values) {
|
|
293
|
-
if (!
|
|
320
|
+
if (!fn12.equivalentValues.includes(value.text) && !(fn12.generator && value.text === fn12.literal)) yield candidate("EffectSucceed", `${succeed7}(${value.text})`, value);
|
|
294
321
|
}
|
|
295
322
|
}
|
|
296
323
|
const fail4 = api("Effect", "fail");
|
|
@@ -299,7 +326,7 @@ function* generateFunction(fn11) {
|
|
|
299
326
|
if (fail4 && fits(error3)) yield candidate("EffectFail", `${fail4}(${error3.text})`, error3, `${fail4}(${error3.text}) [${error3.synthetic ? "synthetic tag cast" : "constructed error"}]`);
|
|
300
327
|
const recoveries = values.length ? shape.enumerateRecoveries ? values : values.slice(0, 1) : [void 0];
|
|
301
328
|
const gen11 = api("Effect", "gen");
|
|
302
|
-
const original =
|
|
329
|
+
const original = fn12.generator ? gen11 && `((): ${fn12.returnType} => ${gen11}(function* () ${fn12.original}))()` : fn12.block ? `((): ${fn12.returnType} => ${fn12.original})()` : `((): ${fn12.returnType} => (${fn12.original}))()`;
|
|
303
330
|
for (const value of recoveries) {
|
|
304
331
|
const die3 = api("Effect", "die");
|
|
305
332
|
const recovery = value && succeed7 ? `${succeed7}(${value.text})` : die3 ? `${die3}(${JSON.stringify(`mutant.cafe: swallowed ${error3.tag}`)})` : void 0;
|
|
@@ -323,10 +350,10 @@ function* generateFunction(fn11) {
|
|
|
323
350
|
}
|
|
324
351
|
case "Stream": {
|
|
325
352
|
const empty = api("Stream", "empty");
|
|
326
|
-
const
|
|
353
|
+
const make12 = api("Stream", "make");
|
|
327
354
|
const fail4 = api("Stream", "fail");
|
|
328
355
|
if (empty) yield candidate("StreamEmpty", empty);
|
|
329
|
-
if (
|
|
356
|
+
if (make12) for (const value of values) yield candidate("StreamOne", `${make12}(${value.text})`, value);
|
|
330
357
|
if (fail4) {
|
|
331
358
|
for (const error3 of shape.errors) if (fits(error3)) yield candidate("StreamFail", `${fail4}(${error3.text})`, error3);
|
|
332
359
|
}
|
|
@@ -343,32 +370,32 @@ function* generateFunction(fn11) {
|
|
|
343
370
|
break;
|
|
344
371
|
}
|
|
345
372
|
case "Void":
|
|
346
|
-
yield makeMutant(
|
|
373
|
+
if (!fn12.equivalentValues.includes("{}")) yield makeMutant(fn12, "FnValue", "{}", false, "an empty body");
|
|
347
374
|
break;
|
|
348
375
|
default: {
|
|
349
376
|
const genre = shape.kind === "Boolean" ? "BooleanFlip" : shape.kind === "Literal" ? "LiteralCycle" : "FnValue";
|
|
350
377
|
for (const value of values) {
|
|
351
|
-
if (value.text ===
|
|
378
|
+
if (value.text === fn12.literal || fn12.equivalentValues.includes(value.text)) continue;
|
|
352
379
|
yield candidate(genre, value.text, value);
|
|
353
380
|
}
|
|
354
381
|
}
|
|
355
382
|
}
|
|
356
383
|
}
|
|
357
|
-
function makeMutant(
|
|
358
|
-
const additions =
|
|
359
|
-
const prefix =
|
|
360
|
-
const insertion =
|
|
361
|
-
const replacement = additions.length &&
|
|
362
|
-
const id = createHash("sha256").update(JSON.stringify([
|
|
384
|
+
function makeMutant(fn12, genre, text, synthetic, description) {
|
|
385
|
+
const additions = fn12.extraImports?.filter((item) => text.includes(`${item.namespace}.`)) ?? [];
|
|
386
|
+
const prefix = fn12.sourcePrefix ?? "";
|
|
387
|
+
const insertion = fn12.importInsertionOffset ?? 0;
|
|
388
|
+
const replacement = additions.length && fn12.sourcePrefix !== void 0 ? { startOffset: 0, endOffset: fn12.endOffset, text: prefix.slice(0, insertion) + (insertion ? "\n" : "") + additions.map((item) => item.statement).join("\n") + "\n" + prefix.slice(insertion) + text } : { startOffset: fn12.startOffset, endOffset: fn12.endOffset, text };
|
|
389
|
+
const id = createHash("sha256").update(JSON.stringify([fn12.identityFile ?? fn12.file, fn12.name, fn12.identityOrdinal ?? 0, fn12.logicalSpan, genre, text, additions.map((item) => item.statement)])).digest("hex").slice(0, 24);
|
|
363
390
|
return {
|
|
364
391
|
id,
|
|
365
|
-
file:
|
|
366
|
-
functionName:
|
|
367
|
-
returnType:
|
|
368
|
-
displayReturnType:
|
|
392
|
+
file: fn12.file,
|
|
393
|
+
functionName: fn12.name,
|
|
394
|
+
returnType: fn12.returnType,
|
|
395
|
+
displayReturnType: fn12.displayReturnType,
|
|
369
396
|
genre,
|
|
370
|
-
description: `replace ${
|
|
371
|
-
span:
|
|
397
|
+
description: `replace ${fn12.name} -> ${fn12.returnType} with ${description}`,
|
|
398
|
+
span: fn12.span,
|
|
372
399
|
replacement,
|
|
373
400
|
synthetic
|
|
374
401
|
};
|
|
@@ -395,6 +422,8 @@ var ProgramSession = class {
|
|
|
395
422
|
if (config.error) throw new ProgramLoadError({ tsconfig: configPath, diagnostics: diagnosticsText([config.error]) });
|
|
396
423
|
const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, resolve(configPath, ".."));
|
|
397
424
|
if (parsed.errors.length) throw new ProgramLoadError({ tsconfig: configPath, diagnostics: diagnosticsText(parsed.errors) });
|
|
425
|
+
parsed.options.incremental = false;
|
|
426
|
+
delete parsed.options.tsBuildInfoFile;
|
|
398
427
|
this.host = ts.createCompilerHost(parsed.options, true);
|
|
399
428
|
const read = this.host.getSourceFile;
|
|
400
429
|
this.host.getSourceFile = (file, languageVersion, onError, shouldCreateNewSourceFile) => {
|
|
@@ -490,7 +519,7 @@ function makeTypeScriptOracle() {
|
|
|
490
519
|
const b = source.getLineAndCharacterOfPosition(end);
|
|
491
520
|
const beforePipeables = wrapped && ts.isFunctionExpression(node) ? generatorContract(node, checker) : void 0;
|
|
492
521
|
const shape = beforePipeables?.shape ?? shapeOf(type, checker, node, body);
|
|
493
|
-
const originals = equivalentSuccessValues(body,
|
|
522
|
+
const originals = generator ? equivalentLiteralValues(body) : equivalentSuccessValues(body, checker);
|
|
494
523
|
if (!beforePipeables && type.flags & ts.TypeFlags.TypeParameter && !("values" in shape && shape.values.length) || (beforePipeables ? !nameableContract(beforePipeables, checker, node) : hasUnnameableType(type, checker, node))) {
|
|
495
524
|
notMutated.push({ file, functionName: name, span: nodeSpan(node), reason: "generic: naked or context-only type-parameter return" });
|
|
496
525
|
} else found.push({
|
|
@@ -503,7 +532,7 @@ function makeTypeScriptOracle() {
|
|
|
503
532
|
returnType: beforePipeables?.text ?? returnTypeText(type, checker, node),
|
|
504
533
|
displayReturnType: node.type?.getText(source) ?? checker.typeToString(type, node),
|
|
505
534
|
skipReason: beforePipeables ? `no synthesizable generator success value: ${beforePipeables.text}` : synthesisReason(type, checker, node),
|
|
506
|
-
equivalentValues: shape.kind === "
|
|
535
|
+
equivalentValues: shape.kind === "Void" && ts.isBlock(body) && body.statements.length === 0 ? ["{}"] : "values" in shape ? shape.values.filter((value) => isEquivalentSuccess(value.text, shape.kind === "Effect" ? originals : equivalentLiteralValues(body))).map((value) => value.text) : [],
|
|
507
536
|
span: { start: { line: a.line + 1, column: a.character + 1 }, end: { line: b.line + 1, column: b.character + 1 } },
|
|
508
537
|
startOffset: start,
|
|
509
538
|
endOffset: end,
|
|
@@ -576,10 +605,10 @@ function makeTypeScriptOracle() {
|
|
|
576
605
|
const found = [];
|
|
577
606
|
visit(source);
|
|
578
607
|
const occurrences = /* @__PURE__ */ new Map();
|
|
579
|
-
for (const
|
|
580
|
-
const ordinal = occurrences.get(
|
|
581
|
-
occurrences.set(
|
|
582
|
-
functions.push({ ...
|
|
608
|
+
for (const fn12 of found) {
|
|
609
|
+
const ordinal = occurrences.get(fn12.name) ?? 0;
|
|
610
|
+
occurrences.set(fn12.name, ordinal + 1);
|
|
611
|
+
functions.push({ ...fn12, identityOrdinal: ordinal });
|
|
583
612
|
}
|
|
584
613
|
}
|
|
585
614
|
const unmatched = config.include.filter((glob) => !matched.has(glob));
|
|
@@ -804,11 +833,25 @@ function generatorContract(node, checker) {
|
|
|
804
833
|
};
|
|
805
834
|
}
|
|
806
835
|
function literalOfBody(body, checker) {
|
|
807
|
-
const
|
|
808
|
-
const expression = ts.isBlock(body) ? first && ts.isReturnStatement(first) ? first.expression : void 0 : body;
|
|
836
|
+
const expression = returnedExpression(body);
|
|
809
837
|
if (!expression) return void 0;
|
|
810
|
-
|
|
811
|
-
|
|
838
|
+
if (ts.isStringLiteral(expression)) return JSON.stringify(expression.text);
|
|
839
|
+
if (ts.isNumericLiteral(expression)) return String(Number(expression.text));
|
|
840
|
+
if (expression.kind === ts.SyntaxKind.TrueKeyword) return "true";
|
|
841
|
+
if (expression.kind === ts.SyntaxKind.FalseKeyword) return "false";
|
|
842
|
+
if (expression.kind === ts.SyntaxKind.NullKeyword) return "null";
|
|
843
|
+
if (ts.isIdentifier(expression)) {
|
|
844
|
+
let symbol = checker.getSymbolAtLocation(expression);
|
|
845
|
+
if (symbol && symbol.flags & ts.SymbolFlags.Alias) symbol = checker.getAliasedSymbol(symbol);
|
|
846
|
+
const constant = symbol?.declarations?.some((declaration) => ts.isEnumMember(declaration) || ts.isVariableDeclaration(declaration) && ts.isVariableDeclarationList(declaration.parent) && !!(declaration.parent.flags & ts.NodeFlags.Const));
|
|
847
|
+
if (constant) {
|
|
848
|
+
const type = checker.getTypeAtLocation(expression);
|
|
849
|
+
if (type.isStringLiteral()) return JSON.stringify(type.value);
|
|
850
|
+
if (type.isNumberLiteral()) return String(type.value);
|
|
851
|
+
if (type.flags & ts.TypeFlags.BooleanLiteral) return checker.typeToString(type);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return void 0;
|
|
812
855
|
}
|
|
813
856
|
function generatorBody(node, checker) {
|
|
814
857
|
if (!node.body) return void 0;
|
|
@@ -1012,10 +1055,13 @@ function returnTypeText(type, checker, node) {
|
|
|
1012
1055
|
return print(type);
|
|
1013
1056
|
}
|
|
1014
1057
|
function literalData(node) {
|
|
1015
|
-
if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node)) return literalData(node.expression);
|
|
1058
|
+
if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isTypeAssertionExpression(node) || ts.isNonNullExpression(node)) return literalData(node.expression);
|
|
1016
1059
|
if (ts.isStringLiteral(node) || ts.isNumericLiteral(node)) return [node.kind, node.text];
|
|
1017
1060
|
if (ts.isIdentifier(node) && node.text === "undefined") return ["undefined"];
|
|
1018
|
-
if (ts.isPrefixUnaryExpression(node))
|
|
1061
|
+
if (ts.isPrefixUnaryExpression(node)) {
|
|
1062
|
+
const operand = literalData(node.operand);
|
|
1063
|
+
return operand === void 0 ? void 0 : [node.operator, operand];
|
|
1064
|
+
}
|
|
1019
1065
|
if (ts.isArrayLiteralExpression(node)) {
|
|
1020
1066
|
const items = node.elements.map(literalData);
|
|
1021
1067
|
return items.every((item) => item !== void 0) ? ["array", items] : void 0;
|
|
@@ -1033,17 +1079,54 @@ function literalData(node) {
|
|
|
1033
1079
|
}
|
|
1034
1080
|
return void 0;
|
|
1035
1081
|
}
|
|
1036
|
-
function
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1082
|
+
function unwrapped(node) {
|
|
1083
|
+
while (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isTypeAssertionExpression(node) || ts.isNonNullExpression(node)) node = node.expression;
|
|
1084
|
+
return node;
|
|
1085
|
+
}
|
|
1086
|
+
function returnedExpression(body) {
|
|
1087
|
+
if (!ts.isBlock(body)) return unwrapped(body);
|
|
1088
|
+
const statement = body.statements.length === 1 ? body.statements[0] : void 0;
|
|
1089
|
+
return statement && ts.isReturnStatement(statement) && statement.expression ? unwrapped(statement.expression) : void 0;
|
|
1090
|
+
}
|
|
1091
|
+
function equivalentLiteralValues(body) {
|
|
1092
|
+
const expression = returnedExpression(body);
|
|
1093
|
+
const value = expression && literalData(expression);
|
|
1094
|
+
return value === void 0 ? [] : [JSON.stringify(value)];
|
|
1095
|
+
}
|
|
1096
|
+
function equivalentSuccessValues(body, checker) {
|
|
1097
|
+
const expression = returnedExpression(body);
|
|
1098
|
+
if (!expression) return [];
|
|
1099
|
+
const namespace = (node, seen = /* @__PURE__ */ new Set()) => {
|
|
1100
|
+
node = unwrapped(node);
|
|
1101
|
+
if (!ts.isIdentifier(node) && !ts.isPropertyAccessExpression(node)) return false;
|
|
1102
|
+
if (ts.isPropertyAccessExpression(node) && !namespace(node.expression, seen)) return false;
|
|
1103
|
+
let symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(node) ? node.name : node);
|
|
1104
|
+
if (!symbol || seen.has(symbol)) return false;
|
|
1105
|
+
seen.add(symbol);
|
|
1106
|
+
if (symbol.flags & ts.SymbolFlags.Alias) symbol = checker.getAliasedSymbol(symbol);
|
|
1107
|
+
return symbol.declarations?.some((declaration) => {
|
|
1108
|
+
if (ts.isSourceFile(declaration)) return /\/node_modules\/effect\/(?:.*\/)?(?:Effect|index)\.(?:d\.)?ts$/.test(declaration.fileName);
|
|
1109
|
+
return ts.isVariableDeclaration(declaration) && !!declaration.initializer && ts.isVariableDeclarationList(declaration.parent) && !!(declaration.parent.flags & ts.NodeFlags.Const) && namespace(declaration.initializer, seen);
|
|
1110
|
+
}) ?? false;
|
|
1111
|
+
};
|
|
1112
|
+
const member = (node, seen = /* @__PURE__ */ new Set()) => {
|
|
1113
|
+
node = unwrapped(node);
|
|
1114
|
+
if (!ts.isIdentifier(node) && !ts.isPropertyAccessExpression(node)) return void 0;
|
|
1115
|
+
if (ts.isPropertyAccessExpression(node) && !namespace(node.expression)) return void 0;
|
|
1116
|
+
let symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(node) ? node.name : node);
|
|
1117
|
+
if (!symbol || seen.has(symbol)) return void 0;
|
|
1118
|
+
seen.add(symbol);
|
|
1119
|
+
if (symbol.flags & ts.SymbolFlags.Alias) symbol = checker.getAliasedSymbol(symbol);
|
|
1120
|
+
for (const declaration of symbol.declarations ?? []) {
|
|
1121
|
+
if (/\/node_modules\/effect\/(?:.*\/)?Effect\.(?:d\.)?ts$/.test(declaration.getSourceFile().fileName)) return symbol.name === "void_" ? "void" : symbol.name;
|
|
1122
|
+
if (ts.isVariableDeclaration(declaration) && declaration.initializer && ts.isVariableDeclarationList(declaration.parent) && declaration.parent.flags & ts.NodeFlags.Const) return member(declaration.initializer, seen);
|
|
1042
1123
|
}
|
|
1043
|
-
|
|
1124
|
+
return void 0;
|
|
1044
1125
|
};
|
|
1045
|
-
|
|
1046
|
-
return
|
|
1126
|
+
if (member(expression) === "void") return [JSON.stringify(["undefined"])];
|
|
1127
|
+
if (!ts.isCallExpression(expression) || expression.arguments.length !== 1 || member(expression.expression) !== "succeed") return [];
|
|
1128
|
+
const value = literalData(expression.arguments[0]);
|
|
1129
|
+
return value === void 0 ? [] : [JSON.stringify(value)];
|
|
1047
1130
|
}
|
|
1048
1131
|
function isEquivalentSuccess(text, values) {
|
|
1049
1132
|
const source = ts.createSourceFile("literal.ts", `(${text})`, ts.ScriptTarget.Latest, true);
|
|
@@ -1233,18 +1316,18 @@ function synthesizeValues(type, checker, location, ancestors, depth, issues) {
|
|
|
1233
1316
|
// packages/engine/src/index.ts
|
|
1234
1317
|
var MutantSourceLive = Layer.effect(
|
|
1235
1318
|
MutantSource,
|
|
1236
|
-
|
|
1319
|
+
Effect2.sync(() => makeMutantSource(makeTypeScriptOracle()))
|
|
1237
1320
|
);
|
|
1238
1321
|
function makeMutantSource(oracle) {
|
|
1239
|
-
const discover = (config) =>
|
|
1322
|
+
const discover = (config) => Effect2.try({
|
|
1240
1323
|
try: () => {
|
|
1241
1324
|
const discovered = oracle.discover(config);
|
|
1242
1325
|
const notMutated = [...discovered.notMutated];
|
|
1243
1326
|
const mutants = [];
|
|
1244
1327
|
const failed = /* @__PURE__ */ new Set();
|
|
1245
|
-
const generatedFunctions = discovered.functions.map((
|
|
1328
|
+
const generatedFunctions = discovered.functions.map((fn12) => {
|
|
1246
1329
|
try {
|
|
1247
|
-
const iterator = generateFunction(
|
|
1330
|
+
const iterator = generateFunction(fn12);
|
|
1248
1331
|
const generated = [];
|
|
1249
1332
|
let step = iterator.next();
|
|
1250
1333
|
while (!step.done) {
|
|
@@ -1252,32 +1335,32 @@ function makeMutantSource(oracle) {
|
|
|
1252
1335
|
step = iterator.next();
|
|
1253
1336
|
}
|
|
1254
1337
|
if (step.value) {
|
|
1255
|
-
failed.add(
|
|
1256
|
-
notMutated.push({ file:
|
|
1257
|
-
return { fn:
|
|
1338
|
+
failed.add(fn12);
|
|
1339
|
+
notMutated.push({ file: fn12.file, functionName: fn12.name, span: fn12.span, reason: step.value });
|
|
1340
|
+
return { fn: fn12, generated: [] };
|
|
1258
1341
|
}
|
|
1259
|
-
return { fn:
|
|
1342
|
+
return { fn: fn12, generated };
|
|
1260
1343
|
} catch (error3) {
|
|
1261
|
-
failed.add(
|
|
1344
|
+
failed.add(fn12);
|
|
1262
1345
|
notMutated.push({
|
|
1263
|
-
file:
|
|
1264
|
-
functionName:
|
|
1265
|
-
span:
|
|
1346
|
+
file: fn12.file,
|
|
1347
|
+
functionName: fn12.name,
|
|
1348
|
+
span: fn12.span,
|
|
1266
1349
|
reason: `analysis failed: ${error3 instanceof Error ? error3.message : String(error3)}`
|
|
1267
1350
|
});
|
|
1268
|
-
return { fn:
|
|
1351
|
+
return { fn: fn12, generated: [] };
|
|
1269
1352
|
}
|
|
1270
1353
|
});
|
|
1271
|
-
for (const { fn:
|
|
1272
|
-
if (failed.has(
|
|
1354
|
+
for (const { fn: fn12, generated } of generatedFunctions) {
|
|
1355
|
+
if (failed.has(fn12)) continue;
|
|
1273
1356
|
{
|
|
1274
|
-
const reasons = [...
|
|
1275
|
-
if (!generated.length && !reasons.length) reasons.push(
|
|
1276
|
-
const innerMutated = !generated.length && generatedFunctions.some(({ fn: inner, generated: generated2 }) => inner.file ===
|
|
1357
|
+
const reasons = [...fn12.notices ?? []];
|
|
1358
|
+
if (!generated.length && !reasons.length) reasons.push(fn12.skipReason ?? `return not synthesizable (type ${fn12.displayReturnType})`);
|
|
1359
|
+
const innerMutated = !generated.length && generatedFunctions.some(({ fn: inner, generated: generated2 }) => inner.file === fn12.file && inner.startOffset > fn12.startOffset && inner.endOffset < fn12.endOffset && generated2.length > 0);
|
|
1277
1360
|
if (innerMutated && !generated.length) {
|
|
1278
1361
|
for (let i = 0; i < reasons.length; i++) if (reasons[i].startsWith("return not synthesizable")) reasons[i] += "; inner functions mutated";
|
|
1279
1362
|
}
|
|
1280
|
-
if (reasons.length) notMutated.push({ file:
|
|
1363
|
+
if (reasons.length) notMutated.push({ file: fn12.file, functionName: fn12.name, span: fn12.span, reason: [...new Set(reasons)].join("; ") });
|
|
1281
1364
|
}
|
|
1282
1365
|
mutants.push(...generated);
|
|
1283
1366
|
}
|
|
@@ -1289,9 +1372,9 @@ function makeMutantSource(oracle) {
|
|
|
1289
1372
|
}
|
|
1290
1373
|
});
|
|
1291
1374
|
return {
|
|
1292
|
-
notMutated: (config) => discover(config).pipe(
|
|
1293
|
-
generate: (config) => Stream.unwrap(discover(config).pipe(
|
|
1294
|
-
checkViable: (mutant) =>
|
|
1375
|
+
notMutated: (config) => discover(config).pipe(Effect2.map((result5) => result5.notMutated)),
|
|
1376
|
+
generate: (config) => Stream.unwrap(discover(config).pipe(Effect2.map((result5) => Stream.fromIterable(result5.mutants)))),
|
|
1377
|
+
checkViable: (mutant) => Effect2.sync(() => {
|
|
1295
1378
|
try {
|
|
1296
1379
|
return oracle.checkViable(mutant);
|
|
1297
1380
|
} catch (error3) {
|
|
@@ -1307,11 +1390,15 @@ function makeMutantSource(oracle) {
|
|
|
1307
1390
|
}
|
|
1308
1391
|
|
|
1309
1392
|
// packages/runner/src/Scratch.ts
|
|
1310
|
-
import * as
|
|
1393
|
+
import * as Effect3 from "effect/Effect";
|
|
1311
1394
|
import * as Console from "effect/Console";
|
|
1312
1395
|
import * as FileSystem from "effect/FileSystem";
|
|
1313
1396
|
import * as Layer2 from "effect/Layer";
|
|
1314
|
-
import * as
|
|
1397
|
+
import * as Path3 from "effect/Path";
|
|
1398
|
+
import * as ChildProcess from "effect/process/ChildProcess";
|
|
1399
|
+
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
|
1400
|
+
import * as Stream2 from "effect/Stream";
|
|
1401
|
+
import * as Schema5 from "effect/Schema";
|
|
1315
1402
|
|
|
1316
1403
|
// packages/runner/src/Poison.ts
|
|
1317
1404
|
function prologueEnd(source) {
|
|
@@ -1373,46 +1460,186 @@ throw new Error(${JSON.stringify(token)});
|
|
|
1373
1460
|
}
|
|
1374
1461
|
|
|
1375
1462
|
// packages/runner/src/Scratch.ts
|
|
1376
|
-
var ScratchLive = Layer2.effect(Scratch,
|
|
1463
|
+
var ScratchLive = Layer2.effect(Scratch, Effect3.gen(function* () {
|
|
1377
1464
|
const fs = yield* FileSystem.FileSystem;
|
|
1378
|
-
const path = yield*
|
|
1465
|
+
const path = yield* Path3.Path;
|
|
1466
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
1379
1467
|
const failure = (operation, location, error3) => new ScratchError({ operation, path: location, message: error3.message });
|
|
1380
|
-
const skipVanished = (from, to) => (effect5) => effect5.pipe(
|
|
1381
|
-
if (error3._tag !== "PlatformError" || error3.reason._tag !== "NotFound") return
|
|
1382
|
-
return
|
|
1383
|
-
const entry = yield* fs.lstat(from).pipe(
|
|
1384
|
-
if (entry._tag === "Success")
|
|
1385
|
-
|
|
1468
|
+
const skipVanished = (from, to) => (effect5) => effect5.pipe(Effect3.catch((error3) => {
|
|
1469
|
+
if (error3._tag !== "PlatformError" || error3.reason._tag !== "NotFound") return Effect3.fail(error3);
|
|
1470
|
+
return Effect3.gen(function* () {
|
|
1471
|
+
const entry = yield* fs.lstat(from).pipe(Effect3.result);
|
|
1472
|
+
if (entry._tag === "Success") {
|
|
1473
|
+
if (entry.success.type !== "SymbolicLink") return yield* Effect3.fail(error3);
|
|
1474
|
+
const target = yield* fs.stat(from).pipe(Effect3.result);
|
|
1475
|
+
if (target._tag === "Success") return yield* Effect3.fail(error3);
|
|
1476
|
+
if (target.failure.reason._tag !== "NotFound") return yield* Effect3.fail(target.failure);
|
|
1477
|
+
yield* Console.warn(`Warning: scratch copy skipped a dangling symlink: ${from}`);
|
|
1478
|
+
} else if (entry.failure.reason._tag !== "NotFound") return yield* Effect3.fail(entry.failure);
|
|
1386
1479
|
yield* fs.remove(to, { recursive: true, force: true });
|
|
1387
|
-
yield*
|
|
1480
|
+
yield* Effect3.logDebug("Scratch copy skipped a vanished source", { source: from });
|
|
1388
1481
|
});
|
|
1389
1482
|
}));
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1483
|
+
const discover = Effect3.fn("Scratch.discover")(function* (root) {
|
|
1484
|
+
let source = path.resolve(root);
|
|
1485
|
+
let copyRoot = source;
|
|
1486
|
+
let ancestor = source;
|
|
1487
|
+
while (true) {
|
|
1488
|
+
if ((yield* fs.exists(path.join(ancestor, "pnpm-workspace.yaml"))) || (yield* fs.exists(path.join(ancestor, ".git")))) {
|
|
1489
|
+
copyRoot = ancestor;
|
|
1490
|
+
break;
|
|
1491
|
+
}
|
|
1492
|
+
const parent = path.dirname(ancestor);
|
|
1493
|
+
if (parent === ancestor) break;
|
|
1494
|
+
ancestor = parent;
|
|
1495
|
+
}
|
|
1496
|
+
const git2 = (args, cwd = source) => Effect3.scoped(Effect3.gen(function* () {
|
|
1497
|
+
const env = { ...process.env };
|
|
1498
|
+
for (const key of ["GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE"]) delete env[key];
|
|
1499
|
+
const child = yield* spawner.spawn(ChildProcess.make("git", ["-C", cwd, ...args], { stdin: "ignore", env, extendEnv: false }));
|
|
1500
|
+
const [code, output] = yield* Effect3.all([child.exitCode, child.stdout.pipe(Stream2.decodeText(), Stream2.mkString), child.stderr.pipe(Stream2.runDrain)], { concurrency: "unbounded" });
|
|
1501
|
+
return { code, output };
|
|
1502
|
+
}));
|
|
1503
|
+
let gitAncestor = source;
|
|
1504
|
+
let inRepository = false;
|
|
1505
|
+
while (true) {
|
|
1506
|
+
if (yield* fs.exists(path.join(gitAncestor, ".git"))) {
|
|
1507
|
+
inRepository = true;
|
|
1508
|
+
break;
|
|
1509
|
+
}
|
|
1510
|
+
const parent = path.dirname(gitAncestor);
|
|
1511
|
+
if (parent === gitAncestor) break;
|
|
1512
|
+
gitAncestor = parent;
|
|
1513
|
+
}
|
|
1514
|
+
let selected;
|
|
1515
|
+
let directories;
|
|
1516
|
+
const linked = /* @__PURE__ */ new Set();
|
|
1517
|
+
const unreadable = /* @__PURE__ */ new Set();
|
|
1518
|
+
const ignoredRoots = /* @__PURE__ */ new Set();
|
|
1519
|
+
const pruneUnreadable = (location) => Effect3.gen(function* () {
|
|
1520
|
+
unreadable.add(location);
|
|
1521
|
+
yield* Console.warn(`Warning: scratch copy skipped an unreadable ignored tree: ${location}`);
|
|
1522
|
+
});
|
|
1523
|
+
const originalSource = source;
|
|
1524
|
+
const originalCopyRoot = copyRoot;
|
|
1525
|
+
if (inRepository) yield* Effect3.gen(function* () {
|
|
1526
|
+
const repository = yield* git2(["rev-parse", "--show-toplevel"]);
|
|
1527
|
+
if (repository.code !== 0) return yield* new ScratchError({ operation: "git rev-parse", path: source, message: `Git exited ${repository.code}` });
|
|
1528
|
+
source = yield* fs.realPath(source);
|
|
1529
|
+
copyRoot = path.resolve(repository.output.trim());
|
|
1530
|
+
const files = yield* git2(["ls-files", "--cached", "--others", "--exclude-standard", "--full-name", "-z"], copyRoot).pipe(Effect3.mapError((error3) => failure("git", source, error3)));
|
|
1531
|
+
if (files.code !== 0) return yield* Effect3.fail(new ScratchError({ operation: "git ls-files", path: source, message: `Git exited ${files.code}` }));
|
|
1532
|
+
selected = new Set(files.output.split("\0").filter(Boolean).map((file) => path.resolve(copyRoot, file)));
|
|
1533
|
+
const ignored = yield* git2(["ls-files", "--others", "--ignored", "--exclude-standard", "--directory", "-z"], copyRoot);
|
|
1534
|
+
if (ignored.code !== 0) return yield* new ScratchError({ operation: "git ls-files", path: source, message: `Git exited ${ignored.code}` });
|
|
1535
|
+
const independent = (dir) => Effect3.gen(function* () {
|
|
1536
|
+
if ((yield* fs.exists(path.join(dir, ".git"))) || (yield* fs.exists(path.join(dir, "node_modules")))) return true;
|
|
1537
|
+
for (const name of yield* fs.readDirectory(dir)) {
|
|
1538
|
+
const child = path.join(dir, name);
|
|
1539
|
+
const info = yield* fs.lstat(child).pipe(Effect3.result);
|
|
1540
|
+
if (info._tag === "Failure") {
|
|
1541
|
+
if (info.failure.reason._tag === "PermissionDenied") {
|
|
1542
|
+
yield* pruneUnreadable(child);
|
|
1543
|
+
continue;
|
|
1544
|
+
}
|
|
1545
|
+
return yield* info.failure;
|
|
1546
|
+
}
|
|
1547
|
+
if (info.success.type === "Directory" && (yield* independent(child))) return true;
|
|
1548
|
+
}
|
|
1549
|
+
return false;
|
|
1550
|
+
}).pipe(Effect3.catch((error3) => error3.reason._tag === "PermissionDenied" ? pruneUnreadable(dir).pipe(Effect3.as(false)) : Effect3.fail(error3)));
|
|
1551
|
+
for (const file of ignored.output.split("\0").filter(Boolean)) {
|
|
1552
|
+
const target = path.resolve(copyRoot, file);
|
|
1553
|
+
if (path.relative(copyRoot, target).split(path.sep).some((part) => ["node_modules", ".git", "mutants.out", ".agent_sources", ".agent-sources", ".brain", ".pi", ".rift"].includes(part))) continue;
|
|
1554
|
+
ignoredRoots.add(target);
|
|
1555
|
+
const info = yield* fs.lstat(target).pipe(Effect3.result);
|
|
1556
|
+
if (info._tag === "Failure") {
|
|
1557
|
+
if (info.failure.reason._tag === "NotFound") continue;
|
|
1558
|
+
if (info.failure.reason._tag === "PermissionDenied") {
|
|
1559
|
+
yield* pruneUnreadable(target);
|
|
1560
|
+
continue;
|
|
1561
|
+
}
|
|
1562
|
+
return yield* info.failure;
|
|
1563
|
+
}
|
|
1564
|
+
if (info.success.type !== "Directory") {
|
|
1565
|
+
selected.add(target);
|
|
1566
|
+
continue;
|
|
1567
|
+
}
|
|
1568
|
+
if (yield* independent(target)) linked.add(target);
|
|
1569
|
+
else selected.add(target);
|
|
1570
|
+
}
|
|
1571
|
+
const PackageEntries = Schema5.fromJsonString(Schema5.Struct({
|
|
1572
|
+
exports: Schema5.optional(Schema5.Unknown),
|
|
1573
|
+
imports: Schema5.optional(Schema5.Unknown),
|
|
1574
|
+
main: Schema5.optional(Schema5.String),
|
|
1575
|
+
module: Schema5.optional(Schema5.String),
|
|
1576
|
+
types: Schema5.optional(Schema5.String)
|
|
1577
|
+
}));
|
|
1578
|
+
const targets = (entry) => typeof entry === "string" ? [entry] : Array.isArray(entry) ? entry.flatMap(targets) : entry !== null && typeof entry === "object" ? Object.values(entry).flatMap(targets) : [];
|
|
1579
|
+
for (const file of [...selected]) {
|
|
1580
|
+
if (path.basename(file) !== "package.json" || !(yield* fs.exists(file))) continue;
|
|
1581
|
+
const decoded = yield* Schema5.decodeEffect(PackageEntries)(yield* fs.readFileString(file)).pipe(Effect3.result);
|
|
1582
|
+
if (decoded._tag === "Failure") {
|
|
1583
|
+
yield* Console.warn(`Warning: cannot inspect package entry points for scratch copying: ${file}`);
|
|
1584
|
+
continue;
|
|
1585
|
+
}
|
|
1586
|
+
const pkg = decoded.success;
|
|
1587
|
+
const root2 = path.dirname(file);
|
|
1588
|
+
const entries = [...targets(pkg.exports), ...targets(pkg.imports)].filter((entry) => entry.startsWith("./"));
|
|
1589
|
+
entries.push(...[pkg.main, pkg.module, pkg.types].filter((entry) => entry !== void 0));
|
|
1590
|
+
for (const entry of entries) {
|
|
1591
|
+
const relative2 = path.relative(root2, path.resolve(root2, entry));
|
|
1592
|
+
if (!relative2 || relative2 === ".." || relative2.startsWith(`..${path.sep}`) || path.isAbsolute(relative2)) continue;
|
|
1593
|
+
const first = relative2.split(path.sep)[0];
|
|
1594
|
+
if (!["node_modules", ".git"].includes(first)) selected.add(path.join(root2, first));
|
|
1399
1595
|
}
|
|
1400
|
-
const parent = path.dirname(ancestor);
|
|
1401
|
-
if (parent === ancestor) break;
|
|
1402
|
-
ancestor = parent;
|
|
1403
1596
|
}
|
|
1404
|
-
|
|
1597
|
+
directories = /* @__PURE__ */ new Set([copyRoot]);
|
|
1598
|
+
for (const file of [...selected, ...linked]) {
|
|
1599
|
+
let parent = path.dirname(file);
|
|
1600
|
+
while (parent !== copyRoot && parent !== path.dirname(parent)) {
|
|
1601
|
+
directories.add(parent);
|
|
1602
|
+
parent = path.dirname(parent);
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
}).pipe(Effect3.catch((error3) => Effect3.gen(function* () {
|
|
1606
|
+
yield* Console.warn(`Warning: Git scratch discovery failed; using recursive copy: ${error3.message}`);
|
|
1607
|
+
source = originalSource;
|
|
1608
|
+
copyRoot = originalCopyRoot;
|
|
1609
|
+
selected = void 0;
|
|
1610
|
+
directories = void 0;
|
|
1611
|
+
linked.clear();
|
|
1612
|
+
unreadable.clear();
|
|
1613
|
+
ignoredRoots.clear();
|
|
1614
|
+
})));
|
|
1615
|
+
const linkedRoots = () => [...linked].filter((root2) => !selected?.has(root2) && !unreadable.has(root2)).map((root2) => path.relative(source, root2)).filter((root2) => root2 !== ".." && !root2.startsWith(`..${path.sep}`) && !path.isAbsolute(root2));
|
|
1616
|
+
return { source, copyRoot, selected, directories, linked, unreadable, ignoredRoots, pruneUnreadable, linkedRoots };
|
|
1617
|
+
}, (effect5, root) => effect5.pipe(Effect3.mapError((error3) => failure("discover", root, error3))));
|
|
1618
|
+
return Scratch.of({
|
|
1619
|
+
inspect: Effect3.fn("Scratch.inspect")(function* (root) {
|
|
1620
|
+
return (yield* discover(root)).linkedRoots();
|
|
1621
|
+
}),
|
|
1622
|
+
acquire: Effect3.fn("Scratch.acquire")(function* (root) {
|
|
1623
|
+
const plan = yield* discover(root);
|
|
1624
|
+
const { source, copyRoot, selected, directories, linked, unreadable, ignoredRoots, pruneUnreadable } = plan;
|
|
1625
|
+
const skipUnreadable = (from, to, enabled) => (effect5) => effect5.pipe(Effect3.catch((error3) => enabled && error3._tag === "PlatformError" && error3.reason._tag === "PermissionDenied" && error3.reason.pathOrDescriptor === from && ["access", "realPath", "stat", "lstat", "readDirectory"].includes(error3.reason.method) ? pruneUnreadable(from).pipe(Effect3.andThen(fs.remove(to, { recursive: true, force: true }))) : Effect3.fail(error3)));
|
|
1626
|
+
const temp = yield* Effect3.acquireRelease(
|
|
1405
1627
|
fs.makeTempDirectory({ prefix: "mutant-cafe-" }).pipe(
|
|
1406
|
-
|
|
1628
|
+
Effect3.mapError((error3) => failure("create", source, error3))
|
|
1407
1629
|
),
|
|
1408
|
-
(dir2) => fs.remove(dir2, { recursive: true, force: true }).pipe(
|
|
1630
|
+
(dir2) => fs.remove(dir2, { recursive: true, force: true }).pipe(Effect3.interruptible, Effect3.timeout(3e4), Effect3.catch((error3) => Console.warn(`Warning: scratch removal did not complete within its cleanup budget: ${error3.message}`, { path: dir2 })))
|
|
1409
1631
|
);
|
|
1410
|
-
const copy = (from, to, ancestors) =>
|
|
1632
|
+
const copy = (from, to, ancestors, filter = true, ignored = false) => Effect3.gen(function* () {
|
|
1633
|
+
if (unreadable.has(from)) return;
|
|
1634
|
+
if (linked.has(from) && !selected?.has(from)) {
|
|
1635
|
+
yield* fs.symlink(from, to);
|
|
1636
|
+
return;
|
|
1637
|
+
}
|
|
1411
1638
|
const real = yield* fs.realPath(from);
|
|
1412
1639
|
const info = yield* fs.stat(from);
|
|
1413
1640
|
if (info.type === "Directory") {
|
|
1414
1641
|
if (ancestors.includes(real)) {
|
|
1415
|
-
return yield*
|
|
1642
|
+
return yield* Effect3.fail(new ScratchError({ operation: "copy", path: from, message: "Cyclic directory symlink" }));
|
|
1416
1643
|
}
|
|
1417
1644
|
yield* fs.makeDirectory(to, { recursive: true });
|
|
1418
1645
|
const entries = yield* fs.readDirectory(from);
|
|
@@ -1420,84 +1647,92 @@ var ScratchLive = Layer2.effect(Scratch, Effect2.gen(function* () {
|
|
|
1420
1647
|
if ([".git", "mutants.out", ".agent_sources", ".agent-sources", ".brain", ".pi", ".rift"].includes(entry)) continue;
|
|
1421
1648
|
const src = path.join(from, entry);
|
|
1422
1649
|
const dest = path.join(to, entry);
|
|
1650
|
+
const filterChildren = filter && !selected?.has(from);
|
|
1651
|
+
if (filterChildren && selected && directories && !selected.has(src) && !directories.has(src) && !linked.has(src) && entry !== "node_modules") continue;
|
|
1423
1652
|
if (entry === "node_modules") {
|
|
1424
|
-
const linkDependencies = (from2, to2) =>
|
|
1653
|
+
const linkDependencies = (from2, to2, ignored2) => Effect3.gen(function* () {
|
|
1425
1654
|
yield* fs.makeDirectory(to2, { recursive: true });
|
|
1426
1655
|
for (const name of yield* fs.readDirectory(from2)) {
|
|
1427
1656
|
if ([".vite", ".vite-temp", ".vitest", ".cache"].includes(name)) continue;
|
|
1428
1657
|
const dependency = path.join(from2, name);
|
|
1429
1658
|
const destination = path.join(to2, name);
|
|
1430
|
-
yield*
|
|
1659
|
+
yield* Effect3.gen(function* () {
|
|
1431
1660
|
if (name.startsWith("@")) {
|
|
1432
|
-
yield* linkDependencies(dependency, destination);
|
|
1661
|
+
yield* linkDependencies(dependency, destination, ignored2);
|
|
1433
1662
|
return;
|
|
1434
1663
|
}
|
|
1435
1664
|
const realDependency = yield* fs.realPath(dependency);
|
|
1436
1665
|
const rel = path.relative(copyRoot, realDependency);
|
|
1437
|
-
const inside = rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) && !rel.split(path.sep).includes("node_modules");
|
|
1666
|
+
const inside = rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) && !rel.split(path.sep).includes("node_modules") && (!selected || selected.has(realDependency) || directories?.has(realDependency));
|
|
1438
1667
|
yield* fs.symlink(inside ? path.join(temp, rel) : realDependency, destination);
|
|
1439
|
-
}).pipe(skipVanished(dependency, destination));
|
|
1668
|
+
}).pipe(skipVanished(dependency, destination), skipUnreadable(dependency, destination, ignored2));
|
|
1440
1669
|
}
|
|
1441
1670
|
});
|
|
1442
|
-
yield* linkDependencies(src, dest).pipe(skipVanished(src, dest));
|
|
1671
|
+
yield* linkDependencies(src, dest, ignored || ignoredRoots.has(from)).pipe(skipVanished(src, dest), skipUnreadable(src, dest, ignored || ignoredRoots.has(from)));
|
|
1443
1672
|
} else {
|
|
1444
|
-
yield* copy(src, dest, [...ancestors, real]);
|
|
1673
|
+
yield* copy(src, dest, [...ancestors, real], filterChildren, ignored || ignoredRoots.has(from));
|
|
1445
1674
|
}
|
|
1446
1675
|
}
|
|
1447
1676
|
} else if (info.type === "File") {
|
|
1677
|
+
if (ignored || ignoredRoots.has(from)) yield* fs.access(from, { readable: true });
|
|
1448
1678
|
yield* fs.copyFile(from, to);
|
|
1449
1679
|
}
|
|
1450
|
-
}).pipe(skipVanished(from, to),
|
|
1680
|
+
}).pipe(skipVanished(from, to), skipUnreadable(from, to, ignored || ignoredRoots.has(from)), Effect3.mapError((error3) => failure("copy", from, error3)));
|
|
1451
1681
|
yield* copy(copyRoot, temp, []);
|
|
1452
1682
|
const packageRoot = yield* fs.realPath(path.join(temp, path.relative(copyRoot, source))).pipe(
|
|
1453
|
-
|
|
1683
|
+
Effect3.mapError((error3) => failure("resolve", source, error3))
|
|
1454
1684
|
);
|
|
1685
|
+
const packageRelative = path.relative(yield* fs.realPath(temp), packageRoot);
|
|
1686
|
+
if (packageRelative === ".." || packageRelative.startsWith(`..${path.sep}`) || path.isAbsolute(packageRelative)) {
|
|
1687
|
+
return yield* new ScratchError({ operation: "resolve", path: source, message: "Requested package is inside a linked ignored tree; refusing to mutate the original checkout. Choose an editable source package outside that tree." });
|
|
1688
|
+
}
|
|
1455
1689
|
const originals = /* @__PURE__ */ new Map();
|
|
1456
|
-
const target = (mutant) =>
|
|
1690
|
+
const target = (mutant) => Effect3.gen(function* () {
|
|
1457
1691
|
const relative2 = path.isAbsolute(mutant.file) ? path.relative(source, mutant.file) : mutant.file;
|
|
1458
1692
|
const location = path.resolve(packageRoot, relative2);
|
|
1459
1693
|
const rel = path.relative(packageRoot, location);
|
|
1460
1694
|
if (rel === "" || rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel) || rel.split(path.sep).includes("node_modules")) {
|
|
1461
|
-
return yield*
|
|
1695
|
+
return yield* Effect3.fail(new ScratchError({ operation: "resolve", path: mutant.file, message: "Mutant file must be inside the copied source tree" }));
|
|
1462
1696
|
}
|
|
1463
|
-
const real = yield* fs.realPath(location).pipe(
|
|
1697
|
+
const real = yield* fs.realPath(location).pipe(Effect3.mapError((error3) => failure("resolve", location, error3)));
|
|
1464
1698
|
const realRelative = path.relative(packageRoot, real);
|
|
1465
1699
|
if (realRelative === ".." || realRelative.startsWith(`..${path.sep}`) || path.isAbsolute(realRelative)) {
|
|
1466
|
-
return yield*
|
|
1700
|
+
return yield* Effect3.fail(new ScratchError({ operation: "resolve", path: mutant.file, message: "Mutant file resolves outside the scratch package" }));
|
|
1467
1701
|
}
|
|
1468
1702
|
return location;
|
|
1469
1703
|
});
|
|
1470
1704
|
const dir = {
|
|
1471
1705
|
path: packageRoot,
|
|
1472
|
-
|
|
1706
|
+
linkedRoots: plan.linkedRoots(),
|
|
1707
|
+
apply: Effect3.fn("Scratch.apply")(function* (mutant) {
|
|
1473
1708
|
const location = yield* target(mutant);
|
|
1474
1709
|
const bytes = yield* fs.readFile(location);
|
|
1475
1710
|
originals.set(location, bytes);
|
|
1476
1711
|
const original = new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes);
|
|
1477
1712
|
const { startOffset, endOffset, text } = mutant.replacement;
|
|
1478
1713
|
if (startOffset < 0 || endOffset < startOffset || endOffset > original.length) {
|
|
1479
|
-
return yield*
|
|
1714
|
+
return yield* Effect3.fail(new ScratchError({ operation: "apply", path: location, message: "Replacement offsets are outside the file" }));
|
|
1480
1715
|
}
|
|
1481
1716
|
yield* fs.writeFileString(location, original.slice(0, startOffset) + text + original.slice(endOffset));
|
|
1482
|
-
}, (effect5, mutant) => effect5.pipe(
|
|
1483
|
-
poison:
|
|
1717
|
+
}, (effect5, mutant) => effect5.pipe(Effect3.mapError((error3) => failure("apply", mutant.file, error3)))),
|
|
1718
|
+
poison: Effect3.fn("Scratch.poison")(function* (mutant, signal, token) {
|
|
1484
1719
|
const location = yield* target(mutant);
|
|
1485
|
-
const bytes = yield* fs.readFile(location).pipe(
|
|
1720
|
+
const bytes = yield* fs.readFile(location).pipe(Effect3.mapError((error3) => failure("probe", location, error3)));
|
|
1486
1721
|
const original = new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes);
|
|
1487
1722
|
const insertion = poisonInsertion(original, signal, token);
|
|
1488
1723
|
yield* dir.apply({ ...mutant, replacement: { startOffset: insertion.offset, endOffset: insertion.offset, text: insertion.text } });
|
|
1489
1724
|
}),
|
|
1490
|
-
revert:
|
|
1725
|
+
revert: Effect3.fn("Scratch.revert")(function* (mutant) {
|
|
1491
1726
|
const location = yield* target(mutant);
|
|
1492
1727
|
const bytes = originals.get(location);
|
|
1493
1728
|
if (bytes !== void 0) {
|
|
1494
1729
|
yield* fs.writeFile(location, bytes);
|
|
1495
1730
|
originals.delete(location);
|
|
1496
1731
|
}
|
|
1497
|
-
}, (effect5, mutant) => effect5.pipe(
|
|
1732
|
+
}, (effect5, mutant) => effect5.pipe(Effect3.mapError((error3) => failure("revert", mutant.file, error3))))
|
|
1498
1733
|
};
|
|
1499
1734
|
return dir;
|
|
1500
|
-
}, (effect5, root) => effect5.pipe(
|
|
1735
|
+
}, (effect5, root) => effect5.pipe(Effect3.mapError((error3) => error3._tag === "ScratchError" ? error3 : failure("acquire", root, error3))))
|
|
1501
1736
|
});
|
|
1502
1737
|
}));
|
|
1503
1738
|
|
|
@@ -1506,11 +1741,11 @@ import * as Clock4 from "effect/Clock";
|
|
|
1506
1741
|
import * as Console4 from "effect/Console";
|
|
1507
1742
|
|
|
1508
1743
|
// packages/runner/src/Preflight.ts
|
|
1509
|
-
import * as
|
|
1744
|
+
import * as Effect5 from "effect/Effect";
|
|
1510
1745
|
import * as Clock2 from "effect/Clock";
|
|
1511
|
-
import * as
|
|
1512
|
-
import * as
|
|
1513
|
-
import * as
|
|
1746
|
+
import * as Schema7 from "effect/Schema";
|
|
1747
|
+
import * as ChildProcess2 from "effect/process/ChildProcess";
|
|
1748
|
+
import * as ChildProcessSpawner3 from "effect/process/ChildProcessSpawner";
|
|
1514
1749
|
|
|
1515
1750
|
// packages/runner/src/ProcessTree.ts
|
|
1516
1751
|
import { createEffectActor, createEffectLogic, join, send, setupEffect } from "@xstate/effect";
|
|
@@ -1527,26 +1762,70 @@ const traceProcess = (stage, details = {}) => {
|
|
|
1527
1762
|
};
|
|
1528
1763
|
`;
|
|
1529
1764
|
|
|
1765
|
+
// packages/runner/src/RuntimeArgs.ts
|
|
1766
|
+
import { isAbsolute, resolve as resolve2 } from "node:path";
|
|
1767
|
+
import { pathToFileURL } from "node:url";
|
|
1768
|
+
var isPath = (value) => isAbsolute(value) || /^\.{1,2}([/\\]|$)/.test(value);
|
|
1769
|
+
function runtimeArgs(argv, cwd, bun) {
|
|
1770
|
+
const args = [];
|
|
1771
|
+
const dropped = [];
|
|
1772
|
+
for (let index = 0; index < argv.length; index++) {
|
|
1773
|
+
const raw = argv[index];
|
|
1774
|
+
const attached = /^(-[Crep])(?:=)?(.+)$/.exec(raw);
|
|
1775
|
+
const equals = raw.indexOf("=");
|
|
1776
|
+
const key = attached?.[1] ?? (equals < 0 ? raw : raw.slice(0, equals));
|
|
1777
|
+
const inline = attached?.[2] ?? (equals < 0 ? void 0 : raw.slice(equals + 1));
|
|
1778
|
+
if (["-e", "--eval", "-p", "--print", "-i", "--interactive", "-c", "--check"].includes(key)) {
|
|
1779
|
+
dropped.push(key);
|
|
1780
|
+
break;
|
|
1781
|
+
}
|
|
1782
|
+
if (/^--(?:inspect|test|watch)(?:-|$)/.test(key)) {
|
|
1783
|
+
dropped.push(key);
|
|
1784
|
+
continue;
|
|
1785
|
+
}
|
|
1786
|
+
const condition = key === "--conditions" || key === "-C";
|
|
1787
|
+
const preload = key === "--require" || key === "-r" || key === "--import" || bun && key === "--preload";
|
|
1788
|
+
const loader = !bun && (key === "--loader" || key === "--experimental-loader");
|
|
1789
|
+
if (!bun && key === "--experimental-import-meta-resolve") {
|
|
1790
|
+
if (inline === void 0) args.push(key);
|
|
1791
|
+
continue;
|
|
1792
|
+
}
|
|
1793
|
+
if (!condition && !preload && !loader) continue;
|
|
1794
|
+
const value = inline ?? argv[index + 1];
|
|
1795
|
+
if (!value || inline === void 0 && value.startsWith("-")) continue;
|
|
1796
|
+
if (inline === void 0) index++;
|
|
1797
|
+
if (condition) {
|
|
1798
|
+
args.push(`--conditions=${value}`);
|
|
1799
|
+
continue;
|
|
1800
|
+
}
|
|
1801
|
+
const option = bun ? "--preload" : loader ? "--experimental-loader" : key === "--import" ? key : "--require";
|
|
1802
|
+
const location = !isPath(value) ? value : option === "--import" || loader ? pathToFileURL(resolve2(cwd, value)).href : resolve2(cwd, value);
|
|
1803
|
+
args.push(`${option}=${location}`);
|
|
1804
|
+
}
|
|
1805
|
+
return { args, dropped };
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1530
1808
|
// packages/runner/src/ProcessTree.ts
|
|
1531
1809
|
import * as Console2 from "effect/Console";
|
|
1532
1810
|
import * as Clock from "effect/Clock";
|
|
1533
1811
|
import * as Context2 from "effect/Context";
|
|
1534
|
-
import * as
|
|
1812
|
+
import * as Effect4 from "effect/Effect";
|
|
1535
1813
|
import * as FileSystem3 from "effect/FileSystem";
|
|
1536
1814
|
import * as Result from "effect/Result";
|
|
1537
|
-
import * as
|
|
1815
|
+
import * as Schema6 from "effect/Schema";
|
|
1538
1816
|
import * as Semaphore from "effect/Semaphore";
|
|
1539
1817
|
import { execFile } from "node:child_process";
|
|
1540
1818
|
import { promisify } from "node:util";
|
|
1541
1819
|
import { randomUUID } from "node:crypto";
|
|
1542
|
-
import { pathToFileURL } from "node:url";
|
|
1820
|
+
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
1543
1821
|
var execute = promisify(execFile);
|
|
1544
1822
|
var liveLedgers = /* @__PURE__ */ new Set();
|
|
1545
|
-
var
|
|
1823
|
+
var warnedRuntimeFlags = /* @__PURE__ */ new Set();
|
|
1824
|
+
var ProcessInspector = Context2.Reference("mutant.cafe/ProcessInspector", { defaultValue: () => ({ inspect: (args) => Effect4.tryPromise({
|
|
1546
1825
|
try: (signal) => execute("/bin/ps", [...args], { signal, encoding: "utf8", maxBuffer: 32 * 1024 * 1024, timeout: 2e3, env: { PATH: process.env.PATH, LC_ALL: "C", TZ: "UTC" } }),
|
|
1547
1826
|
catch: () => new TestSpawnError({ command: ["ps"], message: "Cannot inspect owned test processes" })
|
|
1548
1827
|
}) }) });
|
|
1549
|
-
var PartialCwd =
|
|
1828
|
+
var PartialCwd = Schema6.Struct({ code: Schema6.Literal(1), stdout: Schema6.String, signal: Schema6.optional(Schema6.Null), killed: Schema6.optional(Schema6.Literal(false)) });
|
|
1550
1829
|
var inspectScratchCwd = (pids, probe2 = {
|
|
1551
1830
|
live: (pid) => {
|
|
1552
1831
|
if (pid <= 0) return false;
|
|
@@ -1558,7 +1837,7 @@ var inspectScratchCwd = (pids, probe2 = {
|
|
|
1558
1837
|
}
|
|
1559
1838
|
},
|
|
1560
1839
|
read: (pids2, signal) => execute("/usr/sbin/lsof", ["-b", "-w", "-n", "-P", "-a", "-d", "cwd", "-p", pids2.join(","), "-Fpn"], { signal, encoding: "utf8", timeout: 2e3, maxBuffer: 32 * 1024 * 1024, env: { PATH: process.env.PATH, LC_ALL: "C" } })
|
|
1561
|
-
}) =>
|
|
1840
|
+
}) => Effect4.tryPromise({
|
|
1562
1841
|
// @effect-diagnostics-next-line asyncFunction:off -- Native execFile adapter preserves partial stdout while Effect supplies cancellation.
|
|
1563
1842
|
try: async (signal) => {
|
|
1564
1843
|
const live2 = pids.filter(probe2.live);
|
|
@@ -1566,7 +1845,7 @@ var inspectScratchCwd = (pids, probe2 = {
|
|
|
1566
1845
|
try {
|
|
1567
1846
|
return await probe2.read(live2, signal);
|
|
1568
1847
|
} catch (error3) {
|
|
1569
|
-
const partial =
|
|
1848
|
+
const partial = Schema6.decodeUnknownOption(PartialCwd)(error3);
|
|
1570
1849
|
if (partial._tag === "Some") return { stdout: partial.value.stdout };
|
|
1571
1850
|
throw error3;
|
|
1572
1851
|
}
|
|
@@ -1619,7 +1898,7 @@ const environment = node => {
|
|
|
1619
1898
|
const env = { ...process.env };
|
|
1620
1899
|
const ownImport = "--import=" + preload;
|
|
1621
1900
|
const original = (env.NODE_OPTIONS || "").replaceAll(ownImport, "").trim();
|
|
1622
|
-
if (node && env.${ledgerKey} === ledger && env.${tokenKey} === token) env.NODE_OPTIONS = (original + " " + ownImport).trim();
|
|
1901
|
+
if ((node || process.versions.bun !== undefined) && env.${ledgerKey} === ledger && env.${tokenKey} === token) env.NODE_OPTIONS = (original + " " + ownImport).trim();
|
|
1623
1902
|
else if (original) env.NODE_OPTIONS = original;
|
|
1624
1903
|
else delete env.NODE_OPTIONS;
|
|
1625
1904
|
return env;
|
|
@@ -1664,20 +1943,29 @@ for (const name of ["spawn", "fork", "execFile", "exec"]) {
|
|
|
1664
1943
|
syncBuiltinESMExports();
|
|
1665
1944
|
}
|
|
1666
1945
|
`;
|
|
1667
|
-
var Record2 =
|
|
1668
|
-
var acquireProcessTree =
|
|
1946
|
+
var Record2 = Schema6.Struct({ pid: Schema6.Int, birth: Schema6.String });
|
|
1947
|
+
var acquireProcessTree = Effect4.fn("ProcessTree.acquire")(function* (scratch, onBackstop, processesSince) {
|
|
1669
1948
|
const fs = yield* FileSystem3.FileSystem;
|
|
1670
|
-
const
|
|
1949
|
+
const bun = process.versions.bun !== void 0;
|
|
1950
|
+
const inherited = runtimeArgs(process.execArgv, process.cwd(), bun);
|
|
1951
|
+
const launchArgs = (script2) => [...bun ? ["--preload", script2] : [], ...inherited.args];
|
|
1952
|
+
const acquisitionError = (script2) => (error3) => new TestSpawnError({
|
|
1953
|
+
command: [process.execPath, ...launchArgs(script2)],
|
|
1954
|
+
message: `Cannot prepare process ownership: ${error3.message}`
|
|
1955
|
+
});
|
|
1956
|
+
const directory = yield* fs.makeTempDirectory({ prefix: "mutant-processes-" }).pipe(
|
|
1957
|
+
Effect4.mapError(acquisitionError("<unallocated ownership preload>"))
|
|
1958
|
+
);
|
|
1671
1959
|
const ledger = `${directory}/pids.jsonl`;
|
|
1672
1960
|
const script = `${directory}/register.mjs`;
|
|
1673
|
-
const token = yield*
|
|
1674
|
-
const url =
|
|
1675
|
-
yield* fs.writeFileString(ledger, "");
|
|
1676
|
-
yield* fs.writeFileString(script, preloadSource);
|
|
1961
|
+
const token = yield* Effect4.sync(randomUUID);
|
|
1962
|
+
const url = pathToFileURL2(script).href;
|
|
1963
|
+
yield* fs.writeFileString(ledger, "").pipe(Effect4.mapError(acquisitionError(script)));
|
|
1964
|
+
yield* fs.writeFileString(script, preloadSource).pipe(Effect4.mapError(acquisitionError(script)));
|
|
1677
1965
|
liveLedgers.add(ledger);
|
|
1678
1966
|
const trace = (stage, details = {}) => {
|
|
1679
1967
|
const destination = process.env.MUTANT_CAFE_PROCESS_TRACE;
|
|
1680
|
-
return destination ? Clock.currentTimeMillis.pipe(
|
|
1968
|
+
return destination ? Clock.currentTimeMillis.pipe(Effect4.flatMap((at) => fs.writeFileString(destination, JSON.stringify({ at, pid: process.pid, ppid: process.ppid, stage, ...details }) + "\n", { flag: "a" })), Effect4.timeout(100), Effect4.catch(() => Effect4.void)) : Effect4.void;
|
|
1681
1969
|
};
|
|
1682
1970
|
const roots = /* @__PURE__ */ new Set();
|
|
1683
1971
|
const command = ["vitest", "process-cleanup"];
|
|
@@ -1690,19 +1978,19 @@ var acquireProcessTree = Effect3.fn("ProcessTree.acquire")(function* (scratch, o
|
|
|
1690
1978
|
const kill = inspector.signal ?? ((pid, signal2) => {
|
|
1691
1979
|
process.kill(pid, signal2);
|
|
1692
1980
|
});
|
|
1693
|
-
const bounded = (phase, effect5, limit = 7e3) =>
|
|
1981
|
+
const bounded = (phase, effect5, limit = 7e3) => Effect4.suspend(() => {
|
|
1694
1982
|
const remaining = Math.min(limit, deadline - performance.now());
|
|
1695
|
-
if (remaining <= 0) return
|
|
1696
|
-
return effect5.pipe(
|
|
1983
|
+
if (remaining <= 0) return Effect4.fail(new TestSpawnError({ command, message: `Cleanup deadline exceeded during ${phase}` }));
|
|
1984
|
+
return effect5.pipe(Effect4.interruptible, Effect4.timeout(remaining), Effect4.mapError(() => new TestSpawnError({ command, message: `Cleanup ${phase} failed or exceeded its ${Math.ceil(remaining)} ms budget` })));
|
|
1697
1985
|
});
|
|
1698
|
-
const inspect = (args) => bounded("ps inspection",
|
|
1986
|
+
const inspect = (args) => bounded("ps inspection", Effect4.gen(function* () {
|
|
1699
1987
|
const began = performance.now();
|
|
1700
1988
|
yield* trace("inspect-start", { operation: args[0] ?? "ps" });
|
|
1701
1989
|
const result5 = yield* inspector.inspect(args);
|
|
1702
1990
|
yield* trace("inspect-done", { elapsedMs: performance.now() - began });
|
|
1703
1991
|
return result5;
|
|
1704
1992
|
}), 2e3);
|
|
1705
|
-
const snapshot =
|
|
1993
|
+
const snapshot = Effect4.gen(function* () {
|
|
1706
1994
|
const result5 = yield* inspect(["-A", "-ww", "-o", "pid=,ppid=,pgid=,stat=,lstart=,args="]);
|
|
1707
1995
|
const found = /* @__PURE__ */ new Map();
|
|
1708
1996
|
for (const line of result5.stdout.split("\n")) {
|
|
@@ -1715,10 +2003,10 @@ var acquireProcessTree = Effect3.fn("ProcessTree.acquire")(function* (scratch, o
|
|
|
1715
2003
|
lastSnapshot = found;
|
|
1716
2004
|
return found;
|
|
1717
2005
|
});
|
|
1718
|
-
const discover = (preserved, retained) =>
|
|
1719
|
-
const registered = yield* fs.readFileString(ledger).pipe(
|
|
2006
|
+
const discover = (preserved, retained) => Effect4.gen(function* () {
|
|
2007
|
+
const registered = yield* fs.readFileString(ledger).pipe(Effect4.mapError(() => new TestSpawnError({ command, message: "Cannot read the test process ownership ledger" })));
|
|
1720
2008
|
ledgerRows = registered.split("\n").flatMap((line) => {
|
|
1721
|
-
const parsed =
|
|
2009
|
+
const parsed = Schema6.decodeOption(Schema6.fromJsonString(Record2))(line);
|
|
1722
2010
|
return parsed._tag === "Some" ? [parsed.value] : [];
|
|
1723
2011
|
});
|
|
1724
2012
|
const table = yield* snapshot;
|
|
@@ -1754,9 +2042,9 @@ var acquireProcessTree = Effect3.fn("ProcessTree.acquire")(function* (scratch, o
|
|
|
1754
2042
|
for (const item of ledgerRows) if (table.get(item.pid)?.birth === item.birth) claim(item.pid);
|
|
1755
2043
|
closeDescendants();
|
|
1756
2044
|
if (process.platform === "linux") {
|
|
1757
|
-
yield*
|
|
1758
|
-
|
|
1759
|
-
|
|
2045
|
+
yield* Effect4.forEach([...table.keys()], (pid) => fs.readFileString(`/proc/${pid}/environ`).pipe(
|
|
2046
|
+
Effect4.catch(() => Effect4.succeed("")),
|
|
2047
|
+
Effect4.tap((environment) => Effect4.sync(() => {
|
|
1760
2048
|
if (!owned.has(pid) && environment.split("\0").includes(`${tokenKey}=${token}`)) {
|
|
1761
2049
|
claim(pid);
|
|
1762
2050
|
closeDescendants();
|
|
@@ -1771,9 +2059,9 @@ var acquireProcessTree = Effect3.fn("ProcessTree.acquire")(function* (scratch, o
|
|
|
1771
2059
|
const pid = Number(row[1]);
|
|
1772
2060
|
const record = labelled.stdout.slice(row.index, rows[index + 1]?.index);
|
|
1773
2061
|
if (owned.has(pid) || table.get(pid)?.birth !== row[2]?.trim() || !label.test(record)) continue;
|
|
1774
|
-
const argv = yield* inspect(["ww", "-p", String(pid), "-o", "command="]).pipe(
|
|
1775
|
-
const environment = yield* inspect(["eww", "-p", String(pid), "-o", "command="]).pipe(
|
|
1776
|
-
const after = yield* inspect(["ww", "-p", String(pid), "-o", "command="]).pipe(
|
|
2062
|
+
const argv = yield* inspect(["ww", "-p", String(pid), "-o", "command="]).pipe(Effect4.result);
|
|
2063
|
+
const environment = yield* inspect(["eww", "-p", String(pid), "-o", "command="]).pipe(Effect4.result);
|
|
2064
|
+
const after = yield* inspect(["ww", "-p", String(pid), "-o", "command="]).pipe(Effect4.result);
|
|
1777
2065
|
if (Result.isFailure(argv) || Result.isFailure(environment) || Result.isFailure(after)) continue;
|
|
1778
2066
|
const prefix = argv.success.stdout.trimEnd();
|
|
1779
2067
|
if (prefix && prefix === after.success.stdout.trimEnd() && environment.success.stdout.startsWith(prefix + " ") && label.test(environment.success.stdout.slice(prefix.length))) uncertain.add(pid);
|
|
@@ -1785,11 +2073,11 @@ var acquireProcessTree = Effect3.fn("ProcessTree.acquire")(function* (scratch, o
|
|
|
1785
2073
|
if (unverified.length) yield* Console2.warn(`Warning: unverified process PIDs ${unverified.join(", ")}; not signalled. Cleaning verified descendants first.`);
|
|
1786
2074
|
return [...owned].flatMap((pid) => table.has(pid) && !keep.has(pid) ? [table.get(pid)] : []);
|
|
1787
2075
|
});
|
|
1788
|
-
const signal = (pending, value) =>
|
|
2076
|
+
const signal = (pending, value) => Effect4.gen(function* () {
|
|
1789
2077
|
const current = yield* snapshot;
|
|
1790
2078
|
for (const item of pending) {
|
|
1791
2079
|
if (current.get(item.pid)?.birth !== item.birth) continue;
|
|
1792
|
-
yield*
|
|
2080
|
+
yield* Effect4.sync(() => {
|
|
1793
2081
|
try {
|
|
1794
2082
|
if (roots.has(item.pid) && current.get(item.pid)?.pgid === item.pid) kill(-item.pid, value);
|
|
1795
2083
|
} catch {
|
|
@@ -1801,28 +2089,28 @@ var acquireProcessTree = Effect3.fn("ProcessTree.acquire")(function* (scratch, o
|
|
|
1801
2089
|
});
|
|
1802
2090
|
}
|
|
1803
2091
|
});
|
|
1804
|
-
const inspectUnowned =
|
|
2092
|
+
const inspectUnowned = Effect4.gen(function* () {
|
|
1805
2093
|
if (!scratch) return;
|
|
1806
2094
|
const table = lastSnapshot ?? (yield* snapshot);
|
|
1807
|
-
const registered = yield*
|
|
2095
|
+
const registered = yield* Effect4.forEach([...liveLedgers], (path) => fs.readFileString(path).pipe(Effect4.catch(() => Effect4.succeed(""))));
|
|
1808
2096
|
const known = new Set(registered.join("\n").split("\n").flatMap((line) => {
|
|
1809
|
-
const parsed =
|
|
2097
|
+
const parsed = Schema6.decodeOption(Schema6.fromJsonString(Record2))(line);
|
|
1810
2098
|
return parsed._tag === "Some" && table.get(parsed.value.pid)?.birth === parsed.value.birth ? [parsed.value.pid] : [];
|
|
1811
2099
|
}));
|
|
1812
2100
|
const candidates = /* @__PURE__ */ new Set();
|
|
1813
2101
|
const since = processesSince === void 0 ? -Infinity : Math.floor(processesSince / 1e3) * 1e3;
|
|
1814
2102
|
const possible = [...table.values()].filter((item) => !known.has(item.pid) && (processesSince === void 0 || Date.parse(item.birth + " UTC") >= since));
|
|
1815
2103
|
for (const item of possible) if (item.argv.includes(scratch)) candidates.add(item.pid);
|
|
1816
|
-
if (process.platform === "linux") yield*
|
|
1817
|
-
|
|
1818
|
-
|
|
2104
|
+
if (process.platform === "linux") yield* Effect4.forEach(possible.map((item) => item.pid), (pid) => fs.readLink(`/proc/${pid}/cwd`).pipe(
|
|
2105
|
+
Effect4.catch(() => Effect4.succeed("")),
|
|
2106
|
+
Effect4.tap((cwd) => Effect4.sync(() => {
|
|
1819
2107
|
if (cwd === scratch || cwd.startsWith(scratch + "/")) candidates.add(pid);
|
|
1820
2108
|
}))
|
|
1821
2109
|
), { concurrency: 8, discard: true });
|
|
1822
2110
|
else if (process.platform === "darwin" && possible.length) {
|
|
1823
2111
|
const cwdStarted = performance.now();
|
|
1824
2112
|
yield* trace("cwd-start", { candidates: possible.length });
|
|
1825
|
-
const cwd = yield* inspectScratchCwd(possible.map((item) => item.pid)).pipe(
|
|
2113
|
+
const cwd = yield* inspectScratchCwd(possible.map((item) => item.pid)).pipe(Effect4.catch(() => Console2.warn("Warning: cannot inspect scratch working directories; argv backstop remains active").pipe(Effect4.as({ stdout: "" }))));
|
|
1826
2114
|
yield* trace("cwd-done", { elapsedMs: performance.now() - cwdStarted });
|
|
1827
2115
|
let pid = 0;
|
|
1828
2116
|
for (const row of cwd.stdout.split("\n")) {
|
|
@@ -1832,29 +2120,29 @@ var acquireProcessTree = Effect3.fn("ProcessTree.acquire")(function* (scratch, o
|
|
|
1832
2120
|
}
|
|
1833
2121
|
const survivors = [...candidates].filter((pid) => table.has(pid) && !known.has(pid));
|
|
1834
2122
|
if (survivors.length) yield* Console2.warn(`Warning: unowned scratch-related process PIDs ${survivors.join(", ")} survived; not signalled because ownership is unproven`);
|
|
1835
|
-
}).pipe(
|
|
1836
|
-
const warnUnowned =
|
|
2123
|
+
}).pipe(Effect4.catch(() => Console2.warn("Warning: cannot inspect unowned scratch-related survivors; no unverified PID was signalled")));
|
|
2124
|
+
const warnUnowned = Effect4.gen(function* () {
|
|
1837
2125
|
if (!scratch) return;
|
|
1838
2126
|
const started = yield* Clock.currentTimeMillis;
|
|
1839
2127
|
if (!lastSnapshot) return yield* Console2.warn("Warning: scratch backstop unavailable without a process snapshot; no unverified PID was signalled");
|
|
1840
|
-
yield* bounded("scratch backstop", inspectUnowned, 2e3).pipe(
|
|
2128
|
+
yield* bounded("scratch backstop", inspectUnowned, 2e3).pipe(Effect4.catch((error3) => Console2.warn(`Warning: ${error3.message}; unowned PIDs were not signalled`)));
|
|
1841
2129
|
const elapsed = Math.max(0, (yield* Clock.currentTimeMillis) - started);
|
|
1842
|
-
yield*
|
|
2130
|
+
yield* Effect4.sync(() => onBackstop?.(elapsed));
|
|
1843
2131
|
});
|
|
1844
2132
|
const semaphore = yield* Semaphore.make(1);
|
|
1845
2133
|
let closed;
|
|
1846
|
-
const sweep = (preserved, retained = []) =>
|
|
2134
|
+
const sweep = (preserved, retained = []) => Effect4.scoped(Effect4.gen(function* () {
|
|
1847
2135
|
deadline = performance.now() + 1e4;
|
|
1848
2136
|
lastSnapshot = void 0;
|
|
1849
2137
|
ledgerRows = [];
|
|
1850
2138
|
verified.clear();
|
|
1851
2139
|
const keep = new Set(preserved);
|
|
1852
2140
|
effectiveKeep = keep;
|
|
1853
|
-
const discovering = createEffectLogic(() => bounded("discovery", discover(keep, retained)).pipe(
|
|
1854
|
-
const stopping = createEffectLogic(({ input }) => bounded("stop", signal(input, "SIGSTOP"), 3e3).pipe(
|
|
1855
|
-
const killing = createEffectLogic(({ input }) => bounded("kill", signal(input, "SIGKILL"), 3e3).pipe(
|
|
2141
|
+
const discovering = createEffectLogic(() => bounded("discovery", discover(keep, retained)).pipe(Effect4.result));
|
|
2142
|
+
const stopping = createEffectLogic(({ input }) => bounded("stop", signal(input, "SIGSTOP"), 3e3).pipe(Effect4.result));
|
|
2143
|
+
const killing = createEffectLogic(({ input }) => bounded("kill", signal(input, "SIGKILL"), 3e3).pipe(Effect4.result));
|
|
1856
2144
|
const machine = setupEffect({
|
|
1857
|
-
schemas: { context: types(), events: { CLOSE:
|
|
2145
|
+
schemas: { context: types(), events: { CLOSE: Schema6.Struct({}) } },
|
|
1858
2146
|
actors: { discovering, stopping, killing }
|
|
1859
2147
|
}).createMachine({
|
|
1860
2148
|
context: { pending: [], round: 0, failure: void 0 },
|
|
@@ -1877,10 +2165,10 @@ var acquireProcessTree = Effect3.fn("ProcessTree.acquire")(function* (scratch, o
|
|
|
1877
2165
|
});
|
|
1878
2166
|
const actor = yield* createEffectActor(machine);
|
|
1879
2167
|
yield* send(actor, { type: "CLOSE" });
|
|
1880
|
-
const joined = yield* bounded("state machine", join(actor), 8e3).pipe(
|
|
2168
|
+
const joined = yield* bounded("state machine", join(actor), 8e3).pipe(Effect4.result);
|
|
1881
2169
|
const result5 = joined._tag === "Success" ? joined.success : { ...actor.getSnapshot().context, failure: joined.failure.message };
|
|
1882
2170
|
if (result5.failure) {
|
|
1883
|
-
yield*
|
|
2171
|
+
yield* Effect4.sync(() => {
|
|
1884
2172
|
actor.stop();
|
|
1885
2173
|
for (const item of verified.values()) {
|
|
1886
2174
|
try {
|
|
@@ -1895,24 +2183,38 @@ var acquireProcessTree = Effect3.fn("ProcessTree.acquire")(function* (scratch, o
|
|
|
1895
2183
|
yield* warnUnowned;
|
|
1896
2184
|
if (result5.failure) yield* Console2.warn(`Warning: ${result5.failure} (tracked PIDs ${(result5.pending.length ? result5.pending.map((item) => item.pid) : [...roots]).join(", ")}); ownership ledger kept at ${ledger}; continuing without reusing the host`);
|
|
1897
2185
|
return result5.failure ? "warning" : "clean";
|
|
1898
|
-
})).pipe(
|
|
1899
|
-
const reap = (preserved, retained = []) => semaphore.withPermit(
|
|
1900
|
-
const cleanup = semaphore.withPermit(
|
|
2186
|
+
})).pipe(Effect4.uninterruptible);
|
|
2187
|
+
const reap = (preserved, retained = []) => semaphore.withPermit(Effect4.suspend(() => closed === void 0 ? sweep(preserved, retained) : Effect4.succeed(closed)));
|
|
2188
|
+
const cleanup = semaphore.withPermit(Effect4.gen(function* () {
|
|
1901
2189
|
if (closed === void 0) closed = yield* sweep([]);
|
|
1902
2190
|
}));
|
|
1903
|
-
yield*
|
|
2191
|
+
yield* Effect4.addFinalizer(() => Effect4.gen(function* () {
|
|
1904
2192
|
yield* cleanup;
|
|
1905
2193
|
if (closed === "clean") yield* fs.remove(directory, { recursive: true }).pipe(
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
2194
|
+
Effect4.interruptible,
|
|
2195
|
+
Effect4.timeout(2e3),
|
|
2196
|
+
Effect4.catch((error3) => Console2.warn(`Warning: cannot remove process ledger directory: ${error3.message}`))
|
|
1909
2197
|
);
|
|
1910
|
-
}).pipe(
|
|
2198
|
+
}).pipe(Effect4.ensuring(Effect4.sync(() => {
|
|
1911
2199
|
liveLedgers.delete(ledger);
|
|
1912
2200
|
}))));
|
|
1913
2201
|
const existing = process.env.NODE_OPTIONS ?? "";
|
|
2202
|
+
const dropped = [...new Set(inherited.dropped)].filter((flag) => !warnedRuntimeFlags.has(flag));
|
|
2203
|
+
if (dropped.length) {
|
|
2204
|
+
for (const flag of dropped) warnedRuntimeFlags.add(flag);
|
|
2205
|
+
yield* Console2.warn(`Warning: not forwarding runtime flags to Vitest children: ${dropped.join(", ")}`);
|
|
2206
|
+
}
|
|
1914
2207
|
return {
|
|
1915
|
-
env: {
|
|
2208
|
+
env: {
|
|
2209
|
+
...process.env,
|
|
2210
|
+
MUTANT_CAFE_PROCESS_PHASE: void 0,
|
|
2211
|
+
[tokenKey]: token,
|
|
2212
|
+
[ledgerKey]: ledger,
|
|
2213
|
+
[preloadKey]: url,
|
|
2214
|
+
NODE_OPTIONS: `${existing} --import=${url}`.trim(),
|
|
2215
|
+
...bun ? { BUN_OPTIONS: `${process.env.BUN_OPTIONS ?? ""} --preload=${url}`.trim() } : {}
|
|
2216
|
+
},
|
|
2217
|
+
launchArgs: launchArgs(script),
|
|
1916
2218
|
addRoot: (pid) => {
|
|
1917
2219
|
roots.add(pid);
|
|
1918
2220
|
},
|
|
@@ -1923,7 +2225,7 @@ var acquireProcessTree = Effect3.fn("ProcessTree.acquire")(function* (scratch, o
|
|
|
1923
2225
|
});
|
|
1924
2226
|
|
|
1925
2227
|
// packages/runner/src/Preflight.ts
|
|
1926
|
-
var Issues =
|
|
2228
|
+
var Issues = Schema7.Array(SelectionIssue);
|
|
1927
2229
|
var probe = String.raw`
|
|
1928
2230
|
import { readFile, readdir } from "node:fs/promises";
|
|
1929
2231
|
import { resolve, relative, dirname, isAbsolute, sep } from "node:path";
|
|
@@ -1940,6 +2242,14 @@ if (otherRunner) {
|
|
|
1940
2242
|
issues.push({ kind: "runner", reason: 'package.json scripts.test = ' + JSON.stringify(script) + '; mutant.cafe only runs Vitest' });
|
|
1941
2243
|
} else {
|
|
1942
2244
|
if (!vitestScript) issues.push({ kind: "warning", reason: 'package.json scripts.test = ' + JSON.stringify(script) + (delegated ? '; delegated test runner: Vitest selection is unverified' : '; unknown test wrapper: Vitest selection is unverified') });
|
|
2245
|
+
// Resolve from the adopter's package, not mutant.cafe's bundled dependencies.
|
|
2246
|
+
const require = createRequire(resolve(root, "package.json"));
|
|
2247
|
+
let version;
|
|
2248
|
+
try { version = JSON.parse(await readFile(require.resolve("vitest/package.json"), "utf8")).version; } catch {}
|
|
2249
|
+
if (typeof version === "string" && /^\d+\./.test(version) && Number(version.split(".")[0]) < 5) {
|
|
2250
|
+
console.log("mutant-cafe-vitest-version:" + JSON.stringify(version));
|
|
2251
|
+
process.exit(0);
|
|
2252
|
+
}
|
|
1943
2253
|
let ctx;
|
|
1944
2254
|
try {
|
|
1945
2255
|
const { createVitest } = await import("vitest/node");
|
|
@@ -2065,17 +2375,22 @@ if (otherRunner) {
|
|
|
2065
2375
|
}
|
|
2066
2376
|
console.log('mutant-cafe-preflight:' + JSON.stringify([...new Map(issues.map(issue => [JSON.stringify(issue), issue])).values()]));
|
|
2067
2377
|
`;
|
|
2068
|
-
var preflight =
|
|
2069
|
-
const spawner = yield*
|
|
2378
|
+
var preflight = Effect5.fn("TestRunner.preflight")(function* (root, tsconfig = "tsconfig.json", timeoutMs = DEFAULT_BASELINE_TIMEOUT_MS, options = {}) {
|
|
2379
|
+
const spawner = yield* ChildProcessSpawner3.ChildProcessSpawner;
|
|
2070
2380
|
const since = options.processesSince ?? (yield* Clock2.currentTimeMillis);
|
|
2071
2381
|
const owned = yield* acquireProcessTree(root, options.onBackstop, since);
|
|
2072
2382
|
yield* owned.trace("preflight-start", { budgetMs: timeoutMs });
|
|
2073
|
-
const output = yield* spawner.string(
|
|
2383
|
+
const output = yield* spawner.string(ChildProcess2.make(process.execPath, [...owned.launchArgs, "--input-type=module", "--eval", probe, tsconfig], { cwd: root, env: owned.env, detached: true, killSignal: "SIGKILL", forceKillAfter: "100 millis", stdin: "ignore" })).pipe(Effect5.onInterrupt(() => owned.cleanup));
|
|
2074
2384
|
yield* owned.trace("preflight-done");
|
|
2385
|
+
const version = output.split("\n").find((line) => line.startsWith("mutant-cafe-vitest-version:"))?.slice("mutant-cafe-vitest-version:".length);
|
|
2386
|
+
if (version !== void 0) {
|
|
2387
|
+
const found = yield* Schema7.decodeEffect(Schema7.fromJsonString(Schema7.String))(version);
|
|
2388
|
+
return yield* new TestSpawnError({ kind: "vitest-version", command: ["vitest"], message: `mutant.cafe needs vitest >= 5.0, found ${found}` });
|
|
2389
|
+
}
|
|
2075
2390
|
const encoded = output.split("\n").find((line) => line.startsWith("mutant-cafe-preflight:"))?.slice("mutant-cafe-preflight:".length);
|
|
2076
|
-
const issues = encoded === void 0 ? [{ kind: "warning", reason: "Vitest selection probe returned no evidence" }] : yield*
|
|
2391
|
+
const issues = encoded === void 0 ? [{ kind: "warning", reason: "Vitest selection probe returned no evidence" }] : yield* Schema7.decodeEffect(Schema7.fromJsonString(Issues))(encoded);
|
|
2077
2392
|
return issues;
|
|
2078
|
-
}, (effect5, _root, _tsconfig = "tsconfig.json", timeoutMs = DEFAULT_BASELINE_TIMEOUT_MS, _options = {}) => effect5.pipe(
|
|
2393
|
+
}, (effect5, _root, _tsconfig = "tsconfig.json", timeoutMs = DEFAULT_BASELINE_TIMEOUT_MS, _options = {}) => effect5.pipe(Effect5.timeout(timeoutMs), Effect5.scoped));
|
|
2079
2394
|
function unreliableFor(baseline, file, testFiles) {
|
|
2080
2395
|
return baseline.unreliable?.filter((issue) => {
|
|
2081
2396
|
switch (issue.kind) {
|
|
@@ -2092,26 +2407,26 @@ function unreliableFor(baseline, file, testFiles) {
|
|
|
2092
2407
|
}
|
|
2093
2408
|
|
|
2094
2409
|
// packages/runner/src/TestRunner.ts
|
|
2095
|
-
import * as
|
|
2410
|
+
import * as Effect7 from "effect/Effect";
|
|
2096
2411
|
import * as Layer3 from "effect/Layer";
|
|
2097
2412
|
import * as FileSystem7 from "effect/FileSystem";
|
|
2098
|
-
import * as
|
|
2099
|
-
import * as
|
|
2100
|
-
import * as
|
|
2413
|
+
import * as Path5 from "effect/Path";
|
|
2414
|
+
import * as Stream3 from "effect/Stream";
|
|
2415
|
+
import * as Schema9 from "effect/Schema";
|
|
2101
2416
|
import * as Scope3 from "effect/Scope";
|
|
2102
2417
|
import { createRequire } from "node:module";
|
|
2103
|
-
import { pathToFileURL as
|
|
2104
|
-
import * as
|
|
2105
|
-
import * as
|
|
2418
|
+
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
2419
|
+
import * as ChildProcess3 from "effect/process/ChildProcess";
|
|
2420
|
+
import * as ChildProcessSpawner5 from "effect/process/ChildProcessSpawner";
|
|
2106
2421
|
|
|
2107
2422
|
// packages/runner/src/WarmRunner.ts
|
|
2108
2423
|
import { createEffectActor as createEffectActor2, send as send2, setupEffect as setupEffect2 } from "@xstate/effect";
|
|
2109
2424
|
import { spawn } from "node:child_process";
|
|
2110
2425
|
import * as Clock3 from "effect/Clock";
|
|
2111
|
-
import * as
|
|
2426
|
+
import * as Effect6 from "effect/Effect";
|
|
2112
2427
|
import * as Console3 from "effect/Console";
|
|
2113
2428
|
import * as FileSystem5 from "effect/FileSystem";
|
|
2114
|
-
import * as
|
|
2429
|
+
import * as Schema8 from "effect/Schema";
|
|
2115
2430
|
import * as Scope from "effect/Scope";
|
|
2116
2431
|
import * as Exit from "effect/Exit";
|
|
2117
2432
|
|
|
@@ -2413,36 +2728,36 @@ process.on("message", async request => {
|
|
|
2413
2728
|
`;
|
|
2414
2729
|
|
|
2415
2730
|
// packages/runner/src/WarmRunner.ts
|
|
2416
|
-
var Message =
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
type:
|
|
2432
|
-
status:
|
|
2433
|
-
testFiles:
|
|
2434
|
-
testsCollected:
|
|
2435
|
-
testDurations:
|
|
2436
|
-
testTimeouts:
|
|
2437
|
-
testWorkers:
|
|
2438
|
-
testConcurrency:
|
|
2439
|
-
telemetryWarnings:
|
|
2440
|
-
testFileDurations:
|
|
2441
|
-
firstTestStart:
|
|
2442
|
-
probeSupported:
|
|
2443
|
-
probeLoaded:
|
|
2444
|
-
testTimeoutDetails:
|
|
2445
|
-
crashed:
|
|
2731
|
+
var Message = Schema8.Union([
|
|
2732
|
+
Schema8.Struct({ type: Schema8.Literal("ready") }),
|
|
2733
|
+
Schema8.Struct({ type: Schema8.Literal("retained"), pids: Schema8.Array(Schema8.Struct({ pid: Schema8.Int, birth: Schema8.String })) }),
|
|
2734
|
+
Schema8.Struct({ type: Schema8.Literal("invalidated") }),
|
|
2735
|
+
Schema8.Struct({ type: Schema8.Literal("collected") }),
|
|
2736
|
+
Schema8.Struct({ type: Schema8.Literal("failed") }),
|
|
2737
|
+
Schema8.Struct({ type: Schema8.Literal("selected"), files: Schema8.Array(Schema8.String) }),
|
|
2738
|
+
Schema8.Struct({ type: Schema8.Literal("selection"), files: Schema8.Array(Schema8.String) }),
|
|
2739
|
+
Schema8.Struct({ type: Schema8.Literal("probeLoaded") }),
|
|
2740
|
+
Schema8.Struct({ type: Schema8.Literal("quiescing") }),
|
|
2741
|
+
Schema8.Struct({ type: Schema8.Literal("quiesced") }),
|
|
2742
|
+
Schema8.Struct({ type: Schema8.Literal("healthy") }),
|
|
2743
|
+
Schema8.Struct({ type: Schema8.Literal("fallback"), message: Schema8.String }),
|
|
2744
|
+
Schema8.Struct({ type: Schema8.Literal("crash"), message: Schema8.String }),
|
|
2745
|
+
Schema8.Struct({
|
|
2746
|
+
type: Schema8.Literal("result"),
|
|
2747
|
+
status: Schema8.Literals(["passed", "failed", "untested"]),
|
|
2748
|
+
testFiles: Schema8.Array(Schema8.String),
|
|
2749
|
+
testsCollected: Schema8.Boolean,
|
|
2750
|
+
testDurations: Schema8.Record(Schema8.String, Schema8.Finite),
|
|
2751
|
+
testTimeouts: Schema8.Record(Schema8.String, Schema8.Finite),
|
|
2752
|
+
testWorkers: Schema8.optional(Schema8.Int),
|
|
2753
|
+
testConcurrency: Schema8.optional(Schema8.Int),
|
|
2754
|
+
telemetryWarnings: Schema8.optional(Schema8.Array(Schema8.String)),
|
|
2755
|
+
testFileDurations: Schema8.Record(Schema8.String, Schema8.Finite),
|
|
2756
|
+
firstTestStart: Schema8.Finite,
|
|
2757
|
+
probeSupported: Schema8.Boolean,
|
|
2758
|
+
probeLoaded: Schema8.Boolean,
|
|
2759
|
+
testTimeoutDetails: Schema8.Record(Schema8.String, Schema8.Finite),
|
|
2760
|
+
crashed: Schema8.Boolean
|
|
2446
2761
|
})
|
|
2447
2762
|
]);
|
|
2448
2763
|
var ReporterMessageError = class extends Error {
|
|
@@ -2450,7 +2765,7 @@ var ReporterMessageError = class extends Error {
|
|
|
2450
2765
|
};
|
|
2451
2766
|
function decodeWarmMessage(value) {
|
|
2452
2767
|
try {
|
|
2453
|
-
const raw =
|
|
2768
|
+
const raw = Schema8.decodeUnknownSync(Schema8.Record(Schema8.String, Schema8.Unknown))(value);
|
|
2454
2769
|
const cleaned = cleanTelemetry(raw, "warm message");
|
|
2455
2770
|
if (raw.type === "result") {
|
|
2456
2771
|
for (const [key, fallback] of Object.entries({ testDurations: {}, testTimeouts: {}, testFileDurations: {}, testTimeoutDetails: {}, firstTestStart: 0 }))
|
|
@@ -2458,7 +2773,7 @@ function decodeWarmMessage(value) {
|
|
|
2458
2773
|
const previous = cleaned.value.telemetryWarnings;
|
|
2459
2774
|
Reflect.set(cleaned.value, "telemetryWarnings", [...Array.isArray(previous) ? previous : [], ...cleaned.warnings]);
|
|
2460
2775
|
}
|
|
2461
|
-
return
|
|
2776
|
+
return Schema8.decodeUnknownSync(Message)(cleaned.value);
|
|
2462
2777
|
} catch (error3) {
|
|
2463
2778
|
const actual = (() => {
|
|
2464
2779
|
try {
|
|
@@ -2488,7 +2803,7 @@ var Host = class {
|
|
|
2488
2803
|
constructor(root, script, reporter, tree, scope, selectionOnly = false, decode = decodeWarmMessage) {
|
|
2489
2804
|
this.tree = tree;
|
|
2490
2805
|
this.scope = scope;
|
|
2491
|
-
this.child = spawn(process.execPath, [script, reporter, selectionOnly ? "select" : "run"], {
|
|
2806
|
+
this.child = spawn(process.execPath, [...tree.launchArgs, script, reporter, selectionOnly ? "select" : "run"], {
|
|
2492
2807
|
cwd: root,
|
|
2493
2808
|
env: tree.env,
|
|
2494
2809
|
detached: true,
|
|
@@ -2537,10 +2852,10 @@ var Host = class {
|
|
|
2537
2852
|
this.pending?.reject(error3 instanceof ReporterMessageError ? error3 : new ReporterMessageError(String(error3)));
|
|
2538
2853
|
}
|
|
2539
2854
|
});
|
|
2540
|
-
this.exited = new Promise((
|
|
2855
|
+
this.exited = new Promise((resolve3) => this.child.once("close", () => {
|
|
2541
2856
|
this.pending?.reject(new Error(`Vitest host exited: ${this.output.slice(-4e3)}`));
|
|
2542
2857
|
this.pending = void 0;
|
|
2543
|
-
|
|
2858
|
+
resolve3();
|
|
2544
2859
|
}));
|
|
2545
2860
|
this.child.on("error", (error3) => {
|
|
2546
2861
|
this.pending?.reject(error3);
|
|
@@ -2548,16 +2863,16 @@ var Host = class {
|
|
|
2548
2863
|
});
|
|
2549
2864
|
}
|
|
2550
2865
|
wait() {
|
|
2551
|
-
return new Promise((
|
|
2552
|
-
this.pending = { resolve:
|
|
2866
|
+
return new Promise((resolve3, reject) => {
|
|
2867
|
+
this.pending = { resolve: resolve3, reject };
|
|
2553
2868
|
});
|
|
2554
2869
|
}
|
|
2555
2870
|
quiesce() {
|
|
2556
|
-
const started = new Promise((
|
|
2557
|
-
this.quiescing =
|
|
2871
|
+
const started = new Promise((resolve3) => {
|
|
2872
|
+
this.quiescing = resolve3;
|
|
2558
2873
|
});
|
|
2559
|
-
const done = new Promise((
|
|
2560
|
-
this.quiesced =
|
|
2874
|
+
const done = new Promise((resolve3) => {
|
|
2875
|
+
this.quiesced = resolve3;
|
|
2561
2876
|
});
|
|
2562
2877
|
this.post({ type: "quiesce" });
|
|
2563
2878
|
return { started, done };
|
|
@@ -2581,24 +2896,24 @@ var Host = class {
|
|
|
2581
2896
|
}
|
|
2582
2897
|
grace() {
|
|
2583
2898
|
const self = this;
|
|
2584
|
-
return
|
|
2899
|
+
return Effect6.gen(function* () {
|
|
2585
2900
|
self.post({ type: "close" });
|
|
2586
|
-
const exited =
|
|
2587
|
-
const result5 = yield* exited.pipe(
|
|
2588
|
-
if (result5._tag === "Failure") yield*
|
|
2901
|
+
const exited = Effect6.promise(() => self.exited);
|
|
2902
|
+
const result5 = yield* exited.pipe(Effect6.interruptible, Effect6.timeout(500), Effect6.result);
|
|
2903
|
+
if (result5._tag === "Failure") yield* Effect6.sync(() => {
|
|
2589
2904
|
self.child.kill("SIGKILL");
|
|
2590
2905
|
});
|
|
2591
2906
|
});
|
|
2592
2907
|
}
|
|
2593
2908
|
};
|
|
2594
2909
|
var lifecycle = setupEffect2({ schemas: { events: {
|
|
2595
|
-
RUN:
|
|
2596
|
-
DONE:
|
|
2597
|
-
CANCEL:
|
|
2598
|
-
RESTART:
|
|
2599
|
-
READY:
|
|
2600
|
-
FAIL:
|
|
2601
|
-
FALLBACK:
|
|
2910
|
+
RUN: Schema8.Struct({}),
|
|
2911
|
+
DONE: Schema8.Struct({}),
|
|
2912
|
+
CANCEL: Schema8.Struct({}),
|
|
2913
|
+
RESTART: Schema8.Struct({}),
|
|
2914
|
+
READY: Schema8.Struct({}),
|
|
2915
|
+
FAIL: Schema8.Struct({}),
|
|
2916
|
+
FALLBACK: Schema8.Struct({})
|
|
2602
2917
|
} } }).createMachine({
|
|
2603
2918
|
initial: "idle",
|
|
2604
2919
|
on: { FAIL: { target: ".failed" }, FALLBACK: { target: ".cold" } },
|
|
@@ -2611,7 +2926,7 @@ var lifecycle = setupEffect2({ schemas: { events: {
|
|
|
2611
2926
|
cold: { type: "final" }
|
|
2612
2927
|
}
|
|
2613
2928
|
});
|
|
2614
|
-
var openWarmRunner =
|
|
2929
|
+
var openWarmRunner = Effect6.fn("TestRunner.openWarm")(function* (dir, onFallback, options = {}) {
|
|
2615
2930
|
const fs = yield* FileSystem5.FileSystem;
|
|
2616
2931
|
const parentScope = yield* Scope.Scope;
|
|
2617
2932
|
const temp = yield* fs.makeTempDirectoryScoped({ prefix: "mutant-warm-" });
|
|
@@ -2621,77 +2936,77 @@ var openWarmRunner = Effect5.fn("TestRunner.openWarm")(function* (dir, onFallbac
|
|
|
2621
2936
|
yield* fs.writeFileString(reporter, reporterSource("mutant-warm:"));
|
|
2622
2937
|
const actor = yield* createEffectActor2(lifecycle);
|
|
2623
2938
|
let host;
|
|
2624
|
-
const attempt = (
|
|
2625
|
-
try:
|
|
2939
|
+
const attempt = (fn12) => Effect6.tryPromise({
|
|
2940
|
+
try: fn12,
|
|
2626
2941
|
catch: (error3) => new TestSpawnError({ command: ["vitest", "warm"], message: String(error3), ...error3 instanceof ReporterMessageError ? { kind: "reporter" } : {} })
|
|
2627
|
-
}).pipe(
|
|
2628
|
-
const close2 = () => host === void 0 ?
|
|
2629
|
-
const abortHost = (error3) =>
|
|
2942
|
+
}).pipe(Effect6.interruptible);
|
|
2943
|
+
const close2 = () => host === void 0 ? Effect6.void : host.close();
|
|
2944
|
+
const abortHost = (error3) => Effect6.gen(function* () {
|
|
2630
2945
|
yield* send2(actor, { type: "FAIL" });
|
|
2631
2946
|
yield* close2();
|
|
2632
2947
|
return yield* error3;
|
|
2633
2948
|
});
|
|
2634
|
-
yield*
|
|
2635
|
-
const start =
|
|
2949
|
+
yield* Effect6.addFinalizer(() => close2().pipe(Effect6.orDie));
|
|
2950
|
+
const start = Effect6.gen(function* () {
|
|
2636
2951
|
const scope = yield* Scope.make();
|
|
2637
|
-
yield*
|
|
2952
|
+
yield* Effect6.addFinalizer(() => Scope.close(scope, Exit.succeed(void 0))).pipe(Effect6.provideService(Scope.Scope, parentScope));
|
|
2638
2953
|
const tree = yield* acquireProcessTree(dir.path, options.onBackstop, options.processesSince).pipe(
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2954
|
+
Effect6.provideService(Scope.Scope, scope),
|
|
2955
|
+
Effect6.provideService(FileSystem5.FileSystem, fs),
|
|
2956
|
+
Effect6.mapError((error3) => new TestSpawnError({ command: ["vitest", "warm"], message: String(error3) }))
|
|
2642
2957
|
);
|
|
2643
2958
|
const active = new Host(dir.path, script, reporter, tree, scope, options.selectionOnly === true, options.decodeMessage);
|
|
2644
2959
|
host = active;
|
|
2645
|
-
yield*
|
|
2960
|
+
yield* Effect6.addFinalizer(() => active.grace()).pipe(Effect6.provideService(Scope.Scope, scope));
|
|
2646
2961
|
const initialized = yield* attempt(() => host.ready()).pipe(
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2962
|
+
Effect6.timeout(3e4),
|
|
2963
|
+
Effect6.mapError((error3) => error3._tag === "TestSpawnError" ? error3 : new TestSpawnError({ command: ["vitest", "warm"], message: String(error3) })),
|
|
2964
|
+
Effect6.result
|
|
2650
2965
|
);
|
|
2651
2966
|
if (initialized._tag === "Failure") return yield* abortHost(initialized.failure);
|
|
2652
2967
|
const ready = initialized.success;
|
|
2653
2968
|
if (ready.type !== "ready") {
|
|
2654
2969
|
if (!options.quiet) yield* (options.warn ?? Console3.warn)(`Warning: warm Vitest unavailable; using cold mode: ${"message" in ready ? ready.message : ready.type}`);
|
|
2655
|
-
yield*
|
|
2970
|
+
yield* Effect6.sync(() => onFallback("message" in ready ? ready.message : `Unexpected startup frame: ${ready.type}`));
|
|
2656
2971
|
yield* send2(actor, { type: "FALLBACK" });
|
|
2657
2972
|
yield* close2();
|
|
2658
2973
|
}
|
|
2659
2974
|
});
|
|
2660
|
-
const retire =
|
|
2975
|
+
const retire = Effect6.gen(function* () {
|
|
2661
2976
|
yield* send2(actor, { type: "RESTART" });
|
|
2662
2977
|
yield* close2();
|
|
2663
2978
|
});
|
|
2664
|
-
const restart =
|
|
2979
|
+
const restart = Effect6.gen(function* () {
|
|
2665
2980
|
yield* retire;
|
|
2666
2981
|
yield* start;
|
|
2667
|
-
yield*
|
|
2982
|
+
yield* Effect6.sync(() => options.onRestart?.());
|
|
2668
2983
|
if (actor.getSnapshot().value !== "cold") yield* send2(actor, { type: "READY" });
|
|
2669
2984
|
});
|
|
2670
2985
|
yield* start;
|
|
2671
2986
|
const isCold = () => actor.getSnapshot().value === "cold";
|
|
2672
|
-
const invalidate =
|
|
2987
|
+
const invalidate = Effect6.fn("Warm.invalidate")(function* (file) {
|
|
2673
2988
|
if (isCold() || actor.getSnapshot().value === "failed") return;
|
|
2674
2989
|
if (actor.getSnapshot().value === "restarting") {
|
|
2675
2990
|
yield* start;
|
|
2676
|
-
yield*
|
|
2991
|
+
yield* Effect6.sync(() => options.onRestart?.());
|
|
2677
2992
|
if (!isCold()) yield* send2(actor, { type: "READY" });
|
|
2678
2993
|
return;
|
|
2679
2994
|
}
|
|
2680
|
-
const result5 = yield* attempt(() => host.request({ type: "invalidate", file })).pipe(
|
|
2995
|
+
const result5 = yield* attempt(() => host.request({ type: "invalidate", file })).pipe(Effect6.timeout(1e3), Effect6.result);
|
|
2681
2996
|
if (result5._tag === "Failure" && result5.failure._tag === "TestSpawnError" && result5.failure.kind === "reporter") return yield* abortHost(result5.failure);
|
|
2682
2997
|
if (result5._tag === "Failure") yield* restart;
|
|
2683
2998
|
});
|
|
2684
|
-
const finish =
|
|
2999
|
+
const finish = Effect6.fn("Warm.finish")(function* (active, pending) {
|
|
2685
3000
|
const pool = active.quiesce();
|
|
2686
|
-
const started = yield* attempt(() => pool.started).pipe(
|
|
3001
|
+
const started = yield* attempt(() => pool.started).pipe(Effect6.timeout(500), Effect6.result);
|
|
2687
3002
|
const clean = yield* active.tree.reap(active.child.pid === void 0 ? [] : [active.child.pid], active.retained);
|
|
2688
3003
|
if (clean !== "clean" || started._tag === "Failure") return false;
|
|
2689
|
-
yield* attempt(() => pool.done).pipe(
|
|
2690
|
-
const settled = yield* attempt(() => pending).pipe(
|
|
2691
|
-
const health = settled._tag === "Success" ? yield* attempt(() => active.request({ type: "ping" })).pipe(
|
|
3004
|
+
yield* attempt(() => pool.done).pipe(Effect6.timeout(100), Effect6.result);
|
|
3005
|
+
const settled = yield* attempt(() => pending).pipe(Effect6.timeout(500), Effect6.result);
|
|
3006
|
+
const health = settled._tag === "Success" ? yield* attempt(() => active.request({ type: "ping" })).pipe(Effect6.timeout(500), Effect6.result) : settled;
|
|
2692
3007
|
return clean === "clean" && started._tag === "Success" && health._tag === "Success" && health.success.type === "healthy";
|
|
2693
3008
|
});
|
|
2694
|
-
const run2 =
|
|
3009
|
+
const run2 = Effect6.fn("Warm.run")(function* (file, timeoutMs, testTimeout, probe2) {
|
|
2695
3010
|
if (isCold()) return void 0;
|
|
2696
3011
|
if (options.selectionOnly) return yield* abortHost(new TestSpawnError({ command: ["vitest", "select"], kind: "reporter", message: "Selection-only host cannot execute tests" }));
|
|
2697
3012
|
const command = ["vitest", ...file ? ["related", file, "--run"] : ["run"], "--reporter=default"];
|
|
@@ -2704,14 +3019,14 @@ var openWarmRunner = Effect5.fn("TestRunner.openWarm")(function* (dir, onFallbac
|
|
|
2704
3019
|
const started = yield* Clock3.currentTimeMillis;
|
|
2705
3020
|
active.runPending = void 0;
|
|
2706
3021
|
const budgetMs = timeoutMs ?? DEFAULT_BASELINE_TIMEOUT_MS;
|
|
2707
|
-
const operation =
|
|
3022
|
+
const operation = Effect6.gen(function* () {
|
|
2708
3023
|
yield* active.tree.trace("warm-attempt-start", { budgetMs });
|
|
2709
3024
|
yield* send2(actor, { type: "RUN" });
|
|
2710
3025
|
const pending2 = active.request({ type: "run", file, testTimeout, probe: probe2 });
|
|
2711
3026
|
active.runPending = pending2;
|
|
2712
3027
|
return yield* attempt(() => pending2);
|
|
2713
3028
|
});
|
|
2714
|
-
const result5 = yield* operation.pipe(
|
|
3029
|
+
const result5 = yield* operation.pipe(Effect6.interruptible, Effect6.timeout(budgetMs), Effect6.result);
|
|
2715
3030
|
const pending = active.runPending;
|
|
2716
3031
|
if (result5._tag === "Success" && result5.success.type === "result" && !result5.success.crashed) {
|
|
2717
3032
|
if (pending && (yield* finish(active, pending))) yield* send2(actor, { type: "DONE" });
|
|
@@ -2726,7 +3041,7 @@ var openWarmRunner = Effect5.fn("TestRunner.openWarm")(function* (dir, onFallbac
|
|
|
2726
3041
|
};
|
|
2727
3042
|
}
|
|
2728
3043
|
if (result5._tag === "Failure" && result5.failure._tag === "TimeoutError") {
|
|
2729
|
-
yield*
|
|
3044
|
+
yield* Effect6.sync(() => options.onPoolReset?.());
|
|
2730
3045
|
yield* active.tree.trace("warm-deadline", { budgetMs });
|
|
2731
3046
|
const failedAtDeadline = active.failed;
|
|
2732
3047
|
yield* send2(actor, { type: "CANCEL" });
|
|
@@ -2744,7 +3059,7 @@ var openWarmRunner = Effect5.fn("TestRunner.openWarm")(function* (dir, onFallbac
|
|
|
2744
3059
|
};
|
|
2745
3060
|
}
|
|
2746
3061
|
if (result5._tag === "Failure" && result5.failure._tag === "TestSpawnError" && result5.failure.kind === "reporter") return yield* abortHost(result5.failure);
|
|
2747
|
-
yield*
|
|
3062
|
+
yield* Effect6.sync(() => options.onPoolReset?.());
|
|
2748
3063
|
if (crash === 0) {
|
|
2749
3064
|
yield* Console3.warn(`Warning: Vitest pool crashed; restarting once: ${result5._tag === "Failure" ? String(result5.failure) : "message" in result5.success ? result5.success.message : result5.success.type}`);
|
|
2750
3065
|
if (pending && (yield* finish(active, pending))) yield* send2(actor, { type: "DONE" });
|
|
@@ -2753,32 +3068,32 @@ var openWarmRunner = Effect5.fn("TestRunner.openWarm")(function* (dir, onFallbac
|
|
|
2753
3068
|
yield* send2(actor, { type: "FAIL" });
|
|
2754
3069
|
yield* close2();
|
|
2755
3070
|
yield* Console3.warn("Warning: Vitest pool crashed twice for one mutant; using cold mode for the rest of this run");
|
|
2756
|
-
yield*
|
|
3071
|
+
yield* Effect6.sync(() => onFallback("Vitest pool crashed twice for one mutant"));
|
|
2757
3072
|
yield* send2(actor, { type: "FALLBACK" });
|
|
2758
3073
|
}
|
|
2759
3074
|
if (isCold()) return void 0;
|
|
2760
3075
|
}
|
|
2761
3076
|
return void 0;
|
|
2762
|
-
}, (effect5) => effect5.pipe(
|
|
3077
|
+
}, (effect5) => effect5.pipe(Effect6.onInterrupt(() => Effect6.gen(function* () {
|
|
2763
3078
|
yield* send2(actor, { type: "CANCEL" });
|
|
2764
3079
|
const active = host;
|
|
2765
|
-
yield*
|
|
3080
|
+
yield* Effect6.sync(() => options.onPoolReset?.());
|
|
2766
3081
|
active?.post({ type: "cancel" });
|
|
2767
|
-
if (active?.runPending && (yield* finish(active, active.runPending).pipe(
|
|
3082
|
+
if (active?.runPending && (yield* finish(active, active.runPending).pipe(Effect6.orDie))) yield* send2(actor, { type: "DONE" });
|
|
2768
3083
|
else {
|
|
2769
|
-
yield* retire.pipe(
|
|
2770
|
-
yield*
|
|
3084
|
+
yield* retire.pipe(Effect6.orDie);
|
|
3085
|
+
yield* Effect6.sync(() => onFallback("Interrupted run retired its unhealthy host"));
|
|
2771
3086
|
yield* send2(actor, { type: "FALLBACK" });
|
|
2772
3087
|
}
|
|
2773
3088
|
}))));
|
|
2774
|
-
const disable =
|
|
3089
|
+
const disable = Effect6.gen(function* () {
|
|
2775
3090
|
if (isCold()) return;
|
|
2776
3091
|
yield* close2();
|
|
2777
3092
|
yield* send2(actor, { type: "FALLBACK" });
|
|
2778
3093
|
});
|
|
2779
|
-
const select =
|
|
3094
|
+
const select = Effect6.fn("Warm.select")(function* (file) {
|
|
2780
3095
|
if (isCold()) return void 0;
|
|
2781
|
-
const result5 = yield* attempt(() => host.request({ type: "select", file })).pipe(
|
|
3096
|
+
const result5 = yield* attempt(() => host.request({ type: "select", file })).pipe(Effect6.timeout(3e4), Effect6.result);
|
|
2782
3097
|
if (result5._tag === "Success" && result5.success.type === "selection") return result5.success.files;
|
|
2783
3098
|
if (result5._tag === "Failure" && result5.failure._tag === "TestSpawnError" && result5.failure.kind === "reporter") return yield* abortHost(result5.failure);
|
|
2784
3099
|
yield* restart;
|
|
@@ -2804,10 +3119,10 @@ var baselineTimedOut = (timeoutMs, command) => new BaselineTimedOut({
|
|
|
2804
3119
|
command,
|
|
2805
3120
|
message: `Baseline exceeded ${timeoutMs / 1e3} seconds overall, including selection and startup. Increase --baseline-timeout (seconds), or baselineTimeoutMs in mutants.config.json, for a longer suite.`
|
|
2806
3121
|
});
|
|
2807
|
-
var TestRunnerLive = Layer3.effect(TestRunner,
|
|
2808
|
-
const spawner = yield*
|
|
3122
|
+
var TestRunnerLive = Layer3.effect(TestRunner, Effect7.gen(function* () {
|
|
3123
|
+
const spawner = yield* ChildProcessSpawner5.ChildProcessSpawner;
|
|
2809
3124
|
const fs = yield* FileSystem7.FileSystem;
|
|
2810
|
-
const path = yield*
|
|
3125
|
+
const path = yield* Path5.Path;
|
|
2811
3126
|
let warmDisabled = false;
|
|
2812
3127
|
let modeReason;
|
|
2813
3128
|
const sessions = /* @__PURE__ */ new Map();
|
|
@@ -2826,8 +3141,8 @@ var TestRunnerLive = Layer3.effect(TestRunner, Effect6.gen(function* () {
|
|
|
2826
3141
|
let hostRestarts = 0;
|
|
2827
3142
|
let poolResets = 0;
|
|
2828
3143
|
let warned = false;
|
|
2829
|
-
const
|
|
2830
|
-
if (warned) return
|
|
3144
|
+
const warn7 = (message) => Effect7.suspend(() => {
|
|
3145
|
+
if (warned) return Effect7.void;
|
|
2831
3146
|
warned = true;
|
|
2832
3147
|
return Console4.warn(message);
|
|
2833
3148
|
});
|
|
@@ -2836,7 +3151,7 @@ var TestRunnerLive = Layer3.effect(TestRunner, Effect6.gen(function* () {
|
|
|
2836
3151
|
}, onPoolReset: () => {
|
|
2837
3152
|
poolResets++;
|
|
2838
3153
|
} };
|
|
2839
|
-
const execute2 =
|
|
3154
|
+
const execute2 = Effect7.fn("TestRunner.execute")(function* (dir, args, timeoutMs, testTimeoutMs, forceCold = false, probe2) {
|
|
2840
3155
|
const overallMs = timeoutMs ?? baselineBudgetMs;
|
|
2841
3156
|
const beforeBackstop = backstopTotals.get(dir.path) ?? 0;
|
|
2842
3157
|
const backstopMs = () => Math.max(0, (backstopTotals.get(dir.path) ?? 0) - beforeBackstop);
|
|
@@ -2847,15 +3162,14 @@ var TestRunnerLive = Layer3.effect(TestRunner, Effect6.gen(function* () {
|
|
|
2847
3162
|
if (run3 !== void 0) return { ...run3, backstopMs: backstopMs(), exitCode: run3.status === "passed" || run3.status === "untested" ? 0 : 1 };
|
|
2848
3163
|
}
|
|
2849
3164
|
const reporterDir = yield* fs.makeTempDirectoryScoped({ prefix: "mutant-vitest-" }).pipe(
|
|
2850
|
-
|
|
3165
|
+
Effect7.mapError((error3) => new TestSpawnError({ command: ["vitest"], message: String(error3) }))
|
|
2851
3166
|
);
|
|
2852
3167
|
const reporter = path.join(reporterDir, "reporter.mjs");
|
|
2853
3168
|
const launcher = path.join(reporterDir, "launch.mjs");
|
|
2854
|
-
yield* fs.writeFileString(launcher, vitestLauncherSource).pipe(
|
|
3169
|
+
yield* fs.writeFileString(launcher, vitestLauncherSource).pipe(Effect7.mapError((error3) => new TestSpawnError({ command: ["vitest"], message: String(error3) })));
|
|
2855
3170
|
const marker = `mutant-cafe:${path.basename(reporterDir)}:`;
|
|
2856
|
-
yield* fs.writeFileString(reporter, reporterSource(marker, probe2)).pipe(
|
|
2857
|
-
const
|
|
2858
|
-
process.execPath,
|
|
3171
|
+
yield* fs.writeFileString(reporter, reporterSource(marker, probe2)).pipe(Effect7.mapError((error3) => new TestSpawnError({ command: ["vitest"], message: String(error3) })));
|
|
3172
|
+
const vitestArgs = [
|
|
2859
3173
|
launcher,
|
|
2860
3174
|
...args,
|
|
2861
3175
|
"--reporter=default",
|
|
@@ -2868,16 +3182,17 @@ var TestRunnerLive = Layer3.effect(TestRunner, Effect6.gen(function* () {
|
|
|
2868
3182
|
];
|
|
2869
3183
|
const started = yield* Clock4.currentTimeMillis;
|
|
2870
3184
|
const owned = yield* acquireProcessTree(dir.path, onBackstop(dir.path), openedAt.get(dir.path)).pipe(
|
|
2871
|
-
|
|
2872
|
-
|
|
3185
|
+
Effect7.provideService(FileSystem7.FileSystem, fs),
|
|
3186
|
+
Effect7.mapError((error3) => new TestSpawnError({ command: [...error3.command, ...vitestArgs], message: error3.message }))
|
|
2873
3187
|
);
|
|
3188
|
+
const command = [process.execPath, ...owned.launchArgs, ...vitestArgs];
|
|
2874
3189
|
const chunks = [];
|
|
2875
3190
|
let exitCode = 1;
|
|
2876
|
-
const child =
|
|
3191
|
+
const child = Effect7.scoped(Effect7.gen(function* () {
|
|
2877
3192
|
if (timeoutMs === void 0) yield* Console4.error(`Baseline command: ${formatTestCommand(command)} (cwd: ${dir.path})`);
|
|
2878
3193
|
lastCommands.set(dir.path, command);
|
|
2879
3194
|
yield* owned.trace("cold-spawn-start", { budgetMs: overallMs });
|
|
2880
|
-
const handle = yield* spawner.spawn(
|
|
3195
|
+
const handle = yield* spawner.spawn(ChildProcess3.make(command[0], command.slice(1), {
|
|
2881
3196
|
cwd: dir.path,
|
|
2882
3197
|
env: owned.env,
|
|
2883
3198
|
// Node's scoped spawner kills the detached process group, not just pnpm.
|
|
@@ -2886,36 +3201,36 @@ var TestRunnerLive = Layer3.effect(TestRunner, Effect6.gen(function* () {
|
|
|
2886
3201
|
forceKillAfter: "100 millis",
|
|
2887
3202
|
stdin: "ignore"
|
|
2888
3203
|
}));
|
|
2889
|
-
yield*
|
|
3204
|
+
yield* Effect7.sync(() => owned.addRoot(handle.pid));
|
|
2890
3205
|
yield* owned.trace("cold-spawn", { childPid: handle.pid });
|
|
2891
|
-
const collect = handle.all.pipe(
|
|
3206
|
+
const collect = handle.all.pipe(Stream3.decodeText(), Stream3.runForEach((chunk) => Effect7.sync(() => {
|
|
2892
3207
|
chunks.push(chunk);
|
|
2893
3208
|
})));
|
|
2894
|
-
const [code] = yield*
|
|
3209
|
+
const [code] = yield* Effect7.all([handle.exitCode.pipe(Effect7.tap(() => owned.cleanup)), collect], { concurrency: "unbounded" });
|
|
2895
3210
|
exitCode = code;
|
|
2896
3211
|
return code === 0 ? "passed" : "failed";
|
|
2897
|
-
}).pipe(
|
|
3212
|
+
}).pipe(Effect7.onInterrupt(() => owned.cleanup)));
|
|
2898
3213
|
const status = yield* child.pipe(
|
|
2899
|
-
|
|
2900
|
-
|
|
3214
|
+
Effect7.timeout(overallMs),
|
|
3215
|
+
Effect7.catchTag("TimeoutError", () => Effect7.sync(() => {
|
|
2901
3216
|
exitCode = 124;
|
|
2902
3217
|
chunks.push(`
|
|
2903
3218
|
Vitest timed out after ${overallMs}ms overall, including startup.
|
|
2904
3219
|
`);
|
|
2905
3220
|
return "timedOut";
|
|
2906
3221
|
}))
|
|
2907
|
-
).pipe(
|
|
3222
|
+
).pipe(Effect7.mapError((error3) => new TestSpawnError({ command, message: error3.message })));
|
|
2908
3223
|
yield* owned.cleanup;
|
|
2909
3224
|
const ended = yield* Clock4.currentTimeMillis;
|
|
2910
3225
|
const output = chunks.join("");
|
|
2911
3226
|
const failed = output.includes(marker + "failed");
|
|
2912
3227
|
const selection = output.split("\n").find((line) => line.includes(marker + "selected:"))?.split(marker + "selected:")[1];
|
|
2913
|
-
const selected = selection === void 0 ? [] : yield*
|
|
2914
|
-
|
|
3228
|
+
const selected = selection === void 0 ? [] : yield* Schema9.decodeEffect(Schema9.fromJsonString(Schema9.Array(Schema9.String)))(selection).pipe(
|
|
3229
|
+
Effect7.mapError((error3) => new TestSpawnError({ command, kind: "reporter", message: `Internal cold reporter protocol error in selected files: ${String(error3)}` }))
|
|
2915
3230
|
);
|
|
2916
3231
|
const telemetryWarnings = [];
|
|
2917
3232
|
for (const part of output.split(marker + "telemetryWarning:").slice(1)) {
|
|
2918
|
-
const warning =
|
|
3233
|
+
const warning = Schema9.decodeOption(Schema9.fromJsonString(Schema9.String))(part.split("\n")[0]);
|
|
2919
3234
|
if (warning._tag === "Some") telemetryWarnings.push(warning.value);
|
|
2920
3235
|
}
|
|
2921
3236
|
const testDurations = {};
|
|
@@ -2926,7 +3241,7 @@ Vitest timed out after ${overallMs}ms overall, including startup.
|
|
|
2926
3241
|
for (const line of output.split("\n")) {
|
|
2927
3242
|
const entry = line.split(marker + "duration:")[1];
|
|
2928
3243
|
if (entry === void 0) continue;
|
|
2929
|
-
const decoded =
|
|
3244
|
+
const decoded = Schema9.decodeOption(Schema9.fromJsonString(Schema9.Struct({ file: Schema9.String, duration: Schema9.Finite, timeout: Schema9.Finite, key: Schema9.String, start: Schema9.Finite })))(entry);
|
|
2930
3245
|
if (decoded._tag === "None") {
|
|
2931
3246
|
telemetryWarnings.push("Internal reporter telemetry error: invalid cold timing marker; omitted");
|
|
2932
3247
|
continue;
|
|
@@ -2938,7 +3253,7 @@ Vitest timed out after ${overallMs}ms overall, including startup.
|
|
|
2938
3253
|
testTimeouts[timing.file] = Math.max(testTimeouts[timing.file] ?? 0, timing.timeout);
|
|
2939
3254
|
}
|
|
2940
3255
|
for (const part of output.split(marker + "fileDuration:").slice(1)) {
|
|
2941
|
-
const decoded =
|
|
3256
|
+
const decoded = Schema9.decodeOption(Schema9.fromJsonString(Schema9.Struct({ file: Schema9.String, duration: Schema9.Finite })))(part.split("\n")[0]);
|
|
2942
3257
|
if (decoded._tag === "None") {
|
|
2943
3258
|
telemetryWarnings.push("Internal reporter telemetry error: invalid cold file timing marker; omitted");
|
|
2944
3259
|
continue;
|
|
@@ -2965,13 +3280,13 @@ Vitest timed out after ${overallMs}ms overall, including startup.
|
|
|
2965
3280
|
};
|
|
2966
3281
|
const cleaned = cleanTelemetry(run2, "cold run");
|
|
2967
3282
|
return { ...cleaned.value, backstopMs: backstopMs(), telemetryWarnings: [...telemetryWarnings, ...cleaned.warnings], exitCode };
|
|
2968
|
-
},
|
|
3283
|
+
}, Effect7.scoped);
|
|
2969
3284
|
return TestRunner.of({
|
|
2970
|
-
stats:
|
|
2971
|
-
open:
|
|
3285
|
+
stats: Effect7.sync(() => ({ hostRestarts, poolResets })),
|
|
3286
|
+
open: Effect7.fn("TestRunner.open")(function* (dir, cold, warm = false, mutants = 1) {
|
|
2972
3287
|
scopes.set(dir.path, yield* Scope3.Scope);
|
|
2973
3288
|
openedAt.set(dir.path, yield* Clock4.currentTimeMillis);
|
|
2974
|
-
yield*
|
|
3289
|
+
yield* Effect7.addFinalizer(() => Effect7.sync(() => {
|
|
2975
3290
|
sessions.delete(dir.path);
|
|
2976
3291
|
selectors.delete(dir.path);
|
|
2977
3292
|
auto.delete(dir.path);
|
|
@@ -2996,7 +3311,7 @@ Vitest timed out after ${overallMs}ms overall, including startup.
|
|
|
2996
3311
|
const session = yield* openWarmRunner(dir, (reason) => {
|
|
2997
3312
|
warmDisabled = true;
|
|
2998
3313
|
modeReason = reason;
|
|
2999
|
-
}, { ...sessionOptions, quiet: !warm, warn:
|
|
3314
|
+
}, { ...sessionOptions, quiet: !warm, warn: warn7, onBackstop: onBackstop(dir.path), processesSince: openedAt.get(dir.path) }).pipe(Effect7.provideService(FileSystem7.FileSystem, fs), Effect7.mapError((error3) => error3._tag === "TestSpawnError" ? error3 : new TestSpawnError({ command: ["vitest", "warm"], message: String(error3) })));
|
|
3000
3315
|
sessions.set(dir.path, session);
|
|
3001
3316
|
if (warmDisabled || !warm && automaticMode === "cold") {
|
|
3002
3317
|
yield* session.disable;
|
|
@@ -3005,8 +3320,8 @@ Vitest timed out after ${overallMs}ms overall, including startup.
|
|
|
3005
3320
|
if (warm) modeReason = "Explicit --warm; supported configuration";
|
|
3006
3321
|
if (!warm && automaticMode === "pending") auto.set(dir.path, { startupMs: (yield* Clock4.currentTimeMillis) - started, mutants });
|
|
3007
3322
|
}),
|
|
3008
|
-
invalidate: (dir, file) => sessions.get(dir.path)?.invalidate(file) ??
|
|
3009
|
-
selectRelated:
|
|
3323
|
+
invalidate: (dir, file) => sessions.get(dir.path)?.invalidate(file) ?? Effect7.void,
|
|
3324
|
+
selectRelated: Effect7.fn("TestRunner.selectRelated")(function* (dir, file) {
|
|
3010
3325
|
const session = sessions.get(dir.path);
|
|
3011
3326
|
if (session !== void 0 && !warmDisabled) return yield* session.select(file);
|
|
3012
3327
|
let selector = selectors.get(dir.path) ?? selectors.values().next().value;
|
|
@@ -3015,37 +3330,37 @@ Vitest timed out after ${overallMs}ms overall, including startup.
|
|
|
3015
3330
|
if (!scope) return void 0;
|
|
3016
3331
|
selector = yield* openWarmRunner(dir, () => {
|
|
3017
3332
|
}, { quiet: true, selectionOnly: true, onBackstop: onBackstop(dir.path), processesSince: openedAt.get(dir.path) }).pipe(
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3333
|
+
Effect7.provideService(FileSystem7.FileSystem, fs),
|
|
3334
|
+
Effect7.provideService(Scope3.Scope, scope),
|
|
3335
|
+
Effect7.mapError((error3) => error3._tag === "TestSpawnError" ? error3 : new TestSpawnError({ command: ["vitest", "select"], message: String(error3) }))
|
|
3021
3336
|
);
|
|
3022
3337
|
selectors.set(dir.path, selector);
|
|
3023
3338
|
}
|
|
3024
3339
|
return yield* selector.select(file);
|
|
3025
3340
|
}),
|
|
3026
|
-
probeReachability:
|
|
3341
|
+
probeReachability: Effect7.fn("TestRunner.probeReachability")(function* (dir, mutant, timeoutMs) {
|
|
3027
3342
|
if (!dir.poison) return { file: mutant.file, status: "unsupported", durationMs: 0, testCommand: [], output: "Scratch adapter cannot poison modules" };
|
|
3028
3343
|
const temporary = yield* fs.makeTempDirectoryScoped({ prefix: "mutant-probe-" });
|
|
3029
3344
|
const signal = path.join(temporary, "loaded");
|
|
3030
3345
|
const control = path.join(temporary, "control");
|
|
3031
3346
|
const token = `mutant-cafe-probe:${path.basename(temporary)}`;
|
|
3032
3347
|
const setupFile = path.join(temporary, "setup.mjs");
|
|
3033
|
-
const vitest = yield*
|
|
3034
|
-
try: () =>
|
|
3348
|
+
const vitest = yield* Effect7.try({
|
|
3349
|
+
try: () => pathToFileURL3(path.join(path.dirname(createRequire(path.join(dir.path, "package.json")).resolve("vitest/package.json")), "dist/index.js")).href,
|
|
3035
3350
|
catch: (error3) => new TestSpawnError({ command: ["vitest", "probe"], message: String(error3) })
|
|
3036
3351
|
});
|
|
3037
3352
|
yield* fs.writeFileString(setupFile, `import { beforeAll, afterAll } from ${JSON.stringify(vitest)};
|
|
3038
3353
|
beforeAll(() => globalThis.process.getBuiltinModule("node:fs").writeFileSync(${JSON.stringify(control)}, "ready"));
|
|
3039
3354
|
afterAll(() => { if (globalThis[Symbol.for(${JSON.stringify(token)})]) throw new Error(${JSON.stringify(token)}); });`);
|
|
3040
3355
|
const started = yield* Clock4.currentTimeMillis;
|
|
3041
|
-
const invalidate = () => sessions.get(dir.path)?.invalidate(mutant.file) ??
|
|
3042
|
-
const run2 = yield*
|
|
3356
|
+
const invalidate = () => sessions.get(dir.path)?.invalidate(mutant.file) ?? Effect7.void;
|
|
3357
|
+
const run2 = yield* Effect7.acquireUseRelease(
|
|
3043
3358
|
dir.poison(mutant, signal, token),
|
|
3044
|
-
() =>
|
|
3359
|
+
() => Effect7.gen(function* () {
|
|
3045
3360
|
yield* invalidate();
|
|
3046
3361
|
return yield* execute2(dir, ["run", "--passWithNoTests"], timeoutMs, void 0, false, { token, setupFile });
|
|
3047
3362
|
}),
|
|
3048
|
-
() => dir.revert(mutant).pipe(
|
|
3363
|
+
() => dir.revert(mutant).pipe(Effect7.andThen(invalidate), Effect7.orDie)
|
|
3049
3364
|
);
|
|
3050
3365
|
const supported = yield* fs.exists(control);
|
|
3051
3366
|
const loaded = (yield* fs.exists(signal)) || run2.probeLoaded === true;
|
|
@@ -3056,21 +3371,21 @@ Vitest timed out after ${overallMs}ms overall, including startup.
|
|
|
3056
3371
|
testCommand: run2.command,
|
|
3057
3372
|
output: run2.output
|
|
3058
3373
|
};
|
|
3059
|
-
}, (effect5) => effect5.pipe(
|
|
3060
|
-
baseline:
|
|
3374
|
+
}, (effect5) => effect5.pipe(Effect7.scoped, Effect7.mapError((error3) => error3._tag === "ScratchError" || error3._tag === "TestSpawnError" ? error3 : new TestSpawnError({ command: ["vitest", "probe"], message: String(error3) })))),
|
|
3375
|
+
baseline: Effect7.fn("TestRunner.baseline")(function* (dir, tsconfig, timeoutMs = DEFAULT_BASELINE_TIMEOUT_MS) {
|
|
3061
3376
|
baselineBudgetMs = timeoutMs;
|
|
3062
3377
|
lastCommands.delete(dir.path);
|
|
3063
|
-
const unreliable = yield* preflight(dir.path, tsconfig, timeoutMs, { processesSince: openedAt.get(dir.path), onBackstop: onBackstop(dir.path) }).pipe(
|
|
3378
|
+
const unreliable = yield* preflight(dir.path, tsconfig, timeoutMs, { processesSince: openedAt.get(dir.path), onBackstop: onBackstop(dir.path) }).pipe(Effect7.provideService(FileSystem7.FileSystem, fs), Effect7.provideService(ChildProcessSpawner5.ChildProcessSpawner, spawner), Effect7.catch((error3) => error3._tag === "TestSpawnError" && error3.kind === "vitest-version" ? Effect7.fail(error3) : Effect7.succeed([{ kind: "warning", reason: `Cannot verify runner selection: ${String(error3)}` }])));
|
|
3064
3379
|
for (const issue of unreliable) yield* Console4.warn(`Warning (${issue.kind}): ${issue.reason}`);
|
|
3065
3380
|
if (unreliable.some((issue) => issue.kind === "runner")) {
|
|
3066
3381
|
const command = ["npx", "--no", "vitest", "run", "--passWithNoTests"];
|
|
3067
3382
|
yield* Console4.warn(`Baseline command (not executed: unsupported runner): ${command.join(" ")}`);
|
|
3068
|
-
return { durationMs: 0, testCommand: command, unreliable };
|
|
3383
|
+
return { durationMs: 0, testCommand: command, unreliable, runnerMode: "cold", runnerModeReason: "Unsupported test runner" };
|
|
3069
3384
|
}
|
|
3070
3385
|
const run2 = yield* execute2(dir, ["run", "--passWithNoTests"], void 0, void 0, auto.has(dir.path));
|
|
3071
3386
|
if (run2.status === "timedOut") return yield* baselineTimedOut(timeoutMs, run2.command);
|
|
3072
3387
|
if (run2.status !== "passed" && run2.status !== "untested") {
|
|
3073
|
-
return yield*
|
|
3388
|
+
return yield* Effect7.fail(new BaselineFailed({ exitCode: run2.exitCode, output: run2.output, command: run2.command }));
|
|
3074
3389
|
}
|
|
3075
3390
|
if (sessions.has(dir.path)) yield* sessions.get(dir.path).invalidate(run2.testFiles?.[0] ?? "package.json");
|
|
3076
3391
|
if (auto.has(dir.path)) primers.set(dir.path, run2);
|
|
@@ -3092,13 +3407,13 @@ Vitest timed out after ${overallMs}ms overall, including startup.
|
|
|
3092
3407
|
runnerMode: sessions.has(dir.path) && !warmDisabled && !auto.has(dir.path) ? "warm" : "cold"
|
|
3093
3408
|
};
|
|
3094
3409
|
}, (effect5, dir, _tsconfig, timeoutMs = DEFAULT_BASELINE_TIMEOUT_MS) => effect5.pipe(
|
|
3095
|
-
|
|
3096
|
-
|
|
3410
|
+
Effect7.timeout(timeoutMs),
|
|
3411
|
+
Effect7.catchTag("TimeoutError", () => Effect7.fail(baselineTimedOut(timeoutMs, lastCommands.get(dir.path) ?? [])))
|
|
3097
3412
|
)),
|
|
3098
|
-
calibrate:
|
|
3413
|
+
calibrate: Effect7.fn("TestRunner.calibrate")(function* (dir, mutants, copies) {
|
|
3099
3414
|
const primer = primers.get(dir.path) ?? primers.values().next().value;
|
|
3100
3415
|
if (!primer || automaticMode !== "pending" || auto.size === 0 || warmDisabled) return {};
|
|
3101
|
-
const disable =
|
|
3416
|
+
const disable = Effect7.gen(function* () {
|
|
3102
3417
|
automaticMode = "cold";
|
|
3103
3418
|
warmDisabled = true;
|
|
3104
3419
|
auto.clear();
|
|
@@ -3107,7 +3422,6 @@ Vitest timed out after ${overallMs}ms overall, including startup.
|
|
|
3107
3422
|
if (mutants <= (primer.testFiles?.length ?? 0)) {
|
|
3108
3423
|
modeReason = `Auto: small selection (${mutants} testable mutants across ${primer.testFiles?.length ?? 0} files)`;
|
|
3109
3424
|
yield* disable;
|
|
3110
|
-
yield* Console4.warn(`Vitest auto mode: cold; small selection (${mutants} testable mutants across ${primer.testFiles?.length ?? 0} files), skipping paired calibration`);
|
|
3111
3425
|
return { runnerMode: "cold", runnerModeReason: modeReason, testableMutants: mutants };
|
|
3112
3426
|
}
|
|
3113
3427
|
const startups = [...auto.values()].map((entry) => entry.startupMs);
|
|
@@ -3133,13 +3447,12 @@ Vitest timed out after ${overallMs}ms overall, including startup.
|
|
|
3133
3447
|
modeReason = warmDisabled ? modeReason ?? "Warm execution failed during calibration" : !sameSelection || warm.status !== cold.status ? "Auto: cold/warm selection or status mismatch" : `Auto: paired measurements favor ${choice}`;
|
|
3134
3448
|
automaticMode = choice;
|
|
3135
3449
|
auto.clear();
|
|
3136
|
-
yield* Console4.warn(`Vitest auto mode: ${choice}; paired cold ${cold.durationMs} ms, warm ${warm.durationMs} ms; ${mutants} testable mutants, ${copies} copies, startup ${calibration2.warmStartupMs} ms`);
|
|
3137
3450
|
if (choice === "cold") yield* disable;
|
|
3138
3451
|
else if (sessions.has(dir.path)) yield* sessions.get(dir.path).invalidate(warm.testFiles?.[0] ?? "package.json");
|
|
3139
3452
|
const run2 = choice === "cold" ? cold : warm;
|
|
3140
3453
|
return { runnerMode: choice, runnerModeReason: modeReason, calibration: calibration2, testableMutants: mutants, hostPid: run2.hostPid };
|
|
3141
3454
|
}),
|
|
3142
|
-
runRelated:
|
|
3455
|
+
runRelated: Effect7.fn("TestRunner.runRelated")(function* (dir, file, timeoutMs, testTimeoutMs) {
|
|
3143
3456
|
const related = yield* execute2(dir, ["related", file, "--run", "--passWithNoTests"], timeoutMs, testTimeoutMs);
|
|
3144
3457
|
if (related.status !== "untested") return related;
|
|
3145
3458
|
const remaining = Math.max(1, timeoutMs - related.durationMs);
|
|
@@ -3158,26 +3471,27 @@ Vitest timed out after ${overallMs}ms overall, including startup.
|
|
|
3158
3471
|
// packages/runner/src/Run.ts
|
|
3159
3472
|
import { createEffectActor as createEffectActor3, createEffectLogic as createEffectLogic2, join as join2, send as send3, setupEffect as setupEffect3 } from "@xstate/effect";
|
|
3160
3473
|
import { types as types2 } from "xstate";
|
|
3161
|
-
import * as
|
|
3474
|
+
import * as Effect8 from "effect/Effect";
|
|
3475
|
+
import * as Console5 from "effect/Console";
|
|
3162
3476
|
import * as Pool from "effect/Pool";
|
|
3163
|
-
import * as
|
|
3477
|
+
import * as Path7 from "effect/Path";
|
|
3164
3478
|
import * as Result2 from "effect/Result";
|
|
3165
|
-
import * as
|
|
3479
|
+
import * as Schema10 from "effect/Schema";
|
|
3166
3480
|
import * as Scope5 from "effect/Scope";
|
|
3167
|
-
import * as
|
|
3481
|
+
import * as Stream4 from "effect/Stream";
|
|
3168
3482
|
var ScratchPool = class {
|
|
3169
3483
|
value;
|
|
3170
3484
|
constructor(value) {
|
|
3171
3485
|
this.value = value;
|
|
3172
3486
|
}
|
|
3173
3487
|
};
|
|
3174
|
-
var runMutants =
|
|
3488
|
+
var runMutants = Effect8.fn("Runner.runMutants")(function* (config, mutants) {
|
|
3175
3489
|
const scratch = yield* Scratch;
|
|
3176
3490
|
const tests = yield* TestRunner;
|
|
3177
3491
|
const source = yield* MutantSource;
|
|
3178
3492
|
const reporter = yield* Reporter;
|
|
3179
3493
|
const scope = yield* Scope5.Scope;
|
|
3180
|
-
const path = yield*
|
|
3494
|
+
const path = yield* Path7.Path;
|
|
3181
3495
|
const jobs = Math.max(1, Math.floor(config.jobs));
|
|
3182
3496
|
const report = (state2) => sanitizeReportTelemetry({
|
|
3183
3497
|
schemaVersion: 2,
|
|
@@ -3193,35 +3507,39 @@ var runMutants = Effect7.fn("Runner.runMutants")(function* (config, mutants) {
|
|
|
3193
3507
|
...state2.failure === void 0 ? {} : { failure: state2.failure._tag === "BaselineTimedOut" ? `BaselineTimedOut: ${state2.failure.message}` : state2.failure._tag === "BaselineFailed" ? `${state2.failure._tag}: ${formatTestCommand(state2.failure.command)}
|
|
3194
3508
|
${state2.failure.output.slice(-8e3)}` : String(state2.failure) }
|
|
3195
3509
|
}).report;
|
|
3196
|
-
const capture = (effect5) =>
|
|
3197
|
-
const copying = createEffectLogic2(({ input }) => capture(
|
|
3198
|
-
const acquire =
|
|
3510
|
+
const capture = (effect5) => Effect8.result(effect5);
|
|
3511
|
+
const copying = createEffectLogic2(({ input }) => capture(Effect8.gen(function* () {
|
|
3512
|
+
const acquire = Effect8.gen(function* () {
|
|
3199
3513
|
const dir = yield* scratch.acquire(config.root);
|
|
3200
3514
|
if (tests.open) yield* tests.open(dir, config.cold ?? false, config.warm ?? false, input);
|
|
3201
3515
|
return dir;
|
|
3202
|
-
}).pipe(
|
|
3516
|
+
}).pipe(Effect8.mapError((error3) => error3._tag === "ScratchError" ? error3 : new ScratchError({ operation: "warm runner", path: config.root, message: String(error3) })));
|
|
3203
3517
|
const pool = yield* Pool.make({ acquire, size: jobs }).pipe(
|
|
3204
|
-
|
|
3518
|
+
Effect8.provideService(Scope5.Scope, scope)
|
|
3205
3519
|
);
|
|
3206
|
-
yield*
|
|
3520
|
+
yield* Effect8.scoped(Pool.get(pool));
|
|
3207
3521
|
return new ScratchPool(pool);
|
|
3208
3522
|
})));
|
|
3209
|
-
const baselining = createEffectLogic2(({ input }) => capture(
|
|
3210
|
-
if (input === void 0) return yield*
|
|
3211
|
-
const baseline = yield*
|
|
3523
|
+
const baselining = createEffectLogic2(({ input }) => capture(Effect8.gen(function* () {
|
|
3524
|
+
if (input === void 0) return yield* Effect8.die("Missing scratch pool");
|
|
3525
|
+
const baseline = yield* Effect8.scoped(Effect8.gen(function* () {
|
|
3212
3526
|
const dir = yield* Pool.get(input.value);
|
|
3213
3527
|
return yield* tests.baseline(dir, path.isAbsolute(config.tsconfig) ? path.relative(config.root, config.tsconfig) : config.tsconfig, config.baselineTimeoutMs);
|
|
3214
3528
|
}));
|
|
3215
3529
|
return { baseline, timeoutMs: config.timeoutMs ?? Math.max(config.minimumTimeoutMs, Math.ceil(config.timeoutMultiplier * baseline.durationMs)) };
|
|
3216
3530
|
})));
|
|
3217
|
-
const generating = createEffectLogic2(() => capture(
|
|
3218
|
-
const testing = createEffectLogic2(({ input }) => capture(
|
|
3531
|
+
const generating = createEffectLogic2(() => capture(Stream4.runCollect(mutants ?? source.generate(config))));
|
|
3532
|
+
const testing = createEffectLogic2(({ input }) => capture(Effect8.gen(function* () {
|
|
3219
3533
|
const dirs = input.state.pool?.value;
|
|
3220
|
-
if (dirs === void 0) return yield*
|
|
3534
|
+
if (dirs === void 0) return yield* Effect8.die("Missing scratch pool");
|
|
3535
|
+
const linkedRoots = yield* Effect8.scoped(Pool.get(dirs).pipe(Effect8.map((dir) => dir.linkedRoots ?? [])));
|
|
3536
|
+
const eligible = yield* excludeLinkedCandidates(config.root, input.state.pending, linkedRoots);
|
|
3537
|
+
for (const entry of eligible.notMutated) yield* input.skip(entry);
|
|
3538
|
+
const pending = eligible.mutants;
|
|
3221
3539
|
let baseline = input.state.baseline;
|
|
3222
3540
|
const viabilityById = /* @__PURE__ */ new Map();
|
|
3223
3541
|
const preReported = /* @__PURE__ */ new Set();
|
|
3224
|
-
if (!config.cold && !config.warm && tests.calibrate) yield*
|
|
3542
|
+
if (!config.cold && !config.warm && tests.calibrate) yield* Effect8.forEach(pending, (mutant) => Effect8.gen(function* () {
|
|
3225
3543
|
const viability = yield* source.checkViable(mutant);
|
|
3226
3544
|
viabilityById.set(mutant.id, viability);
|
|
3227
3545
|
if (viability.analysisFailed) {
|
|
@@ -3240,13 +3558,13 @@ ${state2.failure.output.slice(-8e3)}` : String(state2.failure) }
|
|
|
3240
3558
|
if (input.state.baseline.probeSupported && selectRelated && probeReachability) {
|
|
3241
3559
|
const seen = /* @__PURE__ */ new Set();
|
|
3242
3560
|
const builtTests = input.state.baseline.unreliable?.flatMap((issue) => issue.kind === "built" ? issue.testFiles : []) ?? [];
|
|
3243
|
-
for (const mutant of
|
|
3561
|
+
for (const mutant of pending) {
|
|
3244
3562
|
if (viabilityById.has(mutant.id) && !viabilityById.get(mutant.id)?.viable) continue;
|
|
3245
3563
|
const file = path.isAbsolute(mutant.file) ? path.relative(config.root, mutant.file) : mutant.file;
|
|
3246
3564
|
if (seen.has(file)) continue;
|
|
3247
3565
|
seen.add(file);
|
|
3248
3566
|
if (unreliableFor(input.state.baseline, file, builtTests).length) continue;
|
|
3249
|
-
const probe2 = yield*
|
|
3567
|
+
const probe2 = yield* Effect8.scoped(Effect8.gen(function* () {
|
|
3250
3568
|
const dir = yield* Pool.get(dirs);
|
|
3251
3569
|
if (!dir.poison) return void 0;
|
|
3252
3570
|
const files = yield* selectRelated(dir, file);
|
|
@@ -3261,29 +3579,30 @@ ${state2.failure.output.slice(-8e3)}` : String(state2.failure) }
|
|
|
3261
3579
|
}
|
|
3262
3580
|
const calibrate = tests.calibrate;
|
|
3263
3581
|
if (calibrate) {
|
|
3264
|
-
const testable =
|
|
3582
|
+
const testable = pending.filter((mutant) => {
|
|
3265
3583
|
const file = path.isAbsolute(mutant.file) ? path.relative(config.root, mutant.file) : mutant.file;
|
|
3266
3584
|
return viabilityById.get(mutant.id)?.viable && !unreachable.has(file) && !unreliableFor(baseline, file).length;
|
|
3267
3585
|
}).length;
|
|
3268
|
-
const selected = yield*
|
|
3586
|
+
const selected = yield* Effect8.scoped(Effect8.gen(function* () {
|
|
3269
3587
|
const dir = yield* Pool.get(dirs);
|
|
3270
3588
|
return yield* calibrate(dir, testable, config.jobs);
|
|
3271
3589
|
}));
|
|
3272
3590
|
baseline = { ...baseline, ...selected };
|
|
3273
3591
|
yield* input.updateBaseline(baseline);
|
|
3274
3592
|
}
|
|
3593
|
+
if (!config.cold && !config.warm) yield* Console5.warn(`Vitest auto mode: ${baseline.runnerMode ?? "cold"}; ${baseline.runnerModeReason ?? "Cold execution; no warm session"}`);
|
|
3275
3594
|
const neverBudgets = /* @__PURE__ */ new Map();
|
|
3276
3595
|
const neverLimits = /* @__PURE__ */ new Map();
|
|
3277
3596
|
const neverBases = /* @__PURE__ */ new Map();
|
|
3278
3597
|
const neverAllowances = /* @__PURE__ */ new Map();
|
|
3279
|
-
for (const mutant of
|
|
3598
|
+
for (const mutant of pending) {
|
|
3280
3599
|
if (viabilityById.has(mutant.id) && !viabilityById.get(mutant.id)?.viable) continue;
|
|
3281
3600
|
if (unreachable.has(path.isAbsolute(mutant.file) ? path.relative(config.root, mutant.file) : mutant.file)) continue;
|
|
3282
3601
|
if (mutant.genre !== "EffectNever" || neverBudgets.has(mutant.file) || unreliableFor(input.state.baseline, path.isAbsolute(mutant.file) ? path.relative(config.root, mutant.file) : mutant.file).length > 0) continue;
|
|
3283
3602
|
let probeTimeout = Math.max(1, Math.floor(input.state.timeoutMs / 2));
|
|
3284
3603
|
const originalTimeouts = new Set(Object.values(baseline.testTimeoutDetails ?? {}));
|
|
3285
3604
|
while (originalTimeouts.has(probeTimeout)) probeTimeout++;
|
|
3286
|
-
const measured = yield*
|
|
3605
|
+
const measured = yield* Effect8.scoped(Effect8.gen(function* () {
|
|
3287
3606
|
const dir = yield* Pool.get(dirs);
|
|
3288
3607
|
return yield* tests.runRelated(dir, path.isAbsolute(mutant.file) ? path.relative(config.root, mutant.file) : mutant.file, input.state.timeoutMs, probeTimeout);
|
|
3289
3608
|
}));
|
|
@@ -3304,8 +3623,8 @@ ${state2.failure.output.slice(-8e3)}` : String(state2.failure) }
|
|
|
3304
3623
|
const explicit = Object.entries(baseline.testTimeoutDetails ?? {}).filter(([key, value]) => value > 0 && measured.testTimeoutDetails?.[key] === value).map(([, value]) => value);
|
|
3305
3624
|
neverLimits.set(mutant.file, Math.max(0, ...explicit));
|
|
3306
3625
|
}
|
|
3307
|
-
yield*
|
|
3308
|
-
|
|
3626
|
+
yield* Stream4.fromIterable(pending).pipe(
|
|
3627
|
+
Stream4.mapEffect((mutant) => Effect8.scoped(Effect8.gen(function* () {
|
|
3309
3628
|
if (preReported.has(mutant.id)) return;
|
|
3310
3629
|
const viability = viabilityById.get(mutant.id) ?? (yield* source.checkViable(mutant));
|
|
3311
3630
|
if (viability.analysisFailed) {
|
|
@@ -3342,17 +3661,17 @@ ${state2.failure.output.slice(-8e3)}` : String(state2.failure) }
|
|
|
3342
3661
|
const dir = yield* Pool.get(dirs);
|
|
3343
3662
|
const testTimeoutMs = mutant.genre === "EffectNever" ? neverBudgets.get(mutant.file) : void 0;
|
|
3344
3663
|
const timeoutMs = testTimeoutMs === void 0 ? input.state.timeoutMs : Math.max(testTimeoutMs, neverLimits.get(mutant.file) ?? 0) + (neverAllowances.get(mutant.file) ?? 0);
|
|
3345
|
-
const run2 = yield*
|
|
3664
|
+
const run2 = yield* Effect8.acquireUseRelease(
|
|
3346
3665
|
dir.apply(mutant),
|
|
3347
|
-
() =>
|
|
3666
|
+
() => Effect8.gen(function* () {
|
|
3348
3667
|
if (tests.invalidate) yield* tests.invalidate(dir, localFile);
|
|
3349
3668
|
return yield* tests.runRelated(dir, localFile, timeoutMs, testTimeoutMs);
|
|
3350
3669
|
}),
|
|
3351
3670
|
// Restore and re-invalidate even on interruption before leasing again.
|
|
3352
|
-
() =>
|
|
3671
|
+
() => Effect8.gen(function* () {
|
|
3353
3672
|
yield* dir.revert(mutant);
|
|
3354
3673
|
if (tests.invalidate) yield* tests.invalidate(dir, localFile);
|
|
3355
|
-
}).pipe(
|
|
3674
|
+
}).pipe(Effect8.orDie)
|
|
3356
3675
|
);
|
|
3357
3676
|
const selectedIssues = unreliableFor(input.state.baseline, localFile, run2.testFiles);
|
|
3358
3677
|
const result5 = {
|
|
@@ -3374,18 +3693,18 @@ ${state2.failure.output.slice(-8e3)}` : String(state2.failure) }
|
|
|
3374
3693
|
yield* input.record(result5);
|
|
3375
3694
|
yield* reporter.progress(result5);
|
|
3376
3695
|
})), { concurrency: jobs }),
|
|
3377
|
-
|
|
3696
|
+
Stream4.runDrain
|
|
3378
3697
|
);
|
|
3379
3698
|
})));
|
|
3380
|
-
const reporting = createEffectLogic2(({ input }) => capture(
|
|
3381
|
-
const stats = yield* tests.stats ??
|
|
3699
|
+
const reporting = createEffectLogic2(({ input }) => capture(Effect8.gen(function* () {
|
|
3700
|
+
const stats = yield* tests.stats ?? Effect8.succeed({ hostRestarts: 0, poolResets: 0 });
|
|
3382
3701
|
if (!input.reported) yield* reporter.write({ ...report(input), ...stats });
|
|
3383
3702
|
return stats;
|
|
3384
3703
|
})));
|
|
3385
3704
|
const machine = setupEffect3({
|
|
3386
3705
|
schemas: {
|
|
3387
3706
|
context: types2(),
|
|
3388
|
-
events: { CANCEL:
|
|
3707
|
+
events: { CANCEL: Schema10.Struct({}), RESULT: Schema10.Struct({ result: MutantResult }), SKIP: Schema10.Struct({ entry: NotMutated }), PROBE: Schema10.Struct({ entry: ReachabilityProbe }), BASELINE: Schema10.Struct({ entry: Baseline }) }
|
|
3389
3708
|
},
|
|
3390
3709
|
actors: { copying, baselining, generating, testing, reporting }
|
|
3391
3710
|
}).createMachine({
|
|
@@ -3463,47 +3782,47 @@ ${state2.failure.output.slice(-8e3)}` : String(state2.failure) }
|
|
|
3463
3782
|
done: { type: "final" }
|
|
3464
3783
|
}
|
|
3465
3784
|
});
|
|
3466
|
-
const state = yield*
|
|
3785
|
+
const state = yield* Effect8.scoped(Effect8.gen(function* () {
|
|
3467
3786
|
const actor = yield* createEffectActor3(machine);
|
|
3468
|
-
return yield* join2(actor).pipe(
|
|
3787
|
+
return yield* join2(actor).pipe(Effect8.orDie, Effect8.onInterrupt(() => Effect8.gen(function* () {
|
|
3469
3788
|
yield* send3(actor, { type: "CANCEL" });
|
|
3470
|
-
yield* join2(actor).pipe(
|
|
3789
|
+
yield* join2(actor).pipe(Effect8.orDie);
|
|
3471
3790
|
})));
|
|
3472
3791
|
}));
|
|
3473
3792
|
if (state.failure !== void 0) return yield* state.failure;
|
|
3474
3793
|
return report(state);
|
|
3475
|
-
},
|
|
3794
|
+
}, Effect8.scoped);
|
|
3476
3795
|
|
|
3477
3796
|
// packages/cli/src/bin.ts
|
|
3478
|
-
import * as
|
|
3797
|
+
import * as Effect13 from "effect/Effect";
|
|
3479
3798
|
import * as Layer5 from "effect/Layer";
|
|
3480
|
-
import * as
|
|
3799
|
+
import * as Stream8 from "effect/Stream";
|
|
3481
3800
|
|
|
3482
3801
|
// packages/cli/src/Command.ts
|
|
3483
|
-
import * as
|
|
3484
|
-
import * as
|
|
3802
|
+
import * as Console7 from "effect/Console";
|
|
3803
|
+
import * as Effect12 from "effect/Effect";
|
|
3485
3804
|
import * as FileSystem15 from "effect/FileSystem";
|
|
3486
3805
|
import * as Option from "effect/Option";
|
|
3487
|
-
import * as
|
|
3806
|
+
import * as Path15 from "effect/Path";
|
|
3488
3807
|
import * as Ref from "effect/Ref";
|
|
3489
|
-
import * as
|
|
3490
|
-
import * as
|
|
3808
|
+
import * as Schema14 from "effect/Schema";
|
|
3809
|
+
import * as Stream7 from "effect/Stream";
|
|
3491
3810
|
import * as Command from "effect/cli/Command";
|
|
3492
3811
|
import * as Flag from "effect/cli/Flag";
|
|
3493
3812
|
|
|
3494
3813
|
// packages/cli/src/Diff.ts
|
|
3495
|
-
import * as
|
|
3814
|
+
import * as Effect9 from "effect/Effect";
|
|
3496
3815
|
import * as FileSystem9 from "effect/FileSystem";
|
|
3497
|
-
import * as
|
|
3498
|
-
import * as
|
|
3499
|
-
import * as
|
|
3500
|
-
import * as
|
|
3501
|
-
var DiffMismatch = class extends
|
|
3502
|
-
path:
|
|
3503
|
-
message:
|
|
3816
|
+
import * as Path9 from "effect/Path";
|
|
3817
|
+
import * as Schema11 from "effect/Schema";
|
|
3818
|
+
import * as Stream5 from "effect/Stream";
|
|
3819
|
+
import * as ChildProcess4 from "effect/process/ChildProcess";
|
|
3820
|
+
var DiffMismatch = class extends Schema11.TaggedError()("DiffMismatch", {
|
|
3821
|
+
path: Schema11.String,
|
|
3822
|
+
message: Schema11.String
|
|
3504
3823
|
}) {
|
|
3505
3824
|
};
|
|
3506
|
-
var parseDiff = (text, path) =>
|
|
3825
|
+
var parseDiff = (text, path) => Effect9.try({
|
|
3507
3826
|
try: () => {
|
|
3508
3827
|
const fail4 = (message) => {
|
|
3509
3828
|
throw new DiffParseError({ path, message });
|
|
@@ -3579,21 +3898,21 @@ var parseDiff = (text, path) => Effect8.try({
|
|
|
3579
3898
|
if (!sawFile) fail4("No unified diff found");
|
|
3580
3899
|
return patches;
|
|
3581
3900
|
},
|
|
3582
|
-
catch: (error3) =>
|
|
3901
|
+
catch: (error3) => Schema11.is(DiffParseError)(error3) ? error3 : new DiffParseError({ path, message: String(error3) })
|
|
3583
3902
|
});
|
|
3584
|
-
var selectDiffScope =
|
|
3903
|
+
var selectDiffScope = Effect9.fn("selectDiffScope")(function* (options) {
|
|
3585
3904
|
const fs = yield* FileSystem9.FileSystem;
|
|
3586
|
-
const path = yield*
|
|
3905
|
+
const path = yield* Path9.Path;
|
|
3587
3906
|
const diffPath = path.resolve(options.root, options.diffPath);
|
|
3588
|
-
const text = options.diffText ?? (yield* fs.readFileString(diffPath).pipe(
|
|
3907
|
+
const text = options.diffText ?? (yield* fs.readFileString(diffPath).pipe(Effect9.mapError((error3) => new DiffParseError({ path: diffPath, message: String(error3) }))));
|
|
3589
3908
|
const patches = yield* parseDiff(text, diffPath);
|
|
3590
|
-
const gitRoot = yield*
|
|
3591
|
-
const handle = yield*
|
|
3592
|
-
const [output, code] = yield*
|
|
3909
|
+
const gitRoot = yield* Effect9.scoped(Effect9.gen(function* () {
|
|
3910
|
+
const handle = yield* ChildProcess4.make("git", ["rev-parse", "--show-toplevel"], { cwd: options.root, stderr: "ignore" });
|
|
3911
|
+
const [output, code] = yield* Effect9.all([Stream5.mkString(Stream5.decodeText(handle.stdout)), handle.exitCode], { concurrency: "unbounded" });
|
|
3593
3912
|
if (Number(code) !== 0 || !output.trim()) return options.root;
|
|
3594
3913
|
const physicalRoot = yield* fs.realPath(options.root);
|
|
3595
3914
|
return path.resolve(options.root, path.relative(physicalRoot, output.trim()));
|
|
3596
|
-
})).pipe(
|
|
3915
|
+
})).pipe(Effect9.catch(() => Effect9.succeed(options.root)));
|
|
3597
3916
|
const changed = /* @__PURE__ */ new Map();
|
|
3598
3917
|
for (const patch of patches) {
|
|
3599
3918
|
const repositoryPath = path.resolve(gitRoot, patch.file);
|
|
@@ -3605,7 +3924,7 @@ var selectDiffScope = Effect8.fn("selectDiffScope")(function* (options) {
|
|
|
3605
3924
|
return yield* new DiffParseError({ path: diffPath, message: "Diff path escapes repository root" });
|
|
3606
3925
|
}
|
|
3607
3926
|
if (!(yield* fs.exists(candidate))) continue;
|
|
3608
|
-
const current = yield* fs.readFileString(candidate).pipe(
|
|
3927
|
+
const current = yield* fs.readFileString(candidate).pipe(Effect9.mapError((error3) => new DiffMismatch({ path: patch.file, message: String(error3) })));
|
|
3609
3928
|
const lines2 = current.split("\n");
|
|
3610
3929
|
const finalLine = current.endsWith("\n") ? lines2.length - 1 : lines2.length;
|
|
3611
3930
|
if (patch.lines.every((line) => {
|
|
@@ -3639,6 +3958,8 @@ var errorExitCode = (error3) => {
|
|
|
3639
3958
|
return 4;
|
|
3640
3959
|
case "BaselineTimedOut":
|
|
3641
3960
|
return 3;
|
|
3961
|
+
case "TestSpawnError":
|
|
3962
|
+
return error3.kind === "vitest-version" ? 8 : 70;
|
|
3642
3963
|
case "DiffMismatch":
|
|
3643
3964
|
return 5;
|
|
3644
3965
|
case "DiffParseError":
|
|
@@ -3657,12 +3978,12 @@ var errorExitCode = (error3) => {
|
|
|
3657
3978
|
|
|
3658
3979
|
// packages/cli/src/Reporter.ts
|
|
3659
3980
|
import * as Clock5 from "effect/Clock";
|
|
3660
|
-
import * as
|
|
3661
|
-
import * as
|
|
3981
|
+
import * as Console6 from "effect/Console";
|
|
3982
|
+
import * as Effect10 from "effect/Effect";
|
|
3662
3983
|
import * as FileSystem11 from "effect/FileSystem";
|
|
3663
3984
|
import * as Layer4 from "effect/Layer";
|
|
3664
|
-
import * as
|
|
3665
|
-
import * as
|
|
3985
|
+
import * as Path11 from "effect/Path";
|
|
3986
|
+
import * as Schema12 from "effect/Schema";
|
|
3666
3987
|
import * as Semaphore2 from "effect/Semaphore";
|
|
3667
3988
|
|
|
3668
3989
|
// packages/cli/src/UnifiedDiff.ts
|
|
@@ -3788,14 +4109,14 @@ var shortType = (text) => {
|
|
|
3788
4109
|
return line.length > 80 ? line.slice(0, 79) + "\u2026" : line;
|
|
3789
4110
|
};
|
|
3790
4111
|
var outcomes = ["caught", "missed", "timeout", "unviable", "untested", "unreliable"];
|
|
3791
|
-
var jsonReport =
|
|
4112
|
+
var jsonReport = Schema12.encodeEffect(Schema12.fromJsonString(RunReport));
|
|
3792
4113
|
var logText = (result5) => [
|
|
3793
4114
|
..."output" in result5 && typeof result5.output === "string" ? [result5.output] : [],
|
|
3794
4115
|
...result5.diagnostics
|
|
3795
4116
|
].join("\n");
|
|
3796
|
-
var makeReporter =
|
|
4117
|
+
var makeReporter = Effect10.fn("makeReporter")(function* (options) {
|
|
3797
4118
|
const fs = yield* FileSystem11.FileSystem;
|
|
3798
|
-
const path = yield*
|
|
4119
|
+
const path = yield* Path11.Path;
|
|
3799
4120
|
const dir = path.resolve(options.root, options.outDir);
|
|
3800
4121
|
const started = yield* Clock5.currentTimeMillis;
|
|
3801
4122
|
const semaphore = yield* Semaphore2.make(1);
|
|
@@ -3809,7 +4130,7 @@ var makeReporter = Effect9.fn("makeReporter")(function* (options) {
|
|
|
3809
4130
|
if (!/^[A-Za-z0-9_-]+$/.test(mutant.id) || ids.has(mutant.id)) return yield* writeError("Mutant ids must be unique safe filenames");
|
|
3810
4131
|
ids.add(mutant.id);
|
|
3811
4132
|
}
|
|
3812
|
-
yield*
|
|
4133
|
+
yield* Effect10.gen(function* () {
|
|
3813
4134
|
const relative2 = path.relative(dir, path.resolve(options.root));
|
|
3814
4135
|
if (relative2 === "" || relative2 !== ".." && !relative2.startsWith(`..${path.sep}`) && !path.isAbsolute(relative2)) {
|
|
3815
4136
|
return yield* new ReportWriteError({ path: dir, message: "Output cannot be the project root or an ancestor" });
|
|
@@ -3824,40 +4145,40 @@ var makeReporter = Effect9.fn("makeReporter")(function* (options) {
|
|
|
3824
4145
|
}
|
|
3825
4146
|
yield* fs.makeDirectory(path.join(dir, "diff"), { recursive: true });
|
|
3826
4147
|
yield* fs.makeDirectory(path.join(dir, "logs"), { recursive: true });
|
|
3827
|
-
}).pipe(
|
|
3828
|
-
const encodedMutants = yield*
|
|
3829
|
-
yield* fs.writeFileString(path.join(dir, "mutants.json"), encodedMutants).pipe(
|
|
4148
|
+
}).pipe(Effect10.mapError(writeError));
|
|
4149
|
+
const encodedMutants = yield* Schema12.encodeEffect(Schema12.fromJsonString(Schema12.Array(Mutant)))(options.mutants).pipe(Effect10.mapError(writeError));
|
|
4150
|
+
yield* fs.writeFileString(path.join(dir, "mutants.json"), encodedMutants).pipe(Effect10.mapError(writeError));
|
|
3830
4151
|
yield* fs.writeFileString(path.join(dir, "not-mutated.txt"), (options.notMutated ?? []).map((item) => `${path.relative(options.root, item.file)}:${item.span?.start.line ?? "?"}:${item.span?.start.column ?? "?"}: ${item.functionName}: ${item.reason}
|
|
3831
|
-
`).join("")).pipe(
|
|
3832
|
-
yield*
|
|
4152
|
+
`).join("")).pipe(Effect10.mapError(writeError));
|
|
4153
|
+
yield* Effect10.forEach(outcomes, (outcome) => fs.writeFileString(path.join(dir, `${outcome}.txt`), ""), { discard: true }).pipe(Effect10.mapError(writeError));
|
|
3833
4154
|
for (const mutant of options.mutants) {
|
|
3834
|
-
const original = yield* fs.readFileString(path.resolve(options.root, mutant.file)).pipe(
|
|
3835
|
-
yield* fs.writeFileString(path.join(dir, "diff", `${mutant.id}.diff`), unifiedDiff(original, original.slice(0, mutant.replacement.startOffset) + mutant.replacement.text + original.slice(mutant.replacement.endOffset), path.relative(options.root, path.resolve(options.root, mutant.file)).replaceAll("\\", "/"))).pipe(
|
|
4155
|
+
const original = yield* fs.readFileString(path.resolve(options.root, mutant.file)).pipe(Effect10.mapError(writeError));
|
|
4156
|
+
yield* fs.writeFileString(path.join(dir, "diff", `${mutant.id}.diff`), unifiedDiff(original, original.slice(0, mutant.replacement.startOffset) + mutant.replacement.text + original.slice(mutant.replacement.endOffset), path.relative(options.root, path.resolve(options.root, mutant.file)).replaceAll("\\", "/"))).pipe(Effect10.mapError(writeError));
|
|
3836
4157
|
}
|
|
3837
|
-
const writeLists = (items) =>
|
|
4158
|
+
const writeLists = (items) => Effect10.forEach(outcomes, (outcome) => {
|
|
3838
4159
|
const lines2 = items.filter((result5) => result5.outcome === outcome).map((result5) => mutantLine(result5.mutant, options.root, path));
|
|
3839
4160
|
return fs.writeFileString(path.join(dir, `${outcome}.txt`), lines2.length === 0 ? "" : lines2.join("\n") + "\n");
|
|
3840
4161
|
}, { discard: true });
|
|
3841
4162
|
const service = Reporter.of({
|
|
3842
|
-
progress: (result5) => semaphore.withPermit(
|
|
4163
|
+
progress: (result5) => semaphore.withPermit(Effect10.gen(function* () {
|
|
3843
4164
|
results.push(result5);
|
|
3844
|
-
if (!options.markdown?.stdout) yield*
|
|
3845
|
-
yield*
|
|
4165
|
+
if (!options.markdown?.stdout) yield* Console6.log(`${result5.outcome} ${mutantLine(result5.mutant, options.root, path)} (${result5.durationMs}ms)`);
|
|
4166
|
+
yield* Effect10.gen(function* () {
|
|
3846
4167
|
if (!ids.has(result5.mutant.id)) return yield* writeError("Progress result does not belong to this report");
|
|
3847
4168
|
yield* writeLists(results);
|
|
3848
4169
|
yield* fs.writeFileString(path.join(dir, "logs", `${result5.mutant.id}.log`), logText(result5));
|
|
3849
|
-
}).pipe(
|
|
4170
|
+
}).pipe(Effect10.catch((error3) => Effect10.gen(function* () {
|
|
3850
4171
|
if (pendingError === void 0) {
|
|
3851
4172
|
pendingError = writeError(error3);
|
|
3852
|
-
yield*
|
|
4173
|
+
yield* Console6.warn(`Report write failed: ${pendingError.message}`);
|
|
3853
4174
|
}
|
|
3854
4175
|
})));
|
|
3855
4176
|
})),
|
|
3856
|
-
write: (report) => semaphore.withPermit(
|
|
4177
|
+
write: (report) => semaphore.withPermit(Effect10.gen(function* () {
|
|
3857
4178
|
if (pendingError !== void 0) return yield* pendingError;
|
|
3858
4179
|
const notMutated = [...new Map([...options.notMutated ?? [], ...report.notMutated ?? []].map((item) => [JSON.stringify(item), item])).values()];
|
|
3859
4180
|
yield* fs.writeFileString(path.join(dir, "not-mutated.txt"), notMutated.map((item) => `${path.relative(options.root, item.file)}:${item.span?.start.line ?? "?"}:${item.span?.start.column ?? "?"}: ${item.functionName}: ${item.reason}
|
|
3860
|
-
`).join("")).pipe(
|
|
4181
|
+
`).join("")).pipe(Effect10.mapError(writeError));
|
|
3861
4182
|
const telemetry = sanitizeReportTelemetry(report);
|
|
3862
4183
|
const counted = {
|
|
3863
4184
|
...telemetry.report,
|
|
@@ -3866,64 +4187,64 @@ var makeReporter = Effect9.fn("makeReporter")(function* (options) {
|
|
|
3866
4187
|
run: report.results.length,
|
|
3867
4188
|
budgetSkipped: options.budgetSkipped ?? 0
|
|
3868
4189
|
};
|
|
3869
|
-
const encoded = yield* jsonReport(counted).pipe(
|
|
3870
|
-
yield* fs.writeFileString(path.join(dir, "outcomes.json.tmp"), encoded).pipe(
|
|
3871
|
-
yield* fs.rename(path.join(dir, "outcomes.json.tmp"), path.join(dir, "outcomes.json")).pipe(
|
|
3872
|
-
yield* writeLists(report.results).pipe(
|
|
4190
|
+
const encoded = yield* jsonReport(counted).pipe(Effect10.mapError(writeError));
|
|
4191
|
+
yield* fs.writeFileString(path.join(dir, "outcomes.json.tmp"), encoded).pipe(Effect10.mapError(writeError));
|
|
4192
|
+
yield* fs.rename(path.join(dir, "outcomes.json.tmp"), path.join(dir, "outcomes.json")).pipe(Effect10.mapError(writeError));
|
|
4193
|
+
yield* writeLists(report.results).pipe(Effect10.mapError(writeError));
|
|
3873
4194
|
for (const result5 of report.results) {
|
|
3874
4195
|
if (!ids.has(result5.mutant.id)) return yield* writeError("Final result does not belong to this report");
|
|
3875
|
-
yield* fs.writeFileString(path.join(dir, "logs", `${result5.mutant.id}.log`), logText(result5)).pipe(
|
|
4196
|
+
yield* fs.writeFileString(path.join(dir, "logs", `${result5.mutant.id}.log`), logText(result5)).pipe(Effect10.mapError(writeError));
|
|
3876
4197
|
}
|
|
3877
4198
|
for (const warning of telemetry.warnings) if (!telemetryWarned.has(warning)) {
|
|
3878
4199
|
telemetryWarned.add(warning);
|
|
3879
|
-
yield*
|
|
4200
|
+
yield* Console6.warn(warning);
|
|
3880
4201
|
}
|
|
3881
4202
|
if (options.markdown !== void 0) {
|
|
3882
4203
|
const markdown = markdownSummary({ ...options.markdown, root: options.root, path, report: counted, notMutated: notMutated.length });
|
|
3883
4204
|
for (const file of new Set(options.markdown.files)) {
|
|
3884
|
-
yield* fs.writeFileString(file, markdown).pipe(
|
|
4205
|
+
yield* fs.writeFileString(file, markdown).pipe(Effect10.mapError((error3) => new ReportWriteError({ path: file, message: String(error3) })));
|
|
3885
4206
|
}
|
|
3886
|
-
if (!summarized && options.markdown.stdout) yield*
|
|
4207
|
+
if (!summarized && options.markdown.stdout) yield* Console6.log(markdown);
|
|
3887
4208
|
}
|
|
3888
4209
|
if (summarized) return;
|
|
3889
4210
|
summarized = true;
|
|
3890
|
-
if (report.results.some((result5) => result5.outcome === "unreliable")) yield*
|
|
4211
|
+
if (report.results.some((result5) => result5.outcome === "unreliable")) yield* Console6.warn("Unreliable: the configured Vitest run cannot see all tests. See unreliable.txt and per-mutant diagnostics; these are not missed mutants.");
|
|
3891
4212
|
const elapsed = (yield* Clock5.currentTimeMillis) - started;
|
|
3892
|
-
if (!options.markdown?.stdout) yield*
|
|
3893
|
-
if (options.markdown === void 0 && report.failure !== void 0) yield*
|
|
4213
|
+
if (!options.markdown?.stdout) yield* Console6.log(countsLine(counted, notMutated.length) + `; ${(elapsed / 1e3).toFixed(2)}s`);
|
|
4214
|
+
if (options.markdown === void 0 && report.failure !== void 0) yield* Console6.warn(report.failure);
|
|
3894
4215
|
}))
|
|
3895
4216
|
});
|
|
3896
4217
|
return service;
|
|
3897
4218
|
});
|
|
3898
4219
|
|
|
3899
4220
|
// packages/cli/src/Git.ts
|
|
3900
|
-
import * as
|
|
4221
|
+
import * as Effect11 from "effect/Effect";
|
|
3901
4222
|
import * as FileSystem13 from "effect/FileSystem";
|
|
3902
|
-
import * as
|
|
3903
|
-
import * as
|
|
3904
|
-
import * as
|
|
3905
|
-
import * as
|
|
3906
|
-
var UsageError = class extends
|
|
4223
|
+
import * as Path13 from "effect/Path";
|
|
4224
|
+
import * as Schema13 from "effect/Schema";
|
|
4225
|
+
import * as Stream6 from "effect/Stream";
|
|
4226
|
+
import * as ChildProcess5 from "effect/process/ChildProcess";
|
|
4227
|
+
var UsageError = class extends Schema13.TaggedError()("UsageError", { message: Schema13.String }) {
|
|
3907
4228
|
};
|
|
3908
|
-
var git =
|
|
4229
|
+
var git = Effect11.fn("git")(function* (root, args) {
|
|
3909
4230
|
const command = `git ${args.join(" ")}`;
|
|
3910
|
-
return yield*
|
|
3911
|
-
const handle = yield*
|
|
3912
|
-
const [stdout, stderr, code] = yield*
|
|
3913
|
-
|
|
3914
|
-
|
|
4231
|
+
return yield* Effect11.scoped(Effect11.gen(function* () {
|
|
4232
|
+
const handle = yield* ChildProcess5.make("git", args, { cwd: root });
|
|
4233
|
+
const [stdout, stderr, code] = yield* Effect11.all([
|
|
4234
|
+
Stream6.mkString(Stream6.decodeText(handle.stdout)),
|
|
4235
|
+
Stream6.mkString(Stream6.decodeText(handle.stderr)),
|
|
3915
4236
|
handle.exitCode
|
|
3916
4237
|
], { concurrency: "unbounded" });
|
|
3917
4238
|
if (Number(code) !== 0) return yield* new UsageError({ message: `${command}:
|
|
3918
4239
|
${stderr}` });
|
|
3919
4240
|
return stdout;
|
|
3920
|
-
})).pipe(
|
|
4241
|
+
})).pipe(Effect11.mapError((error3) => error3._tag === "UsageError" ? error3 : new UsageError({ message: `${command}: ${String(error3)}` })));
|
|
3921
4242
|
});
|
|
3922
|
-
var repositoryRoot =
|
|
3923
|
-
const path = yield*
|
|
4243
|
+
var repositoryRoot = Effect11.fn("repositoryRoot")(function* (root) {
|
|
4244
|
+
const path = yield* Path13.Path;
|
|
3924
4245
|
const fs = yield* FileSystem13.FileSystem;
|
|
3925
4246
|
const top = (yield* git(root, ["rev-parse", "--show-toplevel"])).trim();
|
|
3926
|
-
const physical = yield* fs.realPath(root).pipe(
|
|
4247
|
+
const physical = yield* fs.realPath(root).pipe(Effect11.mapError((error3) => new UsageError({ message: String(error3) })));
|
|
3927
4248
|
return path.resolve(root, path.relative(physical, top));
|
|
3928
4249
|
});
|
|
3929
4250
|
|
|
@@ -3950,9 +4271,9 @@ var flags = {
|
|
|
3950
4271
|
output: Flag.String("output").pipe(Flag.withDefault("mutants.out"), Flag.withDescription("Report directory; default mutants.out")),
|
|
3951
4272
|
tsconfig: Flag.String("tsconfig").pipe(Flag.withDefault("tsconfig.json"), Flag.withDescription("TypeScript project path; default tsconfig.json"))
|
|
3952
4273
|
};
|
|
3953
|
-
var makeCommand = (options) => Command.make("mutant-cafe", flags, (input) =>
|
|
4274
|
+
var makeCommand = (options) => Command.make("mutant-cafe", flags, (input) => Effect12.gen(function* () {
|
|
3954
4275
|
const fs = yield* FileSystem15.FileSystem;
|
|
3955
|
-
const path = yield*
|
|
4276
|
+
const path = yield* Path15.Path;
|
|
3956
4277
|
const root = path.resolve(options.root);
|
|
3957
4278
|
if (input.cold && input.warm) return yield* new UsageError({ message: "--warm and --cold are mutually exclusive" });
|
|
3958
4279
|
const range = Option.getOrUndefined(input.inDiffRange);
|
|
@@ -3966,15 +4287,15 @@ var makeCommand = (options) => Command.make("mutant-cafe", flags, (input) => Eff
|
|
|
3966
4287
|
if (maxMutants !== void 0 && (!Number.isSafeInteger(maxMutants) || maxMutants < 0)) return yield* new UsageError({ message: "--max-mutants must be a nonnegative safe integer" });
|
|
3967
4288
|
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" });
|
|
3968
4289
|
if (/[\r\n]/.test(input.summaryMarker)) return yield* new UsageError({ message: "--summary-marker must be one line" });
|
|
3969
|
-
const gitRoot = range !== void 0 ? yield* repositoryRoot(root) : yield* repositoryRoot(root).pipe(
|
|
4290
|
+
const gitRoot = range !== void 0 ? yield* repositoryRoot(root) : yield* repositoryRoot(root).pipe(Effect12.catch(() => Effect12.succeed(root)));
|
|
3970
4291
|
const diffText = range === void 0 ? void 0 : yield* git(gitRoot, ["diff", "--no-ext-diff", "--no-color", range, "--"]);
|
|
3971
4292
|
const configPath = path.join(root, "mutants.config.json");
|
|
3972
4293
|
const fileConfig = (yield* fs.exists(configPath)) ? yield* fs.readFileString(configPath).pipe(
|
|
3973
|
-
|
|
3974
|
-
|
|
4294
|
+
Effect12.flatMap(Schema14.decodeEffect(Schema14.fromJsonString(ConfigFile))),
|
|
4295
|
+
Effect12.mapError((error3) => new UsageError({ message: `Invalid mutants.config.json: ${String(error3)}` }))
|
|
3975
4296
|
) : {};
|
|
3976
4297
|
const timeoutMs = Option.map(input.timeout, (seconds) => Math.ceil(seconds * 1e3));
|
|
3977
|
-
const config = yield*
|
|
4298
|
+
const config = yield* Schema14.decodeEffect(RunConfig)({
|
|
3978
4299
|
root,
|
|
3979
4300
|
tsconfig: input.tsconfig,
|
|
3980
4301
|
exportedOnly: input.exportedOnly,
|
|
@@ -3991,25 +4312,28 @@ var makeCommand = (options) => Command.make("mutant-cafe", flags, (input) => Eff
|
|
|
3991
4312
|
minimumTimeoutMs: Option.match(input.minimumTimeout, { onNone: () => fileConfig.minimumTimeoutMs ?? 2e4, onSome: (seconds) => Math.ceil(seconds * 1e3) }),
|
|
3992
4313
|
neverTimeoutMs: 1e3,
|
|
3993
4314
|
outDir: input.output
|
|
3994
|
-
}).pipe(
|
|
4315
|
+
}).pipe(Effect12.mapError((error3) => new UsageError({ message: String(error3) })));
|
|
3995
4316
|
if (config.jobs < 1 || config.timeoutMultiplier <= 0 || config.minimumTimeoutMs <= 0 || config.timeoutMs !== void 0 && config.timeoutMs <= 0 || config.baselineTimeoutMs !== void 0 && config.baselineTimeoutMs <= 0) {
|
|
3996
4317
|
return yield* new UsageError({ message: "Jobs and timeout values must be positive" });
|
|
3997
4318
|
}
|
|
3998
4319
|
const source = yield* MutantSource;
|
|
3999
|
-
const generated = yield*
|
|
4000
|
-
|
|
4320
|
+
const generated = yield* Stream7.runCollect(source.generate(config)).pipe(
|
|
4321
|
+
Effect12.mapError((error3) => error3.reason === "selection" ? new UsageError({ message: error3.diagnostics.join("\n") }) : error3)
|
|
4001
4322
|
);
|
|
4002
4323
|
const skipped2 = yield* source.notMutated(config);
|
|
4003
4324
|
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 });
|
|
4325
|
+
const scratch = yield* Scratch;
|
|
4326
|
+
const roots = selected.mutants.length && scratch.inspect ? yield* scratch.inspect(root) : [];
|
|
4327
|
+
const eligible = yield* excludeLinkedCandidates(root, selected.mutants, roots);
|
|
4004
4328
|
const relative2 = (mutant) => path.relative(gitRoot, path.resolve(root, mutant.file)).replaceAll("\\", "/");
|
|
4005
4329
|
const compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
4006
|
-
const ordered = [...
|
|
4330
|
+
const ordered = [...eligible.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));
|
|
4007
4331
|
const mutants = ordered.slice(0, maxMutants);
|
|
4008
|
-
const notMutated = selected.notMutated;
|
|
4332
|
+
const notMutated = [...new Map([...selected.notMutated, ...eligible.notMutated].map((entry) => [JSON.stringify(entry), entry])).values()];
|
|
4009
4333
|
const counts = { selected: ordered.length, run: 0, budgetSkipped: ordered.length - mutants.length };
|
|
4010
4334
|
if (mutants.length === 0) {
|
|
4011
|
-
const cause = ordered.length > 0 ? "budget" : range !== void 0 ? "range" : inDiff !== void 0 || diffText !== void 0 ? "diff" : config.functionFilter.length || config.exportedOnly ? "filter" : "file selection";
|
|
4012
|
-
yield*
|
|
4335
|
+
const cause = ordered.length > 0 ? "budget" : eligible.notMutated.length > 0 ? "linked ignored trees" : range !== void 0 ? "range" : inDiff !== void 0 || diffText !== void 0 ? "diff" : config.functionFilter.length || config.exportedOnly ? "filter" : "file selection";
|
|
4336
|
+
yield* Console7.error(`0 mutants selected (${counts.selected} before budget); cause: ${cause}. Baseline skipped.`);
|
|
4013
4337
|
}
|
|
4014
4338
|
const markdown = input.format === "github" || summaryMd !== void 0 ? {
|
|
4015
4339
|
gitRoot,
|
|
@@ -4030,33 +4354,33 @@ var makeCommand = (options) => Command.make("mutant-cafe", flags, (input) => Eff
|
|
|
4030
4354
|
report: { schemaVersion: 2, tool: "mutant.cafe", root, baseline: { durationMs: 0, testCommand: [] }, timeoutMs: 0, results: [], ...counts }
|
|
4031
4355
|
});
|
|
4032
4356
|
for (const file of new Set(markdown.files)) yield* fs.writeFileString(file, text).pipe(
|
|
4033
|
-
|
|
4357
|
+
Effect12.mapError((error3) => new ReportWriteError({ path: file, message: String(error3) }))
|
|
4034
4358
|
);
|
|
4035
4359
|
if (markdown.stdout) {
|
|
4036
|
-
yield*
|
|
4360
|
+
yield* Console7.log(text);
|
|
4037
4361
|
if (options.onExit !== void 0) yield* options.onExit(0);
|
|
4038
4362
|
return;
|
|
4039
4363
|
}
|
|
4040
4364
|
}
|
|
4041
4365
|
if (input.list && input.format === "json") {
|
|
4042
|
-
yield*
|
|
4366
|
+
yield* Console7.log(yield* Schema14.encodeEffect(Schema14.fromJsonString(MutantList))({ schemaVersion: 2, tool: "mutant.cafe", mutants, notMutated, counts }));
|
|
4043
4367
|
if (options.onExit !== void 0) yield* options.onExit(0);
|
|
4044
4368
|
return;
|
|
4045
4369
|
}
|
|
4046
4370
|
if (input.list) {
|
|
4047
|
-
for (const mutant of mutants) yield*
|
|
4371
|
+
for (const mutant of mutants) yield* Console7.log(mutantLine(mutant, config.root, path));
|
|
4048
4372
|
const perFile = /* @__PURE__ */ new Map();
|
|
4049
4373
|
for (const mutant of mutants) {
|
|
4050
4374
|
const file = path.relative(root, path.resolve(root, mutant.file));
|
|
4051
4375
|
perFile.set(file, (perFile.get(file) ?? 0) + 1);
|
|
4052
4376
|
}
|
|
4053
|
-
for (const [file, count] of [...perFile].sort(([a], [b]) => a.localeCompare(b))) yield*
|
|
4054
|
-
yield*
|
|
4377
|
+
for (const [file, count] of [...perFile].sort(([a], [b]) => a.localeCompare(b))) yield* Console7.log(`${file}: ${count} mutants`);
|
|
4378
|
+
yield* Console7.log(`${mutants.length} mutants total; ${notMutated.length} not mutated; ${counts.selected} selected, 0 run, ${counts.budgetSkipped} budget-skipped`);
|
|
4055
4379
|
if (options.onExit !== void 0) yield* options.onExit(0);
|
|
4056
4380
|
return;
|
|
4057
4381
|
}
|
|
4058
4382
|
const reporter = yield* makeReporter({ root, outDir: config.outDir, mutants, notMutated, selected: counts.selected, budgetSkipped: counts.budgetSkipped, ...markdown === void 0 ? {} : { markdown } });
|
|
4059
|
-
const report = yield* (mutants.length === 0 ?
|
|
4383
|
+
const report = yield* (mutants.length === 0 ? Effect12.succeed({
|
|
4060
4384
|
schemaVersion: 2,
|
|
4061
4385
|
tool: "mutant.cafe",
|
|
4062
4386
|
root,
|
|
@@ -4064,8 +4388,8 @@ var makeCommand = (options) => Command.make("mutant-cafe", flags, (input) => Eff
|
|
|
4064
4388
|
timeoutMs: 0,
|
|
4065
4389
|
results: []
|
|
4066
4390
|
}) : options.run(config, mutants)).pipe(
|
|
4067
|
-
|
|
4068
|
-
|
|
4391
|
+
Effect12.provideService(Reporter, reporter),
|
|
4392
|
+
Effect12.catchTag("BaselineFailed", (error3) => Effect12.gen(function* () {
|
|
4069
4393
|
const failed = {
|
|
4070
4394
|
schemaVersion: 2,
|
|
4071
4395
|
tool: "mutant.cafe",
|
|
@@ -4078,10 +4402,10 @@ ${error3.output.slice(-8e3)}`
|
|
|
4078
4402
|
};
|
|
4079
4403
|
yield* reporter.write(failed);
|
|
4080
4404
|
if (!input.advisory) return yield* error3;
|
|
4081
|
-
if (markdown === void 0) yield*
|
|
4405
|
+
if (markdown === void 0) yield* Console7.log("Advisory: baseline failed; would exit 4 without --advisory.");
|
|
4082
4406
|
return failed;
|
|
4083
4407
|
})),
|
|
4084
|
-
|
|
4408
|
+
Effect12.catchTag("BaselineTimedOut", (error3) => Effect12.gen(function* () {
|
|
4085
4409
|
const timedOut = {
|
|
4086
4410
|
schemaVersion: 2,
|
|
4087
4411
|
tool: "mutant.cafe",
|
|
@@ -4096,22 +4420,22 @@ ${error3.output.slice(-8e3)}`
|
|
|
4096
4420
|
return timedOut;
|
|
4097
4421
|
}))
|
|
4098
4422
|
);
|
|
4099
|
-
if (input.advisory && reportExitCode(report) !== 0 && markdown === void 0) yield*
|
|
4423
|
+
if (input.advisory && reportExitCode(report) !== 0 && markdown === void 0) yield* Console7.log(`Advisory: would exit ${reportExitCode(report)} without --advisory.`);
|
|
4100
4424
|
yield* reporter.write(report);
|
|
4101
4425
|
if (options.onExit !== void 0) yield* options.onExit(input.advisory ? 0 : reportExitCode(report));
|
|
4102
4426
|
}));
|
|
4103
|
-
var runCli =
|
|
4427
|
+
var runCli = Effect12.fn("runCli")(function* (options) {
|
|
4104
4428
|
const code = yield* Ref.make(0);
|
|
4105
4429
|
const command = makeCommand({ ...options, onExit: (value) => Ref.set(code, value) });
|
|
4106
|
-
yield* Command.runWith(command, { version: "0.1.
|
|
4107
|
-
|
|
4108
|
-
yield*
|
|
4109
|
-
${error3.diagnostics.join("\n")}` : error3._tag === "BaselineTimedOut" ? error3.message : error3._tag === "BaselineFailed" ? `Baseline failed (${error3.exitCode}): ${formatTestCommand(error3.command)}
|
|
4430
|
+
yield* Command.runWith(command, { version: "0.1.8" })(options.args).pipe(
|
|
4431
|
+
Effect12.catch((error3) => Effect12.gen(function* () {
|
|
4432
|
+
yield* Console7.error(error3._tag === "ProgramLoadError" ? `${error3.tsconfig}:
|
|
4433
|
+
${error3.diagnostics.join("\n")}` : error3._tag === "TestSpawnError" && error3.kind === "vitest-version" ? error3.message : error3._tag === "BaselineTimedOut" ? error3.message : error3._tag === "BaselineFailed" ? `Baseline failed (${error3.exitCode}): ${formatTestCommand(error3.command)}
|
|
4110
4434
|
${error3.output.slice(-8e3)}` : String(error3));
|
|
4111
4435
|
yield* Ref.set(code, errorExitCode(error3));
|
|
4112
4436
|
})),
|
|
4113
|
-
|
|
4114
|
-
yield*
|
|
4437
|
+
Effect12.catchDefect((defect) => Effect12.gen(function* () {
|
|
4438
|
+
yield* Console7.error(`Internal error: ${String(defect)}`);
|
|
4115
4439
|
yield* Ref.set(code, 70);
|
|
4116
4440
|
}))
|
|
4117
4441
|
);
|
|
@@ -4119,15 +4443,15 @@ ${error3.output.slice(-8e3)}` : String(error3));
|
|
|
4119
4443
|
});
|
|
4120
4444
|
|
|
4121
4445
|
// packages/cli/src/bin.ts
|
|
4122
|
-
var run = (config, mutants) => runMutants(config,
|
|
4446
|
+
var run = (config, mutants) => runMutants(config, Stream8.fromIterable(mutants));
|
|
4123
4447
|
var live = Layer5.mergeAll(MutantSourceLive, ScratchLive, TestRunnerLive).pipe(
|
|
4124
4448
|
Layer5.provideMerge(NodeServices.layer)
|
|
4125
4449
|
);
|
|
4126
|
-
var main =
|
|
4450
|
+
var main = Effect13.gen(function* () {
|
|
4127
4451
|
const code = yield* runCli({ root: process.cwd(), args: process.argv.slice(2), run });
|
|
4128
|
-
yield*
|
|
4452
|
+
yield* Effect13.sync(() => {
|
|
4129
4453
|
process.exitCode = code;
|
|
4130
4454
|
});
|
|
4131
|
-
}).pipe(
|
|
4455
|
+
}).pipe(Effect13.provide(live));
|
|
4132
4456
|
NodeRuntime.runMain(main);
|
|
4133
4457
|
//# sourceMappingURL=bin.js.map
|