@godzillaba/mutest 1.0.2 → 1.1.0

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.
Files changed (2) hide show
  1. package/index.ts +23 -6
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -15,12 +15,13 @@ interface Mutant {
15
15
  async function setupWorkers(workerCount: number): Promise<string> {
16
16
  const { stdout: tempDir } = await execFile("mktemp", ["-d"]);
17
17
  const root = tempDir.trim();
18
+ const cwd = process.cwd()
18
19
 
19
20
  const workers = Array.from({ length: workerCount }, (_, i) => {
20
21
  const dir = `${root}/worker-${i}`;
21
22
  return execFile("bash", [
22
23
  "-c",
23
- `mkdir -p "${dir}" && git ls-files -z | tar -c --null -T - | tar -x -C "${dir}"`,
24
+ `mkdir -p "${dir}" && git ls-files -z | tar -c --null -T - | tar -x -C "${dir}" && ln -s ${cwd}/node_modules ${dir}/node_modules && ln -s ${cwd}/lib ${dir}/lib`,
24
25
  ]);
25
26
  });
26
27
  await Promise.all(workers);
@@ -32,11 +33,27 @@ async function runGambit(solFiles: string[]): Promise<Mutant[]> {
32
33
  const { stdout: remappingsRaw } = await execFile("forge", ["remappings"]);
33
34
  const remappings = remappingsRaw.trim().split("\n").filter(Boolean);
34
35
  const remapArgs = remappings.flatMap((r) => ["--solc_remappings", r]);
35
- for (const file of solFiles) {
36
- await execFile("gambit", ["mutate", "--filename", file, ...remapArgs]);
36
+
37
+ const results: Mutant[] = [];
38
+ const pending = [...solFiles];
39
+ const concurrency = 10;
40
+
41
+ async function worker() {
42
+ while (pending.length > 0) {
43
+ const file = pending.shift()!;
44
+ const outdir = `gambit_out/${file}`;
45
+ await execFile("gambit", [
46
+ "mutate", "--filename", file, "--outdir", outdir, ...remapArgs,
47
+ ]);
48
+ const raw = await readFile(`${outdir}/gambit_results.json`, "utf-8");
49
+ const mutants: Mutant[] = JSON.parse(raw);
50
+ for (const m of mutants) m.name = `${file}/${m.name}`;
51
+ results.push(...mutants);
52
+ }
37
53
  }
38
- const raw = await readFile("gambit_out/gambit_results.json", "utf-8");
39
- return JSON.parse(raw);
54
+
55
+ await Promise.all(Array.from({ length: concurrency }, worker));
56
+ return results;
40
57
  }
41
58
 
42
59
  async function processMutants(
@@ -56,7 +73,7 @@ async function processMutants(
56
73
  for (const mutant of queue) {
57
74
  await cp(`gambit_out/${mutant.name}`, `${workerDir}/${mutant.original}`);
58
75
  try {
59
- await execFile("forge", ["test", "--root", workerDir]);
76
+ await execFile("forge", ["test", "--optimize", "false", "--root", workerDir]);
60
77
  survived++;
61
78
  console.log(
62
79
  `[SURVIVED] #${mutant.id} ${mutant.description} ${mutant.original}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@godzillaba/mutest",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "bin": {
5
5
  "mutest": "./index.ts"
6
6
  },