@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,441 @@
|
|
|
1
|
+
import { dirname, join, relative, resolve } from 'node:path';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { mutationSettingsInput } from '../../instrument/instrument.schema.js';
|
|
4
|
+
import { planFileOf, planTestOf } from '../../instrument/instrument.operations.js';
|
|
5
|
+
import { fileWalkOf } from '../../graph/symbols/file.js';
|
|
6
|
+
import { clearWorking, getWorking, markWorking, unmarkWorking } from '../../record/edges/markers.db.js';
|
|
7
|
+
import { getJudged } from '../../record/edges/parts.db.js';
|
|
8
|
+
import { setRecordedState } from '../../record/edges/judged-state.db.js';
|
|
9
|
+
import { clearPasses } from '../../record/edges/passes.db.js';
|
|
10
|
+
import { clearGoneTestFiles } from '../../record/edges/parts.edges.js';
|
|
11
|
+
import { getPlan, getPlanCodesNullable, setPlan, setPlanCodes } from '../../record/edges/plan.db.js';
|
|
12
|
+
import { measureWritesOf, openCurrentRecord, openRecord, recordVersion } from '../../record/edges/record.db.js';
|
|
13
|
+
import { hashOf, planCacheKeyOf, rulesKeyOf } from '../../record/record.operations.js';
|
|
14
|
+
import { parse } from '../../utils/ast.js';
|
|
15
|
+
import { failed } from '../../utils/errors.js';
|
|
16
|
+
import { entryAt } from '../../utils/lookup.js';
|
|
17
|
+
import { clearRefusal, pathsIn, readJudgeSource, readJudgeSourceNullable, readJudgeSources } from './judge.fs.js';
|
|
18
|
+
import { cachedImportsOf, jsxFilePattern, projectResolverOf, reachCacheOf, reachPathsOf, setReached } from './reach.js';
|
|
19
|
+
import { forkPluginsInput } from '../../forks/forks.schema.js';
|
|
20
|
+
import { planSpeedKey } from './speed.js';
|
|
21
|
+
import { exploreLimitsProvideKey, explorePathsProvideKey, exploreSeedProvideKey, judgeFilesProvideKey, judgeCoordinators, judgeRedundantProvideKey, judgeRelatedProvideKey, questionsRelatedProvideKey, judgeShardsProvideKey, ownExtension, phaseProvideKey, recordTestFilesProvideKey, recordPathOf, removableTestsProvideKey, rootProvideKey, rulesProvideKey, stepsProvideKey, vitestProvideKey, } from './vitest.js';
|
|
22
|
+
import { exploreLimitsInput } from '../../explore/limits.operations.js';
|
|
23
|
+
import { clearExploreRuns } from '../../explore/edges/explore.db.js';
|
|
24
|
+
import { markedExploreOf, missingVitestOf, staleExploreOf } from '../refusals.js';
|
|
25
|
+
// The judge folder, holding the counters, the runner and crush's merge and report tests.
|
|
26
|
+
const judgeFolder = join(import.meta.dirname, '..');
|
|
27
|
+
const countersPath = join(judgeFolder, `counters${ownExtension}`);
|
|
28
|
+
const runnerPath = join(judgeFolder, `runner${ownExtension}`);
|
|
29
|
+
const reportTest = `report.test${ownExtension}`;
|
|
30
|
+
const stressesTest = `stresses.test${ownExtension}`;
|
|
31
|
+
const exploreTest = `explore.test${ownExtension}`;
|
|
32
|
+
const commandTests = [...judgeCoordinators, reportTest, stressesTest, exploreTest].map((name) => join(judgeFolder, name));
|
|
33
|
+
// Matches crush's counters and runner, which Vitest must load natively rather than through Vite: the counters so each test file's run and its runner share one copy, the runner so what it imports is never instrumented, even when crush checks itself.
|
|
34
|
+
export const nativePattern = /\/judge\/(counters|runner)\.[jt]s$/;
|
|
35
|
+
// Matches a source crush never gates: one in an edges or fixtures folder, which the project tests by integration, or one that loads natively and never runs instrumented.
|
|
36
|
+
export const ungatedPattern = new RegExp(`(^|/)(edges|fixtures)/|${nativePattern.source}`);
|
|
37
|
+
// Matches a test file, a parity run file included, which supplies the checks and is never instrumented.
|
|
38
|
+
export const testFilePattern = /\.(test|spec|parity)\.tsx?$/;
|
|
39
|
+
// Matches a source crush instruments: TypeScript of the project's own, never a declaration file.
|
|
40
|
+
export const sourcePattern = /^(?!.*\.d\.ts$).*\.tsx?$/;
|
|
41
|
+
// Matches a tool's config file, as `vite.config.ts`, which the tool loads itself and no test runs, so crush never plans it.
|
|
42
|
+
export const configFilePattern = /(^|\/)[^/]+\.config\.tsx?$/;
|
|
43
|
+
// Whether a project file is one crush loads but never instruments, an edges or fixtures source, where no step counts.
|
|
44
|
+
export const leavesUninstrumented = (path) => !path.startsWith('../') && !path.split('/').includes('node_modules') && sourcePattern.test(path) && !testFilePattern.test(path) && ungatedPattern.test(path);
|
|
45
|
+
// An uninstrumented file marked loaded by a line after its last, since imports hoist, so every line and column above stays where a trace names it.
|
|
46
|
+
export const markedOutside = (source, path, counters) => `${source}\nimport { __u } from ${JSON.stringify(counters)};__u(${JSON.stringify(path)});`;
|
|
47
|
+
// Every source crush plans, `.jsx` and `.tsx` only when the project asks for them.
|
|
48
|
+
export const sourcesIn = (root, folder, jsx) => {
|
|
49
|
+
return pathsIn(root, folder, (at) => sourcePattern.test(at) && !testFilePattern.test(at) && !ungatedPattern.test(at) && !configFilePattern.test(at) && (jsx || !jsxFilePattern.test(at)));
|
|
50
|
+
};
|
|
51
|
+
// What a cached transform rests on: every source's instrumented code, which holds its text, its plan's counter numbers and the counters module it imports, so a change to crush's instrumenter, its version or its tree serves no stale code.
|
|
52
|
+
export const planKeyOf = (byPath) => hashOf(JSON.stringify([...byPath].map(([path, { code }]) => [path, code])));
|
|
53
|
+
// Matches the relative specifier of a static import or re-export, as `from './x.ts'`, or `from './x.js'` in crush's built copy.
|
|
54
|
+
export const relativeImportPattern = /from '(\.{1,2}\/[^']+\.(?:tsx?|js))'/g;
|
|
55
|
+
// The files record and judge load first: the plugin, the runner and counters, and the coordinators that judge.
|
|
56
|
+
const judgingEntries = ['judge/edges/plugin', 'judge/runner', 'judge/counters'].map((name) => `${name}${ownExtension}`).concat(judgeCoordinators.map((name) => `judge/${name}`));
|
|
57
|
+
// Every source the judging entries reach by import, so an edit to reporting code a verdict never reads leaves every basis standing.
|
|
58
|
+
export const toolSourcesIn = (folder) => {
|
|
59
|
+
const reached = new Set();
|
|
60
|
+
const pending = [...judgingEntries];
|
|
61
|
+
for (let path = pending.pop(); path !== undefined; path = pending.pop()) {
|
|
62
|
+
if (reached.has(path))
|
|
63
|
+
continue;
|
|
64
|
+
const source = readJudgeSourceNullable(folder, path);
|
|
65
|
+
if (source === null)
|
|
66
|
+
continue;
|
|
67
|
+
reached.add(path);
|
|
68
|
+
for (const [, specifier = ''] of source.matchAll(relativeImportPattern))
|
|
69
|
+
pending.push(relative(folder, resolve(folder, dirname(path), specifier)).replaceAll('\\', '/'));
|
|
70
|
+
}
|
|
71
|
+
return [...reached].toSorted();
|
|
72
|
+
};
|
|
73
|
+
// The code crush plans and judges with, its own sources' text, read once a process, so a cached plan or a reused verdict never outlives a change to crush itself.
|
|
74
|
+
const crushSrc = join(judgeFolder, '..');
|
|
75
|
+
let toolHash = '';
|
|
76
|
+
// A verdict rests on the tool's content alone, its paths from crush's own folder, so a checkout moved elsewhere keeps every basis a justification names.
|
|
77
|
+
export const toolHashIn = (folder) => hashOf(JSON.stringify(toolSourcesIn(folder).map((path) => `${path}:${hashOf(readJudgeSource(folder, path))}`)));
|
|
78
|
+
export const toolHashOf = () => {
|
|
79
|
+
toolHash ||= toolHashIn(crushSrc);
|
|
80
|
+
return toolHash;
|
|
81
|
+
};
|
|
82
|
+
// An explore serves the code its record was planned with and writes no row the record owns, so a source edited since refuses it, naming the record that catches it up.
|
|
83
|
+
// An explore reads what the record's tests passed and threw, so it refuses a record made from other sources than these: a planned one, or any file a test file loaded, an edges file its sources import among them.
|
|
84
|
+
const exploredPlanOf = (root, record, kept, fileHashes) => {
|
|
85
|
+
const isChanged = ({ path, hash }) => {
|
|
86
|
+
const known = fileHashes.get(path);
|
|
87
|
+
if (known !== undefined)
|
|
88
|
+
return known !== hash;
|
|
89
|
+
const source = readJudgeSourceNullable(root, path);
|
|
90
|
+
return source === null || hashOf(source) !== hash;
|
|
91
|
+
};
|
|
92
|
+
const parts = getJudged(record, { withHits: false });
|
|
93
|
+
const readFiles = parts.flatMap(({ file, hash, reads }) => reads.concat({ path: file, hash }));
|
|
94
|
+
const changedReads = readFiles.filter(isChanged).map(({ path }) => path);
|
|
95
|
+
if (!kept || changedReads.length) {
|
|
96
|
+
const changedPlanned = getPlan(record).files.flatMap((file) => (isChanged(file) ? [file.path] : []));
|
|
97
|
+
const changed = [...new Set([...changedPlanned, ...changedReads])];
|
|
98
|
+
const named = changed.length ? changed.join(' ') : '<paths>';
|
|
99
|
+
return failed(staleExploreOf(named));
|
|
100
|
+
}
|
|
101
|
+
const served = new Map(kept.map(({ path, hash, code }) => [path, { code, plan: { hash } }]));
|
|
102
|
+
return { data: { byPath: served, hash: planKeyOf(served), cached: true }, error: null };
|
|
103
|
+
};
|
|
104
|
+
const plannedOf = async (root, record, reach, write, explore, testFiles) => {
|
|
105
|
+
const byPath = new Map();
|
|
106
|
+
let pointBase = 0;
|
|
107
|
+
let siteBase = 0;
|
|
108
|
+
let unitBase = 0;
|
|
109
|
+
const sourcePaths = sourcesIn(root, root, reach.jsx).filter((path) => !testFiles.has(path));
|
|
110
|
+
const reachPaths = reachPathsOf(root, reach.jsx, testFiles);
|
|
111
|
+
const snapshot = await readJudgeSources(root, [...sourcePaths, ...testFiles, ...reachPaths.sources, ...reachPaths.components]);
|
|
112
|
+
const fileHashes = new Map([...snapshot].map(([path, source]) => [path, hashOf(source)]));
|
|
113
|
+
const hashAt = (path) => entryAt(fileHashes, path, 'the planning file hash');
|
|
114
|
+
const textOf = (path) => ({ path, source: entryAt(snapshot, path, 'the planning file') });
|
|
115
|
+
const texts = sourcePaths.map(textOf);
|
|
116
|
+
const testTexts = [...testFiles].map(textOf);
|
|
117
|
+
// An unchanged project serves the code its last plan kept, planning nothing; the plan itself is still the one that plan stored.
|
|
118
|
+
const settings = { entries: reach.entries, jsx: reach.jsx, steps: reach.steps, mutation: reach.mutation, tests: [...testFiles] };
|
|
119
|
+
const files = [...texts, ...testTexts].map(({ path }) => ({ path, hash: hashAt(path) }));
|
|
120
|
+
const scanned = new Map();
|
|
121
|
+
const resolve = () => projectResolverOf({ root, paths: reachPaths, texts: snapshot, hashes: fileHashes, resolveImport: reach.resolveImport, cache: reach.cache, scanned });
|
|
122
|
+
const { data: resolver, error: unresolved } = reach.plugins.length ? await resolve() : { data: null, error: null };
|
|
123
|
+
if (unresolved)
|
|
124
|
+
return { data: null, error: unresolved };
|
|
125
|
+
const plugins = hashOf(JSON.stringify(resolver ? [reach.plugins, resolver.basis] : reach.plugins));
|
|
126
|
+
const cacheKey = planCacheKeyOf({ files, settings, plugins, tool: `${toolHashOf()}|${countersPath}` });
|
|
127
|
+
const kept = getPlanCodesNullable(record, cacheKey);
|
|
128
|
+
if (explore)
|
|
129
|
+
return exploredPlanOf(root, record, kept, fileHashes);
|
|
130
|
+
const reached = async () => {
|
|
131
|
+
const { data, error } = resolver ? { data: resolver, error: null } : await resolve();
|
|
132
|
+
if (error)
|
|
133
|
+
return error;
|
|
134
|
+
setReached({ root, record, resolver: data, entries: reach.entries, cache: reach.cache, testFiles, write });
|
|
135
|
+
return null;
|
|
136
|
+
};
|
|
137
|
+
if (kept) {
|
|
138
|
+
const error = await reached();
|
|
139
|
+
if (error)
|
|
140
|
+
return { data: null, error };
|
|
141
|
+
const served = new Map(kept.map(({ path, hash, code }) => [path, { code, plan: { hash } }]));
|
|
142
|
+
return { data: { byPath: served, hash: planKeyOf(served), cached: true }, error: null };
|
|
143
|
+
}
|
|
144
|
+
const forkPlugins = { plugins: reach.plugins, resolve: resolver?.resolve ?? (() => null) };
|
|
145
|
+
const sources = [];
|
|
146
|
+
for (const { path, source } of texts) {
|
|
147
|
+
const scan = resolver?.scanned.get(path);
|
|
148
|
+
const { data: parsed, error } = scan ? { data: scan.parsed, error: null } : parse(source, path);
|
|
149
|
+
if (error)
|
|
150
|
+
return { data: null, error };
|
|
151
|
+
sources.push({ path, source, parsed });
|
|
152
|
+
}
|
|
153
|
+
const project = new Map(sources.map(({ path, parsed }) => [path, parsed.program]));
|
|
154
|
+
for (const { path, source, parsed } of sources) {
|
|
155
|
+
// The plan's walk of the file also collects what the graph reads of it, so the graph walks no file again.
|
|
156
|
+
const { walked, listener } = fileWalkOf(path);
|
|
157
|
+
const { data: file, error } = planFileOf({ path, hash: hashAt(path), source, parsed, project, forkPlugins, mutation: reach.mutation, pointBase, siteBase, unitBase, counters: countersPath, listeners: [listener] });
|
|
158
|
+
if (error)
|
|
159
|
+
return { data: null, error };
|
|
160
|
+
const { code, plan, cfg } = file;
|
|
161
|
+
scanned.set(path, { parsed, references: cfg.paths.references, definitions: cfg.paths.definitions, parameters: cfg.paths.parameters, unresolved: cfg.paths.unresolved, walked });
|
|
162
|
+
pointBase += plan.points.length;
|
|
163
|
+
siteBase += plan.switches.length;
|
|
164
|
+
unitBase += plan.units.length;
|
|
165
|
+
byPath.set(path, { code, plan });
|
|
166
|
+
}
|
|
167
|
+
const planned = [...byPath.values()].map(({ plan }) => plan);
|
|
168
|
+
// Each test file is marked but never mutated, so a verdict rests on the test bodies its file's run entered rather than on the whole file.
|
|
169
|
+
const tests = [];
|
|
170
|
+
for (const { path, source } of testTexts) {
|
|
171
|
+
const scan = resolver?.scanned.get(path);
|
|
172
|
+
const { data: parsed, error } = scan ? { data: scan.parsed, error: null } : parse(source, path);
|
|
173
|
+
if (error)
|
|
174
|
+
return { data: null, error };
|
|
175
|
+
const { walked, listener } = fileWalkOf(path);
|
|
176
|
+
const { data: test, error: broken } = planTestOf({ path, hash: hashAt(path), source, parsed, unitBase, counters: countersPath, listeners: [listener] });
|
|
177
|
+
if (broken)
|
|
178
|
+
return { data: null, error: broken };
|
|
179
|
+
scanned.set(path, { parsed, references: test.paths.references, definitions: test.paths.definitions, parameters: test.paths.parameters, unresolved: test.paths.unresolved, walked });
|
|
180
|
+
unitBase += test.plan.units.length;
|
|
181
|
+
tests.push(test);
|
|
182
|
+
}
|
|
183
|
+
const error = await reached();
|
|
184
|
+
if (error)
|
|
185
|
+
return { data: null, error };
|
|
186
|
+
const testPlans = tests.map(({ plan }) => plan);
|
|
187
|
+
write(() => setPlan(record, planned, testPlans));
|
|
188
|
+
const served = new Map([...byPath, ...tests.map(({ code, plan }) => [plan.path, { code, plan }])]);
|
|
189
|
+
const codes = [...served].map(([path, { code, plan }]) => ({ path, hash: plan.hash, code }));
|
|
190
|
+
write(() => setPlanCodes(record, cacheKey, codes));
|
|
191
|
+
return { data: { byPath: served, hash: planKeyOf(served), cached: false }, error: null };
|
|
192
|
+
};
|
|
193
|
+
const projectVitestPlugin = (root, discoverTests) => {
|
|
194
|
+
let vitest = '';
|
|
195
|
+
return {
|
|
196
|
+
name: 'crush:vitest',
|
|
197
|
+
enforce: 'pre',
|
|
198
|
+
configureVitest: async ({ project }) => {
|
|
199
|
+
const resolved = await project.vite.pluginContainer.resolveId('vite-plus/test', join(root, 'package.json'), { ssr: true });
|
|
200
|
+
if (!resolved)
|
|
201
|
+
throw new Error(missingVitestOf(root));
|
|
202
|
+
vitest = resolved.id;
|
|
203
|
+
project.provide(vitestProvideKey, vitest);
|
|
204
|
+
if (discoverTests)
|
|
205
|
+
project.provide(recordTestFilesProvideKey, await discoverTests(project));
|
|
206
|
+
},
|
|
207
|
+
resolveId: (source, importer) => (source === 'vite-plus/test' && importer?.startsWith(judgeFolder) ? vitest : null),
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
// The paths a related explore names, from the project's root, leaving out the phases crush adds to Vitest's filter, or null for a full explore.
|
|
211
|
+
// Vitest starts every project's configureVitest together, so each reads the paths off the filter itself rather than waiting on another.
|
|
212
|
+
const namedPathsOf = (root, related) => {
|
|
213
|
+
if (!related)
|
|
214
|
+
return null;
|
|
215
|
+
const named = related.map((path) => resolve(root, path)).filter((path) => !path.startsWith(judgeFolder));
|
|
216
|
+
return named.map((path) => relative(root, path));
|
|
217
|
+
};
|
|
218
|
+
// Hands the explore project Vitest's `--sequence.seed`, which its search draws from, so a seed given on the command line repeats a run, and the paths a related explore names.
|
|
219
|
+
const exploreSeedPlugin = (root) => ({
|
|
220
|
+
name: 'crush:explore-seed',
|
|
221
|
+
configureVitest: ({ vitest, project }) => {
|
|
222
|
+
project.provide(exploreSeedProvideKey, vitest.config.sequence.seed);
|
|
223
|
+
project.provide(explorePathsProvideKey, namedPathsOf(root, vitest.config.related));
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
export const crushPlugin = ({ root, entries, jsx, plugins, steps, mutation, explore, discoverTests }) => {
|
|
227
|
+
let planned = null;
|
|
228
|
+
let planning = null;
|
|
229
|
+
let record = null;
|
|
230
|
+
const speed = { plan: 0, cachedPlan: 0, built: 0, cached: 0, writes: 0 };
|
|
231
|
+
const write = measureWritesOf(speed);
|
|
232
|
+
let publish = () => { };
|
|
233
|
+
const recordOf = () => {
|
|
234
|
+
if (record)
|
|
235
|
+
return record;
|
|
236
|
+
if (!explore) {
|
|
237
|
+
record = write(() => openRecord(recordPathOf(root)));
|
|
238
|
+
return record;
|
|
239
|
+
}
|
|
240
|
+
const { data, error } = openCurrentRecord(recordPathOf(root));
|
|
241
|
+
if (error)
|
|
242
|
+
throw error;
|
|
243
|
+
record = data;
|
|
244
|
+
return record;
|
|
245
|
+
};
|
|
246
|
+
let testFiles = new Set();
|
|
247
|
+
let imports;
|
|
248
|
+
const cache = reachCacheOf();
|
|
249
|
+
const replan = () => {
|
|
250
|
+
if (planning)
|
|
251
|
+
return planning;
|
|
252
|
+
const started = performance.now();
|
|
253
|
+
planning = plannedOf(root, recordOf(), { entries, jsx, resolveImport: imports.resolve, cache, plugins, steps, mutation }, write, explore, testFiles)
|
|
254
|
+
.then(({ data, error }) => {
|
|
255
|
+
const ms = performance.now() - started;
|
|
256
|
+
if (data?.cached) {
|
|
257
|
+
speed.cachedPlan += ms;
|
|
258
|
+
speed.cached += 1;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
speed.plan += ms;
|
|
262
|
+
speed.built += 1;
|
|
263
|
+
}
|
|
264
|
+
publish();
|
|
265
|
+
if (error)
|
|
266
|
+
throw error;
|
|
267
|
+
planned = data;
|
|
268
|
+
return data;
|
|
269
|
+
})
|
|
270
|
+
.finally(() => {
|
|
271
|
+
planning = null;
|
|
272
|
+
});
|
|
273
|
+
return planning;
|
|
274
|
+
};
|
|
275
|
+
return {
|
|
276
|
+
name: 'crush',
|
|
277
|
+
enforce: 'pre',
|
|
278
|
+
config: () => ({ test: { server: { deps: { external: [nativePattern] } } } }),
|
|
279
|
+
configResolved: (config) => {
|
|
280
|
+
// A config that selects the record project for explore would run a record under `--mode explore`, which reads as an explore that found nothing, so that run is refused.
|
|
281
|
+
if (config.mode === 'explore' && !explore)
|
|
282
|
+
throw new Error('crush ran under --mode explore with record projects; use exploreProject');
|
|
283
|
+
},
|
|
284
|
+
watchChange: () => imports?.clear(),
|
|
285
|
+
configureVitest: async ({ vitest, project, defineCacheKeyGenerator }) => {
|
|
286
|
+
if (!explore)
|
|
287
|
+
root = project.config.root;
|
|
288
|
+
imports = cachedImportsOf((id, importer) => project.vite.pluginContainer.resolveId(id, importer, { ssr: true }));
|
|
289
|
+
testFiles = new Set(await discoverTests(project));
|
|
290
|
+
publish = () => project.provide(planSpeedKey, { ...speed });
|
|
291
|
+
// A part stands only while its test file does, so a deleted file's part goes before anything reads the parts, and the sites it caught fall to the files left.
|
|
292
|
+
const db = recordOf();
|
|
293
|
+
if (explore) {
|
|
294
|
+
const markers = getWorking(db).length;
|
|
295
|
+
if (markers)
|
|
296
|
+
throw new Error(markedExploreOf(markers));
|
|
297
|
+
const initial = await (planning ?? planned ?? replan());
|
|
298
|
+
if (vitest.config.related)
|
|
299
|
+
vitest.config.related = [...new Set([...vitest.config.related, join(judgeFolder, exploreTest)])];
|
|
300
|
+
defineCacheKeyGenerator?.(() => (planned ?? initial).hash);
|
|
301
|
+
clearExploreRuns(db);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
clearGoneTestFiles(db, root, write);
|
|
305
|
+
// A marker a killed run left standing would hold up this run's phases, and no test file works before the project starts.
|
|
306
|
+
write(() => clearWorking(db));
|
|
307
|
+
clearRefusal(root);
|
|
308
|
+
// The passes a killed run's shards ended would let this run's shards go on before the others, so a judge clears them before any shard starts.
|
|
309
|
+
if (project.config.provide[phaseProvideKey] === 'judge')
|
|
310
|
+
write(() => clearPasses(db));
|
|
311
|
+
// One record marker covers the project, leaving each file's evidence in one transaction.
|
|
312
|
+
if (project.config.provide[phaseProvideKey] === 'record') {
|
|
313
|
+
const marker = `record-${process.pid}`;
|
|
314
|
+
write(() => markWorking(db, marker));
|
|
315
|
+
vitest.onClose(async () => {
|
|
316
|
+
// A record that reran every test file's baseline and kept each part confirms the state the last clean judge judged.
|
|
317
|
+
const ran = new Set(vitest.state.getFiles().map(({ filepath }) => relative(root, filepath)));
|
|
318
|
+
write(() => setRecordedState(db, ran));
|
|
319
|
+
const error = await unmarkWorking(db, marker, write);
|
|
320
|
+
if (error)
|
|
321
|
+
throw error;
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
const initial = await (planning ?? planned ?? replan());
|
|
325
|
+
defineCacheKeyGenerator?.(() => (planned ?? initial).hash);
|
|
326
|
+
},
|
|
327
|
+
transform: async (source, id) => {
|
|
328
|
+
const path = relative(root, id.split('?')[0] ?? id);
|
|
329
|
+
const current = await (planning ?? planned ?? replan());
|
|
330
|
+
const kept = current.byPath.get(path);
|
|
331
|
+
// An uninstrumented project file still marks itself loaded, so a test whose steps fell can be asked whether its work moved there.
|
|
332
|
+
if (!kept)
|
|
333
|
+
return leavesUninstrumented(path) ? { code: markedOutside(source, path, countersPath), map: null } : null;
|
|
334
|
+
if (kept.plan.hash === hashOf(source))
|
|
335
|
+
return { code: kept.code, map: null };
|
|
336
|
+
imports.clear();
|
|
337
|
+
const updated = await replan();
|
|
338
|
+
return { code: updated.byPath.get(path)?.code ?? source, map: null };
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
// Every command runs in the project's own pool, since a test may change the working folder only in a process of its own.
|
|
343
|
+
// The runner reloads each file's modules itself, so workers share them, and as many run as the judge command has shards.
|
|
344
|
+
const workers = { isolate: false, maxWorkers: judgeCoordinators.length };
|
|
345
|
+
const discoverTestsOf = ({ root, include, exclude = [] }) => {
|
|
346
|
+
let files;
|
|
347
|
+
return (project) => (files ??= project.globFiles(include, ['**/node_modules/**', ...exclude, ...commandTests], root).then((paths) => paths.map((path) => relative(root, path).replaceAll('\\', '/')).toSorted()));
|
|
348
|
+
};
|
|
349
|
+
const relatedPathsOf = ({ vitest, root, own }) => {
|
|
350
|
+
const named = namedPathsOf(root, vitest.config.related) ?? [];
|
|
351
|
+
if (vitest.config.related)
|
|
352
|
+
vitest.config.related = [...new Set([...vitest.config.related, ...own])];
|
|
353
|
+
return named;
|
|
354
|
+
};
|
|
355
|
+
export const questionsProject = ({ root, include, exclude, removableTests = 'all', steps = true }) => ({
|
|
356
|
+
plugins: [
|
|
357
|
+
projectVitestPlugin(root, discoverTestsOf({ root, include, exclude })),
|
|
358
|
+
{
|
|
359
|
+
name: 'crush:questions-related',
|
|
360
|
+
configureVitest: ({ vitest, project }) => project.provide(questionsRelatedProvideKey, relatedPathsOf({ vitest, root, own: [join(judgeFolder, reportTest)] })),
|
|
361
|
+
},
|
|
362
|
+
],
|
|
363
|
+
test: {
|
|
364
|
+
name: 'questions',
|
|
365
|
+
root: judgeFolder,
|
|
366
|
+
include: [reportTest],
|
|
367
|
+
provide: { [rootProvideKey]: root, [removableTestsProvideKey]: removableTests, [stepsProvideKey]: steps },
|
|
368
|
+
...workers,
|
|
369
|
+
},
|
|
370
|
+
});
|
|
371
|
+
export const stressesProject = ({ root }) => ({
|
|
372
|
+
plugins: [projectVitestPlugin(root)],
|
|
373
|
+
test: {
|
|
374
|
+
name: 'stresses',
|
|
375
|
+
root: judgeFolder,
|
|
376
|
+
include: [stressesTest],
|
|
377
|
+
provide: { [rootProvideKey]: root },
|
|
378
|
+
...workers,
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
const recordProjectWithTests = ({ root, include, entries, jsx = false, exclude = [], removableTests = 'all', steps = true, forks = [], mutation: written = {} }, discoverTests) => {
|
|
382
|
+
const plugins = forkPluginsInput.parse(forks);
|
|
383
|
+
const mutation = mutationSettingsInput.parse(written);
|
|
384
|
+
return {
|
|
385
|
+
plugins: [projectVitestPlugin(root), crushPlugin({ root, entries, jsx, plugins, steps, mutation, explore: false, discoverTests })],
|
|
386
|
+
test: {
|
|
387
|
+
name: 'record',
|
|
388
|
+
root,
|
|
389
|
+
include,
|
|
390
|
+
exclude: ['**/node_modules/**', ...exclude, ...commandTests],
|
|
391
|
+
runner: runnerPath,
|
|
392
|
+
...workers,
|
|
393
|
+
provide: { [phaseProvideKey]: 'record', [rulesProvideKey]: rulesKeyOf({ version: recordVersion, tool: toolHashOf(), settings: { steps, forks: plugins, mutation } }), [removableTestsProvideKey]: removableTests },
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
};
|
|
397
|
+
export const recordProject = (input) => recordProjectWithTests(input, discoverTestsOf(input));
|
|
398
|
+
export const judgeProject = (input) => {
|
|
399
|
+
const discoverTests = discoverTestsOf(input);
|
|
400
|
+
const project = recordProjectWithTests(input, discoverTests);
|
|
401
|
+
const { root, redundant = false } = input;
|
|
402
|
+
const coordinators = judgeCoordinators.map((name) => join(judgeFolder, name));
|
|
403
|
+
return {
|
|
404
|
+
plugins: [
|
|
405
|
+
...project.plugins,
|
|
406
|
+
{
|
|
407
|
+
name: 'crush:judge-files',
|
|
408
|
+
configureVitest: async ({ vitest, project }) => {
|
|
409
|
+
project.provide(judgeRelatedProvideKey, relatedPathsOf({ vitest, root, own: coordinators }));
|
|
410
|
+
project.provide(judgeRedundantProvideKey, redundant);
|
|
411
|
+
project.provide(judgeShardsProvideKey, Math.min(judgeCoordinators.length, project.config.maxWorkers));
|
|
412
|
+
const files = await discoverTests(project);
|
|
413
|
+
project.provide(judgeFilesProvideKey, files.map((path) => join(root, path)));
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
],
|
|
417
|
+
// The coordinators live in crush's own folder, under the project's `node_modules` once crush is installed, so the judge excludes nothing beyond the files it names.
|
|
418
|
+
test: { ...project.test, name: 'judge', include: coordinators, exclude: [], provide: { ...Object(project.test.provide), [phaseProvideKey]: 'judge', [judgeRelatedProvideKey]: [] } },
|
|
419
|
+
};
|
|
420
|
+
};
|
|
421
|
+
export const exploreProject = ({ root, include, exclude, entries, jsx = false, removableTests = 'all', steps = true, forks = [], mutation: written = {}, explore = {} }) => {
|
|
422
|
+
const plugins = forkPluginsInput.parse(forks);
|
|
423
|
+
const mutation = mutationSettingsInput.parse(written);
|
|
424
|
+
return {
|
|
425
|
+
plugins: [projectVitestPlugin(root), crushPlugin({ root, entries, jsx, plugins, steps, mutation, explore: true, discoverTests: discoverTestsOf({ root, include, exclude }) }), exploreSeedPlugin(root)],
|
|
426
|
+
test: {
|
|
427
|
+
name: 'explore',
|
|
428
|
+
root: judgeFolder,
|
|
429
|
+
include: [exploreTest],
|
|
430
|
+
runner: runnerPath,
|
|
431
|
+
...workers,
|
|
432
|
+
provide: {
|
|
433
|
+
[rootProvideKey]: root,
|
|
434
|
+
[phaseProvideKey]: 'property',
|
|
435
|
+
[exploreLimitsProvideKey]: exploreLimitsInput.parse(explore),
|
|
436
|
+
[removableTestsProvideKey]: removableTests,
|
|
437
|
+
[rulesProvideKey]: rulesKeyOf({ version: recordVersion, tool: toolHashOf(), settings: { steps, forks: plugins, mutation } }),
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { CrushError } from '../../utils/errors.ts';
|
|
2
|
+
import type { Safe } from '../../utils/safe.ts';
|
|
3
|
+
import { type FileSymbols, type FileSymbolsInput } from '../../graph/symbols/file.ts';
|
|
4
|
+
import { type Runners } from '../../graph/unused/tests.ts';
|
|
5
|
+
import { type Reach } from '../../graph/unused/unused.ts';
|
|
6
|
+
import { type MeasureWrite, type Record } from '../../record/edges/record.db.ts';
|
|
7
|
+
export declare const projectFilePattern: RegExp;
|
|
8
|
+
export declare const testRootPattern: RegExp;
|
|
9
|
+
export declare const configFilePattern: RegExp;
|
|
10
|
+
export declare const componentFilePattern: RegExp;
|
|
11
|
+
export declare const componentImportPattern: RegExp;
|
|
12
|
+
export declare const resolvedIdSuffixPattern: RegExp;
|
|
13
|
+
type Walked = {
|
|
14
|
+
sources: string[];
|
|
15
|
+
components: string[];
|
|
16
|
+
tests: ReadonlySet<string>;
|
|
17
|
+
};
|
|
18
|
+
export declare const jsxFilePattern: RegExp;
|
|
19
|
+
export declare const reachPathsOf: (root: string, jsx: boolean, tests: ReadonlySet<string>) => Walked;
|
|
20
|
+
export type FileRead = {
|
|
21
|
+
symbols: FileSymbols;
|
|
22
|
+
runners: Runners | null;
|
|
23
|
+
};
|
|
24
|
+
export type ReachCache = {
|
|
25
|
+
facts: Map<string, {
|
|
26
|
+
hash: string;
|
|
27
|
+
read: FileRead;
|
|
28
|
+
}>;
|
|
29
|
+
last: Reach | null;
|
|
30
|
+
};
|
|
31
|
+
export declare const reachCacheOf: () => ReachCache;
|
|
32
|
+
export type ReachScan = NonNullable<FileSymbolsInput['scan']>;
|
|
33
|
+
export type Scanned = ReadonlyMap<string, ReachScan>;
|
|
34
|
+
export type ResolveImport = (id: string, importer: string) => Promise<{
|
|
35
|
+
id: string;
|
|
36
|
+
} | null>;
|
|
37
|
+
export declare const cachedImportsOf: (resolveImport: ResolveImport) => {
|
|
38
|
+
resolve: ResolveImport;
|
|
39
|
+
clear: () => void;
|
|
40
|
+
};
|
|
41
|
+
type ProjectResolver = {
|
|
42
|
+
scanned: Scanned;
|
|
43
|
+
facts: FileRead[];
|
|
44
|
+
fromComponents: string[];
|
|
45
|
+
resolve: (from: string, specifier: string) => string | null;
|
|
46
|
+
basis: string;
|
|
47
|
+
};
|
|
48
|
+
type ProjectResolverInput = {
|
|
49
|
+
root: string;
|
|
50
|
+
paths: Walked;
|
|
51
|
+
texts: ReadonlyMap<string, string>;
|
|
52
|
+
hashes: ReadonlyMap<string, string>;
|
|
53
|
+
resolveImport: ResolveImport;
|
|
54
|
+
cache: ReachCache;
|
|
55
|
+
scanned: Scanned;
|
|
56
|
+
};
|
|
57
|
+
export declare const projectResolverOf: ({ root, paths, texts, hashes, resolveImport, cache, scanned }: ProjectResolverInput) => Promise<Safe<ProjectResolver, CrushError>>;
|
|
58
|
+
export type ReachedInput = {
|
|
59
|
+
root: string;
|
|
60
|
+
record: Record;
|
|
61
|
+
entries: string[];
|
|
62
|
+
resolver: ProjectResolver;
|
|
63
|
+
cache: ReachCache;
|
|
64
|
+
testFiles: ReadonlySet<string>;
|
|
65
|
+
write?: MeasureWrite;
|
|
66
|
+
};
|
|
67
|
+
export declare const setReached: ({ root, record, entries, resolver, cache, testFiles, write }: ReachedInput) => void;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { isAbsolute, join, relative } from 'node:path';
|
|
2
|
+
import { referencesOf } from '../../graph/cfg/paths.js';
|
|
3
|
+
import { symbolGraphOf } from '../../graph/symbols/symbols.js';
|
|
4
|
+
import { fileSymbolsOf, fileTreeOf, fileWalkOf } from '../../graph/symbols/file.js';
|
|
5
|
+
import { runnersOf } from '../../graph/unused/tests.js';
|
|
6
|
+
import { reachChangesOf, reachOf, unusedOf } from '../../graph/unused/unused.js';
|
|
7
|
+
import { getReachEdges, getReachNodes, setReachChanges } from '../../record/edges/reach.db.js';
|
|
8
|
+
import { writeDirectly } from '../../record/edges/record.db.js';
|
|
9
|
+
import { hashOf } from '../../record/record.operations.js';
|
|
10
|
+
import { parse } from '../../utils/ast.js';
|
|
11
|
+
import { entryAt } from '../../utils/lookup.js';
|
|
12
|
+
import { pathsIn, resolveEntryPaths } from './judge.fs.js';
|
|
13
|
+
// Matches a file the graph reads: TypeScript of the project's own, module and CommonJS flavours included, never a declaration file.
|
|
14
|
+
export const projectFilePattern = /^(?!.*\.d\.[cm]?ts$).*\.[cm]?tsx?$/;
|
|
15
|
+
// Matches a test file the graph starts from, a type test, which Vitest checks without running, and a `.testing.ts` helper only tests import included.
|
|
16
|
+
export const testRootPattern = /\.(test|spec|test-d|spec-d|testing)\.[cm]?tsx?$/;
|
|
17
|
+
// Matches a tool's config file, as `vite.config.ts`, which the tool loads by its name.
|
|
18
|
+
export const configFilePattern = /(^|\/)[^/]+\.config\.[cm]?tsx?$/;
|
|
19
|
+
// Matches a component file of a framework whose script the graph cannot read, which may import the project's TypeScript.
|
|
20
|
+
export const componentFilePattern = /\.(vue|svelte|astro)$/;
|
|
21
|
+
// Matches a fixed specifier a component's script imports, statically or dynamically.
|
|
22
|
+
export const componentImportPattern = /(?:\bfrom\s*|\bimport\s*\(?\s*)(['"])([^'"]+)\1/g;
|
|
23
|
+
// Matches the start of a query or fragment on an ID returned by Vite.
|
|
24
|
+
export const resolvedIdSuffixPattern = /[?#]/;
|
|
25
|
+
// Matches a JSX or TSX file, which crush reads only when a project asks it to.
|
|
26
|
+
export const jsxFilePattern = /\.[jt]sx$/;
|
|
27
|
+
export const reachPathsOf = (root, jsx, tests) => {
|
|
28
|
+
const into = { sources: Array.of(), components: Array.of() };
|
|
29
|
+
for (const path of pathsIn(root, root, () => true)) {
|
|
30
|
+
if (tests.has(path))
|
|
31
|
+
into.sources.push(path);
|
|
32
|
+
else if (!jsx && jsxFilePattern.test(path))
|
|
33
|
+
into.components.push(path);
|
|
34
|
+
else if (projectFilePattern.test(path))
|
|
35
|
+
into.sources.push(path);
|
|
36
|
+
else if (componentFilePattern.test(path))
|
|
37
|
+
into.components.push(path);
|
|
38
|
+
}
|
|
39
|
+
return { sources: [...new Set([...into.sources, ...tests])], components: into.components, tests };
|
|
40
|
+
};
|
|
41
|
+
export const reachCacheOf = () => ({ facts: new Map(), last: null });
|
|
42
|
+
// Keeps Vite's results for one project until a watched input changes.
|
|
43
|
+
export const cachedImportsOf = (resolveImport) => {
|
|
44
|
+
const imports = new Map();
|
|
45
|
+
return {
|
|
46
|
+
resolve: (id, importer) => {
|
|
47
|
+
const key = `${importer}\0${id}`;
|
|
48
|
+
const found = imports.get(key);
|
|
49
|
+
if (found)
|
|
50
|
+
return found;
|
|
51
|
+
const resolved = resolveImport(id, importer);
|
|
52
|
+
imports.set(key, resolved);
|
|
53
|
+
return resolved;
|
|
54
|
+
},
|
|
55
|
+
clear: () => imports.clear(),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const factsIn = ({ paths, texts, hashes, scanned, cache }) => {
|
|
59
|
+
const { sources, tests } = paths;
|
|
60
|
+
const scans = new Map(scanned);
|
|
61
|
+
const facts = [];
|
|
62
|
+
for (const path of sources) {
|
|
63
|
+
const source = entryAt(texts, path, 'the planning source');
|
|
64
|
+
const hash = entryAt(hashes, path, 'the planning source hash');
|
|
65
|
+
const kept = cache.facts.get(path);
|
|
66
|
+
if (kept?.hash === hash) {
|
|
67
|
+
facts.push(kept.read);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const scanOf = () => {
|
|
71
|
+
const { data: parsed } = parse(source, path);
|
|
72
|
+
// A file that fails to parse is still a node of the graph, with no scan.
|
|
73
|
+
if (!parsed)
|
|
74
|
+
return { data: null, error: null };
|
|
75
|
+
const { walked, listener } = fileWalkOf(path);
|
|
76
|
+
const { data: references, error } = referencesOf(parsed, [listener]);
|
|
77
|
+
return error ? { data: null, error } : { data: { parsed, ...references, walked }, error: null };
|
|
78
|
+
};
|
|
79
|
+
const held = scanned.get(path);
|
|
80
|
+
const { data: scan, error } = held ? { data: held, error: null } : scanOf();
|
|
81
|
+
if (error)
|
|
82
|
+
return { data: null, error };
|
|
83
|
+
if (scan)
|
|
84
|
+
scans.set(path, scan);
|
|
85
|
+
const tree = scan && fileTreeOf(path, scan);
|
|
86
|
+
const made = { symbols: fileSymbolsOf(path, source, tree), runners: tests.has(path) ? runnersOf(path, tree) : null };
|
|
87
|
+
cache.facts.set(path, { hash, read: made });
|
|
88
|
+
facts.push(made);
|
|
89
|
+
}
|
|
90
|
+
return { data: { facts, scanned: scans }, error: null };
|
|
91
|
+
};
|
|
92
|
+
// Vite resolves each distinct import before the synchronous graph and fork passes read it.
|
|
93
|
+
export const projectResolverOf = async ({ root, paths, texts, hashes, resolveImport, cache, scanned }) => {
|
|
94
|
+
const sources = new Set(paths.sources);
|
|
95
|
+
const { data: found, error } = factsIn({ paths, texts, hashes, scanned, cache });
|
|
96
|
+
if (error)
|
|
97
|
+
return { data: null, error };
|
|
98
|
+
const { facts, scanned: scans } = found;
|
|
99
|
+
const components = paths.components.map((path) => ({
|
|
100
|
+
path,
|
|
101
|
+
specs: [...entryAt(texts, path, 'the planning component').matchAll(componentImportPattern)].flatMap(([, , specifier]) => specifier ?? []),
|
|
102
|
+
}));
|
|
103
|
+
const imports = [...facts.map(({ symbols }) => ({ path: symbols.path, specs: [...symbols.stars, ...symbols.edges.flatMap(({ to }) => ('specifier' in to ? [to.specifier] : []))] })), ...components];
|
|
104
|
+
const resolved = new Map(await Promise.all(imports.flatMap(({ path, specs }) => {
|
|
105
|
+
return [...new Set(specs)].map(async (specifier) => {
|
|
106
|
+
const result = await resolveImport(specifier, join(root, path));
|
|
107
|
+
const id = result?.id.split(resolvedIdSuffixPattern, 1)[0];
|
|
108
|
+
const local = id && isAbsolute(id) ? relative(root, id).replaceAll('\\', '/') : null;
|
|
109
|
+
return [`${path}\0${specifier}`, local && sources.has(local) ? local : null];
|
|
110
|
+
});
|
|
111
|
+
})));
|
|
112
|
+
const resolve = (from, specifier) => resolved.get(`${from}\0${specifier}`) ?? null;
|
|
113
|
+
const fromComponents = components.flatMap(({ path, specs }) => specs.flatMap((specifier) => resolve(path, specifier) ?? []));
|
|
114
|
+
return { data: { facts, scanned: scans, fromComponents, resolve, basis: hashOf(JSON.stringify([...resolved])) }, error: null };
|
|
115
|
+
};
|
|
116
|
+
export const setReached = ({ root, record, entries, resolver, cache, testFiles, write = writeDirectly }) => {
|
|
117
|
+
const { facts, resolve, fromComponents } = resolver;
|
|
118
|
+
const entryFiles = new Set([...resolveEntryPaths(root, entries), ...fromComponents]);
|
|
119
|
+
const roots = new Map();
|
|
120
|
+
for (const path of facts.map(({ symbols }) => symbols.path)) {
|
|
121
|
+
if (testFiles.has(path))
|
|
122
|
+
roots.set(path, 'test');
|
|
123
|
+
else if (entryFiles.has(path) || configFilePattern.test(path))
|
|
124
|
+
roots.set(path, 'entry');
|
|
125
|
+
}
|
|
126
|
+
const symbols = symbolGraphOf({ files: facts.map((read) => read.symbols), roots, resolve });
|
|
127
|
+
const runners = new Map(facts.flatMap((read) => (read.runners && roots.get(read.symbols.path) === 'test' ? [[read.symbols.path, read.runners]] : [])));
|
|
128
|
+
const reach = reachOf(symbols, unusedOf({ symbols, roots, runners }));
|
|
129
|
+
const changes = reachChangesOf(cache.last ?? { nodes: getReachNodes(record), edges: getReachEdges(record) }, reach);
|
|
130
|
+
write(() => setReachChanges(record, changes));
|
|
131
|
+
cache.last = reach;
|
|
132
|
+
};
|