@whaaaley/crush 0.3.0-next.8 → 0.3.0-next.9

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.
@@ -1,6 +1,4 @@
1
1
  import { z } from 'zod';
2
- import { type stateOf } from '../../judge/counters.ts';
3
- import { type Safe } from '../../utils/safe.ts';
4
2
  export type Finding = {
5
3
  key: string;
6
4
  kind: 'throw' | 'property';
@@ -33,11 +31,6 @@ export type ExploreTarget = {
33
31
  key: string;
34
32
  search: (slice: ExploreSlice) => Explored | Error;
35
33
  };
36
- type Counted<T> = Safe<T, Error> & {
37
- ticks: number;
38
- isPastLimit: boolean;
39
- };
40
- export declare const countedOn: (counters: ReturnType<typeof stateOf>) => <T>(counts: Map<string, number>, call: () => T, limit: number) => Counted<T>;
41
34
  export declare const lineOf: (source: string, name: string, file?: string) => number;
42
35
  type PropertyInput = {
43
36
  file: string;
@@ -1,55 +1,3 @@
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
1
  // oxlint-disable typescript/no-unsafe-argument, typescript/no-unsafe-assignment, typescript/no-unsafe-return -- this file handles values the code under test makes, passes or throws, which no static type names
54
2
  import { readFileSync } from 'node:fs';
55
3
  import { join } from 'node:path';
@@ -57,15 +5,13 @@ import { parseSync } from 'oxc-parser';
57
5
  import { z } from 'zod';
58
6
  import { encodedOf, snapshotOf, throwLocationOf } from '../../capture/capture.operations.js';
59
7
  import { hashOf, unitFieldsOf, unitKeyOf } from '../../record/record.operations.js';
60
- import { limitedRun, state, stepLimitOf } from '../../judge/counters.js';
8
+ import { countedOn, state, stepLimitOf } from '../../judge/counters.js';
61
9
  import { safe, ThrownValue } from '../../utils/safe.js';
62
10
  import { locate } from '../../utils/ast.js';
63
11
  import { itemAt } from '../../utils/lookup.js';
64
12
  import { drawsOf } from '../utils/draws.js';
65
13
  import { seededDraw } from './random.js';
66
14
  import { searchOf } from '../explore.operations.js';
67
- // The id the counters credit an explored call's sides to, so a run reads its sides off the passes as a test's baseline does.
68
- const exploreId = 'crush:explore';
69
15
  // A property's two sides and the export holding the relation between them, as a test's meta declares it.
70
16
  const twinMeta = z.object({ first: z.string(), second: z.string(), related: z.string() });
71
17
  // What a test's `meta` declares for explore: the export of its own file that maps an input to a verdict, and for a two-run property its twin.
@@ -89,40 +35,6 @@ const isPromised = (data) => {
89
35
  safe(() => Reflect.apply(then, data, [() => null, () => null]));
90
36
  return true;
91
37
  };
92
- // `limit` is the most ticks the call may take, as a rerun's is, 0 for none, so a call that would run past the cap stops.
93
- export const countedOn = (counters) => {
94
- return (counts, call, limit) => {
95
- const env_1 = { stack: [], error: void 0, hasError: false };
96
- try {
97
- const { current, isCapturing, isLimitHit } = counters;
98
- const started = counters.ticks;
99
- // The counters go back however the call ends, so a judging run after it credits its own test and captures again.
100
- const restored = __addDisposableResource(env_1, new DisposableStack(), false);
101
- restored.defer(() => {
102
- counters.passes.clear();
103
- counters.current = current;
104
- counters.isCapturing = isCapturing;
105
- counters.isLimitHit = isLimitHit;
106
- });
107
- counters.current = exploreId;
108
- // An explored call is no test's, so capture keeps none of the calls it makes.
109
- counters.isCapturing = false;
110
- counters.passes.clear();
111
- counters.isLimitHit = false;
112
- const result = safe(() => limitedRun(counters, limit, call));
113
- for (const [key, passes] of counters.passes)
114
- counts.set(String(key), passes);
115
- return Object.assign(result, { ticks: counters.ticks - started, isPastLimit: counters.isLimitHit });
116
- }
117
- catch (e_1) {
118
- env_1.error = e_1;
119
- env_1.hasError = true;
120
- }
121
- finally {
122
- __disposeResources(env_1);
123
- }
124
- };
125
- };
126
38
  const counted = countedOn(state);
127
39
  // The rerun limit of the longest seed, each seed run once with no limit as the tests ran it, so every search call, the first variation included, runs within it; null when a seed answers with a promise.
128
40
  const seedLimitOf = (seeds, call) => {
@@ -1,5 +1,6 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
2
  import type { callOutcomes } from '../crush.tables.ts';
3
+ import { type Safe } from '../utils/safe.ts';
3
4
  export declare const loadId = "crush:load";
4
5
  type CounterState = {
5
6
  forced: Map<number, boolean | 'once'>;
@@ -76,6 +77,11 @@ export declare const stepLimitFactor = 10;
76
77
  export declare const stepLimitFloor = 1000;
77
78
  export declare const stepLimitOf: (ticks: number) => number;
78
79
  export declare const limitedRun: <T>(state: CounterState, limit: number, call: () => T) => T;
80
+ type Counted<T> = Safe<T, Error> & {
81
+ ticks: number;
82
+ isPastLimit: boolean;
83
+ };
84
+ export declare const countedOn: (counters: CounterState) => <T>(counts: Map<string, number>, call: () => T, limit: number) => Counted<T>;
79
85
  export declare const clearedCalls: (state: CounterState) => void;
80
86
  export declare const setObservations: (state: CounterState, hits?: CounterState['hits'], reach?: CounterState['reach']) => void;
81
87
  export declare const countersOf: (state: CounterState) => Counters;
@@ -1,3 +1,55 @@
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
+ });
1
53
  // oxlint-disable typescript/no-unsafe-assignment, typescript/no-unsafe-return -- this file handles values the code under test makes, passes or throws, which no static type names
2
54
  import { AsyncLocalStorage } from 'node:async_hooks';
3
55
  import { snapshotterOf, uncloned } from '../capture/capture.operations.js';
@@ -113,6 +165,42 @@ export const limitedRun = (state, limit, call) => {
113
165
  state.limit = held;
114
166
  }
115
167
  };
168
+ // The id the counters credit a plugin's call to, so its sides are no test's.
169
+ const pluginId = 'crush:plugin';
170
+ // `limit` is the most ticks the call may take, as a rerun's is, 0 for none, so a call that would run past the cap stops.
171
+ export const countedOn = (counters) => {
172
+ return (counts, call, limit) => {
173
+ const env_1 = { stack: [], error: void 0, hasError: false };
174
+ try {
175
+ const { current, isCapturing, isLimitHit } = counters;
176
+ const started = counters.ticks;
177
+ // The counters go back however the call ends, so a judging run after it credits its own test and captures again.
178
+ const restored = __addDisposableResource(env_1, new DisposableStack(), false);
179
+ restored.defer(() => {
180
+ counters.passes.clear();
181
+ counters.current = current;
182
+ counters.isCapturing = isCapturing;
183
+ counters.isLimitHit = isLimitHit;
184
+ });
185
+ counters.current = pluginId;
186
+ // A plugin's call is no test's, so capture keeps none of the calls it makes.
187
+ counters.isCapturing = false;
188
+ counters.passes.clear();
189
+ counters.isLimitHit = false;
190
+ const result = safe(() => limitedRun(counters, limit, call));
191
+ for (const [key, passes] of counters.passes)
192
+ counts.set(String(key), passes);
193
+ return Object.assign(result, { ticks: counters.ticks - started, isPastLimit: counters.isLimitHit });
194
+ }
195
+ catch (e_1) {
196
+ env_1.error = e_1;
197
+ env_1.hasError = true;
198
+ }
199
+ finally {
200
+ __disposeResources(env_1);
201
+ }
202
+ };
203
+ };
116
204
  // Starts the next test file's capture from nothing, its calls, counts, step numbers and running calls, leaving any call the last file left running to settle unseen.
117
205
  export const clearedCalls = (state) => {
118
206
  state.calls = [];
@@ -3,9 +3,14 @@ import { type Finding } from '../../explore/edges/explore.db.ts';
3
3
  import type { ReachEdgeOutput, ReachNodeOutput } from '../../graph/symbols/symbols.schema.ts';
4
4
  import type { CrushError } from '../../utils/errors.ts';
5
5
  import { type Safe } from '../../utils/safe.ts';
6
- export { countedOn } from '../../explore/edges/explore.ts';
7
- export { state as counters, stateOf } from '../counters.ts';
6
+ export { countedOn, state as counters, stateOf, stepLimitOf } from '../counters.ts';
7
+ export { throwLocationOf, uncloned } from '../../capture/capture.operations.ts';
8
+ export { hashOf, unitFieldsOf, unitKeyOf } from '../../record/record.operations.ts';
9
+ export { encodeReachKey } from '../../graph/symbols/keys.ts';
10
+ export { reachedFrom } from '../../graph/symbols/symbols.ts';
8
11
  export type { ExportCallOutput, Finding };
12
+ export type { LoadedTestFile } from '../judge.schema.ts';
13
+ export declare const encodedValueOf: (value: unknown) => string;
9
14
  export declare const capturedCallsOf: (root: string) => Safe<ExportCallOutput[], CrushError>;
10
15
  type PlannedSource = {
11
16
  path: string;
@@ -50,6 +50,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
50
50
  var e = new Error(message);
51
51
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
52
  });
53
+ import { encodedOf, snapshotOf } from '../../capture/capture.operations.js';
53
54
  import { setFindings } from '../../explore/edges/explore.db.js';
54
55
  import { getExportCalls } from '../../record/edges/calls.db.js';
55
56
  import { getPlanCodes } from '../../record/edges/plan.db.js';
@@ -58,8 +59,13 @@ import { openCurrentRecord, readCurrentRecord } from '../../record/edges/record.
58
59
  import { safe } from '../../utils/safe.js';
59
60
  import { recordPathOf } from './vitest.js';
60
61
  // What another plugin reads and writes of a project's record, as a fuzzer outside crush needs: the captured calls to seed from, the counters to run a call on, and the findings `vp run questions` asks about.
61
- export { countedOn } from '../../explore/edges/explore.js';
62
- export { state as counters, stateOf } from '../counters.js';
62
+ export { countedOn, state as counters, stateOf, stepLimitOf } from '../counters.js';
63
+ export { throwLocationOf, uncloned } from '../../capture/capture.operations.js';
64
+ export { hashOf, unitFieldsOf, unitKeyOf } from '../../record/record.operations.js';
65
+ export { encodeReachKey } from '../../graph/symbols/keys.js';
66
+ export { reachedFrom } from '../../graph/symbols/symbols.js';
67
+ // A value as crush's questions print it, the form a finding's input takes.
68
+ export const encodedValueOf = (value) => encodedOf(snapshotOf(value));
63
69
  // Every call the record's baseline captured to an exported function, with its arguments and how it ended.
64
70
  export const capturedCallsOf = (root) => readCurrentRecord(recordPathOf(root), getExportCalls);
65
71
  // The code each source was instrumented with by the last plan, with the hash of the source it was made from.
@@ -131,7 +131,8 @@ export declare const judgeProject: (input: CrushProjectsInput) => CrushProject;
131
131
  type PluginProjectInput = CrushProjectsInput & {
132
132
  name: string;
133
133
  coordinator: string;
134
+ metaKey: string;
134
135
  };
135
- export declare const pluginProject: ({ name, coordinator, ...options }: PluginProjectInput) => CrushProject;
136
+ export declare const pluginProject: ({ name, coordinator, metaKey, ...options }: PluginProjectInput) => CrushProject;
136
137
  export declare const exploreProject: ({ root, include, exclude, entries, jsx, removableTests, steps, forks, mutation: written, explore }: CrushProjectsInput) => CrushProject;
137
138
  export {};
@@ -18,7 +18,7 @@ import { clearRefusal, pathsIn, readJudgeSource, readJudgeSourceNullable, readJu
18
18
  import { cachedImportsOf, jsxFilePattern, projectResolverOf, reachCacheOf, reachPathsOf, setReached } from './reach.js';
19
19
  import { forkPluginsInput } from '../../forks/forks.schema.js';
20
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';
21
+ import { exploreLimitsProvideKey, explorePathsProvideKey, pluginMetaKeyProvideKey, exploreSeedProvideKey, judgeFilesProvideKey, judgeCoordinators, judgeRedundantProvideKey, judgeRelatedProvideKey, questionsRelatedProvideKey, judgeShardsProvideKey, ownExtension, phaseProvideKey, recordTestFilesProvideKey, recordPathOf, removableTestsProvideKey, rootProvideKey, rulesProvideKey, stepsProvideKey, vitestProvideKey, } from './vitest.js';
22
22
  import { exploreLimitsInput } from '../../explore/limits.operations.js';
23
23
  import { clearExploreRuns } from '../../explore/edges/explore.db.js';
24
24
  import { markedExploreOf, missingVitestOf, staleExploreOf } from '../refusals.js';
@@ -419,9 +419,9 @@ export const judgeProject = (input) => {
419
419
  };
420
420
  };
421
421
  // Another plugin's command, as explore's own is: its coordinator test runs under the plugin's mode against the planned record, with the counters loaded.
422
- export const pluginProject = ({ name, coordinator, ...options }) => {
422
+ export const pluginProject = ({ name, coordinator, metaKey, ...options }) => {
423
423
  const project = exploreProject(options);
424
- return { ...project, test: { ...project.test, name, root: options.root, include: [coordinator], exclude: [] } };
424
+ return { ...project, test: { ...project.test, name, root: options.root, include: [coordinator], exclude: [], provide: { ...Object(project.test.provide), [pluginMetaKeyProvideKey]: metaKey } } };
425
425
  };
426
426
  export const exploreProject = ({ root, include, exclude, entries, jsx = false, removableTests = 'all', steps = true, forks = [], mutation: written = {}, explore = {} }) => {
427
427
  const plugins = forkPluginsInput.parse(forks);
@@ -437,6 +437,7 @@ export const exploreProject = ({ root, include, exclude, entries, jsx = false, r
437
437
  provide: {
438
438
  [rootProvideKey]: root,
439
439
  [phaseProvideKey]: 'property',
440
+ [pluginMetaKeyProvideKey]: null,
440
441
  [exploreLimitsProvideKey]: exploreLimitsInput.parse(explore),
441
442
  [removableTestsProvideKey]: removableTests,
442
443
  [rulesProvideKey]: rulesKeyOf({ version: recordVersion, tool: toolHashOf(), settings: { steps, forks: plugins, mutation } }),
@@ -8,6 +8,7 @@ export declare const recordTestFilesProvideKey = "crushRecordTestFiles";
8
8
  export declare const explorePathsProvideKey = "crushExplorePaths";
9
9
  export declare const exploreLimitsProvideKey = "crushExploreLimits";
10
10
  export declare const exploreSeedProvideKey = "crushExploreSeed";
11
+ export declare const pluginMetaKeyProvideKey = "crushPluginMetaKey";
11
12
  export declare const judgeFilesProvideKey = "crushJudgeFiles";
12
13
  export declare const judgeRelatedProvideKey = "crushJudgeRelated";
13
14
  export declare const questionsRelatedProvideKey = "crushQuestionsRelated";
@@ -16,6 +16,8 @@ export const recordTestFilesProvideKey = 'crushRecordTestFiles';
16
16
  export const explorePathsProvideKey = 'crushExplorePaths';
17
17
  export const exploreLimitsProvideKey = 'crushExploreLimits';
18
18
  export const exploreSeedProvideKey = 'crushExploreSeed';
19
+ // The meta key a plugin's tests declare, whose files the runner loads for its coordinator, or null for explore's own run.
20
+ export const pluginMetaKeyProvideKey = 'crushPluginMetaKey';
19
21
  export const judgeFilesProvideKey = 'crushJudgeFiles';
20
22
  export const judgeRelatedProvideKey = 'crushJudgeRelated';
21
23
  // The paths a related questions run names, from Vitest's own `related` filter, whose reach the report shows alone.
@@ -1,3 +1,4 @@
1
+ import type { TaskMeta } from 'vite-plus/test';
1
2
  import { z } from 'zod';
2
3
  export declare const candidateInput: z.ZodObject<{
3
4
  key: z.ZodString;
@@ -132,4 +133,13 @@ export declare const verifiedInput: z.ZodObject<{
132
133
  }, z.core.$strip>>;
133
134
  }, z.core.$strip>;
134
135
  export type Verified = z.infer<typeof verifiedInput>;
136
+ export type LoadedTestFile = {
137
+ file: string;
138
+ source: string;
139
+ module: unknown;
140
+ tests: {
141
+ name: string;
142
+ meta: TaskMeta;
143
+ }[];
144
+ };
135
145
  export {};
@@ -1,11 +1,12 @@
1
1
  import type { ExploreTarget } from '../explore/edges/explore.ts';
2
- import { exploreLimitsProvideKey, explorePathsProvideKey, exploreSeedProvideKey, judgeRedundantProvideKey, judgeFilesProvideKey, judgeRelatedProvideKey, questionsRelatedProvideKey, judgeShardsProvideKey, phaseProvideKey, recordTestFilesProvideKey, removableTestsProvideKey, rootProvideKey, rulesProvideKey, stepsProvideKey, vitestProvideKey } from './edges/vitest.ts';
3
- import type { RemovableTests } from './judge.schema.ts';
2
+ import { exploreLimitsProvideKey, explorePathsProvideKey, exploreSeedProvideKey, pluginMetaKeyProvideKey, judgeRedundantProvideKey, judgeFilesProvideKey, judgeRelatedProvideKey, questionsRelatedProvideKey, judgeShardsProvideKey, phaseProvideKey, recordTestFilesProvideKey, removableTestsProvideKey, rootProvideKey, rulesProvideKey, stepsProvideKey, vitestProvideKey } from './edges/vitest.ts';
3
+ import type { LoadedTestFile, RemovableTests } from './judge.schema.ts';
4
4
  import { type BaselineSpeed, type JudgeSpeed, type PlanSpeed, planSpeedKey } from './edges/speed.ts';
5
5
  import type { CrushTaskMeta } from './task-meta.ts';
6
6
  declare module 'vite-plus/test' {
7
7
  interface TestContext {
8
8
  crushExploreProperties?: ExploreTarget[];
9
+ crushLoadedTestFiles?: LoadedTestFile[];
9
10
  }
10
11
  interface TaskMeta extends CrushTaskMeta {
11
12
  crushBaselineSpeed?: BaselineSpeed;
@@ -23,6 +24,7 @@ declare module 'vite-plus/test' {
23
24
  [recordTestFilesProvideKey]: string[];
24
25
  [explorePathsProvideKey]: string[] | null;
25
26
  [exploreSeedProvideKey]: number;
27
+ [pluginMetaKeyProvideKey]: string | null;
26
28
  [exploreLimitsProvideKey]: {
27
29
  maxTotalTime: number;
28
30
  runs: number;
@@ -1,2 +1,2 @@
1
- import { exploreLimitsProvideKey, explorePathsProvideKey, exploreSeedProvideKey, judgeRedundantProvideKey, judgeFilesProvideKey, judgeRelatedProvideKey, questionsRelatedProvideKey, judgeShardsProvideKey, phaseProvideKey, recordTestFilesProvideKey, removableTestsProvideKey, rootProvideKey, rulesProvideKey, stepsProvideKey, vitestProvideKey, } from './edges/vitest.js';
1
+ import { exploreLimitsProvideKey, explorePathsProvideKey, exploreSeedProvideKey, pluginMetaKeyProvideKey, judgeRedundantProvideKey, judgeFilesProvideKey, judgeRelatedProvideKey, questionsRelatedProvideKey, judgeShardsProvideKey, phaseProvideKey, recordTestFilesProvideKey, removableTestsProvideKey, rootProvideKey, rulesProvideKey, stepsProvideKey, vitestProvideKey, } from './edges/vitest.js';
2
2
  import { planSpeedKey } from './edges/speed.js';
@@ -82,7 +82,7 @@ import { hasRefusal, markRefusal, readJudgeSource, readJudgeSourceNullable } fro
82
82
  import { mergeJudged } from './edges/merge.js';
83
83
  import { browserModuleOutput, runnerModuleOutput, workerStateOutput } from './edges/vitest.schema.js';
84
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';
85
+ import { explorePathsProvideKey, pluginMetaKeyProvideKey, judgeCoordinators, judgeFilesProvideKey, judgeRedundantProvideKey, judgeRelatedProvideKey, judgeShardsProvideKey, phaseProvideKey, recordPathOf, rootProvideKey, rulesProvideKey, vitestProvideKey, } from './edges/vitest.js';
86
86
  import { changedDuringRunOf, failedJudgingOf, stalePlanOf } from './refusals.js';
87
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
88
  // The values the command project provides reach the worker whichever copy reads them, so crush's own `inject` finds the project's copy.
@@ -493,6 +493,14 @@ export default function CrushRunner(config) {
493
493
  const onBeforeRunTask = async (task) => {
494
494
  await base.onBeforeRunTask(task);
495
495
  if (phase === 'property') {
496
+ const metaKey = inject(pluginMetaKeyProvideKey);
497
+ if (metaKey !== null) {
498
+ const { data: loaded, error: loadError } = await loadTestFilesDeclaring(metaKey);
499
+ if (loadError)
500
+ thrownToVitest(loadError);
501
+ task.context.crushLoadedTestFiles = loaded;
502
+ return;
503
+ }
496
504
  const { data, error } = await exploreProperties();
497
505
  if (error)
498
506
  thrownToVitest(error);
@@ -1445,13 +1453,52 @@ export default function CrushRunner(config) {
1445
1453
  }, { calls: [], clearVerification: false, clearFailure: session.pass === 'record' && session.ran.size > 0 });
1446
1454
  return refusal;
1447
1455
  };
1456
+ // Loads one test file through Vitest's own loader without running its tests, so a plugin reads each test's meta and calls what the module exports.
1457
+ // Vitest's shared runner collects one file at a time, so a caller loads files in turn.
1458
+ const loadTestFile = async (file) => {
1459
+ const root = inject(rootProvideKey);
1460
+ const path = join(root, file);
1461
+ const { data: files, error: collectError } = await safeAsync(() => collectTests([path], runner));
1462
+ if (collectError)
1463
+ return { data: null, error: collectError };
1464
+ const loaded = itemAt(files, 0);
1465
+ const failure = runFailureOf(loaded);
1466
+ if (failure)
1467
+ return { data: null, error: new CrushError(failure) };
1468
+ // The module was just collected by the same Vitest loader, so importing it again loads nothing new.
1469
+ const { data: module, error: loadError } = await safeAsync(async () => await runner.importFile(path, 'collect'));
1470
+ if (loadError)
1471
+ return { data: null, error: loadError };
1472
+ const tests = testsOf(loaded).map(({ name, meta }) => ({ name, meta }));
1473
+ return { data: { file, source: readJudgeSource(root, file), module, tests }, error: null };
1474
+ };
1475
+ // Loads each recorded test file whose source names a plugin's meta key, in turn, for that plugin's coordinator to read.
1476
+ const loadTestFilesDeclaring = async (metaKey) => {
1477
+ const { data: edges, error } = currentEdgesOf();
1478
+ if (error)
1479
+ return { data: null, error };
1480
+ const root = inject(rootProvideKey);
1481
+ const files = [];
1482
+ const loadDeclaring = async ({ file }) => {
1483
+ if (!readJudgeSource(root, file).includes(metaKey))
1484
+ return null;
1485
+ const { data: loaded, error: loadError } = await loadTestFile(file);
1486
+ if (loadError)
1487
+ return loadError;
1488
+ files.push(loaded);
1489
+ return null;
1490
+ };
1491
+ const loadError = await firstInOrder(edges.getJudged({ withHits: false }), loadDeclaring);
1492
+ if (loadError)
1493
+ return { data: null, error: loadError };
1494
+ return { data: files, error: null };
1495
+ };
1448
1496
  // Collects declarations from eligible recorded test modules without executing their tests.
1449
1497
  const exploreProperties = async () => {
1450
1498
  const { data: edges, error } = currentEdgesOf();
1451
1499
  if (error)
1452
1500
  return { data: null, error };
1453
1501
  const targets = [];
1454
- const root = inject(rootProvideKey);
1455
1502
  const graph = graphOf({ nodes: edges.getReachNodes(), edges: edges.getReachEdges() });
1456
1503
  const paths = inject(explorePathsProvideKey);
1457
1504
  const related = paths === null ? null : new Set(paths);
@@ -1462,20 +1509,11 @@ export default function CrushRunner(config) {
1462
1509
  const allowed = new Set(explorableOf({ ...graph, keys, paths: related }).map(({ key }) => key));
1463
1510
  if (!allowed.size)
1464
1511
  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'));
1512
+ const { data: loaded, error: loadError } = await loadTestFile(file);
1475
1513
  if (loadError)
1476
1514
  return loadError;
1477
- const source = readJudgeSource(root, file);
1478
- for (const task of testsOf(loaded)) {
1515
+ const { source, module } = loaded;
1516
+ for (const task of loaded.tests) {
1479
1517
  const declaration = exploresMeta.safeParse(task.meta);
1480
1518
  if (!declaration.success)
1481
1519
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whaaaley/crush",
3
- "version": "0.3.0-next.8",
3
+ "version": "0.3.0-next.9",
4
4
  "description": "Mutation testing for TypeScript inside Vitest, built for agent loops",
5
5
  "license": "MIT",
6
6
  "repository": {