mutant-cafe 0.1.1 → 0.1.2

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/dist/bin.js CHANGED
@@ -33,6 +33,7 @@ var ConfigFile = Schema.Struct({
33
33
  import * as Schema2 from "effect/Schema";
34
34
  var ProgramLoadError = class extends Schema2.TaggedError()("ProgramLoadError", {
35
35
  tsconfig: Schema2.String,
36
+ reason: Schema2.optional(Schema2.Literal("selection")),
36
37
  diagnostics: Schema2.Array(Schema2.String)
37
38
  }) {
38
39
  };
@@ -69,6 +70,7 @@ var Genre = Schema3.Literals([
69
70
  "EffectSucceed",
70
71
  "EffectFail",
71
72
  "SwallowTag",
73
+ "TagToDefect",
72
74
  "EffectDie",
73
75
  "EffectNever",
74
76
  "OptionNone",
@@ -96,13 +98,14 @@ var Mutant = Schema3.Struct({
96
98
  file: Schema3.String,
97
99
  functionName: Schema3.String,
98
100
  returnType: Schema3.String,
101
+ displayReturnType: Schema3.optional(Schema3.String),
99
102
  genre: Genre,
100
103
  description: Schema3.String,
101
104
  span: Span,
102
105
  replacement: Replacement,
103
106
  synthetic: Schema3.Boolean
104
107
  });
105
- var Outcome = Schema3.Literals(["caught", "missed", "unviable", "timeout"]);
108
+ var Outcome = Schema3.Literals(["caught", "missed", "unviable", "timeout", "untested"]);
106
109
  var MutantResult = Schema3.Struct({
107
110
  mutant: Mutant,
108
111
  outcome: Outcome,
@@ -146,27 +149,30 @@ import { createHash } from "node:crypto";
146
149
  function* generateFunction(fn7) {
147
150
  const api = fn7.api;
148
151
  const candidate = (genre, expression, value = { text: "", synthetic: false }, description = expression) => {
149
- const text = fn7.block ? `{ return ${fn7.generator ? "yield* " : ""}${expression}; }` : `(${expression})`;
152
+ const pinned = `((): ${fn7.returnType} => (${expression}))()`;
153
+ const text = fn7.block ? `{ return ${fn7.generator ? "yield* " : ""}${pinned}; }` : `(${pinned})`;
150
154
  return makeMutant(fn7, genre, text, value.synthetic, description);
151
155
  };
152
156
  const shape = fn7.shape;
153
157
  switch (shape.kind) {
154
158
  case "Effect": {
155
- const succeed2 = api("Effect", "succeed");
156
- if (succeed2) {
157
- for (const value of shape.values) yield candidate("EffectSucceed", `${succeed2}(${value.text})`, value);
159
+ const succeed3 = api("Effect", "succeed");
160
+ if (succeed3) {
161
+ for (const value of shape.values) {
162
+ if (!fn7.equivalentValues.includes(value.text)) yield candidate("EffectSucceed", `${succeed3}(${value.text})`, value);
163
+ }
158
164
  }
159
165
  const fail4 = api("Effect", "fail");
160
166
  const catchTag2 = api("Effect", "catchTag");
161
167
  for (const error2 of shape.errors) {
162
- if (fail4) yield candidate("EffectFail", `${fail4}(${error2.text})`, error2);
168
+ if (fail4) yield candidate("EffectFail", `${fail4}(${error2.text})`, error2, `${fail4}(${error2.text}) [${error2.synthetic ? "synthetic tag cast" : "constructed error"}]`);
163
169
  const value = shape.values[0];
164
170
  const die3 = api("Effect", "die");
165
- const recovery = value && succeed2 ? `${succeed2}(${value.text})` : die3 ? `${die3}(${JSON.stringify(`mutant.cafe: swallowed ${error2.tag}`)})` : void 0;
171
+ const recovery = value && succeed3 ? `${succeed3}(${value.text})` : die3 ? `${die3}(${JSON.stringify(`mutant.cafe: swallowed ${error2.tag}`)})` : void 0;
166
172
  if (catchTag2 && recovery) {
167
- const gen7 = api("Effect", "gen");
168
- const original = fn7.generator ? gen7 && `((): ${fn7.returnType} => ${gen7}(function* () ${fn7.original}))()` : fn7.block ? `((): ${fn7.returnType} => ${fn7.original})()` : `((): ${fn7.returnType} => (${fn7.original}))()`;
169
- if (original) yield candidate("SwallowTag", `${original}.pipe(${catchTag2}(${JSON.stringify(error2.tag)}, () => ${recovery}))`, value, `body.pipe(${catchTag2}(${JSON.stringify(error2.tag)}, () => ${recovery}))`);
173
+ const gen8 = api("Effect", "gen");
174
+ const original = fn7.generator ? gen8 && `((): ${fn7.returnType} => ${gen8}(function* () ${fn7.original}))()` : fn7.block ? `((): ${fn7.returnType} => ${fn7.original})()` : `((): ${fn7.returnType} => (${fn7.original}))()`;
175
+ if (original) yield candidate(value ? "SwallowTag" : "TagToDefect", `${original}.pipe(${catchTag2}(${JSON.stringify(error2.tag)}, () => ${recovery}))`, value, value ? `body.pipe(${catchTag2}(${JSON.stringify(error2.tag)}, () => ${recovery}))` : `turn ${error2.tag} into a defect`);
170
176
  }
171
177
  }
172
178
  const die2 = api("Effect", "die");
@@ -184,18 +190,18 @@ function* generateFunction(fn7) {
184
190
  }
185
191
  case "Stream": {
186
192
  const empty = api("Stream", "empty");
187
- const make6 = api("Stream", "make");
193
+ const make7 = api("Stream", "make");
188
194
  const fail4 = api("Stream", "fail");
189
195
  if (empty) yield candidate("StreamEmpty", empty);
190
- if (make6) for (const value of shape.values) yield candidate("StreamOne", `${make6}(${value.text})`, value);
196
+ if (make7) for (const value of shape.values) yield candidate("StreamOne", `${make7}(${value.text})`, value);
191
197
  if (fail4) for (const error2 of shape.errors) yield candidate("StreamFail", `${fail4}(${error2.text})`, error2);
192
198
  break;
193
199
  }
194
200
  case "Layer": {
195
- const layer2 = api("Layer", "effect");
201
+ const layer2 = api("Layer", "effectContext");
196
202
  const fail4 = api("Effect", "fail");
197
203
  if (layer2 && fail4 && shape.service) {
198
- for (const error2 of shape.errors) yield candidate("LayerFail", `${layer2}(${shape.service}, ${fail4}(${error2.text}))`, error2);
204
+ for (const error2 of shape.errors) yield candidate("LayerFail", `${layer2}(${fail4}(${error2.text}))`, error2);
199
205
  }
200
206
  break;
201
207
  }
@@ -219,6 +225,7 @@ function makeMutant(fn7, genre, text, synthetic, description) {
219
225
  file: fn7.file,
220
226
  functionName: fn7.name,
221
227
  returnType: fn7.returnType,
228
+ displayReturnType: fn7.displayReturnType,
222
229
  genre,
223
230
  description: `replace ${fn7.name} -> ${fn7.returnType} with ${description}`,
224
231
  span: fn7.span,
@@ -295,11 +302,13 @@ function makeTypeScriptOracle() {
295
302
  sessions.set(configPath, session);
296
303
  }
297
304
  const checker = session.program.getTypeChecker();
305
+ const matched = /* @__PURE__ */ new Set();
298
306
  for (const source of session.program.getSourceFiles()) {
299
307
  const file = resolve(source.fileName);
300
308
  const local = relative(config.root, file).replaceAll("\\", "/");
301
309
  const project = relative(dirname(configPath), file).replaceAll("\\", "/");
302
310
  if (source.isDeclarationFile || local.startsWith("../") || /(?:^|\/)(?:node_modules|__tests__|__mocks__|tests?)\//.test(project) || /\.(?:test|spec)\.[cm]?[jt]sx?$/.test(local)) continue;
311
+ for (const glob of config.include) if (matchesGlob(local, glob)) matched.add(glob);
303
312
  if (config.include.length && !config.include.some((glob) => matchesGlob(local, glob))) continue;
304
313
  if (config.exclude.some((glob) => matchesGlob(local, glob))) continue;
305
314
  owners.set(file, session);
@@ -318,10 +327,14 @@ function makeTypeScriptOracle() {
318
327
  const end = body.getEnd();
319
328
  const a = source.getLineAndCharacterOfPosition(start);
320
329
  const b = source.getLineAndCharacterOfPosition(end);
330
+ const shape = shapeOf(type, checker, node, body);
331
+ const originals = equivalentSuccessValues(body, api);
321
332
  found.push({
322
333
  file,
323
334
  name,
324
- returnType: checker.typeToString(type, node, ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | ts.TypeFormatFlags.NoTruncation),
335
+ returnType: returnTypeText(type, checker, node),
336
+ displayReturnType: node.type?.getText(source) ?? checker.typeToString(type, node),
337
+ equivalentValues: shape.kind === "Effect" ? shape.values.filter((value) => isEquivalentSuccess(value.text, originals)).map((value) => value.text) : [],
325
338
  span: { start: { line: a.line + 1, column: a.character + 1 }, end: { line: b.line + 1, column: b.character + 1 } },
326
339
  startOffset: start,
327
340
  endOffset: end,
@@ -329,7 +342,7 @@ function makeTypeScriptOracle() {
329
342
  literal: literalOfBody(body, checker),
330
343
  block: ts.isBlock(body),
331
344
  generator: generator !== void 0,
332
- shape: shapeOf(type, checker, node, body),
345
+ shape,
333
346
  api
334
347
  });
335
348
  }
@@ -342,6 +355,12 @@ function makeTypeScriptOracle() {
342
355
  visit(source);
343
356
  yield* found;
344
357
  }
358
+ const unmatched = config.include.filter((glob) => !matched.has(glob));
359
+ if (unmatched.length) throw new ProgramLoadError({ tsconfig: configPath, reason: "selection", diagnostics: unmatched.map((glob) => {
360
+ const target = relative(config.root, resolve(config.root, glob));
361
+ const outside = target === ".." || target.startsWith("../");
362
+ return `No source file matched ${JSON.stringify(glob)}${outside ? " (path is outside the package root)" : ""}`;
363
+ }) });
345
364
  },
346
365
  checkViable(mutant) {
347
366
  const session = owners.get(resolve(mutant.file));
@@ -376,6 +395,13 @@ function skipped(node) {
376
395
  return false;
377
396
  }
378
397
  function functionName(node) {
398
+ if (ts.isFunctionExpression(node) && node.asteriskToken) {
399
+ let enclosing = node.parent;
400
+ while (!ts.isSourceFile(enclosing)) {
401
+ if (ts.isVariableDeclaration(enclosing)) return enclosing.name.getText();
402
+ enclosing = enclosing.parent;
403
+ }
404
+ }
379
405
  if (node.name) {
380
406
  if (ts.isMethodDeclaration(node) && ts.isClassLike(node.parent) && node.parent.name) return `${node.parent.name.text}.${node.name.getText()}`;
381
407
  return node.name.getText();
@@ -472,6 +498,16 @@ function family(type, checker) {
472
498
  return void 0;
473
499
  }
474
500
  function shapeOf(type, checker, node, body) {
501
+ if (type.isUnion() && type.types.every((member) => family(member, checker)?.kind === "Effect")) {
502
+ const shapes = type.types.map((member) => shapeOf(member, checker, node, body));
503
+ const values = shapes.flatMap((shape) => shape.kind === "Effect" ? shape.values : []);
504
+ const errors = shapes.flatMap((shape) => shape.kind === "Effect" ? shape.errors : []);
505
+ return {
506
+ kind: "Effect",
507
+ values: [...new Map(values.map((value) => [value.text, value])).values()].sort((a, b) => a.text.localeCompare(b.text, "en")),
508
+ errors: [...new Map(errors.map((error2) => [error2.tag, error2])).values()].sort((a, b) => a.tag.localeCompare(b.tag, "en"))
509
+ };
510
+ }
475
511
  const detected = family(type, checker);
476
512
  if (detected) {
477
513
  const [a, e] = detected.args;
@@ -512,9 +548,10 @@ function taggedValues(type, checker, location) {
512
548
  function constructError(type, checker, location, tag) {
513
549
  const symbol = type.getSymbol();
514
550
  if (symbol) {
515
- const visible = checker.getSymbolsInScope(location, ts.SymbolFlags.Value).find((candidate) => {
551
+ const visible = checker.getSymbolsInScope(location, ts.SymbolFlags.Value | ts.SymbolFlags.Alias).find((candidate) => {
552
+ if (candidate.declarations?.some((declaration) => ts.isImportSpecifier(declaration) && (declaration.isTypeOnly || declaration.parent.parent.isTypeOnly))) return false;
516
553
  const target = candidate.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(candidate) : candidate;
517
- return target === symbol;
554
+ return target === symbol || (symbol.declarations?.some((declaration) => target.declarations?.includes(declaration)) ?? false);
518
555
  });
519
556
  if (visible) {
520
557
  const constructor = checker.getTypeOfSymbolAtLocation(visible, location).getConstructSignatures()[0];
@@ -522,12 +559,62 @@ function constructError(type, checker, location, tag) {
522
559
  const param = constructor.parameters[0];
523
560
  if (!param) return { text: `new ${visible.name}()`, synthetic: false };
524
561
  const fields = checker.getTypeOfSymbolAtLocation(param, location);
562
+ if (fields.flags & (ts.TypeFlags.Void | ts.TypeFlags.Undefined)) return { text: `new ${visible.name}()`, synthetic: false };
525
563
  const value = valuesOf(fields, checker, location)[0];
526
- if (value && !value.synthetic) return { text: `new ${visible.name}(${value.text})`, synthetic: false };
564
+ if (value && !value.synthetic) {
565
+ const rest = param.valueDeclaration && ts.isParameter(param.valueDeclaration) && param.valueDeclaration.dotDotDotToken;
566
+ return { text: `new ${visible.name}(${rest ? "..." : ""}${value.text})`, synthetic: false };
567
+ }
527
568
  }
528
569
  }
529
570
  }
530
- return { text: `({ _tag: ${JSON.stringify(tag)} } as unknown as ${checker.typeToString(type, location, ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope)})`, synthetic: true };
571
+ return { text: `({ _tag: ${JSON.stringify(tag)} } as unknown as ${checker.typeToString(type, location, ts.TypeFormatFlags.NoTruncation)})`, synthetic: true };
572
+ }
573
+ function returnTypeText(type, checker, node) {
574
+ const print = (t) => checker.typeToString(t, node, ts.TypeFormatFlags.NoTruncation);
575
+ if (type.isUnion()) {
576
+ const members = type.types.map((member) => family(member, checker));
577
+ if (members.every((member) => member?.kind === "Effect")) {
578
+ const args = [0, 1, 2].map((index) => [...new Set(members.flatMap((member) => member?.args[index] ? [print(member.args[index])] : []))].sort().join(" | ") || "never");
579
+ return `import("effect/Effect").Effect<${args.join(", ")}>`;
580
+ }
581
+ }
582
+ return print(type);
583
+ }
584
+ function literalData(node) {
585
+ if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node)) return literalData(node.expression);
586
+ if (ts.isStringLiteral(node) || ts.isNumericLiteral(node)) return [node.kind, node.text];
587
+ if (node.kind === ts.SyntaxKind.TrueKeyword || node.kind === ts.SyntaxKind.FalseKeyword || node.kind === ts.SyntaxKind.NullKeyword) return [node.kind];
588
+ if (ts.isObjectLiteralExpression(node)) {
589
+ const fields = [];
590
+ for (const field of node.properties) {
591
+ if (!ts.isPropertyAssignment(field) || !field.name || ts.isComputedPropertyName(field.name)) return void 0;
592
+ const value = literalData(field.initializer);
593
+ if (value === void 0) return void 0;
594
+ fields.push([field.name.getText().replace(/^["']|["']$/g, ""), value]);
595
+ }
596
+ return fields.sort(([a], [b]) => a.localeCompare(b, "en"));
597
+ }
598
+ return void 0;
599
+ }
600
+ function equivalentSuccessValues(body, api) {
601
+ const values = [];
602
+ const visit = (node) => {
603
+ if (ts.isCallExpression(node) && node.expression.getText() === api("Effect", "succeed") && node.arguments[0]) {
604
+ const value = literalData(node.arguments[0]);
605
+ if (value !== void 0) values.push(JSON.stringify(value));
606
+ }
607
+ ts.forEachChild(node, visit);
608
+ };
609
+ visit(body);
610
+ return values;
611
+ }
612
+ function isEquivalentSuccess(text, values) {
613
+ const source = ts.createSourceFile("literal.ts", `(${text})`, ts.ScriptTarget.Latest, true);
614
+ const statement = source.statements[0];
615
+ if (!statement || !ts.isExpressionStatement(statement)) return false;
616
+ const value = literalData(statement.expression);
617
+ return value !== void 0 && values.includes(JSON.stringify(value));
531
618
  }
532
619
  function valuesOf(type, checker, location, depth = 0) {
533
620
  if (depth > 4 || type.flags & ts.TypeFlags.Never) return [];
@@ -544,7 +631,7 @@ function valuesOf(type, checker, location, depth = 0) {
544
631
  ...wrap ? values.map((v) => ({ text: `${wrap}(${v.text})`, synthetic: v.synthetic })) : []
545
632
  ];
546
633
  }
547
- if (type.isUnion()) return type.types.flatMap((member) => valuesOf(member, checker, location, depth + 1));
634
+ if (type.isUnion()) return [...type.types].sort((a, b) => a.isNumberLiteral() && b.isNumberLiteral() ? a.value - b.value : checker.typeToString(a).localeCompare(checker.typeToString(b), "en")).flatMap((member) => valuesOf(member, checker, location, depth + 1));
548
635
  if (type.isStringLiteral()) return [value(JSON.stringify(type.value))];
549
636
  if (type.isNumberLiteral()) return [value(String(type.value))];
550
637
  if (type.flags & ts.TypeFlags.BooleanLiteral) return [value(checker.typeToString(type))];
@@ -573,7 +660,7 @@ function valuesOf(type, checker, location, depth = 0) {
573
660
  if (!first) return [];
574
661
  fields.push(`${JSON.stringify(prop.name)}: ${first.text}`);
575
662
  }
576
- return [value(`{ ${fields.join(", ")} }`)];
663
+ return [value(`({ ${fields.join(", ")} } as const)`)];
577
664
  }
578
665
  return [];
579
666
  }
@@ -711,13 +798,41 @@ var ScratchLive = Layer2.effect(Scratch, Effect2.gen(function* () {
711
798
  import * as Clock from "effect/Clock";
712
799
  import * as Effect3 from "effect/Effect";
713
800
  import * as Layer3 from "effect/Layer";
801
+ import * as FileSystem3 from "effect/FileSystem";
802
+ import * as Path3 from "effect/Path";
714
803
  import * as Stream2 from "effect/Stream";
715
804
  import * as ChildProcess from "effect/process/ChildProcess";
716
805
  import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
717
806
  var TestRunnerLive = Layer3.effect(TestRunner, Effect3.gen(function* () {
718
807
  const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
808
+ const fs = yield* FileSystem3.FileSystem;
809
+ const path = yield* Path3.Path;
719
810
  const execute = Effect3.fn("TestRunner.execute")(function* (dir, args, timeoutMs) {
720
- const command = ["npx", "--no", "vitest", ...args, "--no-cache", "--no-fsModuleCache"];
811
+ const reporterDir = yield* fs.makeTempDirectoryScoped({ prefix: "mutant-vitest-" }).pipe(
812
+ Effect3.mapError((error2) => new TestSpawnError({ command: ["vitest"], message: String(error2) }))
813
+ );
814
+ const reporter = path.join(reporterDir, "reporter.mjs");
815
+ const marker = `mutant-cafe:${path.basename(reporterDir)}:`;
816
+ yield* fs.writeFileString(reporter, `export default class {
817
+ files = 0;
818
+ onTestRunStart(specifications) { this.files = specifications.length; }
819
+ onTestModuleCollected() { console.log(${JSON.stringify(marker + "collected")}); }
820
+ onTestCaseResult(test) { if (test.result().state === "failed") console.log(${JSON.stringify(marker + "failed")}); }
821
+ onTestRunEnd() { if (this.files === 0) console.log(${JSON.stringify(marker + "empty")}); }
822
+ }`).pipe(Effect3.mapError((error2) => new TestSpawnError({ command: ["vitest"], message: String(error2) })));
823
+ const command = [
824
+ "npx",
825
+ "--no",
826
+ "vitest",
827
+ ...args,
828
+ "--reporter=default",
829
+ `--reporter=${reporter}`,
830
+ "--bail",
831
+ "1",
832
+ ...timeoutMs === void 0 ? [] : ["--testTimeout", String(Math.max(1, Math.floor(timeoutMs / 2)))],
833
+ "--no-cache",
834
+ "--no-fsModuleCache"
835
+ ];
721
836
  const started = yield* Clock.currentTimeMillis;
722
837
  const chunks = [];
723
838
  let exitCode = 1;
@@ -742,18 +857,36 @@ var TestRunnerLive = Layer3.effect(TestRunner, Effect3.gen(function* () {
742
857
  Effect3.catchTag("TimeoutError", () => Effect3.succeed("timedOut"))
743
858
  )).pipe(Effect3.mapError((error2) => new TestSpawnError({ command, message: error2.message })));
744
859
  const ended = yield* Clock.currentTimeMillis;
745
- const run2 = { status, durationMs: ended - started, command, output: chunks.join("") };
860
+ const output = chunks.join("");
861
+ const failed = output.includes(marker + "failed");
862
+ const run2 = {
863
+ status: failed ? "failed" : status === "passed" && output.includes(marker + "empty") ? "untested" : status,
864
+ durationMs: ended - started,
865
+ command,
866
+ output,
867
+ testsCollected: output.includes(marker + "collected")
868
+ };
746
869
  return { ...run2, exitCode };
747
- });
870
+ }, Effect3.scoped);
748
871
  return TestRunner.of({
749
872
  baseline: Effect3.fn("TestRunner.baseline")(function* (dir) {
750
- const run2 = yield* execute(dir, ["run"]);
751
- if (run2.status !== "passed") {
873
+ const run2 = yield* execute(dir, ["run", "--passWithNoTests"]);
874
+ if (run2.status !== "passed" && run2.status !== "untested") {
752
875
  return yield* Effect3.fail(new BaselineFailed({ exitCode: run2.exitCode, output: run2.output }));
753
876
  }
754
877
  return { durationMs: run2.durationMs, testCommand: run2.command };
755
878
  }),
756
- runRelated: Effect3.fn("TestRunner.runRelated")((dir, file, timeoutMs) => execute(dir, ["related", file, "--run", "--passWithNoTests"], timeoutMs))
879
+ runRelated: Effect3.fn("TestRunner.runRelated")(function* (dir, file, timeoutMs) {
880
+ const related = yield* execute(dir, ["related", file, "--run", "--passWithNoTests"], timeoutMs);
881
+ if (related.status !== "untested") return related;
882
+ const remaining = Math.max(1, timeoutMs - related.durationMs);
883
+ const full = yield* execute(dir, ["run", "--passWithNoTests"], remaining);
884
+ return {
885
+ ...full,
886
+ durationMs: related.durationMs + full.durationMs,
887
+ output: related.output + "\nFull-suite fallback:\n" + full.output
888
+ };
889
+ })
757
890
  });
758
891
  }));
759
892
 
@@ -762,7 +895,7 @@ import { createEffectActor, createEffectLogic, join, send, setupEffect } from "@
762
895
  import { types } from "xstate";
763
896
  import * as Effect4 from "effect/Effect";
764
897
  import * as Pool from "effect/Pool";
765
- import * as Path3 from "effect/Path";
898
+ import * as Path5 from "effect/Path";
766
899
  import * as Result from "effect/Result";
767
900
  import * as Schema5 from "effect/Schema";
768
901
  import * as Scope from "effect/Scope";
@@ -779,7 +912,7 @@ var runMutants = Effect4.fn("Runner.runMutants")(function* (config, mutants) {
779
912
  const source = yield* MutantSource;
780
913
  const reporter = yield* Reporter;
781
914
  const scope = yield* Scope.Scope;
782
- const path = yield* Path3.Path;
915
+ const path = yield* Path5.Path;
783
916
  const jobs = Math.max(1, Math.floor(config.jobs));
784
917
  const report = (state2) => ({
785
918
  schemaVersion: 1,
@@ -809,6 +942,18 @@ var runMutants = Effect4.fn("Runner.runMutants")(function* (config, mutants) {
809
942
  const testing = createEffectLogic(({ input }) => capture(Effect4.gen(function* () {
810
943
  const dirs = input.state.pool?.value;
811
944
  if (dirs === void 0) return yield* Effect4.die("Missing scratch pool");
945
+ const neverBudgets = /* @__PURE__ */ new Map();
946
+ for (const mutant of input.state.pending) {
947
+ if (mutant.genre !== "EffectNever" || neverBudgets.has(mutant.file)) continue;
948
+ const measured = yield* Effect4.scoped(Effect4.gen(function* () {
949
+ const dir = yield* Pool.get(dirs);
950
+ return yield* tests.runRelated(dir, path.isAbsolute(mutant.file) ? path.relative(config.root, mutant.file) : mutant.file, input.state.timeoutMs);
951
+ }));
952
+ if (measured.status === "failed" || measured.status === "timedOut") {
953
+ return yield* new BaselineFailed({ exitCode: 1, output: measured.output });
954
+ }
955
+ neverBudgets.set(mutant.file, Math.max(config.neverTimeoutMs, Math.ceil(measured.durationMs * config.timeoutMultiplier)));
956
+ }
812
957
  yield* Stream3.fromIterable(input.state.pending).pipe(
813
958
  Stream3.mapEffect((mutant) => Effect4.scoped(Effect4.gen(function* () {
814
959
  const viability = yield* source.checkViable(mutant);
@@ -821,14 +966,14 @@ var runMutants = Effect4.fn("Runner.runMutants")(function* (config, mutants) {
821
966
  const dir = yield* Pool.get(dirs);
822
967
  const run2 = yield* Effect4.acquireUseRelease(
823
968
  dir.apply(mutant),
824
- () => tests.runRelated(dir, path.isAbsolute(mutant.file) ? path.relative(config.root, mutant.file) : mutant.file, mutant.genre === "EffectNever" ? config.neverTimeoutMs : input.state.timeoutMs),
969
+ () => tests.runRelated(dir, path.isAbsolute(mutant.file) ? path.relative(config.root, mutant.file) : mutant.file, mutant.genre === "EffectNever" ? neverBudgets.get(mutant.file) : input.state.timeoutMs),
825
970
  // A dirty directory must never return to the pool, even on cancel.
826
971
  () => dir.revert(mutant).pipe(Effect4.orDie)
827
972
  );
828
973
  const result2 = {
829
974
  mutant,
830
- // Effect.never is meant to hang: a test that waits on it and times out noticed the mutant.
831
- outcome: run2.status === "timedOut" ? mutant.genre === "EffectNever" ? "caught" : "timeout" : run2.status === "failed" ? "caught" : "missed",
975
+ // A kill before collection proves nothing about whether tests noticed.
976
+ outcome: run2.status === "timedOut" ? mutant.genre === "EffectNever" && run2.testsCollected ? "caught" : "timeout" : run2.status === "failed" ? "caught" : run2.status === "untested" ? "untested" : "missed",
832
977
  durationMs: run2.durationMs,
833
978
  testCommand: run2.command,
834
979
  diagnostics: [],
@@ -923,25 +1068,27 @@ var runMutants = Effect4.fn("Runner.runMutants")(function* (config, mutants) {
923
1068
  // packages/cli/src/bin.ts
924
1069
  import * as Effect8 from "effect/Effect";
925
1070
  import * as Layer5 from "effect/Layer";
926
- import * as Stream5 from "effect/Stream";
1071
+ import * as Stream6 from "effect/Stream";
927
1072
 
928
1073
  // packages/cli/src/Command.ts
929
1074
  import * as Console2 from "effect/Console";
930
1075
  import * as Effect7 from "effect/Effect";
931
- import * as FileSystem7 from "effect/FileSystem";
1076
+ import * as FileSystem9 from "effect/FileSystem";
932
1077
  import * as Option from "effect/Option";
933
- import * as Path9 from "effect/Path";
1078
+ import * as Path11 from "effect/Path";
934
1079
  import * as Ref from "effect/Ref";
935
1080
  import * as Schema8 from "effect/Schema";
936
- import * as Stream4 from "effect/Stream";
1081
+ import * as Stream5 from "effect/Stream";
937
1082
  import * as Command from "effect/cli/Command";
938
1083
  import * as Flag from "effect/cli/Flag";
939
1084
 
940
1085
  // packages/cli/src/Diff.ts
941
1086
  import * as Effect5 from "effect/Effect";
942
- import * as FileSystem3 from "effect/FileSystem";
943
- import * as Path5 from "effect/Path";
1087
+ import * as FileSystem5 from "effect/FileSystem";
1088
+ import * as Path7 from "effect/Path";
944
1089
  import * as Schema6 from "effect/Schema";
1090
+ import * as Stream4 from "effect/Stream";
1091
+ import * as ChildProcess2 from "effect/process/ChildProcess";
945
1092
  var DiffMismatch = class extends Schema6.TaggedError()("DiffMismatch", {
946
1093
  path: Schema6.String,
947
1094
  message: Schema6.String
@@ -968,7 +1115,7 @@ var parseDiff = (text, path) => Effect5.try({
968
1115
  const decoded = raw.startsWith('"') ? JSON.parse(raw) : raw;
969
1116
  if (typeof decoded !== "string") fail4("Invalid file path");
970
1117
  const file = String(decoded).replace(/^b\//, "");
971
- const lines = [];
1118
+ const lines2 = [];
972
1119
  let hunks = 0;
973
1120
  let previousEnd = 0;
974
1121
  let previousOldEnd = 0;
@@ -986,9 +1133,9 @@ var parseDiff = (text, path) => Effect5.try({
986
1133
  let previousPrefix = "";
987
1134
  const markNoNewline = () => {
988
1135
  if (previousPrefix === "+" || previousPrefix === " ") {
989
- const last = lines.at(-1);
1136
+ const last = lines2.at(-1);
990
1137
  if (last === void 0 || last.noNewline) fail4("Unexpected no-newline marker");
991
- lines[lines.length - 1] = { ...last, noNewline: true };
1138
+ lines2[lines2.length - 1] = { ...last, noNewline: true };
992
1139
  } else if (previousPrefix !== "-") fail4("Unexpected no-newline marker");
993
1140
  previousPrefix = "";
994
1141
  };
@@ -1004,7 +1151,7 @@ var parseDiff = (text, path) => Effect5.try({
1004
1151
  if (prefix === " " || prefix === "-") oldRemaining--;
1005
1152
  if (prefix === " " || prefix === "+") {
1006
1153
  newRemaining--;
1007
- lines.push({ number: newLine++, text: body.slice(1), added: prefix === "+", noNewline: false });
1154
+ lines2.push({ number: newLine++, text: body.slice(1), added: prefix === "+", noNewline: false });
1008
1155
  } else if (prefix !== "-") fail4("Invalid hunk line");
1009
1156
  previousPrefix = prefix;
1010
1157
  if (oldRemaining < 0 || newRemaining < 0) fail4("Hunk count does not match its body");
@@ -1018,7 +1165,7 @@ var parseDiff = (text, path) => Effect5.try({
1018
1165
  }
1019
1166
  if (hunks === 0) fail4("File has no hunks");
1020
1167
  sawFile = true;
1021
- if (file !== "/dev/null") patches.push({ file, lines });
1168
+ if (file !== "/dev/null") patches.push({ file, lines: lines2 });
1022
1169
  }
1023
1170
  if (!sawFile) fail4("No unified diff found");
1024
1171
  return patches;
@@ -1026,25 +1173,41 @@ var parseDiff = (text, path) => Effect5.try({
1026
1173
  catch: (error2) => Schema6.is(DiffParseError)(error2) ? error2 : new DiffParseError({ path, message: String(error2) })
1027
1174
  });
1028
1175
  var selectInDiff = Effect5.fn("selectInDiff")(function* (options) {
1029
- const fs = yield* FileSystem3.FileSystem;
1030
- const path = yield* Path5.Path;
1176
+ const fs = yield* FileSystem5.FileSystem;
1177
+ const path = yield* Path7.Path;
1031
1178
  const diffPath = path.resolve(options.root, options.diffPath);
1032
1179
  const text = yield* fs.readFileString(diffPath).pipe(Effect5.mapError((error2) => new DiffParseError({ path: diffPath, message: String(error2) })));
1033
1180
  const patches = yield* parseDiff(text, diffPath);
1181
+ const gitRoot = yield* Effect5.scoped(Effect5.gen(function* () {
1182
+ const handle = yield* ChildProcess2.make("git", ["rev-parse", "--show-toplevel"], { cwd: options.root, stderr: "ignore" });
1183
+ const [output, code] = yield* Effect5.all([Stream4.mkString(Stream4.decodeText(handle.stdout)), handle.exitCode], { concurrency: "unbounded" });
1184
+ if (Number(code) !== 0 || !output.trim()) return options.root;
1185
+ const physicalRoot = yield* fs.realPath(options.root);
1186
+ return path.resolve(options.root, path.relative(physicalRoot, output.trim()));
1187
+ })).pipe(Effect5.catch(() => Effect5.succeed(options.root)));
1034
1188
  const changed = /* @__PURE__ */ new Map();
1035
1189
  for (const patch of patches) {
1036
- const absolute = path.resolve(options.root, patch.file);
1037
- const relative2 = path.relative(options.root, absolute);
1038
- if (relative2 === ".." || relative2.startsWith(`..${path.sep}`) || path.isAbsolute(relative2)) {
1039
- return yield* new DiffParseError({ path: diffPath, message: "Diff path escapes project root" });
1040
- }
1041
- const current = yield* fs.readFileString(absolute).pipe(Effect5.mapError((error2) => new DiffMismatch({ path: patch.file, message: String(error2) })));
1042
- const lines = current.split("\n");
1043
- for (const line of patch.lines) {
1044
- const finalLine = current.endsWith("\n") ? lines.length - 1 : lines.length;
1045
- const newlineMismatch = line.noNewline ? line.number !== finalLine || current.endsWith("\n") : line.number === finalLine && !current.endsWith("\n");
1046
- if (lines[line.number - 1] !== line.text || newlineMismatch) return yield* new DiffMismatch({ path: patch.file, message: `New-side line ${line.number} does not match tree` });
1190
+ const repositoryPath = path.resolve(gitRoot, patch.file);
1191
+ const candidates = [.../* @__PURE__ */ new Set([repositoryPath, path.resolve(options.root, patch.file)])];
1192
+ let absolute;
1193
+ for (const candidate of candidates) {
1194
+ const relative2 = path.relative(gitRoot, candidate);
1195
+ if (relative2 === ".." || relative2.startsWith(`..${path.sep}`) || path.isAbsolute(relative2)) {
1196
+ return yield* new DiffParseError({ path: diffPath, message: "Diff path escapes repository root" });
1197
+ }
1198
+ if (!(yield* fs.exists(candidate))) continue;
1199
+ const current = yield* fs.readFileString(candidate).pipe(Effect5.mapError((error2) => new DiffMismatch({ path: patch.file, message: String(error2) })));
1200
+ const lines2 = current.split("\n");
1201
+ const finalLine = current.endsWith("\n") ? lines2.length - 1 : lines2.length;
1202
+ if (patch.lines.every((line) => {
1203
+ const newlineMismatch = line.noNewline ? line.number !== finalLine || current.endsWith("\n") : line.number === finalLine && !current.endsWith("\n");
1204
+ return lines2[line.number - 1] === line.text && !newlineMismatch;
1205
+ })) {
1206
+ absolute = candidate;
1207
+ break;
1208
+ }
1047
1209
  }
1210
+ if (absolute === void 0) return yield* new DiffMismatch({ path: patch.file, message: "New-side lines do not match the tree at the Git toplevel or working directory" });
1048
1211
  const added = changed.get(absolute) ?? /* @__PURE__ */ new Set();
1049
1212
  for (const line of patch.lines) if (line.added) added.add(line.number);
1050
1213
  changed.set(absolute, added);
@@ -1057,7 +1220,7 @@ var selectInDiff = Effect5.fn("selectInDiff")(function* (options) {
1057
1220
  });
1058
1221
 
1059
1222
  // packages/cli/src/ExitCode.ts
1060
- var reportExitCode = (report) => report.results.some((result2) => result2.outcome === "missed") ? 2 : report.results.some((result2) => result2.outcome === "timeout") ? 3 : 0;
1223
+ var reportExitCode = (report) => report.results.some((result2) => result2.outcome === "missed" || result2.outcome === "untested") ? 2 : report.results.some((result2) => result2.outcome === "timeout") ? 3 : 0;
1061
1224
  var errorExitCode = (error2) => {
1062
1225
  switch (error2._tag) {
1063
1226
  case "BaselineFailed":
@@ -1081,37 +1244,114 @@ var errorExitCode = (error2) => {
1081
1244
  import * as Clock2 from "effect/Clock";
1082
1245
  import * as Console from "effect/Console";
1083
1246
  import * as Effect6 from "effect/Effect";
1084
- import * as FileSystem5 from "effect/FileSystem";
1247
+ import * as FileSystem7 from "effect/FileSystem";
1085
1248
  import * as Layer4 from "effect/Layer";
1086
- import * as Path7 from "effect/Path";
1249
+ import * as Path9 from "effect/Path";
1087
1250
  import * as Schema7 from "effect/Schema";
1088
1251
  import * as Semaphore from "effect/Semaphore";
1089
- var mutantLine = (mutant, root, path) => `${path.relative(root, path.resolve(root, mutant.file))}:${mutant.span.start.line}:${mutant.span.start.column}: ${mutant.description}`;
1090
- var outcomes = ["caught", "missed", "timeout", "unviable"];
1252
+
1253
+ // packages/cli/src/UnifiedDiff.ts
1254
+ var shortestEdits = (before, after) => {
1255
+ const frontier = /* @__PURE__ */ new Map([[1, 0]]);
1256
+ const trace = [];
1257
+ for (let distance = 0; distance <= before.length + after.length; distance++) {
1258
+ trace.push(new Map(frontier));
1259
+ for (let diagonal = -distance; diagonal <= distance; diagonal += 2) {
1260
+ const down = diagonal === -distance || diagonal !== distance && (frontier.get(diagonal - 1) ?? -Infinity) < (frontier.get(diagonal + 1) ?? -Infinity);
1261
+ let x = down ? frontier.get(diagonal + 1) ?? 0 : (frontier.get(diagonal - 1) ?? 0) + 1;
1262
+ let y = x - diagonal;
1263
+ while (x < before.length && y < after.length && before[x] === after[y]) {
1264
+ x++;
1265
+ y++;
1266
+ }
1267
+ frontier.set(diagonal, x);
1268
+ if (x < before.length || y < after.length) continue;
1269
+ const result2 = [];
1270
+ x = before.length;
1271
+ y = after.length;
1272
+ for (let depth = trace.length - 1; depth >= 0; depth--) {
1273
+ const previous = trace[depth];
1274
+ const k = x - y;
1275
+ const down2 = k === -depth || k !== depth && (previous.get(k - 1) ?? -Infinity) < (previous.get(k + 1) ?? -Infinity);
1276
+ const previousK = down2 ? k + 1 : k - 1;
1277
+ const previousX = previous.get(previousK) ?? 0;
1278
+ const previousY = previousX - previousK;
1279
+ while (x > previousX && y > previousY) {
1280
+ result2.push({ sign: " ", text: before[--x] });
1281
+ y--;
1282
+ }
1283
+ if (depth === 0) break;
1284
+ if (x === previousX) result2.push({ sign: "+", text: after[--y] });
1285
+ else result2.push({ sign: "-", text: before[--x] });
1286
+ }
1287
+ return result2.reverse();
1288
+ }
1289
+ }
1290
+ return [];
1291
+ };
1292
+ var edits = (before, after) => {
1293
+ let prefix = 0;
1294
+ while (prefix < before.length && prefix < after.length && before[prefix] === after[prefix]) prefix++;
1295
+ let suffix = 0;
1296
+ while (suffix < before.length - prefix && suffix < after.length - prefix && before[before.length - suffix - 1] === after[after.length - suffix - 1]) suffix++;
1297
+ const left = before.slice(prefix, before.length - suffix);
1298
+ const right = after.slice(prefix, after.length - suffix);
1299
+ const shared = new Set(left);
1300
+ const middle = right.some((text) => shared.has(text)) ? shortestEdits(left, right) : [...left.map((text) => ({ sign: "-", text })), ...right.map((text) => ({ sign: "+", text }))];
1301
+ return [
1302
+ ...before.slice(0, prefix).map((text) => ({ sign: " ", text })),
1303
+ ...middle,
1304
+ ...before.slice(before.length - suffix).map((text) => ({ sign: " ", text }))
1305
+ ];
1306
+ };
1307
+ var lines = (text) => {
1308
+ if (!text) return [];
1309
+ const result2 = text.split("\n");
1310
+ if (text.endsWith("\n")) result2.pop();
1311
+ else result2[result2.length - 1] += "\n\";
1312
+ return result2;
1313
+ };
1314
+ var unifiedDiff = (original, modified, file) => {
1315
+ if (original === modified) return "";
1316
+ const changes = edits(lines(original), lines(modified));
1317
+ const positions = [];
1318
+ let old = 1;
1319
+ let next = 1;
1320
+ for (const edit of changes) {
1321
+ positions.push({ old, next });
1322
+ if (edit.sign !== "+") old++;
1323
+ if (edit.sign !== "-") next++;
1324
+ }
1325
+ const changed = changes.flatMap((edit, index) => edit.sign === " " ? [] : [index]);
1326
+ const output = [`--- ${JSON.stringify(`a/${file}`)}`, `+++ ${JSON.stringify(`b/${file}`)}`];
1327
+ for (let i = 0; i < changed.length; i++) {
1328
+ const start = Math.max(0, changed[i] - 3);
1329
+ let last = changed[i];
1330
+ while (i + 1 < changed.length && changed[i + 1] - last <= 7) last = changed[++i];
1331
+ const hunk = changes.slice(start, last + 4);
1332
+ const oldCount = hunk.filter((edit) => edit.sign !== "+").length;
1333
+ const newCount = hunk.filter((edit) => edit.sign !== "-").length;
1334
+ const position = positions[start];
1335
+ output.push(`@@ -${oldCount ? position.old : position.old - 1},${oldCount} +${newCount ? position.next : position.next - 1},${newCount} @@`, ...hunk.map((edit) => edit.sign + edit.text));
1336
+ }
1337
+ return [...output, ""].join("\n");
1338
+ };
1339
+
1340
+ // packages/cli/src/Reporter.ts
1341
+ var mutantLine = (mutant, root, path) => `${path.relative(root, path.resolve(root, mutant.file))}:${mutant.span.start.line}:${mutant.span.start.column}: ${mutant.description.replace(mutant.returnType, shortType(mutant.displayReturnType ?? mutant.returnType))} [${mutant.id}]`;
1342
+ var shortType = (text) => {
1343
+ const line = text.replace(/\s+/g, " ");
1344
+ return line.length > 80 ? line.slice(0, 79) + "\u2026" : line;
1345
+ };
1346
+ var outcomes = ["caught", "missed", "timeout", "unviable", "untested"];
1091
1347
  var jsonReport = Schema7.encodeEffect(Schema7.fromJsonString(RunReport));
1092
1348
  var logText = (result2) => [
1093
1349
  ..."output" in result2 && typeof result2.output === "string" ? [result2.output] : [],
1094
1350
  ...result2.diagnostics
1095
1351
  ].join("\n");
1096
- var unifiedDiff = (mutant, original) => {
1097
- const replacement = mutant.replacement;
1098
- const modified = original.slice(0, replacement.startOffset) + replacement.text + original.slice(replacement.endOffset);
1099
- const body = (text, prefix) => {
1100
- if (text === "") return [];
1101
- const lines = text.split("\n");
1102
- if (lines.at(-1) === "") lines.pop();
1103
- const result2 = lines.map((line) => prefix + line);
1104
- if (!text.endsWith("\n")) result2.push("\");
1105
- return result2;
1106
- };
1107
- const count = (text) => text === "" ? 0 : text.split("\n").length - (text.endsWith("\n") ? 1 : 0);
1108
- const oldCount = count(original);
1109
- const newCount = count(modified);
1110
- return [`--- a/${mutant.file}`, `+++ b/${mutant.file}`, `@@ -${oldCount === 0 ? 0 : 1},${oldCount} +${newCount === 0 ? 0 : 1},${newCount} @@`, ...body(original, "-"), ...body(modified, "+"), ""].join("\n");
1111
- };
1112
1352
  var makeReporter = Effect6.fn("makeReporter")(function* (options) {
1113
- const fs = yield* FileSystem5.FileSystem;
1114
- const path = yield* Path7.Path;
1353
+ const fs = yield* FileSystem7.FileSystem;
1354
+ const path = yield* Path9.Path;
1115
1355
  const dir = path.resolve(options.root, options.outDir);
1116
1356
  const started = yield* Clock2.currentTimeMillis;
1117
1357
  const semaphore = yield* Semaphore.make(1);
@@ -1145,11 +1385,11 @@ var makeReporter = Effect6.fn("makeReporter")(function* (options) {
1145
1385
  yield* Effect6.forEach(outcomes, (outcome) => fs.writeFileString(path.join(dir, `${outcome}.txt`), ""), { discard: true }).pipe(Effect6.mapError(writeError));
1146
1386
  for (const mutant of options.mutants) {
1147
1387
  const original = yield* fs.readFileString(path.resolve(options.root, mutant.file)).pipe(Effect6.mapError(writeError));
1148
- yield* fs.writeFileString(path.join(dir, "diff", `${mutant.id}.diff`), unifiedDiff(mutant, original)).pipe(Effect6.mapError(writeError));
1388
+ 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(Effect6.mapError(writeError));
1149
1389
  }
1150
1390
  const writeLists = (items) => Effect6.forEach(outcomes, (outcome) => {
1151
- const lines = items.filter((result2) => result2.outcome === outcome).map((result2) => mutantLine(result2.mutant, options.root, path));
1152
- return fs.writeFileString(path.join(dir, `${outcome}.txt`), lines.length === 0 ? "" : lines.join("\n") + "\n");
1391
+ const lines2 = items.filter((result2) => result2.outcome === outcome).map((result2) => mutantLine(result2.mutant, options.root, path));
1392
+ return fs.writeFileString(path.join(dir, `${outcome}.txt`), lines2.length === 0 ? "" : lines2.join("\n") + "\n");
1153
1393
  }, { discard: true });
1154
1394
  const service = Reporter.of({
1155
1395
  progress: (result2) => semaphore.withPermit(Effect6.gen(function* () {
@@ -1201,8 +1441,8 @@ var flags = {
1201
1441
  tsconfig: Flag.String("tsconfig").pipe(Flag.withDefault("tsconfig.json"))
1202
1442
  };
1203
1443
  var makeCommand = (options) => Command.make("mutant-cafe", flags, (input) => Effect7.gen(function* () {
1204
- const fs = yield* FileSystem7.FileSystem;
1205
- const path = yield* Path9.Path;
1444
+ const fs = yield* FileSystem9.FileSystem;
1445
+ const path = yield* Path11.Path;
1206
1446
  const root = path.resolve(options.root);
1207
1447
  const configPath = path.join(root, "mutants.config.json");
1208
1448
  const fileConfig = (yield* fs.exists(configPath)) ? yield* fs.readFileString(configPath).pipe(
@@ -1214,7 +1454,7 @@ var makeCommand = (options) => Command.make("mutant-cafe", flags, (input) => Eff
1214
1454
  const config = yield* Schema8.decodeEffect(RunConfig)({
1215
1455
  root,
1216
1456
  tsconfig: input.tsconfig,
1217
- include: input.include.length > 0 ? input.include : fileConfig.include ?? ["**/*.ts", "**/*.tsx"],
1457
+ include: input.include.length > 0 ? input.include : fileConfig.include ?? ["**/*.{ts,tsx}"],
1218
1458
  exclude: input.exclude.length > 0 ? input.exclude : fileConfig.exclude ?? [],
1219
1459
  functionFilter: fileConfig.functionFilter ?? [],
1220
1460
  ...inDiff === void 0 ? {} : { inDiff },
@@ -1229,10 +1469,19 @@ var makeCommand = (options) => Command.make("mutant-cafe", flags, (input) => Eff
1229
1469
  return yield* new UsageError({ message: "Jobs and timeout values must be positive" });
1230
1470
  }
1231
1471
  const source = yield* MutantSource;
1232
- const generated = yield* Stream4.runCollect(source.generate(config));
1472
+ const generated = yield* Stream5.runCollect(source.generate(config)).pipe(
1473
+ Effect7.mapError((error2) => error2.reason === "selection" ? new UsageError({ message: error2.diagnostics.join("\n") }) : error2)
1474
+ );
1233
1475
  const mutants = inDiff === void 0 ? generated : yield* selectInDiff({ root, diffPath: inDiff, mutants: generated });
1234
1476
  if (input.list) {
1235
1477
  for (const mutant of mutants) yield* Console2.log(mutantLine(mutant, config.root, path));
1478
+ const counts = /* @__PURE__ */ new Map();
1479
+ for (const mutant of mutants) {
1480
+ const file = path.relative(root, path.resolve(root, mutant.file));
1481
+ counts.set(file, (counts.get(file) ?? 0) + 1);
1482
+ }
1483
+ for (const [file, count] of [...counts].sort(([a], [b]) => a.localeCompare(b))) yield* Console2.log(`${file}: ${count} mutants`);
1484
+ yield* Console2.log(`${mutants.length} mutants total`);
1236
1485
  if (options.onExit !== void 0) yield* options.onExit(0);
1237
1486
  return;
1238
1487
  }
@@ -1244,7 +1493,7 @@ var makeCommand = (options) => Command.make("mutant-cafe", flags, (input) => Eff
1244
1493
  var runCli = Effect7.fn("runCli")(function* (options) {
1245
1494
  const code = yield* Ref.make(0);
1246
1495
  const command = makeCommand({ ...options, onExit: (value) => Ref.set(code, value) });
1247
- yield* Command.runWith(command, { version: "0.1.1" })(options.args).pipe(
1496
+ yield* Command.runWith(command, { version: "0.1.2" })(options.args).pipe(
1248
1497
  Effect7.catch((error2) => Effect7.gen(function* () {
1249
1498
  yield* Console2.error(String(error2));
1250
1499
  yield* Ref.set(code, errorExitCode(error2));
@@ -1258,7 +1507,7 @@ var runCli = Effect7.fn("runCli")(function* (options) {
1258
1507
  });
1259
1508
 
1260
1509
  // packages/cli/src/bin.ts
1261
- var run = (config, mutants) => runMutants(config, Stream5.fromIterable(mutants));
1510
+ var run = (config, mutants) => runMutants(config, Stream6.fromIterable(mutants));
1262
1511
  var live = Layer5.mergeAll(MutantSourceLive, ScratchLive, TestRunnerLive).pipe(
1263
1512
  Layer5.provideMerge(NodeServices.layer)
1264
1513
  );