@whaaaley/crush 0.0.0-stage → 0.2.6
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/LICENSE +32 -0
- package/README.md +185 -2
- package/SKILL.md +187 -0
- package/THIRD_PARTY_NOTICES.md +277 -0
- package/dist/capture/capture.operations.d.ts +23 -0
- package/dist/capture/capture.operations.js +231 -0
- package/dist/capture/capture.schema.d.ts +73 -0
- package/dist/capture/capture.schema.js +28 -0
- package/dist/collapse/collapse.operations.d.ts +2 -0
- package/dist/collapse/collapse.operations.js +82 -0
- package/dist/collapse/collapse.schema.d.ts +40 -0
- package/dist/collapse/collapse.schema.js +35 -0
- package/dist/crush.tables.d.ts +3583 -0
- package/dist/crush.tables.js +456 -0
- package/dist/crushes/callback.crush.d.ts +2 -0
- package/dist/crushes/callback.crush.js +19 -0
- package/dist/crushes/crush.d.ts +36 -0
- package/dist/crushes/crush.js +12 -0
- package/dist/crushes/crush.names.d.ts +1 -0
- package/dist/crushes/crush.names.js +2 -0
- package/dist/crushes/crushes.d.ts +2 -0
- package/dist/crushes/crushes.js +9 -0
- package/dist/crushes/default-value.crush.d.ts +2 -0
- package/dist/crushes/default-value.crush.js +29 -0
- package/dist/crushes/drop-operand.crush.d.ts +2 -0
- package/dist/crushes/drop-operand.crush.js +37 -0
- package/dist/crushes/fold.d.ts +64 -0
- package/dist/crushes/fold.js +366 -0
- package/dist/crushes/force-fork.crush.d.ts +2 -0
- package/dist/crushes/force-fork.crush.js +79 -0
- package/dist/crushes/loop-once.crush.d.ts +2 -0
- package/dist/crushes/loop-once.crush.js +71 -0
- package/dist/crushes/optional-chain.crush.d.ts +2 -0
- package/dist/crushes/optional-chain.crush.js +30 -0
- package/dist/crushes/switch-case.crush.d.ts +2 -0
- package/dist/crushes/switch-case.crush.js +19 -0
- package/dist/decisions/decide.d.ts +61 -0
- package/dist/decisions/decide.js +161 -0
- package/dist/decisions/decisions.d.ts +24 -0
- package/dist/decisions/decisions.js +62 -0
- package/dist/decisions/forks.decision.d.ts +4 -0
- package/dist/decisions/forks.decision.js +32 -0
- package/dist/decisions/kinds.d.ts +101 -0
- package/dist/decisions/kinds.js +38 -0
- package/dist/decisions/loops.decision.d.ts +4 -0
- package/dist/decisions/loops.decision.js +39 -0
- package/dist/decisions/shorts.decision.d.ts +3 -0
- package/dist/decisions/shorts.decision.js +66 -0
- package/dist/decisions/switches.decision.d.ts +3 -0
- package/dist/decisions/switches.decision.js +20 -0
- package/dist/decisions/throws.decision.d.ts +3 -0
- package/dist/decisions/throws.decision.js +35 -0
- package/dist/decisions/values.decision.d.ts +3 -0
- package/dist/decisions/values.decision.js +67 -0
- package/dist/explore/edges/explore.d.ts +60 -0
- package/dist/explore/edges/explore.db.d.ts +22 -0
- package/dist/explore/edges/explore.db.js +55 -0
- package/dist/explore/edges/explore.js +305 -0
- package/dist/explore/edges/random.d.ts +2 -0
- package/dist/explore/edges/random.js +32 -0
- package/dist/explore/explore.operations.d.ts +30 -0
- package/dist/explore/explore.operations.js +117 -0
- package/dist/explore/limits.operations.d.ts +14 -0
- package/dist/explore/limits.operations.js +20 -0
- package/dist/explore/targets.operations.d.ts +36 -0
- package/dist/explore/targets.operations.js +32 -0
- package/dist/explore/utils/draws.d.ts +6 -0
- package/dist/explore/utils/draws.js +2 -0
- package/dist/explore/utils/edits.d.ts +15 -0
- package/dist/explore/utils/edits.js +151 -0
- package/dist/explore/utils/guide.d.ts +23 -0
- package/dist/explore/utils/guide.js +35 -0
- package/dist/explore/utils/keep.d.ts +10 -0
- package/dist/explore/utils/keep.js +61 -0
- package/dist/explore/utils/pools.d.ts +17 -0
- package/dist/explore/utils/pools.js +121 -0
- package/dist/explore/utils/reads.d.ts +19 -0
- package/dist/explore/utils/reads.js +118 -0
- package/dist/explore/utils/twin.d.ts +21 -0
- package/dist/explore/utils/twin.js +55 -0
- package/dist/forks/forks.operations.d.ts +32 -0
- package/dist/forks/forks.operations.js +134 -0
- package/dist/forks/forks.schema.d.ts +20 -0
- package/dist/forks/forks.schema.js +14 -0
- package/dist/graph/cfg/cfg.d.ts +28 -0
- package/dist/graph/cfg/cfg.js +31 -0
- package/dist/graph/cfg/code-paths/analyzer.d.ts +27 -0
- package/dist/graph/cfg/code-paths/analyzer.js +358 -0
- package/dist/graph/cfg/code-paths/segments.d.ts +44 -0
- package/dist/graph/cfg/code-paths/segments.js +105 -0
- package/dist/graph/cfg/code-paths/state.d.ts +121 -0
- package/dist/graph/cfg/code-paths/state.js +611 -0
- package/dist/graph/cfg/entries.d.ts +13 -0
- package/dist/graph/cfg/entries.js +120 -0
- package/dist/graph/cfg/functions.d.ts +6 -0
- package/dist/graph/cfg/functions.js +47 -0
- package/dist/graph/cfg/paths.d.ts +27 -0
- package/dist/graph/cfg/paths.js +91 -0
- package/dist/graph/cfg/scopes/scopes.d.ts +40 -0
- package/dist/graph/cfg/scopes/scopes.js +375 -0
- package/dist/graph/symbols/file.d.ts +90 -0
- package/dist/graph/symbols/file.js +427 -0
- package/dist/graph/symbols/keys.d.ts +13 -0
- package/dist/graph/symbols/keys.js +22 -0
- package/dist/graph/symbols/resolve.operations.d.ts +4 -0
- package/dist/graph/symbols/resolve.operations.js +33 -0
- package/dist/graph/symbols/symbols.d.ts +12 -0
- package/dist/graph/symbols/symbols.js +155 -0
- package/dist/graph/symbols/symbols.schema.d.ts +32 -0
- package/dist/graph/symbols/symbols.schema.js +19 -0
- package/dist/graph/unused/tests.d.ts +7 -0
- package/dist/graph/unused/tests.js +95 -0
- package/dist/graph/unused/unused.d.ts +53 -0
- package/dist/graph/unused/unused.js +319 -0
- package/dist/graph/walk/walk.d.ts +7 -0
- package/dist/graph/walk/walk.js +39 -0
- package/dist/instrument/instrument.operations.d.ts +72 -0
- package/dist/instrument/instrument.operations.js +786 -0
- package/dist/instrument/instrument.schema.d.ts +257 -0
- package/dist/instrument/instrument.schema.js +100 -0
- package/dist/judge/counters.d.ts +86 -0
- package/dist/judge/counters.js +402 -0
- package/dist/judge/edges/api.d.ts +14 -0
- package/dist/judge/edges/api.js +80 -0
- package/dist/judge/edges/completion.reporter.d.ts +9 -0
- package/dist/judge/edges/completion.reporter.js +51 -0
- package/dist/judge/edges/hints.reporter.d.ts +13 -0
- package/dist/judge/edges/hints.reporter.js +29 -0
- package/dist/judge/edges/judge.edges.d.ts +52 -0
- package/dist/judge/edges/judge.edges.js +59 -0
- package/dist/judge/edges/judge.fs.d.ts +8 -0
- package/dist/judge/edges/judge.fs.js +45 -0
- package/dist/judge/edges/merge.d.ts +11 -0
- package/dist/judge/edges/merge.js +60 -0
- package/dist/judge/edges/plugin.d.ts +132 -0
- package/dist/judge/edges/plugin.js +441 -0
- package/dist/judge/edges/reach.d.ts +68 -0
- package/dist/judge/edges/reach.js +132 -0
- package/dist/judge/edges/speed.d.ts +32 -0
- package/dist/judge/edges/speed.js +34 -0
- package/dist/judge/edges/strays.d.ts +1 -0
- package/dist/judge/edges/strays.js +14 -0
- package/dist/judge/edges/vitest.d.ts +20 -0
- package/dist/judge/edges/vitest.js +36 -0
- package/dist/judge/edges/vitest.schema.d.ts +14 -0
- package/dist/judge/edges/vitest.schema.js +16 -0
- package/dist/judge/explore.test.d.ts +1 -0
- package/dist/judge/explore.test.js +101 -0
- package/dist/judge/hints.d.ts +11 -0
- package/dist/judge/hints.js +44 -0
- package/dist/judge/judge.operations.d.ts +218 -0
- package/dist/judge/judge.operations.js +464 -0
- package/dist/judge/judge.schema.d.ts +135 -0
- package/dist/judge/judge.schema.js +129 -0
- package/dist/judge/judge.shard-1.test.d.ts +1 -0
- package/dist/judge/judge.shard-1.test.js +3 -0
- package/dist/judge/judge.shard-2.test.d.ts +1 -0
- package/dist/judge/judge.shard-2.test.js +3 -0
- package/dist/judge/judge.test.d.ts +1 -0
- package/dist/judge/judge.test.js +3 -0
- package/dist/judge/refusals.d.ts +14 -0
- package/dist/judge/refusals.js +10 -0
- package/dist/judge/report.test.d.ts +1 -0
- package/dist/judge/report.test.js +432 -0
- package/dist/judge/runner.d.ts +3 -0
- package/dist/judge/runner.js +1602 -0
- package/dist/judge/stresses.test.d.ts +1 -0
- package/dist/judge/stresses.test.js +12 -0
- package/dist/judge/task-meta.d.ts +51 -0
- package/dist/judge/task-meta.js +3 -0
- package/dist/justify/edges/load.d.ts +7 -0
- package/dist/justify/edges/load.js +40 -0
- package/dist/justify/edges/refresh.fs.d.ts +8 -0
- package/dist/justify/edges/refresh.fs.js +15 -0
- package/dist/justify/justify.operations.d.ts +46 -0
- package/dist/justify/justify.operations.js +80 -0
- package/dist/justify/justify.schema.d.ts +21 -0
- package/dist/justify/justify.schema.js +11 -0
- package/dist/mutators/arithmetic-operator.mutator.d.ts +2 -0
- package/dist/mutators/arithmetic-operator.mutator.js +22 -0
- package/dist/mutators/array-declaration.mutator.d.ts +2 -0
- package/dist/mutators/array-declaration.mutator.js +12 -0
- package/dist/mutators/arrow-function.mutator.d.ts +2 -0
- package/dist/mutators/arrow-function.mutator.js +10 -0
- package/dist/mutators/assignment-operator.mutator.d.ts +2 -0
- package/dist/mutators/assignment-operator.mutator.js +29 -0
- package/dist/mutators/await-expression.mutator.d.ts +2 -0
- package/dist/mutators/await-expression.mutator.js +7 -0
- package/dist/mutators/bitwise-operator.mutator.d.ts +2 -0
- package/dist/mutators/bitwise-operator.mutator.js +19 -0
- package/dist/mutators/block-statement.mutator.d.ts +2 -0
- package/dist/mutators/block-statement.mutator.js +30 -0
- package/dist/mutators/boolean-literal.mutator.d.ts +2 -0
- package/dist/mutators/boolean-literal.mutator.js +5 -0
- package/dist/mutators/coercion.mutator.d.ts +2 -0
- package/dist/mutators/coercion.mutator.js +28 -0
- package/dist/mutators/conditional-expression.mutator.d.ts +2 -0
- package/dist/mutators/conditional-expression.mutator.js +36 -0
- package/dist/mutators/disposal.mutator.d.ts +2 -0
- package/dist/mutators/disposal.mutator.js +13 -0
- package/dist/mutators/empty-destructuring.mutator.d.ts +2 -0
- package/dist/mutators/empty-destructuring.mutator.js +35 -0
- package/dist/mutators/empty-return.mutator.d.ts +2 -0
- package/dist/mutators/empty-return.mutator.js +35 -0
- package/dist/mutators/equality-operator.mutator.d.ts +2 -0
- package/dist/mutators/equality-operator.mutator.js +16 -0
- package/dist/mutators/loop-exit.mutator.d.ts +2 -0
- package/dist/mutators/loop-exit.mutator.js +5 -0
- package/dist/mutators/method-expression.mutator.d.ts +2 -0
- package/dist/mutators/method-expression.mutator.js +59 -0
- package/dist/mutators/missing-lookup.mutator.d.ts +2 -0
- package/dist/mutators/missing-lookup.mutator.js +25 -0
- package/dist/mutators/mutator.d.ts +40 -0
- package/dist/mutators/mutator.js +49 -0
- package/dist/mutators/mutator.names.d.ts +3 -0
- package/dist/mutators/mutator.names.js +43 -0
- package/dist/mutators/mutators.d.ts +8 -0
- package/dist/mutators/mutators.js +84 -0
- package/dist/mutators/nested-condition.mutator.d.ts +2 -0
- package/dist/mutators/nested-condition.mutator.js +16 -0
- package/dist/mutators/number-literal.mutator.d.ts +3 -0
- package/dist/mutators/number-literal.mutator.js +13 -0
- package/dist/mutators/object-literal.mutator.d.ts +2 -0
- package/dist/mutators/object-literal.mutator.js +6 -0
- package/dist/mutators/odd-number.mutator.d.ts +2 -0
- package/dist/mutators/odd-number.mutator.js +15 -0
- package/dist/mutators/operand-deletion.mutator.d.ts +2 -0
- package/dist/mutators/operand-deletion.mutator.js +9 -0
- package/dist/mutators/outcome.mutator.d.ts +3 -0
- package/dist/mutators/outcome.mutator.js +45 -0
- package/dist/mutators/plain-assignment.mutator.d.ts +2 -0
- package/dist/mutators/plain-assignment.mutator.js +7 -0
- package/dist/mutators/power-operator.mutator.d.ts +2 -0
- package/dist/mutators/power-operator.mutator.js +13 -0
- package/dist/mutators/private-brand.mutator.d.ts +2 -0
- package/dist/mutators/private-brand.mutator.js +7 -0
- package/dist/mutators/regex.mutator.d.ts +2 -0
- package/dist/mutators/regex.mutator.js +29 -0
- package/dist/mutators/short-iteration.mutator.d.ts +2 -0
- package/dist/mutators/short-iteration.mutator.js +8 -0
- package/dist/mutators/string-literal.mutator.d.ts +3 -0
- package/dist/mutators/string-literal.mutator.js +149 -0
- package/dist/mutators/switch-default.mutator.d.ts +2 -0
- package/dist/mutators/switch-default.mutator.js +13 -0
- package/dist/mutators/sync-iteration.mutator.d.ts +3 -0
- package/dist/mutators/sync-iteration.mutator.js +9 -0
- package/dist/mutators/thrown-call.mutator.d.ts +2 -0
- package/dist/mutators/thrown-call.mutator.js +7 -0
- package/dist/mutators/unary-operator.mutator.d.ts +2 -0
- package/dist/mutators/unary-operator.mutator.js +18 -0
- package/dist/mutators/unbound-call.mutator.d.ts +2 -0
- package/dist/mutators/unbound-call.mutator.js +14 -0
- package/dist/mutators/update-operator.mutator.d.ts +2 -0
- package/dist/mutators/update-operator.mutator.js +15 -0
- package/dist/mutators/yield-value.mutator.d.ts +2 -0
- package/dist/mutators/yield-value.mutator.js +7 -0
- package/dist/parity/compare.d.ts +27 -0
- package/dist/parity/compare.js +26 -0
- package/dist/parity/corpus.parity.d.ts +1 -0
- package/dist/parity/corpus.parity.js +97 -0
- package/dist/parity/edges/corpus.fs.d.ts +3 -0
- package/dist/parity/edges/corpus.fs.js +30 -0
- package/dist/parity/edges/ports.d.ts +2 -0
- package/dist/parity/edges/ports.js +21 -0
- package/dist/parity/edges/vitest.d.ts +2 -0
- package/dist/parity/edges/vitest.js +3 -0
- package/dist/parity/parity.operations.d.ts +33 -0
- package/dist/parity/parity.operations.js +60 -0
- package/dist/parity/parity.schema.d.ts +5 -0
- package/dist/parity/parity.schema.js +6 -0
- package/dist/parity/stryker/compare.d.ts +14 -0
- package/dist/parity/stryker/compare.js +52 -0
- package/dist/parity/stryker/edges/ports.d.ts +12 -0
- package/dist/parity/stryker/edges/ports.js +28 -0
- package/dist/parity/stryker/equivalence.d.ts +1 -0
- package/dist/parity/stryker/equivalence.js +42 -0
- package/dist/parity/stryker/intended.d.ts +29 -0
- package/dist/parity/stryker/intended.js +152 -0
- package/dist/parity/stryker/normalize.d.ts +27 -0
- package/dist/parity/stryker/normalize.js +181 -0
- package/dist/parity/stryker/rules.d.ts +6 -0
- package/dist/parity/stryker/rules.js +116 -0
- package/dist/parity/stryker/sides.d.ts +46 -0
- package/dist/parity/stryker/sides.js +199 -0
- package/dist/parity/stryker/stryker.parity.d.ts +1 -0
- package/dist/parity/stryker/stryker.parity.js +147 -0
- package/dist/parity/stryker/stryker.schema.d.ts +6 -0
- package/dist/parity/stryker/stryker.schema.js +7 -0
- package/dist/parity/views.d.ts +21 -0
- package/dist/parity/views.js +119 -0
- package/dist/questions/questions.operations.d.ts +110 -0
- package/dist/questions/questions.operations.js +446 -0
- package/dist/questions/questions.schema.d.ts +57 -0
- package/dist/questions/questions.schema.js +28 -0
- package/dist/record/edges/calls.db.d.ts +10 -0
- package/dist/record/edges/calls.db.js +91 -0
- package/dist/record/edges/hits.db.d.ts +3 -0
- package/dist/record/edges/hits.db.js +5 -0
- package/dist/record/edges/holds.db.d.ts +4 -0
- package/dist/record/edges/holds.db.js +31 -0
- package/dist/record/edges/judged-state.db.d.ts +5 -0
- package/dist/record/edges/judged-state.db.js +25 -0
- package/dist/record/edges/markers.db.d.ts +11 -0
- package/dist/record/edges/markers.db.js +55 -0
- package/dist/record/edges/merge.db.d.ts +7 -0
- package/dist/record/edges/merge.db.js +46 -0
- package/dist/record/edges/parts.db.d.ts +42 -0
- package/dist/record/edges/parts.db.js +389 -0
- package/dist/record/edges/parts.edges.d.ts +2 -0
- package/dist/record/edges/parts.edges.js +7 -0
- package/dist/record/edges/parts.fs.d.ts +1 -0
- package/dist/record/edges/parts.fs.js +11 -0
- package/dist/record/edges/parts.writer.d.ts +1 -0
- package/dist/record/edges/parts.writer.js +85 -0
- package/dist/record/edges/passes.db.d.ts +19 -0
- package/dist/record/edges/passes.db.js +31 -0
- package/dist/record/edges/plan.db.d.ts +21 -0
- package/dist/record/edges/plan.db.js +174 -0
- package/dist/record/edges/reach.db.d.ts +6 -0
- package/dist/record/edges/reach.db.js +62 -0
- package/dist/record/edges/record.db.d.ts +22 -0
- package/dist/record/edges/record.db.js +176 -0
- package/dist/record/edges/record.fs.d.ts +3 -0
- package/dist/record/edges/record.fs.js +7 -0
- package/dist/record/edges/site-verdicts.db.d.ts +11 -0
- package/dist/record/edges/site-verdicts.db.js +66 -0
- package/dist/record/edges/verified.db.d.ts +7 -0
- package/dist/record/edges/verified.db.js +71 -0
- package/dist/record/parts.operations.d.ts +26 -0
- package/dist/record/parts.operations.js +31 -0
- package/dist/record/path-checks.operations.d.ts +15 -0
- package/dist/record/path-checks.operations.js +84 -0
- package/dist/record/record.operations.d.ts +36 -0
- package/dist/record/record.operations.js +11 -0
- package/dist/stresses/edges/stresses.record.d.ts +4 -0
- package/dist/stresses/edges/stresses.record.js +37 -0
- package/dist/stresses/stresses.operations.d.ts +28 -0
- package/dist/stresses/stresses.operations.js +22 -0
- package/dist/utils/ast.d.ts +55 -0
- package/dist/utils/ast.js +181 -0
- package/dist/utils/errors.d.ts +8 -0
- package/dist/utils/errors.js +12 -0
- package/dist/utils/faults.d.ts +6 -0
- package/dist/utils/faults.js +10 -0
- package/dist/utils/lookup.d.ts +4 -0
- package/dist/utils/lookup.js +27 -0
- package/dist/utils/order.d.ts +2 -0
- package/dist/utils/order.js +17 -0
- package/dist/utils/retry.d.ts +14 -0
- package/dist/utils/retry.js +15 -0
- package/dist/utils/safe.d.ts +11 -0
- package/dist/utils/safe.js +31 -0
- package/migrations/main/20261129123324_initial/migration.sql +418 -0
- package/migrations/main/20261129123324_initial/snapshot.json +3641 -0
- package/package.json +89 -4
- package/references/consumer-setup.md +92 -0
- package/src/graph/cfg/code-paths/LICENSE +21 -0
- package/src/graph/cfg/scopes/LICENSE +24 -0
|
@@ -0,0 +1,1602 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
53
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
54
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
55
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
56
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return path;
|
|
60
|
+
};
|
|
61
|
+
import { join, relative, resolve, sep } from 'node:path';
|
|
62
|
+
import { pathToFileURL } from 'node:url';
|
|
63
|
+
import { inject, vi } from 'vite-plus/test';
|
|
64
|
+
import { suiteJustificationsOf } from '../justify/edges/load.js';
|
|
65
|
+
import { openCurrentJudgeEdges } from './edges/judge.edges.js';
|
|
66
|
+
import { throwSiteOf } from '../capture/capture.operations.js';
|
|
67
|
+
import { reachedFrom } from '../graph/symbols/symbols.js';
|
|
68
|
+
import { basisOf, hashOf, unitFieldsOf, unitKeyOf } from '../record/record.operations.js';
|
|
69
|
+
import { measureWritesOf } from '../record/edges/record.db.js';
|
|
70
|
+
import { judgePasses } from '../crush.tables.js';
|
|
71
|
+
import { entryAt, itemAt, present } from '../utils/lookup.js';
|
|
72
|
+
import { eachInOrder, firstInOrder } from '../utils/order.js';
|
|
73
|
+
import { CrushError, failed, thrownToVitest } from '../utils/errors.js';
|
|
74
|
+
import { safeAsync } from '../utils/safe.js';
|
|
75
|
+
import { clearedCalls, isLiteralJustification, loadId, setObservations, state, stepLimitOf } from './counters.js';
|
|
76
|
+
import { exploreProperty, exploresMeta } from '../explore/edges/explore.js';
|
|
77
|
+
import { explorableOf, graphOf } from '../explore/targets.operations.js';
|
|
78
|
+
import { answerSitesOf, answeringRidersOf, backupRidersOf, candidatesHashOf, caughtOf, creditedOf, groupOf, fileFailureOf, runFailureOf, hookedOf, metaOf, pointKeyOf, ridersOf, ridingSidesOf, shareOf, suitedOf, stalePartsOf, runKeyOf, testDisplayNameOf, testFileOfKey, testKeyOf, testsUnderOf, timedOutPattern, } from './judge.operations.js';
|
|
79
|
+
import {} from './judge.schema.js';
|
|
80
|
+
import { droppedStrays } from './edges/strays.js';
|
|
81
|
+
import { hasRefusal, markRefusal, readJudgeSource, readJudgeSourceNullable } from './edges/judge.fs.js';
|
|
82
|
+
import { mergeJudged } from './edges/merge.js';
|
|
83
|
+
import { browserModuleOutput, runnerModuleOutput, workerStateOutput } from './edges/vitest.schema.js';
|
|
84
|
+
import { judgeSpeedOf, now } from './edges/speed.js';
|
|
85
|
+
import { explorePathsProvideKey, judgeCoordinators, judgeFilesProvideKey, judgeRedundantProvideKey, judgeRelatedProvideKey, judgeShardsProvideKey, phaseProvideKey, recordPathOf, rootProvideKey, rulesProvideKey, vitestProvideKey, } from './edges/vitest.js';
|
|
86
|
+
import { changedDuringRunOf, failedJudgingOf, stalePlanOf } from './refusals.js';
|
|
87
|
+
// This file loads natively from crush's own tree, where `vite-plus/test` names crush's copy, and the project's tests register with the copy the plugin resolved from the project, whose test functions only that copy can hand back.
|
|
88
|
+
// The values the command project provides reach the worker whichever copy reads them, so crush's own `inject` finds the project's copy.
|
|
89
|
+
const vitestPath = inject(vitestProvideKey);
|
|
90
|
+
if (!vitestPath)
|
|
91
|
+
thrownToVitest(new Error(`crush's runner needs ${vitestProvideKey}, the project's vite-plus/test, which the command project provides`));
|
|
92
|
+
const phase = inject(phaseProvideKey);
|
|
93
|
+
if (!phase)
|
|
94
|
+
thrownToVitest(new Error(`crush's runner needs ${phaseProvideKey}, the pass its project runs, which the command project provides`));
|
|
95
|
+
const { TestRunner } = runnerModuleOutput.parse(await import(__rewriteRelativeImportExtension(vitestPath)));
|
|
96
|
+
// A judging pass keeps each export's calls in every file's baseline; its reruns run under no current test, so they keep none.
|
|
97
|
+
state.isCapturing = phase === 'record' || phase === 'judge';
|
|
98
|
+
// Vitest's own collector and starter, which load a test file and register or run its tests, from the copy the project's tests register with.
|
|
99
|
+
// Neither is a public export, so each is reached through the file Vitest's browser runner imports it from.
|
|
100
|
+
const browserModuleURL = new URL('./browser.js', import.meta.resolve('vitest', pathToFileURL(vitestPath).href)).href;
|
|
101
|
+
const { collectTests, startTests } = browserModuleOutput.parse(await import(__rewriteRelativeImportExtension(browserModuleURL)));
|
|
102
|
+
const judgeFiles = inject(judgeFilesProvideKey);
|
|
103
|
+
// Only `judge:redundant` searches a caught site's other tests for a second catcher.
|
|
104
|
+
const isRedundantSearched = inject(judgeRedundantProvideKey) ?? false;
|
|
105
|
+
// Vitest's private worker state, which it keeps on a global its types do not declare.
|
|
106
|
+
const workerStateOf = () => {
|
|
107
|
+
const parsed = workerStateOutput.safeParse(Object.getOwnPropertyDescriptor(globalThis, '__vitest_worker__')?.value);
|
|
108
|
+
return parsed.success ? { data: parsed.data, error: null } : failed(`crush found no module cache in Vitest's worker state: ${parsed.error.message}`);
|
|
109
|
+
};
|
|
110
|
+
// What every verdict's basis rests on beside its riders and reads, worked out from the command settings.
|
|
111
|
+
const rules = inject(rulesProvideKey);
|
|
112
|
+
if (!rules)
|
|
113
|
+
thrownToVitest(new Error(`crush's runner needs ${rulesProvideKey}, what its verdicts rest on, which the command project provides`));
|
|
114
|
+
// A test's title with every describe above it, outermost first, leaving out the file.
|
|
115
|
+
const titlesOf = (task) => (task.suite ? [...titlesOf(task.suite), task.name] : [task.name]);
|
|
116
|
+
const nameOf = (task) => ({ groups: task.suite ? titlesOf(task.suite) : [], title: task.name });
|
|
117
|
+
const testKeysIn = (root, files) => {
|
|
118
|
+
const keys = new Map();
|
|
119
|
+
for (const each of files) {
|
|
120
|
+
const file = relative(root, each.filepath);
|
|
121
|
+
const seen = new Map();
|
|
122
|
+
const visit = (task) => {
|
|
123
|
+
if (task.type === 'suite')
|
|
124
|
+
task.tasks.forEach(visit);
|
|
125
|
+
else
|
|
126
|
+
keys.set(task.id, testKeyOf(file, nameOf(task), seen));
|
|
127
|
+
};
|
|
128
|
+
each.tasks.forEach(visit);
|
|
129
|
+
}
|
|
130
|
+
return keys;
|
|
131
|
+
};
|
|
132
|
+
// The key of each place code runs that no test body runs, by the id it runs under: the file's load, its own hooks and every suite's hooks.
|
|
133
|
+
const runKeysOf = (testFile, file) => {
|
|
134
|
+
const keys = new Map([
|
|
135
|
+
[loadId, runKeyOf({ file, titles: null })],
|
|
136
|
+
[testFile.id, runKeyOf({ file, titles: [] })],
|
|
137
|
+
]);
|
|
138
|
+
const walk = (suite) => {
|
|
139
|
+
for (const task of suite.tasks) {
|
|
140
|
+
if (task.type !== 'suite')
|
|
141
|
+
continue;
|
|
142
|
+
keys.set(task.id, runKeyOf({ file, titles: titlesOf(task) }));
|
|
143
|
+
walk(task);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
walk(testFile);
|
|
147
|
+
return keys;
|
|
148
|
+
};
|
|
149
|
+
// Every suite around a test, outermost first, the file's own included.
|
|
150
|
+
const suitesOf = (task) => {
|
|
151
|
+
const suites = [];
|
|
152
|
+
for (let suite = task.suite; suite; suite = suite.suite)
|
|
153
|
+
suites.unshift(suite);
|
|
154
|
+
if (suites[0] !== task.file)
|
|
155
|
+
suites.unshift(task.file);
|
|
156
|
+
return suites;
|
|
157
|
+
};
|
|
158
|
+
// A test's two reruns, each hook bound to the arguments Vitest calls it with.
|
|
159
|
+
// The plain one runs the body inside its `aroundEach`, `beforeEach` and `afterEach`, which every rerun needs so nothing leaks into the next.
|
|
160
|
+
// The suited one runs that inside its suites' `aroundAll`, `beforeAll` and `afterAll` too, since the baseline's suite work is torn down by judging, and a mutant in that work takes effect only when it runs again.
|
|
161
|
+
const rerunsOf = (task, sequence, body) => {
|
|
162
|
+
const levels = suitesOf(task).map((suite) => ({ suite, hooks: TestRunner.getSuiteHooks(suite) }));
|
|
163
|
+
const each = {
|
|
164
|
+
before: levels.map(({ suite, hooks }) => hooks.beforeEach.map((hook) => () => hook(task.context, suite))),
|
|
165
|
+
after: levels.toReversed().map(({ suite, hooks }) => hooks.afterEach.map((hook) => () => hook(task.context, suite))),
|
|
166
|
+
around: levels.flatMap(({ suite, hooks }) => hooks.aroundEach.map((hook) => (use) => hook(use, task.context, suite))),
|
|
167
|
+
};
|
|
168
|
+
const all = levels.map(({ suite, hooks }) => ({
|
|
169
|
+
before: [hooks.beforeAll.map((hook) => () => hook(suite))],
|
|
170
|
+
after: [hooks.afterAll.map((hook) => () => hook(suite))],
|
|
171
|
+
around: hooks.aroundAll.map((hook) => (use) => hook(use, suite)),
|
|
172
|
+
}));
|
|
173
|
+
const hooked = hookedOf({ sequence, wraps: 'test', hooks: each, body: caughtOf(body) });
|
|
174
|
+
const measured = { ticks: 0, budget: 0 };
|
|
175
|
+
// A budget bounds the test's own part alone, so work its suite hooks do around it never spends the test's allowance.
|
|
176
|
+
const plain = async () => {
|
|
177
|
+
const from = state.ticks;
|
|
178
|
+
const outer = state.limit;
|
|
179
|
+
if (measured.budget)
|
|
180
|
+
state.limit = from + measured.budget;
|
|
181
|
+
const error = await hooked();
|
|
182
|
+
measured.ticks = state.ticks - from;
|
|
183
|
+
// The suite hooks' own allowance resumes past the ticks the test's part took, which spent the test's budget, never theirs.
|
|
184
|
+
state.limit = measured.budget && outer ? outer + measured.ticks : outer;
|
|
185
|
+
return error;
|
|
186
|
+
};
|
|
187
|
+
const hasSuiteHooks = levels.some(({ hooks }) => hooks.beforeAll.length + hooks.afterAll.length + hooks.aroundAll.length > 0);
|
|
188
|
+
const budgeted = (budget) => {
|
|
189
|
+
measured.budget = budget;
|
|
190
|
+
};
|
|
191
|
+
return { plain, suited: suitedOf({ sequence, suites: all, body: plain }), hasSuiteHooks, bodyTicks: () => measured.ticks, budgeted };
|
|
192
|
+
};
|
|
193
|
+
// Bounds the test's own part by its baseline and gives suite hooks their own allowance.
|
|
194
|
+
const suiteHookTickCeiling = 10_000_000;
|
|
195
|
+
const failureOf = async (ran) => {
|
|
196
|
+
state.ticks = 0;
|
|
197
|
+
state.isLimitHit = false;
|
|
198
|
+
state.limit = suiteHookTickCeiling;
|
|
199
|
+
ran.budgeted(stepLimitOf(ran.ticks));
|
|
200
|
+
try {
|
|
201
|
+
return await ran.fn();
|
|
202
|
+
}
|
|
203
|
+
finally {
|
|
204
|
+
state.limit = 0;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const rerun = async (ran) => !(await failureOf(ran));
|
|
208
|
+
// Every test of a test file's tree, in run order.
|
|
209
|
+
const testsOf = (suite) => suite.tasks.flatMap((task) => (task.type === 'suite' ? testsOf(task) : [task]));
|
|
210
|
+
const treeRunOf = async ({ file, sequence, keyOf, limitOf, isEligible, isHookBroken }) => {
|
|
211
|
+
const run = { failed: [], isHookFailed: false, isTimedOut: false, ran: 0 };
|
|
212
|
+
// Every test under a suite, keyed in order, for a suite whose hooks kept its tests from running.
|
|
213
|
+
const keysOfTask = (task) => {
|
|
214
|
+
if (task.mode === 'skip' || task.mode === 'todo')
|
|
215
|
+
return [];
|
|
216
|
+
return task.type === 'suite' ? keysUnder(task) : [keyOf(task)];
|
|
217
|
+
};
|
|
218
|
+
const keysUnder = (suite) => suite.tasks.flatMap(keysOfTask);
|
|
219
|
+
// Runs a suite inside its own hooks, answering the keys of every test under it.
|
|
220
|
+
const runSuite = async (suite) => {
|
|
221
|
+
const keys = [];
|
|
222
|
+
const hooks = TestRunner.getSuiteHooks(suite);
|
|
223
|
+
const all = {
|
|
224
|
+
before: [hooks.beforeAll.map((hook) => () => hook(suite))],
|
|
225
|
+
after: [hooks.afterAll.map((hook) => () => hook(suite))],
|
|
226
|
+
around: hooks.aroundAll.map((hook) => (use) => hook(use, suite)),
|
|
227
|
+
};
|
|
228
|
+
// Suites and tests run in order, as Vitest runs them.
|
|
229
|
+
const runTask = async (task) => {
|
|
230
|
+
if (task.mode === 'skip' || task.mode === 'todo')
|
|
231
|
+
return;
|
|
232
|
+
if (task.type === 'suite') {
|
|
233
|
+
keys.push(...(await runSuite(task)));
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
// The first failure decides the run, so later tests are skipped while every suite's own hooks still run.
|
|
237
|
+
// Every test takes its key in order, a skipped one included, so a repeated title is numbered as the baseline numbered it.
|
|
238
|
+
const key = keyOf(task);
|
|
239
|
+
keys.push(key);
|
|
240
|
+
if (run.failed.length)
|
|
241
|
+
return;
|
|
242
|
+
const { plain } = rerunsOf(task, sequence, TestRunner.getTestFn(task));
|
|
243
|
+
state.ticks = 0;
|
|
244
|
+
state.limit = limitOf(key);
|
|
245
|
+
run.ran += 1;
|
|
246
|
+
const error = await plain();
|
|
247
|
+
state.limit = 0;
|
|
248
|
+
// Only a test that may judge the site, one whose baseline and unforced rerun passed, can catch it, so another's failure leaves the run going.
|
|
249
|
+
if (!error || !isEligible(key))
|
|
250
|
+
return;
|
|
251
|
+
if (timedOutPattern.test(error.message))
|
|
252
|
+
run.isTimedOut = true;
|
|
253
|
+
run.failed.push(key);
|
|
254
|
+
};
|
|
255
|
+
const children = async () => {
|
|
256
|
+
await eachInOrder(suite.tasks, runTask);
|
|
257
|
+
return null;
|
|
258
|
+
};
|
|
259
|
+
const error = await hookedOf({ sequence, wraps: 'suite', hooks: all, body: children })();
|
|
260
|
+
// A hook failing before its suite's tests ran left them unkeyed, so they take their keys now, in order.
|
|
261
|
+
if (error && !keys.length)
|
|
262
|
+
keys.push(...keysUnder(suite));
|
|
263
|
+
// A suite hook's failure is a catch only for a test under it that may judge the site, and only in a file whose suite hooks all passed on the baseline, since a hook broken without any mutant shows nothing about it, and a mutant can move which suite is which.
|
|
264
|
+
const witness = keys.find(isEligible);
|
|
265
|
+
if (!error || !witness || isHookBroken)
|
|
266
|
+
return keys;
|
|
267
|
+
run.isHookFailed = true;
|
|
268
|
+
// A failing suite hook decides the run's verdict when no test failed first, so its timeout keeps the verdict from reuse.
|
|
269
|
+
if (!run.failed.length && timedOutPattern.test(error.message))
|
|
270
|
+
run.isTimedOut = true;
|
|
271
|
+
if (!run.failed.length)
|
|
272
|
+
run.failed.push(witness);
|
|
273
|
+
return keys;
|
|
274
|
+
};
|
|
275
|
+
await runSuite(file);
|
|
276
|
+
return run;
|
|
277
|
+
};
|
|
278
|
+
// Whether any suite hook of a test file failed on its baseline run, the file's own included, which shows a hook failing whatever any mutant does.
|
|
279
|
+
const isHookBrokenOf = (suite) => Boolean(suite.result?.errors?.length) || suite.tasks.some((task) => task.type === 'suite' && isHookBrokenOf(task));
|
|
280
|
+
// A test whose function the runner's copy cannot hand back reruns as a throw at every site, each read as a catch, so its file stops the run with its stale part gone.
|
|
281
|
+
const refuseUnfound = ({ unfound, root, clearPart }) => {
|
|
282
|
+
if (!unfound.length)
|
|
283
|
+
return null;
|
|
284
|
+
clearPart();
|
|
285
|
+
markRefusal(root);
|
|
286
|
+
const lines = [
|
|
287
|
+
`crush found no test function for ${unfound.join(', ')}`,
|
|
288
|
+
`The tests registered with another Vitest copy than the runner loads, here ${vitestPath}.`,
|
|
289
|
+
"Every site's rerun would fail and score as caught, so no site is judged.",
|
|
290
|
+
];
|
|
291
|
+
return new CrushError(lines.join('\n'));
|
|
292
|
+
};
|
|
293
|
+
// The first test of another group that fails with the site switched on, a test answering a question about it first, and the reruns that took.
|
|
294
|
+
// Without `judge:redundant`, only the tests answering a question about the site are tried, since their answer counts only where they catch.
|
|
295
|
+
const secondCatchOf = async ({ riders, catcher, site, isRedundantSearched }) => {
|
|
296
|
+
let reruns = 0;
|
|
297
|
+
const caughtBy = async (other) => {
|
|
298
|
+
reruns += 1;
|
|
299
|
+
const failure = await failureOf(other);
|
|
300
|
+
return failure ? { backup: other.key, isTimedOut: timedOutPattern.test(failure.message) } : null;
|
|
301
|
+
};
|
|
302
|
+
const candidates = isRedundantSearched ? backupRidersOf({ riders, catcher, site }) : answeringRidersOf({ riders, catcher, site });
|
|
303
|
+
const found = await firstInOrder(candidates, caughtBy);
|
|
304
|
+
return { backup: found?.backup ?? null, reruns, isTimedOut: found?.isTimedOut ?? false };
|
|
305
|
+
};
|
|
306
|
+
// A plain judge stops at the first catch, and only `judge:redundant` searches the other groups for a second catcher, which is what makes a test redundant.
|
|
307
|
+
const judge = async ({ riders, site, isReachedUntold, isRedundantSearched }) => {
|
|
308
|
+
if (!riders.length)
|
|
309
|
+
return { status: isReachedUntold ? 'survived' : 'unreached', catcher: null, backup: null, reruns: 0, isTimedOut: false };
|
|
310
|
+
let reruns = 0;
|
|
311
|
+
// The site is switched on in the shared counters, so its riders rerun one at a time, stopping at the first catch, and the backup search at the first other group's.
|
|
312
|
+
const caughtBy = async (rider) => {
|
|
313
|
+
reruns += 1;
|
|
314
|
+
const failure = await failureOf(rider);
|
|
315
|
+
if (!failure)
|
|
316
|
+
return null;
|
|
317
|
+
const isTimedOut = timedOutPattern.test(failure.message);
|
|
318
|
+
const second = await secondCatchOf({ riders, catcher: rider, site, isRedundantSearched });
|
|
319
|
+
reruns += second.reruns;
|
|
320
|
+
return { status: 'caught', catcher: rider.key, backup: second.backup, reruns, isTimedOut: isTimedOut || second.isTimedOut };
|
|
321
|
+
};
|
|
322
|
+
return (await firstInOrder(riders, caughtBy)) ?? { status: 'survived', catcher: null, backup: null, reruns, isTimedOut: false };
|
|
323
|
+
};
|
|
324
|
+
// A test file's literal justifications as a unit of its own, beside its top level, whose hash leaves them out.
|
|
325
|
+
const metadataUnitOf = (path) => unitKeyOf(path, '<metadata>');
|
|
326
|
+
// Indexes the read units in the worker's plan. Dynamic source hashes belong to the file that read them.
|
|
327
|
+
const planReadIndexesOf = (plan) => {
|
|
328
|
+
const hashOfPath = new Map();
|
|
329
|
+
const keyOfUnit = new Map();
|
|
330
|
+
const unitHashes = new Map();
|
|
331
|
+
for (const { path, hash, units } of [...plan.files, ...plan.tests]) {
|
|
332
|
+
hashOfPath.set(path, hash);
|
|
333
|
+
for (const unit of units) {
|
|
334
|
+
const key = unitKeyOf(path, unit.name);
|
|
335
|
+
keyOfUnit.set(unit.index, key);
|
|
336
|
+
unitHashes.set(key, unit.hash);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return { hashOfPath, keyOfUnit, unitHashes };
|
|
340
|
+
};
|
|
341
|
+
// A side or site some suite hook took is judged by rerunning its tests inside their suite hooks, which redo that work; any other reruns plain, without the cost of those hooks.
|
|
342
|
+
const rawAt = (counted, index) => [...(counted.get(index) ?? [])];
|
|
343
|
+
// The riders of a site in one file, a suite hook's included: those rerun inside their suite hooks, which redo that work, and those whose own body reached it.
|
|
344
|
+
// An unsteady test does different work on two runs with nothing forced, so it never rides, since its verdicts would differ between judges.
|
|
345
|
+
const ridersFor = ({ observed: { testsUnder, passing, isSuited, steady }, reached, rawIds }) => {
|
|
346
|
+
const riders = ridersOf(reached, passing).filter(({ key }) => steady.has(key));
|
|
347
|
+
// A site code reached at load is judged by a fresh run of the whole file, so every test credited with it rides.
|
|
348
|
+
if (rawIds.includes(loadId) || !rawIds.some((id) => testsUnder.has(id)))
|
|
349
|
+
return riders;
|
|
350
|
+
const bodyKeys = new Set(rawIds.flatMap((id) => passing.get(id)?.key ?? []));
|
|
351
|
+
return riders.filter(({ key }) => isSuited.has(key) || bodyKeys.has(key));
|
|
352
|
+
};
|
|
353
|
+
// Vitest's own runner, crediting each test's fork sides and sites to it, then judging every site this file's tests reached, inside this file's own run.
|
|
354
|
+
// Vitest constructs the runner a project names, so this builds its own runner and returns it with crush's hooks in place of the ones they wrap.
|
|
355
|
+
export default function CrushRunner(config) {
|
|
356
|
+
const runner = new TestRunner(config);
|
|
357
|
+
// The hooks of Vitest's own runner that crush's run before or after.
|
|
358
|
+
const base = {
|
|
359
|
+
onAfterRunFiles: runner.onAfterRunFiles.bind(runner),
|
|
360
|
+
onAfterRunSuite: runner.onAfterRunSuite.bind(runner),
|
|
361
|
+
onAfterRunTask: runner.onAfterRunTask.bind(runner),
|
|
362
|
+
onBeforeRunSuite: runner.onBeforeRunSuite.bind(runner),
|
|
363
|
+
onBeforeRunTask: runner.onBeforeRunTask.bind(runner),
|
|
364
|
+
};
|
|
365
|
+
const session = {
|
|
366
|
+
pass: phase,
|
|
367
|
+
isRunningPass: false,
|
|
368
|
+
coordinationError: null,
|
|
369
|
+
recordSpeed: { started: 0, ended: 0, writes: 0 },
|
|
370
|
+
judgeSpeed: judgeSpeedOf(),
|
|
371
|
+
verificationCandidates: null,
|
|
372
|
+
ran: new Map(),
|
|
373
|
+
edges: null,
|
|
374
|
+
plan: null,
|
|
375
|
+
planReadIndexes: null,
|
|
376
|
+
answerSites: null,
|
|
377
|
+
forcible: null,
|
|
378
|
+
siteKeyOfPoint: null,
|
|
379
|
+
keys: new Map(),
|
|
380
|
+
displaySeen: new Map(),
|
|
381
|
+
unfound: [],
|
|
382
|
+
properties: [],
|
|
383
|
+
loadTicks: 0,
|
|
384
|
+
refusal: null,
|
|
385
|
+
staleLoads: new Map(),
|
|
386
|
+
judgedFiles: new Set(),
|
|
387
|
+
collected: [],
|
|
388
|
+
ownedFiles: new Set(),
|
|
389
|
+
relatedSources: null,
|
|
390
|
+
};
|
|
391
|
+
// Each test of the current file by key with the ticks its baseline took, which bound its part of a fresh run.
|
|
392
|
+
const baselineTicksOf = () => new Map([...session.ran.values()].map(({ key, ticks }) => [key, ticks]));
|
|
393
|
+
// A worker runs several files, so it opens the record, which the plugin made before any file ran, once.
|
|
394
|
+
const currentEdgesOf = () => {
|
|
395
|
+
if (session.edges)
|
|
396
|
+
return { data: session.edges, error: null };
|
|
397
|
+
const opened = openCurrentJudgeEdges(recordPathOf(phase === 'property' ? inject(rootProvideKey) : runner.config.root), (write) => measureWritesOf(session.pass === 'record' ? session.recordSpeed : session.judgeSpeed)(write));
|
|
398
|
+
session.edges = opened.data;
|
|
399
|
+
return opened;
|
|
400
|
+
};
|
|
401
|
+
// Every test file of the project runs in this one worker, so each loads its modules afresh, as an isolated worker would.
|
|
402
|
+
const onBeforeCollect = () => {
|
|
403
|
+
vi.resetModules();
|
|
404
|
+
};
|
|
405
|
+
// A worker can run several files, so each file starts from empty counters.
|
|
406
|
+
// The modules load before runner, so what they took is kept here and their sides and sites stay recorded.
|
|
407
|
+
const onBeforeRunFiles = async (files) => {
|
|
408
|
+
if (phase === 'property')
|
|
409
|
+
return;
|
|
410
|
+
if (judgeFiles && !session.isRunningPass) {
|
|
411
|
+
const coordinator = itemAt(files, 0);
|
|
412
|
+
coordinator.meta.crushJudgeSpeed = session.judgeSpeed;
|
|
413
|
+
const index = judgeCoordinators.findIndex((name) => coordinator.filepath.endsWith(`/${name}`));
|
|
414
|
+
const count = inject(judgeShardsProvideKey);
|
|
415
|
+
// A coordinator past the shards that run at once judges nothing, since the others would wait at a pass's end for one that cannot start.
|
|
416
|
+
if (index >= count)
|
|
417
|
+
return;
|
|
418
|
+
session.coordinationError = await runJudge(judgeFiles, { index, count });
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if (session.pass === 'record')
|
|
422
|
+
session.recordSpeed = { started: now(), ended: 0, writes: 0 };
|
|
423
|
+
session.loadTicks = state.ticks;
|
|
424
|
+
state.limit = 0;
|
|
425
|
+
session.ran.clear();
|
|
426
|
+
session.keys = testKeysIn(runner.config.root, files);
|
|
427
|
+
session.displaySeen.clear();
|
|
428
|
+
session.unfound = [];
|
|
429
|
+
session.properties = [];
|
|
430
|
+
};
|
|
431
|
+
// A suite's `beforeAll` and `afterAll` run under the suite's own id, which judging credits to every test under it.
|
|
432
|
+
const onBeforeRunSuite = async (suite) => {
|
|
433
|
+
await base.onBeforeRunSuite(suite);
|
|
434
|
+
state.current = suite.id;
|
|
435
|
+
};
|
|
436
|
+
// A file is judged as its own suite ends, before Vitest reports it, so a judging failure fails the file where Vitest shows it, and the worker goes on to the next file.
|
|
437
|
+
const onAfterRunSuite = async (suite) => {
|
|
438
|
+
state.current = suite.suite?.id ?? '';
|
|
439
|
+
if (phase !== 'property' && suite.file === suite && (!judgeFiles || session.isRunningPass))
|
|
440
|
+
await judgeOrVerify(suite.file);
|
|
441
|
+
await base.onAfterRunSuite(suite);
|
|
442
|
+
};
|
|
443
|
+
// The next file's modules load under the load id from empty counters, and the next pass starts from them too.
|
|
444
|
+
const clearCounters = () => {
|
|
445
|
+
setObservations(state);
|
|
446
|
+
state.metadataReaders.clear();
|
|
447
|
+
state.passes.clear();
|
|
448
|
+
state.repeats.clear();
|
|
449
|
+
state.weighed.clear();
|
|
450
|
+
state.infected.clear();
|
|
451
|
+
state.entries.clear();
|
|
452
|
+
state.current = loadId;
|
|
453
|
+
state.ticks = 0;
|
|
454
|
+
clearedCalls(state);
|
|
455
|
+
};
|
|
456
|
+
const judgeOrVerify = async (file) => {
|
|
457
|
+
session.judgedFiles.add(file.id);
|
|
458
|
+
if (session.pass === 'record') {
|
|
459
|
+
session.recordSpeed.ended = now();
|
|
460
|
+
file.meta.crushBaselineSpeed = session.recordSpeed;
|
|
461
|
+
}
|
|
462
|
+
const { data: edges, error: recordError } = currentEdgesOf();
|
|
463
|
+
// The verify phase reruns this file's tests with every candidate forced together, where the first phase judges each site alone.
|
|
464
|
+
const verification = session.verificationCandidates;
|
|
465
|
+
let error = recordError;
|
|
466
|
+
const path = relative(runner.config.root, file.filepath);
|
|
467
|
+
if (edges) {
|
|
468
|
+
if (session.pass === 'collect')
|
|
469
|
+
edges.clearFileFailure(path, session.ran.size > 0);
|
|
470
|
+
const judgeWork = session.pass === 'collect' ? () => collectFile(edges, file) : () => recordFile(edges, file);
|
|
471
|
+
const work = verification ? () => verifyFile(edges, file, verification.list, verification.hash) : judgeWork;
|
|
472
|
+
if (session.pass === 'record') {
|
|
473
|
+
const result = await safeAsync(work);
|
|
474
|
+
error = result.error ?? result.data;
|
|
475
|
+
}
|
|
476
|
+
else
|
|
477
|
+
error = await edges.marked(`${process.pid}-${file.id}`, work);
|
|
478
|
+
}
|
|
479
|
+
// Vitest imports a file's modules before onBeforeRunFiles, so the sources it loaded are cleared only once its work is done, failed or not, since the next file in this worker would otherwise read them as its own.
|
|
480
|
+
state.loaded.clear();
|
|
481
|
+
state.outside.clear();
|
|
482
|
+
state.entered = new Set();
|
|
483
|
+
// A refused run stops once the file is reported, as refusing means; any other failure fails this file alone, since a throw would end the worker's run and leave every later file in it unjudged.
|
|
484
|
+
if (error && hasRefusal(runner.config.root))
|
|
485
|
+
session.refusal = error;
|
|
486
|
+
else if (error)
|
|
487
|
+
file.result = { ...file.result, state: 'fail', errors: [...(file.result?.errors ?? []), { name: error.name, message: error.message, stack: error.stack }] };
|
|
488
|
+
const failure = runFailureOf(file);
|
|
489
|
+
if (edges && failure !== null && (session.pass !== 'record' || error))
|
|
490
|
+
edges.setFileFailure(path, failure);
|
|
491
|
+
clearCounters();
|
|
492
|
+
};
|
|
493
|
+
const onBeforeRunTask = async (task) => {
|
|
494
|
+
await base.onBeforeRunTask(task);
|
|
495
|
+
if (phase === 'property') {
|
|
496
|
+
const { data, error } = await exploreProperties();
|
|
497
|
+
if (error)
|
|
498
|
+
thrownToVitest(error);
|
|
499
|
+
task.context.crushExploreProperties = data;
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (judgeFiles && !session.isRunningPass) {
|
|
503
|
+
if (session.coordinationError)
|
|
504
|
+
thrownToVitest(session.coordinationError);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
state.current = task.id;
|
|
508
|
+
state.steps = 0;
|
|
509
|
+
state.ticks = 0;
|
|
510
|
+
};
|
|
511
|
+
const onAfterRunTask = async (task) => {
|
|
512
|
+
if (phase === 'property')
|
|
513
|
+
return base.onAfterRunTask(task);
|
|
514
|
+
if (judgeFiles && !session.isRunningPass)
|
|
515
|
+
return;
|
|
516
|
+
const passed = task.result?.state === 'pass';
|
|
517
|
+
const [failure] = task.result?.errors ?? [];
|
|
518
|
+
const file = relative(runner.config.root, task.file.filepath);
|
|
519
|
+
const key = entryAt(session.keys, task.id, 'the test registered in this file');
|
|
520
|
+
const name = testDisplayNameOf(file, nameOf(task), session.displaySeen);
|
|
521
|
+
// A count no answer could close would ask forever, so a test stating one is refused here, where its meta enters.
|
|
522
|
+
const { data: stated, error: refusal } = metaOf(task.meta);
|
|
523
|
+
if (refusal)
|
|
524
|
+
thrownToVitest(new CrushError(`${key}: ${refusal.message}`));
|
|
525
|
+
// A property's declaration is refused here, where its meta enters, so a misspelled one never explores in silence.
|
|
526
|
+
if (task.meta.explores !== undefined) {
|
|
527
|
+
const declared = exploresMeta.safeParse(task.meta);
|
|
528
|
+
if (!declared.success)
|
|
529
|
+
thrownToVitest(new CrushError(`${key}: its explore meta is no property declaration: ${declared.error.message}`));
|
|
530
|
+
session.properties.push({ meta: declared.data, key });
|
|
531
|
+
}
|
|
532
|
+
const fn = TestRunner.getTestFn(task);
|
|
533
|
+
// The copy that registered the test hands its function back, so another copy gives none.
|
|
534
|
+
if (fn === undefined) {
|
|
535
|
+
session.unfound.push(key);
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
const reruns = rerunsOf(task, runner.config.sequence.hooks, fn);
|
|
539
|
+
session.ran.set(task.id, {
|
|
540
|
+
key,
|
|
541
|
+
name,
|
|
542
|
+
ticks: state.ticks,
|
|
543
|
+
group: groupOf(file, name.groups),
|
|
544
|
+
passed,
|
|
545
|
+
failure: passed ? null : (failure?.message ?? 'failed'),
|
|
546
|
+
steps: state.steps,
|
|
547
|
+
ns: Math.round((task.result?.duration ?? 0) * 1_000_000),
|
|
548
|
+
...stated,
|
|
549
|
+
...reruns,
|
|
550
|
+
fn: reruns.plain,
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
state.current = task.suite?.id ?? task.file.id;
|
|
554
|
+
base.onAfterRunTask(task);
|
|
555
|
+
};
|
|
556
|
+
const onAfterRunFiles = async (files) => {
|
|
557
|
+
if (phase === 'property' || (judgeFiles && !session.isRunningPass))
|
|
558
|
+
return base.onAfterRunFiles(files);
|
|
559
|
+
// Every file judges in the one shared counters state, so files are judged one at a time.
|
|
560
|
+
const unjudged = files.filter(({ id }) => !session.judgedFiles.has(id));
|
|
561
|
+
await eachInOrder(unjudged, judgeOrVerify);
|
|
562
|
+
const { error: afterError } = await safeAsync(() => base.onAfterRunFiles(files));
|
|
563
|
+
// The refusal comes first, since Vitest's cleanup failing after it says less about what went wrong.
|
|
564
|
+
const thrown = session.refusal ?? afterError;
|
|
565
|
+
session.refusal = null;
|
|
566
|
+
if (thrown)
|
|
567
|
+
thrownToVitest(thrown);
|
|
568
|
+
};
|
|
569
|
+
// Each shard runs every pass over its share of the files in its own worker, and ends each pass before any shard starts the next, since the owed work, the merge and the joint check each read every shard's parts.
|
|
570
|
+
const runJudge = async (files, shard) => {
|
|
571
|
+
const { data: edges, error } = currentEdgesOf();
|
|
572
|
+
if (error)
|
|
573
|
+
return error;
|
|
574
|
+
const root = runner.config.root;
|
|
575
|
+
const baselines = edges.getJudged({ withHits: false });
|
|
576
|
+
session.plan ??= edges.getPlan({ withRewrites: false });
|
|
577
|
+
const { hashOfPath } = (session.planReadIndexes ??= planReadIndexesOf(session.plan));
|
|
578
|
+
const currentHashOf = (path) => {
|
|
579
|
+
const kept = hashOfPath.get(path);
|
|
580
|
+
if (kept !== undefined)
|
|
581
|
+
return kept;
|
|
582
|
+
const source = readJudgeSourceNullable(root, path);
|
|
583
|
+
return source === null ? null : hashOf(source);
|
|
584
|
+
};
|
|
585
|
+
const staleParts = stalePartsOf({ parts: baselines, testFiles: files.map((path) => relative(root, path)), hashOf: currentHashOf });
|
|
586
|
+
const missing = new Set(staleParts.map(({ file }) => file));
|
|
587
|
+
let collectFiles = files;
|
|
588
|
+
session.relatedSources = null;
|
|
589
|
+
const paths = (inject(judgeRelatedProvideKey) ?? []).map((path) => relative(root, resolve(root, path.replaceAll('\\', '/'))));
|
|
590
|
+
// A site verdict owned by a test file gone since was dropped with that file's part, so only a whole judge gives its site to the files that remain.
|
|
591
|
+
const current = new Set(files.map((path) => relative(root, path)));
|
|
592
|
+
const isTestGone = () => {
|
|
593
|
+
const keys = present(session.plan).files.flatMap(({ switches, crushes }) => [...switches, ...crushes].map(({ key }) => key));
|
|
594
|
+
return [...edges.getSiteVerdicts(keys).values()].some(({ owner }) => owner !== null && !current.has(owner));
|
|
595
|
+
};
|
|
596
|
+
if (paths.length && !paths.includes('') && !isTestGone()) {
|
|
597
|
+
const matches = (file) => paths.some((path) => file === path || file.startsWith(path + sep));
|
|
598
|
+
const nodes = edges.getReachNodes();
|
|
599
|
+
const out = new Map([...Map.groupBy(edges.getReachEdges(), ({ fromKey }) => fromKey)].map(([key, links]) => [key, links.map(({ toKey }) => toKey)]));
|
|
600
|
+
const reached = reachedFrom(out, nodes.filter(({ file }) => matches(file)).map(({ key }) => key));
|
|
601
|
+
const sources = new Set(nodes.filter(({ key }) => reached.has(key)).map(({ file }) => file));
|
|
602
|
+
const tests = new Set(baselines.filter(({ file, reads }) => matches(file) || reads.some(({ path }) => sources.has(path))).map(({ file }) => file));
|
|
603
|
+
const backwards = new Map();
|
|
604
|
+
for (const [from, destinations] of out) {
|
|
605
|
+
for (const to of destinations) {
|
|
606
|
+
const previous = backwards.get(to);
|
|
607
|
+
if (previous)
|
|
608
|
+
previous.push(from);
|
|
609
|
+
else
|
|
610
|
+
backwards.set(to, [from]);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
const upstream = reachedFrom(backwards, [...reached]);
|
|
614
|
+
for (const { key, file } of nodes)
|
|
615
|
+
if (missing.has(file) && upstream.has(key))
|
|
616
|
+
tests.add(file);
|
|
617
|
+
if (baselines.length)
|
|
618
|
+
for (const file of missing)
|
|
619
|
+
tests.add(file);
|
|
620
|
+
if (!files.some((path) => tests.has(relative(root, path)) || matches(relative(root, path))))
|
|
621
|
+
return null;
|
|
622
|
+
// A site is judged once over its riders from every file, so a related judge judges the sources the paths reach and those its named test files read, collecting every file that reads one.
|
|
623
|
+
// A test file new or changed since its part has reads no run knows yet, so with one a related judge judges every site, where a part stale only for a source it read adds that source.
|
|
624
|
+
const isTestChanged = staleParts.some(({ file, changes }) => changes.some(({ path }) => path === file));
|
|
625
|
+
if (!isTestChanged) {
|
|
626
|
+
const changedSources = staleParts.flatMap(({ changes }) => changes.map(({ path }) => path));
|
|
627
|
+
const judged = new Set([...sources, ...changedSources, ...baselines.filter(({ file }) => matches(file)).flatMap(({ reads }) => reads.map(({ path }) => path))]);
|
|
628
|
+
const readers = new Set(baselines.filter(({ file, reads }) => matches(file) || reads.some(({ path }) => judged.has(path))).map(({ file }) => file));
|
|
629
|
+
collectFiles = files.filter((path) => readers.has(relative(root, path)));
|
|
630
|
+
session.relatedSources = judged;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
const failed = new Map();
|
|
634
|
+
const { data: worker, error: workerError } = workerStateOf();
|
|
635
|
+
if (workerError)
|
|
636
|
+
return workerError;
|
|
637
|
+
const provided = worker.providedContext;
|
|
638
|
+
const run = async (pass, paths) => {
|
|
639
|
+
const started = performance.now();
|
|
640
|
+
session.pass = pass;
|
|
641
|
+
// Tests read the collect pass as the judge phase, the name crushPhase gives it.
|
|
642
|
+
Reflect.set(provided, phaseProvideKey, pass === 'collect' ? 'judge' : pass);
|
|
643
|
+
session.judgedFiles.clear();
|
|
644
|
+
try {
|
|
645
|
+
// Every file in the joint check forces the same list the merge just saved.
|
|
646
|
+
if (pass === 'verify' && paths.length) {
|
|
647
|
+
const list = edges.getCandidates();
|
|
648
|
+
session.verificationCandidates = { list, hash: candidatesHashOf(list) };
|
|
649
|
+
}
|
|
650
|
+
// The files' tests share one module loader and counters state, so files run one at a time.
|
|
651
|
+
const runFile = async (path) => {
|
|
652
|
+
// A spare coordinator ending in this worker leaves no test current, so each file clears the counters itself and loads under the load id.
|
|
653
|
+
clearCounters();
|
|
654
|
+
state.isCapturing = pass === 'collect' && missing.has(relative(root, path));
|
|
655
|
+
const results = await startTests([path], runner);
|
|
656
|
+
for (const file of results) {
|
|
657
|
+
if (file.result?.state !== 'fail')
|
|
658
|
+
continue;
|
|
659
|
+
const failedPath = relative(root, file.filepath);
|
|
660
|
+
const firstFailure = testsOf(file).find(({ result }) => result?.state === 'fail');
|
|
661
|
+
const message = file.result.errors?.[0]?.message ?? firstFailure?.result?.errors?.[0]?.message ?? 'test failed';
|
|
662
|
+
if (!failed.has(failedPath))
|
|
663
|
+
failed.set(failedPath, message);
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
await eachInOrder(paths, runFile);
|
|
667
|
+
}
|
|
668
|
+
finally {
|
|
669
|
+
session.verificationCandidates = null;
|
|
670
|
+
session.judgeSpeed[pass === 'collect' ? 'judge' : 'verify'].ms += performance.now() - started;
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
// A shard ends each pass in the record, with its failure if it threw, and waits for every other shard to end it before starting the next.
|
|
674
|
+
// A pass only the first shard runs, as the merge, is ended by it alone, so the others wait for its end rather than their own.
|
|
675
|
+
const ended = async (pass, work, shards = shard.count) => {
|
|
676
|
+
const { data: failure, error: thrown } = await safeAsync(work);
|
|
677
|
+
const error = thrown ?? failure;
|
|
678
|
+
if (shards === shard.count || !shard.index)
|
|
679
|
+
edges.setPassEnded({ pass, shard: shard.index, failure: error?.message ?? null });
|
|
680
|
+
return error ?? (await edges.passEnded({ pass, shards }));
|
|
681
|
+
};
|
|
682
|
+
const mine = (paths) => shareOf(paths, shard);
|
|
683
|
+
// The passes of this shard, answering the first failure that stops it.
|
|
684
|
+
const passes = async () => {
|
|
685
|
+
// What this judge would judge: crush's rules, every planned file and test by hash, and the test files it runs.
|
|
686
|
+
// What a test read outside them, or its environment, only a rerun of its baseline shows, which a record confirming the state did.
|
|
687
|
+
const plan = present(session.plan);
|
|
688
|
+
const fileHashes = plan.files.map(({ path, hash }) => [path, hash]);
|
|
689
|
+
const testHashes = plan.tests.map(({ path, hash, metadataHash }) => [path, hash, metadataHash ?? null]);
|
|
690
|
+
const judgedStateHash = hashOf(JSON.stringify([rules, fileHashes, testHashes, files.map((path) => relative(root, path)).toSorted()]));
|
|
691
|
+
// Every shard reads the parts before any shard's judging rewrites one, so all of them choose the same files and agree on whether anything moved since the last clean judge.
|
|
692
|
+
let isJudged = false;
|
|
693
|
+
const planError = await ended('plan', async () => {
|
|
694
|
+
// `judge:redundant` searches what a plain judge left unsearched, so it never ends early on a plain judge's state.
|
|
695
|
+
isJudged = !isRedundantSearched && edges.getRecordedStateNullable() === judgedStateHash;
|
|
696
|
+
return null;
|
|
697
|
+
});
|
|
698
|
+
if (planError)
|
|
699
|
+
return planError;
|
|
700
|
+
// A judge of the same parts, sources and settings as the last clean one, every baseline rerun by a record since, judges every site as it did, so each pass ends with the record as that judge left it.
|
|
701
|
+
// The first shard spends the record's confirmation, once every shard read it, so a judge with no record before it judges again.
|
|
702
|
+
if (isJudged) {
|
|
703
|
+
if (!shard.index)
|
|
704
|
+
edges.clearRecordedState();
|
|
705
|
+
const skipped = async (pass) => await ended(pass, async () => null, pass === 'merge' ? 1 : shard.count);
|
|
706
|
+
return await firstInOrder(['judge', 'parts', 'merge', 'verify'], skipped);
|
|
707
|
+
}
|
|
708
|
+
// Every shard runs every test file's baseline and judges its share of the sites once over their riders from all of them.
|
|
709
|
+
session.ownedFiles = new Set(mine(collectFiles).map((path) => relative(root, path)));
|
|
710
|
+
const judgeError = await ended('judge', async () => {
|
|
711
|
+
await run('collect', collectFiles);
|
|
712
|
+
const judgedAt = performance.now();
|
|
713
|
+
// Judging reads only the units its reruns enter, so with no current test the counters record no hit, reach or weighing a rerun would leave behind.
|
|
714
|
+
state.current = '';
|
|
715
|
+
await judgeSites(present(session.plan), shard);
|
|
716
|
+
session.judgeSpeed.judge.ms += performance.now() - judgedAt;
|
|
717
|
+
// Judging reruns record into the counters the last file left, so they clear before the joint check reads its own baseline.
|
|
718
|
+
clearCounters();
|
|
719
|
+
return null;
|
|
720
|
+
});
|
|
721
|
+
if (judgeError)
|
|
722
|
+
return judgeError;
|
|
723
|
+
// Every shard's site verdicts are saved, so each writes its own files' parts before any merges them.
|
|
724
|
+
// Shards writing their parts at once keep retaking the write lock until another's insert waits out SQLite's busy timeout, so each writes once the shards before it ended theirs.
|
|
725
|
+
const partsError = await ended('parts', async () => {
|
|
726
|
+
const turn = await edges.passEnded({ pass: 'parts', shards: shard.index });
|
|
727
|
+
if (turn)
|
|
728
|
+
return turn;
|
|
729
|
+
writeParts(edges);
|
|
730
|
+
return null;
|
|
731
|
+
});
|
|
732
|
+
if (partsError)
|
|
733
|
+
return partsError;
|
|
734
|
+
// The first shard alone merges every part, which the others wait for before checking its candidates.
|
|
735
|
+
const merge = { holds: null };
|
|
736
|
+
const mergeWork = async () => {
|
|
737
|
+
if (shard.index)
|
|
738
|
+
return null;
|
|
739
|
+
const mergedAt = performance.now();
|
|
740
|
+
const merged = mergeJudged(edges, root);
|
|
741
|
+
session.judgeSpeed.merge += performance.now() - mergedAt;
|
|
742
|
+
if (merged.error)
|
|
743
|
+
return merged.error;
|
|
744
|
+
merge.holds = merged.data.saveHolds;
|
|
745
|
+
return null;
|
|
746
|
+
};
|
|
747
|
+
const mergeError = await ended('merge', mergeWork, 1);
|
|
748
|
+
if (mergeError)
|
|
749
|
+
return mergeError;
|
|
750
|
+
const runVerify = async () => {
|
|
751
|
+
await run('verify', mine(collectFiles));
|
|
752
|
+
return null;
|
|
753
|
+
};
|
|
754
|
+
const verifyError = await ended('verify', runVerify);
|
|
755
|
+
if (verifyError)
|
|
756
|
+
return verifyError;
|
|
757
|
+
if (merge.holds) {
|
|
758
|
+
const heldAt = performance.now();
|
|
759
|
+
merge.holds();
|
|
760
|
+
session.judgeSpeed.merge += performance.now() - heldAt;
|
|
761
|
+
}
|
|
762
|
+
// Every shard ended its joint check, so the first saves what this judge judged once nothing failed.
|
|
763
|
+
// A related judge judged only the sites a change reached, so it leaves the state a whole judge would save unsaved.
|
|
764
|
+
if (!failed.size && !shard.index && !session.relatedSources && !isRedundantSearched)
|
|
765
|
+
edges.setJudgedState(judgedStateHash);
|
|
766
|
+
return failed.size ? new CrushError(`${failedJudgingOf(failed.size)}\n${[...failed].map(([path, message]) => `${path}: ${message}`).join('\n')}`) : null;
|
|
767
|
+
};
|
|
768
|
+
session.isRunningPass = true;
|
|
769
|
+
const { data: stopped, error: thrown } = await safeAsync(passes);
|
|
770
|
+
const failure = thrown ?? stopped;
|
|
771
|
+
// A shard stopping early ends every pass it has not, with why, so no other shard waits at one for it.
|
|
772
|
+
if (failure)
|
|
773
|
+
for (const pass of judgePasses)
|
|
774
|
+
edges.setPassEnded({ pass, shard: shard.index, failure: failure.message });
|
|
775
|
+
state.isCapturing = false;
|
|
776
|
+
Reflect.set(provided, phaseProvideKey, phase);
|
|
777
|
+
session.isRunningPass = false;
|
|
778
|
+
return failure;
|
|
779
|
+
};
|
|
780
|
+
// Loads a test file again in fresh module state and registers its tests anew, as Vitest's own collector does, with nothing recorded while it loads.
|
|
781
|
+
const reloadedFileOf = async (filepath) => {
|
|
782
|
+
vi.resetModules();
|
|
783
|
+
const { current } = state;
|
|
784
|
+
state.current = '';
|
|
785
|
+
const { data: files, error } = await safeAsync(() => collectTests([filepath], runner));
|
|
786
|
+
state.current = current;
|
|
787
|
+
if (error)
|
|
788
|
+
return { data: null, error };
|
|
789
|
+
return { data: itemAt(files, 0), error: null };
|
|
790
|
+
};
|
|
791
|
+
// One whole run of a test file loaded with the sites forced from the start, as a plain mutated run: caught by the first test that failed, or by none when the load itself failed, else survived.
|
|
792
|
+
// The load keeps the step limit the file's own load set, each test the limit its baseline set, and the forced modules are cleared after, so nothing judged later sees them.
|
|
793
|
+
const forcedRunOf = async ({ edges, filepath, keys, eligible, isHookBroken, loadTicks, ticksOf }) => {
|
|
794
|
+
session.plan ??= edges.getPlan({ withRewrites: false });
|
|
795
|
+
const { files } = session.plan;
|
|
796
|
+
session.forcible ??= {
|
|
797
|
+
switches: new Map(files.flatMap(({ switches }) => switches.map(({ key, index }) => [key, index]))),
|
|
798
|
+
crushes: new Map(files.flatMap(({ crushes }) => crushes.map(({ key, point, forced }) => [key, { point, forced }]))),
|
|
799
|
+
};
|
|
800
|
+
if (keys.size === 1)
|
|
801
|
+
state.site = session.forcible.switches.get(itemAt([...keys], 0)) ?? -1;
|
|
802
|
+
for (const key of keys) {
|
|
803
|
+
const forcedCrush = session.forcible.crushes.get(key);
|
|
804
|
+
if (forcedCrush)
|
|
805
|
+
state.forced.set(forcedCrush.point, forcedCrush.forced);
|
|
806
|
+
}
|
|
807
|
+
state.ticks = 0;
|
|
808
|
+
state.limit = stepLimitOf(loadTicks);
|
|
809
|
+
const { data: file, error: loadError } = await reloadedFileOf(filepath);
|
|
810
|
+
state.limit = 0;
|
|
811
|
+
const reloaded = file ? testKeysIn(runner.config.root, [file]) : new Map();
|
|
812
|
+
const keyOf = (task) => entryAt(reloaded, task.id, 'the test registered in the reloaded file');
|
|
813
|
+
// A test the baseline never ran has no limit of its own, so it keeps the load's.
|
|
814
|
+
const limitOf = (key) => stepLimitOf(ticksOf.get(key) ?? loadTicks);
|
|
815
|
+
const run = loadError || file.result?.state === 'fail' ? null : await treeRunOf({ file, sequence: runner.config.sequence.hooks, keyOf, limitOf, isEligible: (key) => eligible.has(key), isHookBroken });
|
|
816
|
+
state.site = -1;
|
|
817
|
+
state.forced = new Map();
|
|
818
|
+
// Forced code may have written into any module it reached, a dependency included, so every module is cleared after the run.
|
|
819
|
+
vi.resetModules();
|
|
820
|
+
if (!run)
|
|
821
|
+
return { status: 'caught', catcher: null, reruns: 0, isTimedOut: false };
|
|
822
|
+
const [failed] = run.failed;
|
|
823
|
+
if (failed || run.isHookFailed)
|
|
824
|
+
return { status: 'caught', catcher: failed ?? null, reruns: run.ran, isTimedOut: run.isTimedOut };
|
|
825
|
+
return { status: 'survived', catcher: null, reruns: run.ran, isTimedOut: false };
|
|
826
|
+
};
|
|
827
|
+
// Loads the file again in fresh module state after a site's runs broke it, and points every passing test's reruns at its tests there, by their ids, which a fresh load gives again.
|
|
828
|
+
// A source changed since the plan would load under other counter numbers, so the file refuses to load again.
|
|
829
|
+
const reloadPassing = async ({ testFile, plan, passing, isSuited, loaded }) => {
|
|
830
|
+
const root = runner.config.root;
|
|
831
|
+
const changed = plan.files.filter(({ path, hash }) => loaded.has(path) && hashOf(readJudgeSource(root, path)) !== hash);
|
|
832
|
+
if (changed.length)
|
|
833
|
+
return new CrushError(stalePlanOf(changed.map(({ path }) => path)));
|
|
834
|
+
const { data: file, error } = await reloadedFileOf(testFile.filepath);
|
|
835
|
+
if (error)
|
|
836
|
+
return error;
|
|
837
|
+
const tasks = new Map(testsOf(file).map((task) => [task.id, task]));
|
|
838
|
+
for (const [id, ran] of passing) {
|
|
839
|
+
const task = tasks.get(id);
|
|
840
|
+
const fn = task ? TestRunner.getTestFn(task) : undefined;
|
|
841
|
+
if (!task || !fn) {
|
|
842
|
+
passing.delete(id);
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
const reruns = rerunsOf(task, runner.config.sequence.hooks, fn);
|
|
846
|
+
passing.set(id, { ...ran, ...reruns, fn: isSuited.has(ran.key) ? reruns.suited : reruns.plain });
|
|
847
|
+
}
|
|
848
|
+
return null;
|
|
849
|
+
};
|
|
850
|
+
// Keeps a test file's baseline to judge its sites once over every file's riders, judging nothing yet.
|
|
851
|
+
// The counters clear their repeats and weighed sites in place for the next file, so the file keeps copies of them.
|
|
852
|
+
const collectFile = async (edges, testFile) => {
|
|
853
|
+
const root = runner.config.root;
|
|
854
|
+
const path = relative(root, testFile.filepath);
|
|
855
|
+
const unfound = refuseUnfound({ unfound: session.unfound, root, clearPart: () => edges.clearJudged(path) });
|
|
856
|
+
if (unfound)
|
|
857
|
+
return unfound;
|
|
858
|
+
const { data: justifications, error: metaError } = suiteJustificationsOf(path, testFile, isLiteralJustification);
|
|
859
|
+
if (metaError) {
|
|
860
|
+
edges.clearJudged(path);
|
|
861
|
+
markRefusal(root);
|
|
862
|
+
return metaError;
|
|
863
|
+
}
|
|
864
|
+
const stale = refuseStale(edges, testFile, present(session.plan));
|
|
865
|
+
if (stale)
|
|
866
|
+
return stale;
|
|
867
|
+
const observed = await observedOf(testFile, isHookBrokenOf(testFile), false);
|
|
868
|
+
// The collect pass runs once runJudge has read the plan and indexed what it reads.
|
|
869
|
+
const { hashOfPath } = present(session.planReadIndexes);
|
|
870
|
+
const outside = [...state.outside].map((each) => [each, hashOf(readJudgeSource(root, each))]);
|
|
871
|
+
// Sources and the test file are read function by function, so the file-level digest covers only what it read outside them.
|
|
872
|
+
const readsHash = hashOf(JSON.stringify(outside.toSorted(([left = ''], [right = '']) => left.localeCompare(right))));
|
|
873
|
+
const part = session.ownedFiles.has(path) ? partOf({ testFile, path, observed, hashOfPath }) : null;
|
|
874
|
+
const kept = {
|
|
875
|
+
path,
|
|
876
|
+
testFile,
|
|
877
|
+
observed,
|
|
878
|
+
hits: state.hits,
|
|
879
|
+
reach: state.reach,
|
|
880
|
+
repeats: new Map(state.repeats),
|
|
881
|
+
weighed: new Set(state.weighed),
|
|
882
|
+
readsHash,
|
|
883
|
+
part,
|
|
884
|
+
loadTicks: session.loadTicks,
|
|
885
|
+
ticksOf: baselineTicksOf(),
|
|
886
|
+
loaded: new Set(state.loaded),
|
|
887
|
+
calls: part && state.isCapturing ? exportCallsOf(testFile, path) : null,
|
|
888
|
+
isLoadFailed: !session.ran.size && testFile.result?.state === 'fail',
|
|
889
|
+
// A written basis is computed from the verdicts' reads, so the hash leaves it out and writing one changes nothing a reader read.
|
|
890
|
+
justificationsHash: justifications?.length ? hashOf(JSON.stringify(justifications.map(({ basis: _basis, ...rest }) => rest))) : null,
|
|
891
|
+
metadataReaders: new Set([...state.metadataReaders].flatMap((id) => (observed.passing.has(id) ? [id] : (observed.testsUnder.get(id) ?? [])))),
|
|
892
|
+
};
|
|
893
|
+
session.collected.push(kept);
|
|
894
|
+
return null;
|
|
895
|
+
};
|
|
896
|
+
// A test file's part from its baseline as the counters now hold it, its verdicts aside: its tests, hits and passes, the functions its passing tests entered, and what it read.
|
|
897
|
+
const partOf = ({ testFile, path, observed, hashOfPath }) => {
|
|
898
|
+
const root = runner.config.root;
|
|
899
|
+
const plan = present(session.plan);
|
|
900
|
+
const keyOf = (id) => session.ran.get(id)?.key ?? id;
|
|
901
|
+
const hits = [];
|
|
902
|
+
const passes = [];
|
|
903
|
+
const isReached = (planned) => planned.points.some(({ index }) => state.hits.has(index * 2) || state.hits.has(index * 2 + 1)) || planned.switches.some(({ index }) => state.reach.has(index));
|
|
904
|
+
for (const planned of plan.files.filter(isReached)) {
|
|
905
|
+
for (const point of planned.points) {
|
|
906
|
+
const siteKey = pointKeyOf(planned.path, point.decision);
|
|
907
|
+
// Each point counts its true side at the odd counter after its false one.
|
|
908
|
+
const sides = [
|
|
909
|
+
[point.index * 2 + 1, 'true'],
|
|
910
|
+
[point.index * 2, 'false'],
|
|
911
|
+
];
|
|
912
|
+
for (const [counter, sideName] of sides) {
|
|
913
|
+
const passed = state.passes.get(counter);
|
|
914
|
+
if (passed)
|
|
915
|
+
passes.push({ siteKey, side: sideName, passes: passed });
|
|
916
|
+
for (const id of state.hits.get(counter) ?? [])
|
|
917
|
+
hits.push({ siteKey, side: sideName, testKey: keyOf(id) });
|
|
918
|
+
}
|
|
919
|
+
for (const id of state.repeats.get(point.index) ?? [])
|
|
920
|
+
hits.push({ siteKey, side: 'repeat', testKey: keyOf(id) });
|
|
921
|
+
}
|
|
922
|
+
for (const site of planned.switches)
|
|
923
|
+
for (const id of state.reach.get(site.index) ?? [])
|
|
924
|
+
hits.push({ siteKey: site.key, side: 'reached', testKey: keyOf(id) });
|
|
925
|
+
}
|
|
926
|
+
const tests = [...session.ran.values()].map(({ key, name, passed, failure, steps, ticks, ns, answers, keeps, statedSteps, stepsReason }) => ({
|
|
927
|
+
key,
|
|
928
|
+
name,
|
|
929
|
+
passed,
|
|
930
|
+
failure,
|
|
931
|
+
steps,
|
|
932
|
+
ticks,
|
|
933
|
+
ns,
|
|
934
|
+
answers,
|
|
935
|
+
keeps,
|
|
936
|
+
statedSteps,
|
|
937
|
+
stepsReason,
|
|
938
|
+
isSteady: observed.steady.has(key),
|
|
939
|
+
}));
|
|
940
|
+
// A file that threw while it loaded registered no test, so it keeps one failing entry under its load.
|
|
941
|
+
const [loadError] = testFile.result?.errors ?? [];
|
|
942
|
+
if (loadError && !tests.length) {
|
|
943
|
+
tests.push({ key: runKeyOf({ file: path, titles: null }), passed: false, failure: loadError.message, steps: 0, ticks: 0, ns: 0, answers: [], keeps: null, statedSteps: null, stepsReason: null, isSteady: false });
|
|
944
|
+
}
|
|
945
|
+
// Only a test whose baseline and unforced rerun passed shows what the code does, so the functions kept as entered are those such a test's baseline entered.
|
|
946
|
+
const sourceUnits = new Map(plan.files.flatMap(({ path: source, units }) => units.flatMap(({ index, name }) => (name ? [[index, unitKeyOf(source, name)]] : []))));
|
|
947
|
+
const entered = [...observed.entries].flatMap(([index, ids]) => {
|
|
948
|
+
const unit = sourceUnits.get(index);
|
|
949
|
+
return unit ? [...ids].flatMap((id) => observed.passing.get(id)?.key ?? []).map((testKey) => ({ unit, testKey })) : [];
|
|
950
|
+
});
|
|
951
|
+
const outsideReads = [...state.outside].map((each) => ({ path: each, hash: hashOf(readJudgeSource(root, each)) }));
|
|
952
|
+
const reads = [...state.loaded].map((each) => ({ path: each, hash: entryAt(hashOfPath, each, `the loaded path ${each}`) })).concat(outsideReads);
|
|
953
|
+
const { data: justifications } = suiteJustificationsOf(path, testFile, isLiteralJustification);
|
|
954
|
+
return {
|
|
955
|
+
file: path,
|
|
956
|
+
hash: hashOf(readJudgeSource(root, path)),
|
|
957
|
+
tests,
|
|
958
|
+
justifications: justifications ?? [],
|
|
959
|
+
hits,
|
|
960
|
+
entered,
|
|
961
|
+
reads,
|
|
962
|
+
rerunFailing: observed.rerunFailing,
|
|
963
|
+
passes,
|
|
964
|
+
outside: [...state.outside].toSorted(),
|
|
965
|
+
changed: [],
|
|
966
|
+
assignees: [],
|
|
967
|
+
sequence: { generation: 0, units: [] },
|
|
968
|
+
failure: fileFailureOf(testFile),
|
|
969
|
+
properties: session.properties.map(({ meta }) => meta.explores),
|
|
970
|
+
};
|
|
971
|
+
};
|
|
972
|
+
// Writes the parts of this shard's files with the verdicts each holds, once every shard saved the verdicts of its sites.
|
|
973
|
+
const writeParts = (edges) => {
|
|
974
|
+
const plan = present(session.plan);
|
|
975
|
+
const all = edges.getSiteVerdicts(plan.files.flatMap(({ switches, crushes }) => [...switches, ...crushes].map(({ key }) => key)));
|
|
976
|
+
// A part names only its own file's tests, so a backup from another file lives in that file's part as a catch of its own, which the merge takes back as the backup.
|
|
977
|
+
const placed = [...all.values()].flatMap((verdict) => {
|
|
978
|
+
if (verdict.owner === null)
|
|
979
|
+
return [];
|
|
980
|
+
// A verdict a related judge kept may have its backup in a file it did not collect, which the backup's key names.
|
|
981
|
+
const backupFile = verdict.backup === null ? null : testFileOfKey(verdict.backup);
|
|
982
|
+
if (backupFile === null || backupFile === verdict.owner)
|
|
983
|
+
return [{ path: verdict.owner, verdict }];
|
|
984
|
+
return [
|
|
985
|
+
{ path: verdict.owner, verdict: { ...verdict, backup: null } },
|
|
986
|
+
{ path: backupFile, verdict: { ...verdict, catcher: verdict.backup, backup: null } },
|
|
987
|
+
];
|
|
988
|
+
});
|
|
989
|
+
const byFile = Map.groupBy(placed, ({ path }) => path);
|
|
990
|
+
for (const { path, part, calls } of session.collected) {
|
|
991
|
+
if (!part)
|
|
992
|
+
continue;
|
|
993
|
+
const generation = edges.getNextGeneration(path);
|
|
994
|
+
// A justification rests on the code its question's verdicts read, so a verdict that read none adds nothing to it.
|
|
995
|
+
const verdicts = (byFile.get(path) ?? []).map(({ verdict: { key, status, catcher, backup, reruns, basis, isReused, readUnits, readsHash } }) => ({
|
|
996
|
+
key,
|
|
997
|
+
status,
|
|
998
|
+
catcher,
|
|
999
|
+
backup,
|
|
1000
|
+
reruns,
|
|
1001
|
+
basis,
|
|
1002
|
+
readHash: readUnits.length ? readsHash : undefined,
|
|
1003
|
+
reads: { generation, count: 0 },
|
|
1004
|
+
isReused,
|
|
1005
|
+
deferred: null,
|
|
1006
|
+
}));
|
|
1007
|
+
const judged = { ...part, sequence: { generation, units: [] }, verdicts, reused: verdicts.filter(({ isReused }) => isReused).length };
|
|
1008
|
+
edges.setJudged(judged, calls ? { calls, clearVerification: false } : undefined);
|
|
1009
|
+
}
|
|
1010
|
+
};
|
|
1011
|
+
// Judges each site of the shard's share once, over its riders from every collected file, cheapest first.
|
|
1012
|
+
// A site some file reached while its modules loaded needs a fresh load to judge, so it is set aside here.
|
|
1013
|
+
const judgeSites = async (plan, shard) => {
|
|
1014
|
+
const { collected } = session;
|
|
1015
|
+
const passingOf = () => new Map(collected.flatMap(({ observed }) => [...observed.passing]));
|
|
1016
|
+
let passing = passingOf();
|
|
1017
|
+
const answerSites = passing.values().some(({ answers }) => answers.length > 0) ? (session.answerSites ??= answerSitesOf(plan.files)) : new Map();
|
|
1018
|
+
const fileOfKey = new Map(collected.flatMap((each) => [...each.observed.passing.values()].map(({ key }) => [key, each])));
|
|
1019
|
+
const sites = plan.files.flatMap(({ path, switches, crushes }) => [
|
|
1020
|
+
...switches.map(({ key, index }) => ({ key, path, switchIndex: index, crush: null })),
|
|
1021
|
+
...crushes.map((crush) => ({ key: crush.key, path, switchIndex: null, crush })),
|
|
1022
|
+
]);
|
|
1023
|
+
const verdicts = [];
|
|
1024
|
+
const { relatedSources } = session;
|
|
1025
|
+
const judgedSites = relatedSources ? sites.filter(({ path }) => relatedSources.has(path)) : sites;
|
|
1026
|
+
const mine = judgedSites.filter((_, at) => at % shard.count === shard.index);
|
|
1027
|
+
// A verdict rests on the rules, the site, its riders with their steps and what each rider's file read.
|
|
1028
|
+
const readsHashOf = new Map(collected.flatMap(({ readsHash, observed }) => [...observed.passing.values()].map(({ key }) => [key, readsHash])));
|
|
1029
|
+
// A file whose suite hook failed on its baseline counts no hook failure as a catch, so each rider's basis holds whether its file's hooks broke.
|
|
1030
|
+
const isHookBrokenKey = new Set(collected.flatMap(({ testFile, observed }) => (isHookBrokenOf(testFile) ? [...observed.passing.values()].map(({ key }) => key) : [])));
|
|
1031
|
+
const riderBasisOf = ({ key, ticks }) => [key, ticks, readsHashOf.get(key) ?? '', isHookBrokenKey.has(key)];
|
|
1032
|
+
const basisOfSite = (key, riders, isReachedUntold) => hashOf(JSON.stringify([rules, key, isReachedUntold, riders.map(riderBasisOf)]));
|
|
1033
|
+
// What a verdict read, by function and source top level, rests on each unit's text, so an edit to code it never read keeps the verdict.
|
|
1034
|
+
const { keyOfUnit, unitHashes, hashOfPath } = present(session.planReadIndexes);
|
|
1035
|
+
// Only a verdict of a test that read a justification rests on its file's justifications, by their hash as this run found them.
|
|
1036
|
+
const metadataHashes = new Map(collected.flatMap(({ path, justificationsHash }) => (justificationsHash ? [[metadataUnitOf(path), justificationsHash]] : [])));
|
|
1037
|
+
// A test reruns after every test of its file that ran before it, which may have left state it reads, so it reads all their units too, beside its file's and its sources' top levels.
|
|
1038
|
+
// Each file keeps its tests' own units once, in run order, and each test its place there, so no test holds a copy of what came before it.
|
|
1039
|
+
const placeOfTest = new Map();
|
|
1040
|
+
for (const { path, observed, loaded, metadataReaders } of collected) {
|
|
1041
|
+
const ownUnits = new Map();
|
|
1042
|
+
for (const [index, ids] of observed.entries) {
|
|
1043
|
+
const unit = keyOfUnit.get(index);
|
|
1044
|
+
if (unit === undefined)
|
|
1045
|
+
continue;
|
|
1046
|
+
for (const id of ids) {
|
|
1047
|
+
const units = ownUnits.get(id);
|
|
1048
|
+
if (units)
|
|
1049
|
+
units.push(unit);
|
|
1050
|
+
else
|
|
1051
|
+
ownUnits.set(id, [unit]);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
const file = { tops: [unitKeyOf(path, ''), ...[...loaded].map((each) => unitKeyOf(each, ''))], ownUnits: [], prefixes: new Map() };
|
|
1055
|
+
for (const [id, { key }] of observed.passing) {
|
|
1056
|
+
placeOfTest.set(key, { file, at: file.ownUnits.length });
|
|
1057
|
+
const own = ownUnits.get(id) ?? [];
|
|
1058
|
+
file.ownUnits.push(metadataReaders.has(id) ? [...own, metadataUnitOf(path)] : own);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
// A file's top level the plan holds no hash for, as a test file's, is hashed whole, so an edit anywhere in it, a test body written inline included, reaches the verdicts reading it.
|
|
1062
|
+
const unitHashOf = (unit) => {
|
|
1063
|
+
const held = unitHashes.get(unit) ?? metadataHashes.get(unit);
|
|
1064
|
+
if (held !== undefined)
|
|
1065
|
+
return held;
|
|
1066
|
+
const [path, name] = unitFieldsOf(unit);
|
|
1067
|
+
if (name)
|
|
1068
|
+
return '';
|
|
1069
|
+
return hashOfPath.get(path) ?? hashOf(readJudgeSourceNullable(runner.config.root, path) ?? '');
|
|
1070
|
+
};
|
|
1071
|
+
const readsHashOfUnits = (units) => hashOf(JSON.stringify(units.map((unit) => [unit, unitHashOf(unit)])));
|
|
1072
|
+
// The units a site's verdict read: those its reachers' baselines entered, their files' loaded top levels, and those its own reruns entered.
|
|
1073
|
+
// Many sites share a file's last reaching test, so each file keeps the units read up to each test, built once.
|
|
1074
|
+
const prefixOf = (file, last) => {
|
|
1075
|
+
const held = file.prefixes.get(last);
|
|
1076
|
+
if (held)
|
|
1077
|
+
return held;
|
|
1078
|
+
const units = new Set(file.tops);
|
|
1079
|
+
for (const own of file.ownUnits.slice(0, last + 1))
|
|
1080
|
+
for (const unit of own)
|
|
1081
|
+
units.add(unit);
|
|
1082
|
+
const prefix = [...units];
|
|
1083
|
+
file.prefixes.set(last, prefix);
|
|
1084
|
+
return prefix;
|
|
1085
|
+
};
|
|
1086
|
+
const readUnitsOf = (reachers, entered) => {
|
|
1087
|
+
const through = new Map();
|
|
1088
|
+
for (const { key } of reachers) {
|
|
1089
|
+
const place = placeOfTest.get(key);
|
|
1090
|
+
if (place)
|
|
1091
|
+
through.set(place.file, Math.max(through.get(place.file) ?? -1, place.at));
|
|
1092
|
+
}
|
|
1093
|
+
const units = new Set();
|
|
1094
|
+
for (const [file, last] of through)
|
|
1095
|
+
for (const unit of prefixOf(file, last))
|
|
1096
|
+
units.add(unit);
|
|
1097
|
+
for (const index of entered) {
|
|
1098
|
+
const unit = keyOfUnit.get(index);
|
|
1099
|
+
if (unit !== undefined)
|
|
1100
|
+
units.add(unit);
|
|
1101
|
+
}
|
|
1102
|
+
return [...units].toSorted();
|
|
1103
|
+
};
|
|
1104
|
+
const prior = currentEdgesOf().data?.getSiteVerdicts(mine.map(({ key }) => key)) ?? new Map();
|
|
1105
|
+
const judgeSite = async (site) => {
|
|
1106
|
+
const perFile = collected.map((each) => {
|
|
1107
|
+
const { observed, hits, reach, repeats } = each;
|
|
1108
|
+
if (site.switchIndex !== null) {
|
|
1109
|
+
const index = site.switchIndex;
|
|
1110
|
+
const reached = reach.get(index) ?? new Set();
|
|
1111
|
+
const rawIds = rawAt(observed.raw.reach, index);
|
|
1112
|
+
const reachers = ridersFor({ observed, reached, rawIds });
|
|
1113
|
+
const isWeighed = each.weighed.has(index) && !rawIds.includes(loadId);
|
|
1114
|
+
const told = new Set([...(observed.infected.get(index) ?? [])].map((id) => observed.passing.get(id)));
|
|
1115
|
+
return { rawIds, reachers, riders: isWeighed ? reachers.filter((rider) => told.has(rider)) : reachers, isDropped: false };
|
|
1116
|
+
}
|
|
1117
|
+
const crush = site.crush;
|
|
1118
|
+
if (!crush)
|
|
1119
|
+
return { rawIds: [], reachers: [], riders: [], isDropped: false };
|
|
1120
|
+
const sides = ridingSidesOf(crush);
|
|
1121
|
+
const reached = sides.flatMap((side) => [...((side === 'repeat' ? repeats.get(crush.point) : hits.get(crush.point * 2 + (side === 'true' ? 1 : 0))) ?? [])]);
|
|
1122
|
+
const rawIds = sides.flatMap((side) => (side === 'repeat' ? rawAt(observed.raw.repeats, crush.point) : rawAt(observed.raw.hits, crush.point * 2 + (side === 'true' ? 1 : 0))));
|
|
1123
|
+
const passingHitAt = (index) => [...(hits.get(index) ?? [])].some((id) => observed.passing.has(id));
|
|
1124
|
+
const isDropped = crush.crush === 'drop-operand' && (passingHitAt(crush.point * 2) || passingHitAt(crush.point * 2 + 1));
|
|
1125
|
+
const riders = ridersFor({ observed, reached, rawIds });
|
|
1126
|
+
return { rawIds, reachers: riders, riders, isDropped };
|
|
1127
|
+
});
|
|
1128
|
+
const riders = perFile.flatMap(({ riders: each }) => each).toSorted((left, right) => left.ticks - right.ticks || left.key.localeCompare(right.key));
|
|
1129
|
+
// A source edited since the plan loads under other counter numbers, so none of its sites is judged against the stale plan, whichever shard's files saw the edit first.
|
|
1130
|
+
if (changedSources.has(site.path)) {
|
|
1131
|
+
verdicts.push(siteUnjudgedOf(site.key, loaderOf(site.path)));
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
if (riders.some(({ key }) => broken.has(fileOfKey.get(key)))) {
|
|
1135
|
+
verdicts.push(siteUnjudgedOf(site.key, fileOfKey.get(riders[0]?.key ?? '')?.path ?? null));
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
const isReachedUntold = site.switchIndex !== null ? perFile.some(({ reachers }) => reachers.length > 0) : perFile.some(({ isDropped }) => isDropped);
|
|
1139
|
+
const basis = basisOfSite(site.key, riders, isReachedUntold);
|
|
1140
|
+
const kept = prior.get(site.key);
|
|
1141
|
+
const loader = loaderOf(site.path);
|
|
1142
|
+
const ownerOf = (key) => (key === undefined ? loader : (fileOfKey.get(key)?.path ?? loader));
|
|
1143
|
+
const isReusable = ({ basis: keptBasis, status, readUnits, readsHash }) => keptBasis === basis && status !== 'unjudged' && readsHashOfUnits(readUnits) === readsHash;
|
|
1144
|
+
const switchOn = () => {
|
|
1145
|
+
if (site.switchIndex !== null)
|
|
1146
|
+
state.site = site.switchIndex;
|
|
1147
|
+
if (site.crush)
|
|
1148
|
+
state.forced.set(site.crush.point, site.crush.forced);
|
|
1149
|
+
};
|
|
1150
|
+
if (kept && isReusable(kept)) {
|
|
1151
|
+
// A reused verdict lives where this run's files place it, since the file that held it may have lost its tests.
|
|
1152
|
+
const owner = ownerOf(kept.catcher ?? riders[0]?.key);
|
|
1153
|
+
session.judgeSpeed.reused += 1;
|
|
1154
|
+
// `judge:redundant` searches a reused catch it never searched for a second catcher, and judges nothing else about it again.
|
|
1155
|
+
const catcher = isRedundantSearched && kept.status === 'caught' && !kept.isBackupSearched ? riders.find(({ key }) => key === kept.catcher) : undefined;
|
|
1156
|
+
if (!catcher) {
|
|
1157
|
+
verdicts.push({ ...kept, owner, isReused: true });
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
switchOn();
|
|
1161
|
+
const second = await secondCatchOf({ riders, catcher, site: { key: site.key, answerSites }, isRedundantSearched });
|
|
1162
|
+
state.forced.clear();
|
|
1163
|
+
state.site = -1;
|
|
1164
|
+
session.judgeSpeed.judge.reruns += second.reruns;
|
|
1165
|
+
const searchedBasis = second.isTimedOut ? `timed-out:${kept.basis}` : kept.basis;
|
|
1166
|
+
verdicts.push({ ...kept, backup: second.backup, reruns: kept.reruns + second.reruns, basis: searchedBasis, owner, isReused: true, isBackupSearched: true });
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
// The site's own reruns record every unit they enter, from nothing, so its verdict reads exactly those beside its riders' baselines.
|
|
1170
|
+
state.entered = new Set();
|
|
1171
|
+
// A weighed site no rider reruns still rests on the baselines of the tests reaching it, which found nothing to tell apart, so the reads cover every reacher.
|
|
1172
|
+
const reachers = perFile.flatMap(({ reachers: each }) => each);
|
|
1173
|
+
const readsOfSite = () => {
|
|
1174
|
+
const readUnits = readUnitsOf(reachers, state.entered);
|
|
1175
|
+
return { readUnits, readsHash: readsHashOfUnits(readUnits) };
|
|
1176
|
+
};
|
|
1177
|
+
// A site a file reached as its modules loaded takes effect only in a fresh load, so the riders whose own bodies reached it rerun first, and each such file then loads afresh with the site forced from the start.
|
|
1178
|
+
const loadFiles = collected.filter((_, at) => {
|
|
1179
|
+
const each = perFile[at];
|
|
1180
|
+
return each !== undefined && each.reachers.length > 0 && each.rawIds.includes(loadId);
|
|
1181
|
+
});
|
|
1182
|
+
if (loadFiles.length) {
|
|
1183
|
+
const bodied = perFile.flatMap(({ rawIds, riders: each }, at) => {
|
|
1184
|
+
const owner = collected[at];
|
|
1185
|
+
const bodyKeys = new Set(owner ? rawIds.flatMap((id) => owner.observed.passing.get(id)?.key ?? []) : []);
|
|
1186
|
+
return each.filter(({ key }) => bodyKeys.has(key));
|
|
1187
|
+
});
|
|
1188
|
+
switchOn();
|
|
1189
|
+
const bodyRiders = bodied.toSorted((left, right) => left.ticks - right.ticks || left.key.localeCompare(right.key));
|
|
1190
|
+
const bodyJudged = bodied.length ? await judge({ riders: bodyRiders, site: { key: site.key, answerSites }, isReachedUntold, isRedundantSearched }) : null;
|
|
1191
|
+
state.forced.clear();
|
|
1192
|
+
state.site = -1;
|
|
1193
|
+
let reruns = bodyJudged?.reruns ?? 0;
|
|
1194
|
+
if (bodyJudged?.status === 'caught') {
|
|
1195
|
+
const { catcher, backup } = bodyJudged;
|
|
1196
|
+
verdicts.push({ key: site.key, status: 'caught', catcher, backup, reruns, basis, owner: ownerOf(catcher ?? undefined), ...readsOfSite(), isReused: false, isBackupSearched: isRedundantSearched });
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
const edges = present(currentEdgesOf().data);
|
|
1200
|
+
const freshCatchOf = async (owner) => {
|
|
1201
|
+
const eligible = new Set(riders.filter(({ key }) => fileOfKey.get(key) === owner).map(({ key }) => key));
|
|
1202
|
+
const [firstEligible] = eligible;
|
|
1203
|
+
const forced = await forcedRunOf({ edges, filepath: owner.testFile.filepath, keys: new Set([site.key]), eligible, isHookBroken: isHookBrokenOf(owner.testFile), loadTicks: owner.loadTicks, ticksOf: owner.ticksOf });
|
|
1204
|
+
reruns += forced.reruns;
|
|
1205
|
+
// A run whose module load failed ran no test, so the file's first rider stands as the catcher.
|
|
1206
|
+
const catcher = forced.catcher ?? firstEligible;
|
|
1207
|
+
return forced.status === 'caught' && catcher !== undefined ? { catcher, isTimedOut: forced.isTimedOut } : null;
|
|
1208
|
+
};
|
|
1209
|
+
const fresh = await firstInOrder(loadFiles, freshCatchOf);
|
|
1210
|
+
session.judgeSpeed.judge.reruns += reruns;
|
|
1211
|
+
session.judgeSpeed.judge.sites += 1;
|
|
1212
|
+
const freshBasis = fresh?.isTimedOut ? `timed-out:${basis}` : basis;
|
|
1213
|
+
const freshCatcher = fresh?.catcher ?? null;
|
|
1214
|
+
// A catch only a fresh load makes cannot be rerun in place, so its search for a second catcher is over before it starts.
|
|
1215
|
+
const freshVerdict = { key: site.key, status: fresh ? 'caught' : 'survived', catcher: freshCatcher, backup: null, reruns, basis: freshBasis };
|
|
1216
|
+
verdicts.push({ ...freshVerdict, owner: ownerOf(freshCatcher ?? riders[0]?.key), ...readsOfSite(), isReused: false, isBackupSearched: true });
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
switchOn();
|
|
1220
|
+
const { isTimedOut, ...judged } = await judge({ riders, site: { key: site.key, answerSites }, isReachedUntold, isRedundantSearched });
|
|
1221
|
+
session.judgeSpeed.judge.reruns += judged.reruns;
|
|
1222
|
+
session.judgeSpeed.judge.sites += 1;
|
|
1223
|
+
state.forced.clear();
|
|
1224
|
+
state.site = -1;
|
|
1225
|
+
// A verdict lives in its catcher's part or, where none caught it, its first rider's, so the merge reads each site's verdict once.
|
|
1226
|
+
// A timeout catch keeps a basis no later record computes, so the next record judges the site again.
|
|
1227
|
+
const verdict = { key: site.key, ...judged, basis: isTimedOut ? `timed-out:${basis}` : basis, owner: ownerOf(judged.catcher ?? riders[0]?.key), ...readsOfSite(), isReused: false, isBackupSearched: isRedundantSearched };
|
|
1228
|
+
// A test failing its rerun with nothing forced after this site's runs shows they broke its file's module state, so each file whose riders ran is probed by its catcher or its first rider.
|
|
1229
|
+
const ranTo = judged.catcher === null ? riders.length : riders.findIndex(({ key }) => key === judged.catcher) + 1;
|
|
1230
|
+
const probes = new Map();
|
|
1231
|
+
for (const rider of riders.slice(0, ranTo)) {
|
|
1232
|
+
const file = fileOfKey.get(rider.key);
|
|
1233
|
+
if (file && (!probes.has(file) || rider.key === judged.catcher))
|
|
1234
|
+
probes.set(file, rider);
|
|
1235
|
+
}
|
|
1236
|
+
const breaking = [];
|
|
1237
|
+
await eachInOrder([...probes], async ([file, probe]) => {
|
|
1238
|
+
if (!(await rerun(probe)))
|
|
1239
|
+
breaking.push(file);
|
|
1240
|
+
});
|
|
1241
|
+
if (!breaking.length) {
|
|
1242
|
+
verdicts.push(verdict);
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
// A catch stands when its catcher was the first of its file to rerun, since that rerun began in sound state; otherwise one fresh run of each breaking file with the site forced judges it.
|
|
1246
|
+
const catcherFile = judged.catcher === null ? undefined : fileOfKey.get(judged.catcher);
|
|
1247
|
+
const isSound = judged.status === 'caught' && catcherFile !== undefined && riders.find((rider) => fileOfKey.get(rider.key) === catcherFile)?.key === judged.catcher;
|
|
1248
|
+
if (isSound)
|
|
1249
|
+
verdicts.push(verdict);
|
|
1250
|
+
else {
|
|
1251
|
+
const edges = present(currentEdgesOf().data);
|
|
1252
|
+
let reruns = judged.reruns;
|
|
1253
|
+
const freshCatchOf = async (owner) => {
|
|
1254
|
+
const eligible = new Set(riders.filter(({ key }) => fileOfKey.get(key) === owner).map(({ key }) => key));
|
|
1255
|
+
const [firstEligible] = eligible;
|
|
1256
|
+
const forced = await forcedRunOf({ edges, filepath: owner.testFile.filepath, keys: new Set([site.key]), eligible, isHookBroken: isHookBrokenOf(owner.testFile), loadTicks: owner.loadTicks, ticksOf: owner.ticksOf });
|
|
1257
|
+
reruns += forced.reruns;
|
|
1258
|
+
const catcher = forced.catcher ?? firstEligible;
|
|
1259
|
+
return forced.status === 'caught' && catcher !== undefined ? { catcher, isTimedOut: forced.isTimedOut } : null;
|
|
1260
|
+
};
|
|
1261
|
+
const fresh = await firstInOrder(breaking, freshCatchOf);
|
|
1262
|
+
session.judgeSpeed.judge.reruns += reruns - judged.reruns;
|
|
1263
|
+
const freshBasis = fresh?.isTimedOut ? `timed-out:${basis}` : basis;
|
|
1264
|
+
verdicts.push({ ...verdict, status: fresh ? 'caught' : 'survived', catcher: fresh?.catcher ?? null, backup: null, reruns, basis: freshBasis, owner: ownerOf(fresh?.catcher ?? riders[0]?.key) });
|
|
1265
|
+
}
|
|
1266
|
+
// A file that cannot load again, as one whose sources changed, leaves every later site its tests ride unjudged.
|
|
1267
|
+
await eachInOrder(breaking, async (owner) => {
|
|
1268
|
+
const { data: failure, error } = await safeAsync(() => reloadPassing({ testFile: owner.testFile, plan, passing: owner.observed.passing, isSuited: owner.observed.isSuited, loaded: owner.loaded }));
|
|
1269
|
+
if (error ?? failure)
|
|
1270
|
+
broken.add(owner);
|
|
1271
|
+
});
|
|
1272
|
+
passing = passingOf();
|
|
1273
|
+
};
|
|
1274
|
+
const broken = new Set();
|
|
1275
|
+
// An unjudged site rests on nothing and reads nothing, so it is never reused.
|
|
1276
|
+
const siteUnjudgedOf = (key, owner) => ({ key, status: 'unjudged', catcher: null, backup: null, reruns: 0, basis: '', owner, readUnits: [], readsHash: '', isReused: false, isBackupSearched: false });
|
|
1277
|
+
const changedSources = new Set(plan.files.filter(({ path, hash }) => hashOf(readJudgeSourceNullable(runner.config.root, path) ?? '') !== hash).map(({ path }) => path));
|
|
1278
|
+
// A site no test caught or rode lives in the part of the first file that loaded its source, one refused for a stale plan included, so every judged site keeps one verdict.
|
|
1279
|
+
// A file that failed before any test ran keeps its failing part but no verdicts, so the run reads as judging nothing there.
|
|
1280
|
+
const loaderOf = (path) => collected.find(({ loaded, isLoadFailed }) => loaded.has(path) && !isLoadFailed)?.path ?? [...session.staleLoads].find(([, loaded]) => loaded.has(path))?.[0] ?? null;
|
|
1281
|
+
await eachInOrder(mine, judgeSite);
|
|
1282
|
+
const judgedVerdicts = verdicts.flatMap(({ status, ...verdict }) => (status === 'load-time' ? [] : [{ ...verdict, status }]));
|
|
1283
|
+
currentEdgesOf().data?.setSiteVerdicts(judgedVerdicts);
|
|
1284
|
+
return verdicts;
|
|
1285
|
+
};
|
|
1286
|
+
// A test file's observations once its baseline ran: what each suite hook and the file's load reached credited to the tests under them, the counters set to those credited observations, and which passing tests rerun, inside their suite hooks or plain, and hold steady.
|
|
1287
|
+
const observedOf = async (testFile, isHookBroken, isRecording) => {
|
|
1288
|
+
const testsUnder = testsUnderOf(testFile);
|
|
1289
|
+
// Code that ran while the modules loaded is credited to every test whose baseline passed, as a failing one shows nothing about it.
|
|
1290
|
+
testsUnder.set(loadId, [...session.ran].filter(([, { passed }]) => passed).map(([id]) => id));
|
|
1291
|
+
const raw = { hits: state.hits, reach: state.reach, repeats: state.repeats };
|
|
1292
|
+
setObservations(state, creditedOf(state.hits, testsUnder), creditedOf(state.reach, testsUnder));
|
|
1293
|
+
state.repeats = creditedOf(state.repeats, testsUnder);
|
|
1294
|
+
const infected = creditedOf(state.infected, testsUnder);
|
|
1295
|
+
const entries = creditedOf(state.entries, testsUnder);
|
|
1296
|
+
// A test failing its rerun with nothing forced would fail every site's rerun too, so it judges no site; one failing plain but passing inside its suite hooks reruns suited everywhere.
|
|
1297
|
+
const passing = new Map();
|
|
1298
|
+
const rerunFailing = [];
|
|
1299
|
+
// A test under suite hooks reruns inside them, since its body may read what they set up; one whose suite hooks cannot run twice falls back to its plain rerun.
|
|
1300
|
+
const isSuited = new Set();
|
|
1301
|
+
// A test's step count holds only when two identical reruns with nothing forced agree on its ticks.
|
|
1302
|
+
const steady = new Set();
|
|
1303
|
+
const passed = [...session.ran].filter(([, ran]) => ran.passed);
|
|
1304
|
+
// A record reruns nothing, so every test that passed counts as passing at once.
|
|
1305
|
+
if (isRecording)
|
|
1306
|
+
for (const [id, ran] of passed)
|
|
1307
|
+
passing.set(id, ran);
|
|
1308
|
+
// The reruns share the one counters state, so they run one at a time.
|
|
1309
|
+
const rerunUnforced = async ([id, ran]) => {
|
|
1310
|
+
// A suited rerun that meets a limit did work its baseline did not, so the plain reruns it falls back to, which skip its suite hooks, cannot make it steady.
|
|
1311
|
+
// A test in a file whose suite hooks failed on the baseline reruns plain, since a hook failing whatever any mutant does would read as a catch.
|
|
1312
|
+
const isSuiteable = ran.hasSuiteHooks && !isHookBroken;
|
|
1313
|
+
const suitedFailure = isSuiteable ? await failureOf({ ...ran, fn: ran.suited }) : null;
|
|
1314
|
+
const isSuitedPassing = isSuiteable && !suitedFailure;
|
|
1315
|
+
// The hooks return only their first error and may catch the counters' stop, so the counters' own flag, read after every rerun, tells a limit met.
|
|
1316
|
+
const isSuitedLimitMet = isSuiteable && state.isLimitHit;
|
|
1317
|
+
const chosen = isSuitedPassing ? { ...ran, fn: ran.suited } : ran;
|
|
1318
|
+
if (!isSuitedPassing && !(await rerun(ran))) {
|
|
1319
|
+
rerunFailing.push(ran.key);
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
if (isSuitedPassing)
|
|
1323
|
+
isSuited.add(ran.key);
|
|
1324
|
+
passing.set(id, chosen);
|
|
1325
|
+
// The steps a test states are its baseline's, so both reruns must match its baseline, each counted over its own part alone, as a suited rerun's suite hooks are outside the baseline's count.
|
|
1326
|
+
const ticks = ran.bodyTicks();
|
|
1327
|
+
const isFirstLimitMet = isSuitedLimitMet || state.isLimitHit;
|
|
1328
|
+
const isSecondPassing = await rerun(chosen);
|
|
1329
|
+
const isLimitMet = isFirstLimitMet || state.isLimitHit;
|
|
1330
|
+
if (isSecondPassing && ran.bodyTicks() === ticks && ticks === ran.ticks && !isLimitMet)
|
|
1331
|
+
steady.add(ran.key);
|
|
1332
|
+
};
|
|
1333
|
+
await eachInOrder(isRecording ? [] : passed, rerunUnforced);
|
|
1334
|
+
return { testsUnder, raw, infected, entries, passing, rerunFailing, isSuited, steady };
|
|
1335
|
+
};
|
|
1336
|
+
// Writes a test file's part of a record: its baseline, its captured calls, and the verdicts its last part held while the file and everything it read are unchanged.
|
|
1337
|
+
const recordFile = async (edges, testFile) => {
|
|
1338
|
+
const root = runner.config.root;
|
|
1339
|
+
// The plan is read once per worker, so a source edited mid-run is judged against the plan the worker started with.
|
|
1340
|
+
session.plan ??= edges.getPlan({ withRewrites: false });
|
|
1341
|
+
const { plan } = session;
|
|
1342
|
+
const file = relative(root, testFile.filepath);
|
|
1343
|
+
const unfound = refuseUnfound({ unfound: session.unfound, root, clearPart: () => edges.clearJudged(file) });
|
|
1344
|
+
if (unfound)
|
|
1345
|
+
return unfound;
|
|
1346
|
+
const { error: metaError } = suiteJustificationsOf(file, testFile, isLiteralJustification);
|
|
1347
|
+
if (metaError) {
|
|
1348
|
+
edges.clearJudged(file);
|
|
1349
|
+
markRefusal(root);
|
|
1350
|
+
return metaError;
|
|
1351
|
+
}
|
|
1352
|
+
const stale = refuseStale(edges, testFile, plan);
|
|
1353
|
+
if (stale)
|
|
1354
|
+
return stale;
|
|
1355
|
+
const observed = await observedOf(testFile, isHookBrokenOf(testFile), true);
|
|
1356
|
+
const { hashOfPath } = (session.planReadIndexes ??= planReadIndexesOf(plan));
|
|
1357
|
+
const part = partOf({ testFile, path: file, observed, hashOfPath });
|
|
1358
|
+
// A record reruns nothing, so every test that passed counts as steady.
|
|
1359
|
+
const tests = part.tests.map((test) => ({ ...test, isSteady: true }));
|
|
1360
|
+
const previous = edges.getPartStampNullable(file);
|
|
1361
|
+
const previousReads = new Map(previous?.reads.map(({ path, hash }) => [path, hash]));
|
|
1362
|
+
const previousTests = new Map(previous?.tests.map(({ key, passed }) => [key, passed]));
|
|
1363
|
+
const isUnchanged = previous?.hash === part.hash &&
|
|
1364
|
+
previousReads.size === part.reads.length &&
|
|
1365
|
+
part.reads.every(({ path, hash }) => previousReads.get(path) === hash) &&
|
|
1366
|
+
previousTests.size === tests.length &&
|
|
1367
|
+
tests.every(({ key, passed }) => previousTests.get(key) === passed) &&
|
|
1368
|
+
previous.failure === part.failure;
|
|
1369
|
+
// The judge wrote this part from the same file and reads with the steadiness it measured, which a record that reruns nothing cannot, so an unchanged part stands as the judge left it.
|
|
1370
|
+
if (isUnchanged)
|
|
1371
|
+
return null;
|
|
1372
|
+
const generation = edges.getNextGeneration(file);
|
|
1373
|
+
const judged = { ...part, tests, sequence: { generation, units: [] }, verdicts: [], reused: 0 };
|
|
1374
|
+
edges.setJudged(judged, { calls: exportCallsOf(testFile, file), clearVerification: true, clearFailure: session.ran.size > 0 });
|
|
1375
|
+
return null;
|
|
1376
|
+
};
|
|
1377
|
+
// The calls to exports a test file's run captured, each by the test that made it and the steps its path took.
|
|
1378
|
+
const exportCallsOf = (testFile, file) => {
|
|
1379
|
+
const plan = present(session.plan);
|
|
1380
|
+
const root = runner.config.root;
|
|
1381
|
+
session.siteKeyOfPoint ??= new Map(plan.files.flatMap(({ path, points }) => points.map(({ index, decision }) => [index, pointKeyOf(path, decision)])));
|
|
1382
|
+
const { siteKeyOfPoint } = session;
|
|
1383
|
+
// A call no test body made ran as the file loaded or in a suite's hooks, keyed by what the file names, since task ids change between records.
|
|
1384
|
+
const runKeys = runKeysOf(testFile, file);
|
|
1385
|
+
// A call's id is its place in the file's calls, which its children name as their parent.
|
|
1386
|
+
return state.calls.map(({ id: _id, test, stack, path, ...call }) => ({
|
|
1387
|
+
...call,
|
|
1388
|
+
testKey: session.ran.get(test)?.key ?? entryAt(runKeys, test, `the run ${test}`),
|
|
1389
|
+
thrownAt: stack ? throwSiteOf({ stack, root }) : null,
|
|
1390
|
+
// The plan, written as each source loads, may not hold a point yet, whose side the record cannot name.
|
|
1391
|
+
steps: path.flatMap(([step, key, passes]) => {
|
|
1392
|
+
const siteKey = siteKeyOfPoint.get(Math.floor(key / 2));
|
|
1393
|
+
return siteKey ? [{ step, siteKey, side: key % 2 ? 'true' : 'false', passes }] : [];
|
|
1394
|
+
}),
|
|
1395
|
+
}));
|
|
1396
|
+
};
|
|
1397
|
+
// A source this file's run loaded that no longer matches the plan was instrumented from other text, so no counter of this run can be read against the plan.
|
|
1398
|
+
// Every site its run loaded stays unjudged, which the next run judges, and the file fails naming the changed sources.
|
|
1399
|
+
const refuseStale = (edges, first, plan) => {
|
|
1400
|
+
const root = runner.config.root;
|
|
1401
|
+
const file = relative(root, first.filepath);
|
|
1402
|
+
const loaded = plan.files.filter(({ path }) => state.loaded.has(path));
|
|
1403
|
+
const changed = loaded.filter(({ path, hash }) => hashOf(readJudgeSource(root, path)) !== hash).map(({ path }) => path);
|
|
1404
|
+
if (!changed.length)
|
|
1405
|
+
return null;
|
|
1406
|
+
session.staleLoads.set(file, new Set(state.loaded));
|
|
1407
|
+
// An unjudged verdict is never reused, so it rests on no riders and reads nothing.
|
|
1408
|
+
const generation = edges.getNextGeneration(file);
|
|
1409
|
+
const basis = basisOf({ rules, riders: [], isReachedUntold: false, reads: hashOf('') });
|
|
1410
|
+
const unjudgedOf = ({ key }) => ({ key, status: 'unjudged', catcher: null, backup: null, reruns: 0, basis, reads: { generation, count: 0 }, isReused: false, deferred: null });
|
|
1411
|
+
const verdicts = loaded.flatMap(({ switches, crushes }) => [...switches, ...crushes].map(unjudgedOf));
|
|
1412
|
+
const tests = [...session.ran.values()].map(({ key, passed, failure, steps, ticks, ns, answers, keeps, statedSteps, stepsReason }) => ({
|
|
1413
|
+
key,
|
|
1414
|
+
passed,
|
|
1415
|
+
failure,
|
|
1416
|
+
steps,
|
|
1417
|
+
ticks,
|
|
1418
|
+
ns,
|
|
1419
|
+
answers,
|
|
1420
|
+
keeps,
|
|
1421
|
+
statedSteps,
|
|
1422
|
+
stepsReason,
|
|
1423
|
+
isSteady: false,
|
|
1424
|
+
}));
|
|
1425
|
+
const reads = loaded.map(({ path, hash }) => ({ path, hash }));
|
|
1426
|
+
const refusal = new CrushError(changedDuringRunOf(changed));
|
|
1427
|
+
// A stale plan cannot name the sides this run's calls took, so the file keeps no calls, an earlier run's included.
|
|
1428
|
+
edges.setJudged({
|
|
1429
|
+
file,
|
|
1430
|
+
hash: hashOf(readJudgeSource(root, file)),
|
|
1431
|
+
tests,
|
|
1432
|
+
hits: [],
|
|
1433
|
+
entered: [],
|
|
1434
|
+
verdicts,
|
|
1435
|
+
reads,
|
|
1436
|
+
reused: 0,
|
|
1437
|
+
rerunFailing: [],
|
|
1438
|
+
passes: [],
|
|
1439
|
+
outside: [],
|
|
1440
|
+
changed,
|
|
1441
|
+
assignees: [],
|
|
1442
|
+
sequence: { generation, units: [] },
|
|
1443
|
+
failure: refusal.message,
|
|
1444
|
+
properties: session.properties.map(({ meta }) => meta.explores),
|
|
1445
|
+
}, { calls: [], clearVerification: false, clearFailure: session.pass === 'record' && session.ran.size > 0 });
|
|
1446
|
+
return refusal;
|
|
1447
|
+
};
|
|
1448
|
+
// Collects declarations from eligible recorded test modules without executing their tests.
|
|
1449
|
+
const exploreProperties = async () => {
|
|
1450
|
+
const { data: edges, error } = currentEdgesOf();
|
|
1451
|
+
if (error)
|
|
1452
|
+
return { data: null, error };
|
|
1453
|
+
const targets = [];
|
|
1454
|
+
const root = inject(rootProvideKey);
|
|
1455
|
+
const graph = graphOf({ nodes: edges.getReachNodes(), edges: edges.getReachEdges() });
|
|
1456
|
+
const paths = inject(explorePathsProvideKey);
|
|
1457
|
+
const related = paths === null ? null : new Set(paths);
|
|
1458
|
+
const seedsOf = edges.getSeeds();
|
|
1459
|
+
// Vitest's shared runner collects one file at a time, so the files load in turn, stopping at the first that cannot.
|
|
1460
|
+
const collectTargets = async ({ file, properties }) => {
|
|
1461
|
+
const keys = properties.map((name) => unitKeyOf(file, name)).filter((key) => seedsOf.has(key));
|
|
1462
|
+
const allowed = new Set(explorableOf({ ...graph, keys, paths: related }).map(({ key }) => key));
|
|
1463
|
+
if (!allowed.size)
|
|
1464
|
+
return null;
|
|
1465
|
+
const path = join(root, file);
|
|
1466
|
+
const { data: files, error: collectError } = await safeAsync(() => collectTests([path], runner));
|
|
1467
|
+
if (collectError)
|
|
1468
|
+
return collectError;
|
|
1469
|
+
const loaded = itemAt(files, 0);
|
|
1470
|
+
const failure = runFailureOf(loaded);
|
|
1471
|
+
if (failure)
|
|
1472
|
+
return new CrushError(failure);
|
|
1473
|
+
// The module was just collected by the same Vitest loader, so importing it again loads nothing new.
|
|
1474
|
+
const { data: module, error: loadError } = await safeAsync(async () => await runner.importFile(path, 'collect'));
|
|
1475
|
+
if (loadError)
|
|
1476
|
+
return loadError;
|
|
1477
|
+
const source = readJudgeSource(root, file);
|
|
1478
|
+
for (const task of testsOf(loaded)) {
|
|
1479
|
+
const declaration = exploresMeta.safeParse(task.meta);
|
|
1480
|
+
if (!declaration.success)
|
|
1481
|
+
continue;
|
|
1482
|
+
const meta = declaration.data;
|
|
1483
|
+
const key = unitKeyOf(file, meta.explores);
|
|
1484
|
+
if (!allowed.has(key))
|
|
1485
|
+
continue;
|
|
1486
|
+
if (meta.twin && !explorableOf({ ...graph, keys: [unitKeyOf(file, meta.twin.related)], paths: null }).length)
|
|
1487
|
+
continue;
|
|
1488
|
+
const seeds = entryAt(seedsOf, key, 'the recorded property arguments');
|
|
1489
|
+
targets.push({ key, search: exploreProperty({ file, source, module, meta, seeds, seed: runner.config.sequence.seed }) });
|
|
1490
|
+
}
|
|
1491
|
+
return null;
|
|
1492
|
+
};
|
|
1493
|
+
const collectError = await firstInOrder(edges.getJudged({ withHits: false }), collectTargets);
|
|
1494
|
+
if (collectError)
|
|
1495
|
+
return { data: null, error: collectError };
|
|
1496
|
+
return { data: targets, error: null };
|
|
1497
|
+
};
|
|
1498
|
+
// Reruns this file's passing tests with every candidate crush forced together, and when one fails, keeps the candidates one at a time in order, dropping each that a test fails with.
|
|
1499
|
+
const verifyFile = async (edges, first, candidates, candidateHash) => {
|
|
1500
|
+
const root = runner.config.root;
|
|
1501
|
+
const file = relative(root, first.filepath);
|
|
1502
|
+
const unfound = refuseUnfound({ unfound: session.unfound, root, clearPart: () => edges.clearVerified(file) });
|
|
1503
|
+
if (unfound)
|
|
1504
|
+
return unfound;
|
|
1505
|
+
// A file that failed before any test ran checked no set, so it names no candidates and the report leaves the collapse unverified.
|
|
1506
|
+
if (!session.ran.size && first.result?.state === 'fail')
|
|
1507
|
+
return edges.setVerified({ file, candidates: '', dropped: [] });
|
|
1508
|
+
// A file whose every verdict this record reused, checked last against these same candidates, would rerun its tests exactly as that check did, so its joint-check part stands.
|
|
1509
|
+
const isUnchanged = Boolean(edges.getPartIsAllReusedNullable(file)) && edges.getCheckedCandidatesNullable(file) === candidateHash;
|
|
1510
|
+
if (isUnchanged)
|
|
1511
|
+
return null;
|
|
1512
|
+
const passing = [...session.ran.values()].filter(({ passed }) => passed);
|
|
1513
|
+
// A candidate may sit in suite hook work, so a test under suite hooks reruns inside them.
|
|
1514
|
+
for (const ran of passing)
|
|
1515
|
+
if (ran.hasSuiteHooks)
|
|
1516
|
+
ran.fn = ran.suited;
|
|
1517
|
+
// A forced crush changes only the code at its point, so only a test whose baseline reached that point can fail with it, as judging reruns only a site's riders.
|
|
1518
|
+
// Code a suite hook or the file's load reached is credited to the tests under it, as judging credits it.
|
|
1519
|
+
const testsUnder = testsUnderOf(first);
|
|
1520
|
+
testsUnder.set(loadId, [...session.ran].filter(([, { passed }]) => passed).map(([id]) => id));
|
|
1521
|
+
const hits = creditedOf(state.hits, testsUnder);
|
|
1522
|
+
const repeats = creditedOf(state.repeats, testsUnder);
|
|
1523
|
+
const keyOfId = new Map([...session.ran].map(([id, { key }]) => [id, key]));
|
|
1524
|
+
const reachingKeysOf = (point) => [...(hits.get(point * 2) ?? []), ...(hits.get(point * 2 + 1) ?? []), ...(repeats.get(point) ?? [])].flatMap((id) => keyOfId.get(id) ?? []);
|
|
1525
|
+
const allPoints = candidates.map(({ point }) => point);
|
|
1526
|
+
// The first test failing with the forced set, or null when every test passes, of the tests reaching the points checked.
|
|
1527
|
+
const failerOf = async (forced, checked) => {
|
|
1528
|
+
state.forced = forced;
|
|
1529
|
+
const reaching = new Set(checked.flatMap(reachingKeysOf));
|
|
1530
|
+
const checking = passing.filter(({ key }) => reaching.has(key));
|
|
1531
|
+
// The forced crushes switch the one shared counters state, so tests rerun one at a time.
|
|
1532
|
+
const failingKeyOf = async (ran) => {
|
|
1533
|
+
session.judgeSpeed.verify.reruns += 1;
|
|
1534
|
+
return (await rerun(ran)) ? null : ran.key;
|
|
1535
|
+
};
|
|
1536
|
+
return await firstInOrder(checking, failingKeyOf);
|
|
1537
|
+
};
|
|
1538
|
+
const dropped = [];
|
|
1539
|
+
// Whether every test passes with nothing forced, after dropping each candidate a test fails with once all are forced together.
|
|
1540
|
+
const checkedBaseline = async () => {
|
|
1541
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
1542
|
+
try {
|
|
1543
|
+
const _strays = __addDisposableResource(env_1, droppedStrays()
|
|
1544
|
+
// A test that fails with nothing forced cannot check any set, so the file names no candidates and the report leaves the collapse unverified.
|
|
1545
|
+
, true);
|
|
1546
|
+
// A test that fails with nothing forced cannot check any set, so the file names no candidates and the report leaves the collapse unverified.
|
|
1547
|
+
const isPassing = !(await failerOf(new Map(), allPoints));
|
|
1548
|
+
const wholeFailer = isPassing ? await failerOf(new Map(candidates.map(({ point, forced }) => [point, forced])), allPoints) : null;
|
|
1549
|
+
if (wholeFailer) {
|
|
1550
|
+
const kept = new Map();
|
|
1551
|
+
// Each candidate is checked with the ones kept before it, one at a time; those already passed together, so only a test reaching the new one can fail.
|
|
1552
|
+
const keepOrDrop = async ({ key, point, forced }) => {
|
|
1553
|
+
kept.set(point, forced);
|
|
1554
|
+
const failer = await failerOf(kept, [point]);
|
|
1555
|
+
if (!failer)
|
|
1556
|
+
return;
|
|
1557
|
+
kept.delete(point);
|
|
1558
|
+
dropped.push({ key, tests: [...new Set([failer, wholeFailer])] });
|
|
1559
|
+
};
|
|
1560
|
+
await eachInOrder(candidates, keepOrDrop);
|
|
1561
|
+
}
|
|
1562
|
+
state.forced = new Map();
|
|
1563
|
+
return isPassing;
|
|
1564
|
+
}
|
|
1565
|
+
catch (e_1) {
|
|
1566
|
+
env_1.error = e_1;
|
|
1567
|
+
env_1.hasError = true;
|
|
1568
|
+
}
|
|
1569
|
+
finally {
|
|
1570
|
+
const result_1 = __disposeResources(env_1);
|
|
1571
|
+
if (result_1)
|
|
1572
|
+
await result_1;
|
|
1573
|
+
}
|
|
1574
|
+
};
|
|
1575
|
+
const isBaseline = await checkedBaseline();
|
|
1576
|
+
// A load-time candidate takes effect only when modules reload, so check the candidates this file kept together in a fresh run.
|
|
1577
|
+
// A load-time candidate stays only when that run's tests all pass; any failure, or a run that gives no verdict, holds every one of them back.
|
|
1578
|
+
const isLoadTime = ({ point }) => [point * 2, point * 2 + 1].some((index) => state.hits.get(index)?.has(loadId)) || Boolean(state.repeats.get(point)?.has(loadId));
|
|
1579
|
+
const droppedKeys = new Set(dropped.map(({ key }) => key));
|
|
1580
|
+
const kept = candidates.filter(({ key }) => !droppedKeys.has(key));
|
|
1581
|
+
const loadTime = kept.filter(isLoadTime);
|
|
1582
|
+
const [firstPassing] = passing;
|
|
1583
|
+
if (isBaseline && loadTime.length && firstPassing) {
|
|
1584
|
+
const forced = await forcedRunOf({
|
|
1585
|
+
edges,
|
|
1586
|
+
filepath: first.filepath,
|
|
1587
|
+
keys: new Set(kept.map(({ key }) => key)),
|
|
1588
|
+
eligible: new Set(passing.map(({ key }) => key)),
|
|
1589
|
+
isHookBroken: isHookBrokenOf(first),
|
|
1590
|
+
loadTicks: session.loadTicks,
|
|
1591
|
+
ticksOf: baselineTicksOf(),
|
|
1592
|
+
});
|
|
1593
|
+
session.judgeSpeed.verify.reruns += forced.reruns;
|
|
1594
|
+
if (forced.status !== 'survived')
|
|
1595
|
+
for (const { key } of loadTime)
|
|
1596
|
+
dropped.push({ key, tests: [forced.catcher ?? firstPassing.key] });
|
|
1597
|
+
}
|
|
1598
|
+
const verified = { file, candidates: isBaseline ? candidateHash : '', dropped };
|
|
1599
|
+
return edges.setVerified(verified);
|
|
1600
|
+
};
|
|
1601
|
+
return Object.assign(runner, { onBeforeCollect, onBeforeRunFiles, onBeforeRunSuite, onAfterRunSuite, onBeforeRunTask, onAfterRunTask, onAfterRunFiles });
|
|
1602
|
+
}
|