probatio 0.1.2 → 0.2.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.
- package/README.md +109 -17
- package/dist/cli.js +122 -55
- package/dist/contract.js +7 -5
- package/dist/ledger/build.js +14 -0
- package/dist/mcp.js +98 -26
- package/dist/mutate/child-lines.mjs +23 -18
- package/dist/mutate/coverage-map.js +75 -18
- package/dist/mutate/fail-reporter.mjs +21 -0
- package/dist/mutate/generate.js +25 -4
- package/dist/mutate/load-failure.mjs +40 -0
- package/dist/mutate/mocha-coverage.cjs +7 -1
- package/dist/mutate/node-batch-loader.mjs +15 -1
- package/dist/mutate/node-batch.mjs +40 -3
- package/dist/mutate/node-coverage.mjs +7 -32
- package/dist/mutate/patch.js +2 -1
- package/dist/mutate/precise-lines.mjs +147 -31
- package/dist/mutate/probatio-jacoco-run.java +2 -2
- package/dist/mutate/project-config.js +58 -0
- package/dist/mutate/run.js +192 -32
- package/dist/mutate/rust-coverage.js +4 -19
- package/dist/mutate/sealed.js +94 -1
- package/dist/mutate/suite-decision.js +2 -1
- package/dist/mutate/suites.js +136 -163
- package/dist/mutate/tally.js +85 -20
- package/dist/node-version.js +13 -0
- package/dist/swarm/check-kill.js +14 -7
- package/dist/swarm/queue.js +13 -7
- package/dist/verify/change.js +5 -0
- package/package.json +6 -4
package/dist/mutate/suites.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
2
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
3
|
import path from "node:path";
|
|
5
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { projectConfig } from "./project-config.js";
|
|
6
6
|
const SKIP_DIR = new Set(["node_modules", ".git", "target", "dist", "bin", "obj", ".build", "vendor"]);
|
|
7
7
|
export function discoverSuite(pkg, testsDir) {
|
|
8
8
|
return (scriptSuite(pkg) ||
|
|
@@ -34,13 +34,14 @@ export async function runDiscoveredSuite(pkg, files, testsDir, pattern, timeoutM
|
|
|
34
34
|
if (!spec)
|
|
35
35
|
return empty;
|
|
36
36
|
const selected = files.length > 0 ? files : spec.files;
|
|
37
|
-
|
|
37
|
+
// The project's own .probatio.json env, then Probatio's collectors.
|
|
38
|
+
const child = { ...env, ...projectConfig(pkg).env };
|
|
38
39
|
if (extra?.coverageMap)
|
|
39
40
|
child.PROBATIO_COVERAGE_MAP = extra.coverageMap;
|
|
40
41
|
if (extra?.profileFile)
|
|
41
42
|
child.LLVM_PROFILE_FILE = extra.profileFile;
|
|
42
43
|
const result = await launch(pkg, spec, selected, pattern, extra?.names ?? null, timeoutMs, child, hooks);
|
|
43
|
-
const compileToken = result.timedOut ? null : detectCompile(spec.kind, result.stdout, result.stderr, result.code);
|
|
44
|
+
const compileToken = result.timedOut ? null : detectCompile(spec.kind, result.stdout, result.stderr, result.code, projectConfig(pkg));
|
|
44
45
|
// Ignore a report read from disk when this run failed to compile. The previous
|
|
45
46
|
// suite's files are still in the worktree and are not this mutant's result.
|
|
46
47
|
const report = result.timedOut || compileToken ? null : adapt(spec.kind, pkg, result.stdout, result.stderr, result.code);
|
|
@@ -72,7 +73,11 @@ function cargoSuite(pkg) {
|
|
|
72
73
|
return { kind: "cargo", files, command: "cargo test" };
|
|
73
74
|
}
|
|
74
75
|
function goSuite(pkg) {
|
|
75
|
-
|
|
76
|
+
// `go test ./...` needs a module at or above the package and skips a nested module.
|
|
77
|
+
// Go files in an example module inside a Node or Python package are not this suite.
|
|
78
|
+
if (!moduleAbove(pkg, "go.mod"))
|
|
79
|
+
return null;
|
|
80
|
+
const files = outsideNested(pkg, ["go.mod"], walk(pkg, (rel) => rel.endsWith("_test.go")));
|
|
76
81
|
if (files.length === 0)
|
|
77
82
|
return null;
|
|
78
83
|
return { kind: "go", files, command: "go test -json ./..." };
|
|
@@ -186,17 +191,39 @@ const SOURCE_EXT = /\.(?:cobol|cbl|cob|cpp|cxx|cc|java|asm|nasm|yasm|swift|py|go
|
|
|
186
191
|
export function sourceCandidates(pkg) {
|
|
187
192
|
return walk(pkg, (rel) => SOURCE_EXT.test(rel) && (hasSegment(rel, "tests") || hasSegment(rel, "test")));
|
|
188
193
|
}
|
|
194
|
+
/** Files that mark a directory as its own Python project. */
|
|
195
|
+
const PYTHON_PROJECT = ["pytest.ini", "pyproject.toml", "setup.py", "setup.cfg", "tox.ini"];
|
|
189
196
|
function pythonTests(pkg, testsDir) {
|
|
190
197
|
const configured = pytestTestPaths(pkg);
|
|
191
198
|
const roots = new Set(configured ?? [testsDir, "tests", "test"]);
|
|
192
|
-
|
|
199
|
+
// A nested Python project (an example with its own pytest.ini) is not this package's suite.
|
|
200
|
+
return outsideNested(pkg, PYTHON_PROJECT, walk(pkg, (rel) => {
|
|
193
201
|
const base = path.posix.basename(rel);
|
|
194
202
|
if (!/^test_.*\.py$/.test(base) && !/_test\.py$/.test(base) && !/^tests_.*\.py$/.test(base))
|
|
195
203
|
return false;
|
|
196
204
|
if (configured)
|
|
197
205
|
return configured.some((root) => rel === root || rel.startsWith(`${root}/`));
|
|
198
206
|
return rel.split("/").some((part) => roots.has(part));
|
|
199
|
-
});
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
/** True when `name` sits in the package or one of its parents. */
|
|
210
|
+
function moduleAbove(pkg, name) {
|
|
211
|
+
let dir = path.resolve(pkg);
|
|
212
|
+
for (;;) {
|
|
213
|
+
if (existsSync(path.join(dir, name)))
|
|
214
|
+
return true;
|
|
215
|
+
const parent = path.dirname(dir);
|
|
216
|
+
if (parent === dir)
|
|
217
|
+
return false;
|
|
218
|
+
dir = parent;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/** Drops files inside a subdirectory that has one of these manifests. That subdirectory is another project. */
|
|
222
|
+
function outsideNested(pkg, manifests, files) {
|
|
223
|
+
const nested = walk(pkg, (rel) => rel.includes("/") && manifests.includes(path.posix.basename(rel))).map((rel) => path.posix.dirname(rel));
|
|
224
|
+
if (nested.length === 0)
|
|
225
|
+
return files;
|
|
226
|
+
return files.filter((rel) => !nested.some((dir) => rel.startsWith(`${dir}/`)));
|
|
200
227
|
}
|
|
201
228
|
/** Directories pytest itself would collect. A missing setting keeps the broader walk. */
|
|
202
229
|
function pytestTestPaths(pkg) {
|
|
@@ -386,8 +413,8 @@ async function launch(pkg, spec, files, pattern, names, timeoutMs, env, hooks) {
|
|
|
386
413
|
if (spec.kind === "swift")
|
|
387
414
|
return tag(runSwift(pkg, timeoutMs, env), spec.command, wantsNames, selection);
|
|
388
415
|
if (spec.kind === "maven") {
|
|
389
|
-
const tests =
|
|
390
|
-
const args = ["-B", "test", ...(tests.length > 0 ? [`-Dtest=${tests
|
|
416
|
+
const tests = surefireArg(uniqueSurefire(selection));
|
|
417
|
+
const args = ["-B", "test", ...(tests.length > 0 ? [`-Dtest=${tests}`] : [])];
|
|
391
418
|
const whole = wantsNames && tests.length === 0;
|
|
392
419
|
// Surefire leaves the previous run's XML in place. A confirm that did not
|
|
393
420
|
// re-execute a class would otherwise read that class as failed again.
|
|
@@ -405,7 +432,7 @@ async function launch(pkg, spec, files, pattern, names, timeoutMs, env, hooks) {
|
|
|
405
432
|
const command = grep ? `${spec.command} --grep ${JSON.stringify(grep)}` : spec.command;
|
|
406
433
|
return tag(runMocha(pkg, files, timeoutMs, env, selection), command, false, selection);
|
|
407
434
|
}
|
|
408
|
-
// A tty is only for a suite
|
|
435
|
+
// A tty is only for a suite whose scripts run `docker run -it`. Everything else is bash.
|
|
409
436
|
if (spec.kind === "script") {
|
|
410
437
|
const launched = scriptInvocation(pkg);
|
|
411
438
|
return tag(runScript(pkg, timeoutMs, env, launched), launched.command, wantsNames, selection);
|
|
@@ -468,12 +495,47 @@ function goRunFilter(names, pattern) {
|
|
|
468
495
|
return null;
|
|
469
496
|
return `^(${names.map(escapeRegExp).join("|")})$`;
|
|
470
497
|
}
|
|
498
|
+
function uniqueSurefire(names) {
|
|
499
|
+
const out = [];
|
|
500
|
+
const seen = new Set();
|
|
501
|
+
for (const name of names) {
|
|
502
|
+
const selector = surefireTest(name);
|
|
503
|
+
if (!selector || seen.has(selector))
|
|
504
|
+
continue;
|
|
505
|
+
seen.add(selector);
|
|
506
|
+
out.push(selector);
|
|
507
|
+
}
|
|
508
|
+
return out;
|
|
509
|
+
}
|
|
510
|
+
/** Surefire 2.12 splits `-Dtest` on commas and then reads `#method+method`. `Class#a,Class#b` runs only `a`. */
|
|
511
|
+
export function surefireArg(tests) {
|
|
512
|
+
const groups = new Map();
|
|
513
|
+
for (const test of tests) {
|
|
514
|
+
const hash = test.indexOf("#");
|
|
515
|
+
const klass = hash === -1 ? test : test.slice(0, hash);
|
|
516
|
+
const method = hash === -1 ? "" : test.slice(hash + 1);
|
|
517
|
+
const methods = groups.get(klass);
|
|
518
|
+
if (methods) {
|
|
519
|
+
if (method)
|
|
520
|
+
methods.push(method);
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
groups.set(klass, method ? [method] : []);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return [...groups.entries()]
|
|
527
|
+
.map(([klass, methods]) => (methods.length > 0 ? `${klass}#${methods.join("+")}` : klass))
|
|
528
|
+
.join(",");
|
|
529
|
+
}
|
|
471
530
|
function surefireTest(name) {
|
|
472
531
|
const leaf = name.split("::").pop() ?? name;
|
|
473
532
|
const dot = leaf.lastIndexOf(".");
|
|
474
533
|
const body = dot <= 0 ? leaf : `${leaf.slice(0, dot)}#${leaf.slice(dot + 1)}`;
|
|
475
|
-
// testShut[0]
|
|
476
|
-
|
|
534
|
+
// testShut[0] matches nothing. A bare testShut matches on Surefire 3.6 and runs
|
|
535
|
+
// zero tests on 3.5. testShut* matches every invocation on both. method(Parser)[1] keeps the types.
|
|
536
|
+
const invocation = /\[[^\]]*\]$/.test(body);
|
|
537
|
+
const method = body.replace(/\[[^\]]*\]$/, "");
|
|
538
|
+
return invocation ? `${method}*` : method;
|
|
477
539
|
}
|
|
478
540
|
function escapeRegExp(value) {
|
|
479
541
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -764,146 +826,18 @@ function scriptInvocation(pkg) {
|
|
|
764
826
|
if (!suiteNeedsTty(pkg))
|
|
765
827
|
return { bin: "bash", args: ["run_tests.sh"], command: "bash run_tests.sh" };
|
|
766
828
|
if (gnuScript()) {
|
|
767
|
-
|
|
829
|
+
// -e returns the child status. Without it, util-linux script exits 0 and a failing suite looks green.
|
|
830
|
+
const args = ["-q", "-e", "-c", "bash run_tests.sh", "/dev/null"];
|
|
768
831
|
return { bin: "script", args, command: shown("script", args) };
|
|
769
832
|
}
|
|
770
833
|
const args = ["-q", "/dev/null", "bash", "run_tests.sh"];
|
|
771
834
|
return { bin: "script", args, command: shown("script", args) };
|
|
772
835
|
}
|
|
773
836
|
function runScript(pkg, timeoutMs, env, launched) {
|
|
774
|
-
|
|
775
|
-
const shim = writeDockerShim(pkg);
|
|
776
|
-
if (shim)
|
|
777
|
-
next.PATH = `${shim}${path.delimiter}${next.PATH ?? ""}`;
|
|
778
|
-
// This project's CI sets ARCH_NATIVE=1. Without it, ci/run_build.sh skips the tests.
|
|
779
|
-
const inner = path.join(pkg, "test", "run_inner_tests.py");
|
|
780
|
-
const build = path.join(pkg, "ci", "run_build.sh");
|
|
781
|
-
if (!next.ARCH_NATIVE && existsSync(inner) && existsSync(build) && readFileSync(build, "utf8").includes("ARCH_NATIVE")) {
|
|
782
|
-
next.ARCH_NATIVE = "1";
|
|
783
|
-
}
|
|
784
|
-
return spawnCollected(launched.bin, launched.args, pkg, next, timeoutMs);
|
|
785
|
-
}
|
|
786
|
-
function writeDockerShim(pkg) {
|
|
787
|
-
const found = spawnSync("sh", ["-c", "command -v docker"], { encoding: "utf8" });
|
|
788
|
-
const real = found.stdout?.trim() ?? "";
|
|
789
|
-
if (found.status !== 0 || !real)
|
|
790
|
-
return null;
|
|
791
|
-
const dir = path.join(pkg, ".probatio-suite", "bin");
|
|
792
|
-
mkdirSync(dir, { recursive: true });
|
|
793
|
-
const file = path.join(dir, "docker");
|
|
794
|
-
writeFileSync(file, dockerShimScript(real), { mode: 0o755 });
|
|
795
|
-
return dir;
|
|
796
|
-
}
|
|
797
|
-
function dockerShimScript(real) {
|
|
798
|
-
return `#!/bin/bash
|
|
799
|
-
set -euo pipefail
|
|
800
|
-
REAL=${JSON.stringify(real)}
|
|
801
|
-
if [[ "\${1:-}" != "build" ]]; then
|
|
802
|
-
exec "$REAL" "$@"
|
|
803
|
-
fi
|
|
804
|
-
shift
|
|
805
|
-
args=()
|
|
806
|
-
context=""
|
|
807
|
-
while [[ $# -gt 0 ]]; do
|
|
808
|
-
case "$1" in
|
|
809
|
-
--build-arg|--file|-f|--tag|-t|--target|--platform|--iidfile|--label|--network|--output|-o|--secret|--ssh|--cache-from|--cache-to|--build-context|--ulimit|--add-host)
|
|
810
|
-
args+=("$1" "$2"); shift 2 ;;
|
|
811
|
-
--build-arg=*|--file=*|--tag=*|--target=*|--platform=*|--network=*|--output=*)
|
|
812
|
-
args+=("$1"); shift ;;
|
|
813
|
-
--)
|
|
814
|
-
shift; context="\${1:-}"; break ;;
|
|
815
|
-
-*)
|
|
816
|
-
args+=("$1"); shift ;;
|
|
817
|
-
*)
|
|
818
|
-
context="$1"; shift ;;
|
|
819
|
-
esac
|
|
820
|
-
done
|
|
821
|
-
if [[ -z "$context" ]]; then
|
|
822
|
-
exec "$REAL" build --pull=false "\${args[@]}"
|
|
823
|
-
fi
|
|
824
|
-
src=$(cd "$context" && pwd)
|
|
825
|
-
tmp=$(mktemp -d)
|
|
826
|
-
trap 'rm -rf "$tmp"' EXIT
|
|
827
|
-
cp -a "$src"/. "$tmp"/
|
|
828
|
-
deps="$tmp/ci/install_deps.sh"
|
|
829
|
-
if [[ -f "$deps" ]] && grep -q "pip install --upgrade pip" "$deps"; then
|
|
830
|
-
python3 - "$deps" << 'PY'
|
|
831
|
-
import sys
|
|
832
|
-
from pathlib import Path
|
|
833
|
-
p = Path(sys.argv[1])
|
|
834
|
-
text = p.read_text()
|
|
835
|
-
old = "python3 -m pip install --upgrade pip\\npython3 -m pip install virtualenv\\n"
|
|
836
|
-
new = """python3 -m pip install 'pip==20.3.4'
|
|
837
|
-
printf '%s\\\\n' '[global]' 'constraint = /etc/pip-constraints.txt' > /etc/pip.conf
|
|
838
|
-
printf '%s\\\\n' 'virtualenv==16.7.10' 'psutil==5.6.7' 'python-prctl==1.8.1' > /etc/pip-constraints.txt
|
|
839
|
-
python3 -m pip install 'virtualenv==16.7.10'
|
|
840
|
-
"""
|
|
841
|
-
if old not in text:
|
|
842
|
-
raise SystemExit(0)
|
|
843
|
-
p.write_text(text.replace(old, new, 1))
|
|
844
|
-
p.chmod(0o755)
|
|
845
|
-
PY
|
|
846
|
-
fi
|
|
847
|
-
"$REAL" build --pull=false "\${args[@]}" "$tmp"
|
|
848
|
-
`;
|
|
837
|
+
return spawnCollected(launched.bin, launched.args, pkg, env, timeoutMs);
|
|
849
838
|
}
|
|
850
839
|
function runSwift(pkg, timeoutMs, env) {
|
|
851
|
-
|
|
852
|
-
if (declaresOwnPredicate(pkg)) {
|
|
853
|
-
const overlay = foundationPredicateOverlay();
|
|
854
|
-
if (overlay) {
|
|
855
|
-
args.push("-Xswiftc", "-vfsoverlay", "-Xswiftc", overlay.file, "-Xswiftc", "-module-cache-path", "-Xswiftc", overlay.cache);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
return spawnCollected("swift", args, pkg, env, timeoutMs);
|
|
859
|
-
}
|
|
860
|
-
function declaresOwnPredicate(pkg) {
|
|
861
|
-
return walk(pkg, (rel) => rel.endsWith(".swift")).some((rel) => /struct\s+Predicate\s*</.test(readFileSync(path.join(pkg, rel), "utf8")));
|
|
862
|
-
}
|
|
863
|
-
function foundationPredicateOverlay() {
|
|
864
|
-
const sdk = spawnSync("xcrun", ["--sdk", "macosx", "--show-sdk-path"], { encoding: "utf8" });
|
|
865
|
-
const sdkPath = sdk.stdout?.trim() ?? "";
|
|
866
|
-
if (sdk.status !== 0 || !sdkPath)
|
|
867
|
-
return null;
|
|
868
|
-
const moduleDir = path.join(sdkPath, "System/Library/Frameworks/Foundation.framework/Modules/Foundation.swiftmodule");
|
|
869
|
-
if (!existsSync(moduleDir))
|
|
870
|
-
return null;
|
|
871
|
-
const interfaces = readdirSync(moduleDir).filter((name) => name.endsWith(".swiftinterface"));
|
|
872
|
-
if (interfaces.length === 0)
|
|
873
|
-
return null;
|
|
874
|
-
const stamp = String(statSync(path.join(moduleDir, interfaces[0])).mtimeMs);
|
|
875
|
-
const root = path.join(tmpdir(), "probatio-foundation-overlay");
|
|
876
|
-
const edited = path.join(root, "interfaces");
|
|
877
|
-
const file = path.join(root, "overlay.json");
|
|
878
|
-
const cache = path.join(root, "cache");
|
|
879
|
-
const stampFile = path.join(root, "stamp");
|
|
880
|
-
mkdirSync(cache, { recursive: true });
|
|
881
|
-
if (!existsSync(stampFile) || readFileSync(stampFile, "utf8") !== stamp || !existsSync(file)) {
|
|
882
|
-
mkdirSync(edited, { recursive: true });
|
|
883
|
-
const contents = [];
|
|
884
|
-
for (const name of readdirSync(moduleDir).sort()) {
|
|
885
|
-
const original = path.join(moduleDir, name);
|
|
886
|
-
if (!statSync(original).isFile())
|
|
887
|
-
continue;
|
|
888
|
-
let external = original;
|
|
889
|
-
if (name.endsWith(".swiftinterface")) {
|
|
890
|
-
external = path.join(edited, name);
|
|
891
|
-
writeFileSync(external, hideFoundationPredicate(readFileSync(original, "utf8")));
|
|
892
|
-
}
|
|
893
|
-
contents.push({ name, type: "file", "external-contents": external });
|
|
894
|
-
}
|
|
895
|
-
writeFileSync(file, `${JSON.stringify({ version: 0, roots: [{ name: moduleDir, type: "directory", contents }] }, null, 2)}\n`);
|
|
896
|
-
writeFileSync(stampFile, stamp);
|
|
897
|
-
}
|
|
898
|
-
return { file, cache };
|
|
899
|
-
}
|
|
900
|
-
function hideFoundationPredicate(text) {
|
|
901
|
-
return text
|
|
902
|
-
.split("public struct Predicate<each Input>")
|
|
903
|
-
.join("public struct HiddenPredicate<each Input>")
|
|
904
|
-
.split("public macro Predicate<each Input>")
|
|
905
|
-
.join("public macro HiddenPredicate<each Input>")
|
|
906
|
-
.replace(/Foundation::Predicate(?![A-Za-z])/g, "Foundation::HiddenPredicate");
|
|
840
|
+
return spawnCollected("swift", ["test"], pkg, env, timeoutMs);
|
|
907
841
|
}
|
|
908
842
|
function readMochaConfig(pkg) {
|
|
909
843
|
const file = path.join(pkg, "package.json");
|
|
@@ -1109,7 +1043,7 @@ function compileFailed(result) {
|
|
|
1109
1043
|
return { ...result, stderr: `PROB_COMPILE_FAILED\n${result.stderr}` };
|
|
1110
1044
|
}
|
|
1111
1045
|
/** A compiler token when this run failed before any test result exists. Null when tests ran. */
|
|
1112
|
-
export function detectCompile(kind, stdout, stderr, code) {
|
|
1046
|
+
export function detectCompile(kind, stdout, stderr, code, config = projectConfig("")) {
|
|
1113
1047
|
if (code === 0)
|
|
1114
1048
|
return null;
|
|
1115
1049
|
const text = `${stdout}\n${stderr}`;
|
|
@@ -1133,14 +1067,19 @@ export function detectCompile(kind, stdout, stderr, code) {
|
|
|
1133
1067
|
return "tsc";
|
|
1134
1068
|
if (kind === "make-test" && !/Tests run:\s*\d+/.test(text) && /error:|cobc:|syntax error/i.test(text))
|
|
1135
1069
|
return "cobc";
|
|
1136
|
-
// A shell suite that dies in the compiler never prints a test
|
|
1137
|
-
if (kind === "script" && !scriptReported(text) &&
|
|
1070
|
+
// A shell suite that dies in the compiler never prints a test line. That mutant did not build.
|
|
1071
|
+
if (kind === "script" && !scriptReported(text, config) && COMPILER_ERROR.test(text))
|
|
1138
1072
|
return "clang";
|
|
1139
1073
|
return null;
|
|
1140
1074
|
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1075
|
+
/** A C or C++ compiler or linker error: `file.c:12:5: error:`, or an undefined symbol. */
|
|
1076
|
+
const COMPILER_ERROR = /^[^\s:]+\.(?:c|cc|cpp|cxx|h|hh|hpp|m|mm):\d+:\d+:\s+(?:fatal\s+)?error:|undefined reference to|Undefined symbols for architecture/m;
|
|
1077
|
+
/** True when the output already has a test line, so a later error is a test, not the build. */
|
|
1078
|
+
function scriptReported(text, config) {
|
|
1079
|
+
return text.split(/\r?\n/).some((raw) => {
|
|
1080
|
+
const line = scriptLine(raw);
|
|
1081
|
+
return (config.testLine !== null && config.testLine.test(line)) || TAP_LINE.test(line);
|
|
1082
|
+
});
|
|
1144
1083
|
}
|
|
1145
1084
|
function scriptLine(raw) {
|
|
1146
1085
|
// `script` prints ^D and a backspace before the program's own line.
|
|
@@ -1178,7 +1117,7 @@ function adapt(kind, pkg, stdout, stderr, code) {
|
|
|
1178
1117
|
if (kind === "swift")
|
|
1179
1118
|
return parseSwift(`${stdout}\n${stderr}`, code);
|
|
1180
1119
|
if (kind === "script")
|
|
1181
|
-
return parseScriptReport(`${stdout}\n${stderr}`, code);
|
|
1120
|
+
return parseScriptReport(`${stdout}\n${stderr}`, code, projectConfig(pkg));
|
|
1182
1121
|
if (kind === "maven")
|
|
1183
1122
|
return mavenReport(pkg, `${stdout}\n${stderr}`, code);
|
|
1184
1123
|
if (kind === "dotnet")
|
|
@@ -1255,19 +1194,48 @@ function parseCargo(text) {
|
|
|
1255
1194
|
return null;
|
|
1256
1195
|
return { tests: names.length, pass: names.length - failed.length, fail: failed.length, failed, names };
|
|
1257
1196
|
}
|
|
1258
|
-
|
|
1197
|
+
/** TAP: `ok 1 - name`, `not ok 2 - name # SKIP`. Many shell suites print it. */
|
|
1198
|
+
const TAP_LINE = /^(not )?ok\b\s*\d*\s*(?:-\s*)?(.*?)\s*(?:#\s*(SKIP|TODO)\b.*)?$/i;
|
|
1199
|
+
/**
|
|
1200
|
+
* A shell suite names its tests with the project's `testLine` from .probatio.json, or with TAP.
|
|
1201
|
+
* With neither, it is one command: exit 0 passes, and a failure is `::command`, not an invented name.
|
|
1202
|
+
*/
|
|
1203
|
+
function parseScriptReport(text, code, config) {
|
|
1204
|
+
const lines = text.split(/\r?\n/).map(scriptLine);
|
|
1205
|
+
if (config.testLine) {
|
|
1206
|
+
const names = [];
|
|
1207
|
+
for (const line of lines) {
|
|
1208
|
+
const match = config.testLine.exec(line);
|
|
1209
|
+
if (!match)
|
|
1210
|
+
continue;
|
|
1211
|
+
const name = (match[1] ?? match[0]).trim();
|
|
1212
|
+
if (name && !names.includes(name))
|
|
1213
|
+
names.push(name);
|
|
1214
|
+
}
|
|
1215
|
+
// A configured test line that never printed is not a report. The baseline stops on that.
|
|
1216
|
+
if (names.length === 0)
|
|
1217
|
+
return null;
|
|
1218
|
+
const passed = code === 0 || (config.passLine !== null && lines.some((line) => config.passLine.test(line)));
|
|
1219
|
+
// The suite stops at the test that failed, so the last test line is the one that was running.
|
|
1220
|
+
const failed = passed ? [] : [{ name: names[names.length - 1], file: "", line: 0 }];
|
|
1221
|
+
return { tests: names.length, pass: names.length - failed.length, fail: failed.length, failed, names };
|
|
1222
|
+
}
|
|
1259
1223
|
const names = [];
|
|
1260
|
-
const
|
|
1261
|
-
for (const
|
|
1262
|
-
const
|
|
1263
|
-
if (!
|
|
1224
|
+
const failed = [];
|
|
1225
|
+
for (const line of lines) {
|
|
1226
|
+
const match = TAP_LINE.exec(line);
|
|
1227
|
+
if (!match || !match[2])
|
|
1264
1228
|
continue;
|
|
1265
|
-
|
|
1229
|
+
const name = match[2];
|
|
1230
|
+
if (names.includes(name))
|
|
1231
|
+
continue;
|
|
1232
|
+
names.push(name);
|
|
1233
|
+
if (match[1] && !match[3])
|
|
1234
|
+
failed.push({ name, file: "", line: 0 });
|
|
1266
1235
|
}
|
|
1267
|
-
if (names.length
|
|
1268
|
-
return
|
|
1269
|
-
|
|
1270
|
-
return { tests: names.length, pass: names.length - failed.length, fail: failed.length, failed, names };
|
|
1236
|
+
if (names.length > 0)
|
|
1237
|
+
return { tests: names.length, pass: names.length - failed.length, fail: failed.length, failed, names };
|
|
1238
|
+
return exitReport("command", code);
|
|
1271
1239
|
}
|
|
1272
1240
|
function parseSwift(text, code) {
|
|
1273
1241
|
const names = [];
|
|
@@ -1403,6 +1371,11 @@ function mavenReport(pkg, text, code) {
|
|
|
1403
1371
|
}
|
|
1404
1372
|
return parseSurefire(pkg) ?? parseMavenText(text);
|
|
1405
1373
|
}
|
|
1374
|
+
/** An attribute on the opening tag. `classname` must not be read as `name`. */
|
|
1375
|
+
export function surefireAttr(fragment, key) {
|
|
1376
|
+
const open = fragment.slice(0, fragment.indexOf(">") === -1 ? fragment.length : fragment.indexOf(">"));
|
|
1377
|
+
return new RegExp(`(?:^|\\s)${key}="([^"]*)"`).exec(open)?.[1] ?? "";
|
|
1378
|
+
}
|
|
1406
1379
|
function parseSurefire(pkg) {
|
|
1407
1380
|
const dir = path.join(pkg, "target", "surefire-reports");
|
|
1408
1381
|
if (!existsSync(dir))
|
|
@@ -1414,11 +1387,11 @@ function parseSurefire(pkg) {
|
|
|
1414
1387
|
continue;
|
|
1415
1388
|
const xml = readFileSync(path.join(dir, name), "utf8");
|
|
1416
1389
|
for (const part of xml.split("<testcase ").slice(1)) {
|
|
1417
|
-
const test =
|
|
1418
|
-
const klass =
|
|
1390
|
+
const test = surefireAttr(part, "name");
|
|
1391
|
+
const klass = surefireAttr(part, "classname");
|
|
1419
1392
|
if (!test)
|
|
1420
1393
|
continue;
|
|
1421
|
-
const id = `${klass}.${test}
|
|
1394
|
+
const id = klass ? `${klass}.${test}` : test;
|
|
1422
1395
|
names.push(id);
|
|
1423
1396
|
if (part.includes("<failure") || part.includes("<error"))
|
|
1424
1397
|
failed.push({ name: id, file: klass, line: 0 });
|
package/dist/mutate/tally.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { SCHEMA_VERSION } from "../contract.js";
|
|
4
|
-
import { advisePrune } from "../matrix/report.js";
|
|
5
4
|
import { isBuildName } from "./kill-label.js";
|
|
5
|
+
import { normalizeResult } from "./run.js";
|
|
6
6
|
import { leadSummary, TIMEOUT_NEXT, WHOLE_PROGRAM_TEST } from "./suite-decision.js";
|
|
7
7
|
const NOT_A_TEST = new Set(["suite", "pytest", "unittest", "command", WHOLE_PROGRAM_TEST]);
|
|
8
8
|
/**
|
|
@@ -21,7 +21,7 @@ export function tallyRun(outDir) {
|
|
|
21
21
|
next: "Run mutate run, then tally the same --out directory.",
|
|
22
22
|
nextCall: null,
|
|
23
23
|
keep: [],
|
|
24
|
-
|
|
24
|
+
noKillsYet: [],
|
|
25
25
|
gaps: [],
|
|
26
26
|
rest: 0,
|
|
27
27
|
pruning: { mode: "advisory", deletedTests: 0, advice: [] },
|
|
@@ -38,7 +38,7 @@ export function tallyRun(outDir) {
|
|
|
38
38
|
next: "Run mutate run, then tally the same --out directory.",
|
|
39
39
|
nextCall: null,
|
|
40
40
|
keep: [],
|
|
41
|
-
|
|
41
|
+
noKillsYet: [],
|
|
42
42
|
gaps: [],
|
|
43
43
|
rest: 0,
|
|
44
44
|
pruning: { mode: "advisory", deletedTests: 0, advice: [] },
|
|
@@ -55,26 +55,37 @@ export function tallyRun(outDir) {
|
|
|
55
55
|
killCounts.set(name, (killCounts.get(name) ?? 0) + 1);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
// One test can be spelled two ways: the kill names its file, the line map does not.
|
|
59
|
+
// The first spelling seen wins, and kill spellings are added first.
|
|
60
|
+
const seen = [];
|
|
61
|
+
const see = (name) => {
|
|
62
|
+
if (!isTestName(name))
|
|
63
|
+
return;
|
|
64
|
+
if (seen.some((known) => namesMatch(known, name)))
|
|
65
|
+
return;
|
|
66
|
+
seen.push(name);
|
|
67
|
+
};
|
|
68
|
+
for (const name of killCounts.keys())
|
|
69
|
+
see(name);
|
|
70
|
+
for (const name of coverageNames(path.join(outDir, "coverage-map.json")))
|
|
71
|
+
see(name);
|
|
63
72
|
for (const result of results) {
|
|
64
|
-
for (const name of result.selectedTests ?? [])
|
|
65
|
-
|
|
66
|
-
seen.add(name);
|
|
67
|
-
}
|
|
73
|
+
for (const name of result.selectedTests ?? [])
|
|
74
|
+
see(name);
|
|
68
75
|
}
|
|
69
76
|
const counts = new Map();
|
|
70
77
|
for (const name of seen)
|
|
71
78
|
counts.set(name, countFor(name, killCounts));
|
|
72
|
-
const pruning = advisePrune(counts);
|
|
73
79
|
const keep = [...counts.entries()]
|
|
74
80
|
.filter(([, killed]) => killed > 0)
|
|
75
81
|
.map(([name]) => name)
|
|
76
82
|
.sort();
|
|
77
|
-
|
|
83
|
+
// One batch is not evidence for a deletion. These tests saw no mutant die in this batch, nothing more.
|
|
84
|
+
const noKillsYet = [...counts.entries()]
|
|
85
|
+
.filter(([, killed]) => killed === 0)
|
|
86
|
+
.map(([name]) => name)
|
|
87
|
+
.sort();
|
|
88
|
+
const pruning = { mode: "advisory", deletedTests: 0, advice: [] };
|
|
78
89
|
const noCoverage = results.filter((result) => result.outcome === "no coverage").length;
|
|
79
90
|
const survived = results.filter((result) => result.outcome === "survived").length;
|
|
80
91
|
const timeouts = results.filter((result) => result.outcome === "timeout").length;
|
|
@@ -88,12 +99,13 @@ export function tallyRun(outDir) {
|
|
|
88
99
|
}))
|
|
89
100
|
.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.id.localeCompare(b.id));
|
|
90
101
|
const shown = gaps.slice(0, 10);
|
|
91
|
-
const summary = leadSummary(noCoverage, survived, "survived", `${keep.length} tests to keep, ${
|
|
102
|
+
const summary = leadSummary(noCoverage, survived, "survived", `${keep.length} tests to keep, ${noKillsYet.length} tests saw no kill in this batch, ${gaps.length} gaps. No test file was deleted.`);
|
|
92
103
|
const notes = [];
|
|
93
104
|
if (noCoverage > 0)
|
|
94
105
|
notes.push(`${noCoverage} no coverage. That line was not seen. It is not a pass and not a gap.`);
|
|
95
|
-
if (gaps.length > 0)
|
|
96
|
-
notes.push(`First gap is ${gaps[0].id} at ${gaps[0].file}:${gaps[0].line}. A survivor is not a pass.`);
|
|
106
|
+
if (gaps.length > 0) {
|
|
107
|
+
notes.push(`First gap is ${gaps[0].id} at ${gaps[0].file}:${gaps[0].line}. A survivor is not a pass. Add one test that fails on that mutant and passes on the code, commit it, then run nextCall.`);
|
|
108
|
+
}
|
|
97
109
|
if (timeouts > 0)
|
|
98
110
|
notes.push(TIMEOUT_NEXT);
|
|
99
111
|
if (notes.length === 0)
|
|
@@ -105,9 +117,9 @@ export function tallyRun(outDir) {
|
|
|
105
117
|
command: "mutate.tally",
|
|
106
118
|
summary,
|
|
107
119
|
next,
|
|
108
|
-
nextCall: keep.length > 0
|
|
120
|
+
nextCall: nextArgv(outDir, keep, gaps.length > 0),
|
|
109
121
|
keep,
|
|
110
|
-
|
|
122
|
+
noKillsYet,
|
|
111
123
|
gaps,
|
|
112
124
|
rest: 0,
|
|
113
125
|
pruning,
|
|
@@ -117,6 +129,59 @@ export function tallyRun(outDir) {
|
|
|
117
129
|
writeFileSync(fullPath, `${JSON.stringify(complete, null, 2)}\n`);
|
|
118
130
|
return { ...complete, gaps: shown, rest: gaps.length - shown.length };
|
|
119
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* The command after this tally. A gap reruns the batch on HEAD once the new test is committed.
|
|
134
|
+
* Otherwise the keep ids are rescored at the same commit. Either way the out dir is fresh:
|
|
135
|
+
* the stored out dir would skip every finished mutant and echo the old result.
|
|
136
|
+
*/
|
|
137
|
+
function nextArgv(outDir, keep, hasGaps) {
|
|
138
|
+
if (!hasGaps && keep.length === 0)
|
|
139
|
+
return null;
|
|
140
|
+
let stored = {};
|
|
141
|
+
try {
|
|
142
|
+
stored = JSON.parse(readFileSync(path.join(outDir, "run.json"), "utf8"));
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
stored = {};
|
|
146
|
+
}
|
|
147
|
+
const base = stored.out || outDir;
|
|
148
|
+
const argv = ["mutate", "run"];
|
|
149
|
+
if (stored.package)
|
|
150
|
+
argv.push("--package", stored.package);
|
|
151
|
+
for (const dir of stored.patches ?? [])
|
|
152
|
+
argv.push("--patches", dir);
|
|
153
|
+
argv.push("--out", freshDir(base, hasGaps ? "after-gaps" : "rescore"));
|
|
154
|
+
if (stored.repo)
|
|
155
|
+
argv.push("--repo", stored.repo);
|
|
156
|
+
if (!hasGaps && stored.commit)
|
|
157
|
+
argv.push("--commit", stored.commit);
|
|
158
|
+
if (typeof stored.workers === "number")
|
|
159
|
+
argv.push("--workers", String(stored.workers));
|
|
160
|
+
if (stored.confirm === false)
|
|
161
|
+
argv.push("--no-confirm");
|
|
162
|
+
if (stored.testsDir && stored.testsDir !== "tests")
|
|
163
|
+
argv.push("--tests-dir", stored.testsDir);
|
|
164
|
+
if (typeof stored.suiteTimeoutMs === "number")
|
|
165
|
+
argv.push("--suite-timeout-ms", String(stored.suiteTimeoutMs));
|
|
166
|
+
if (typeof stored.testTimeoutMs === "number")
|
|
167
|
+
argv.push("--test-timeout-ms", String(stored.testTimeoutMs));
|
|
168
|
+
if (stored.direction && stored.direction !== "auto")
|
|
169
|
+
argv.push("--direction", stored.direction);
|
|
170
|
+
// --only-test refuses --suite-command, so a keep rescore uses discovery.
|
|
171
|
+
if (stored.suiteCommand && hasGaps)
|
|
172
|
+
argv.push("--suite-command", stored.suiteCommand);
|
|
173
|
+
if (!hasGaps)
|
|
174
|
+
argv.push(...keep.flatMap((id) => ["--only-test", id]));
|
|
175
|
+
return { argv };
|
|
176
|
+
}
|
|
177
|
+
/** First sibling of the out dir that does not exist yet. The same tally prints the same path. */
|
|
178
|
+
function freshDir(base, label) {
|
|
179
|
+
for (let index = 1;; index++) {
|
|
180
|
+
const candidate = index === 1 ? `${base}.${label}` : `${base}.${label}-${index}`;
|
|
181
|
+
if (!existsSync(candidate))
|
|
182
|
+
return candidate;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
120
185
|
function readResults(dir) {
|
|
121
186
|
const out = [];
|
|
122
187
|
for (const name of readdirSync(dir)) {
|
|
@@ -128,7 +193,7 @@ function readResults(dir) {
|
|
|
128
193
|
continue;
|
|
129
194
|
if (!parsed.id)
|
|
130
195
|
parsed.id = name.slice(0, -".json".length);
|
|
131
|
-
out.push(parsed);
|
|
196
|
+
out.push(normalizeResult(parsed));
|
|
132
197
|
}
|
|
133
198
|
catch {
|
|
134
199
|
continue;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** `--experimental-strip-types` needs this. Older Node is refused before a command runs. */
|
|
2
|
+
export const MIN_NODE = "22.6";
|
|
3
|
+
export function nodeTooOld(version) {
|
|
4
|
+
const match = /^(\d+)\.(\d+)/.exec(version);
|
|
5
|
+
const required = `Node ${version} is too old. Probatio needs Node ${MIN_NODE} or newer.`;
|
|
6
|
+
if (!match)
|
|
7
|
+
return required;
|
|
8
|
+
const major = Number(match[1]);
|
|
9
|
+
const minor = Number(match[2]);
|
|
10
|
+
if (major > 22 || (major === 22 && minor >= 6))
|
|
11
|
+
return null;
|
|
12
|
+
return required;
|
|
13
|
+
}
|