@whaaaley/crush 0.2.7 → 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.
- package/README.md +48 -0
- package/dist/crush.tables.d.ts +16 -0
- package/dist/crush.tables.js +3 -1
- package/dist/explore/edges/explore.d.ts +0 -7
- package/dist/explore/edges/explore.db.d.ts +9 -4
- package/dist/explore/edges/explore.db.js +8 -6
- package/dist/explore/edges/explore.js +1 -89
- package/dist/judge/counters.d.ts +6 -0
- package/dist/judge/counters.js +88 -0
- package/dist/judge/edges/api.d.ts +21 -3
- package/dist/judge/edges/api.js +17 -5
- package/dist/judge/edges/judge.edges.d.ts +2 -2
- package/dist/judge/edges/plugin.d.ts +6 -0
- package/dist/judge/edges/plugin.js +7 -1
- package/dist/judge/edges/plugin.npm.d.ts +2 -0
- package/dist/judge/edges/plugin.npm.js +2 -0
- package/dist/judge/edges/vitest.d.ts +1 -0
- package/dist/judge/edges/vitest.js +2 -0
- package/dist/judge/explore.test.js +2 -2
- package/dist/judge/judge.schema.d.ts +10 -0
- package/dist/judge/provided.d.ts +39 -0
- package/dist/judge/provided.js +2 -0
- package/dist/judge/report.test.js +4 -3
- package/dist/judge/runner.js +52 -14
- package/dist/questions/questions.operations.d.ts +5 -1
- package/dist/questions/questions.operations.js +18 -2
- package/dist/questions/questions.schema.d.ts +3 -1
- package/dist/questions/questions.schema.js +1 -1
- package/dist/record/edges/plan.db.d.ts +1 -0
- package/dist/record/edges/plan.db.js +5 -0
- package/dist/record/edges/record.db.d.ts +1 -1
- package/dist/record/edges/record.db.js +1 -1
- package/migrations/main/20261206094906_plugin_findings/migration.sql +20 -0
- package/migrations/main/20261206094906_plugin_findings/snapshot.json +3652 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -57,6 +57,54 @@ A justification whose code moves is reported apart from new questions; setting i
|
|
|
57
57
|
|
|
58
58
|
The answer stands while its position, source and the code read by its verdicts stay the same, and a justified crush is never collapsed.
|
|
59
59
|
|
|
60
|
+
### A worked example
|
|
61
|
+
|
|
62
|
+
This `clamp` takes a range whose callers keep `min <= max`, and has one test below the range and one inside it:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
export const clamp = (value: bigint, min: bigint, max: bigint): bigint => {
|
|
66
|
+
if (value < min) return min
|
|
67
|
+
if (value > max) return max
|
|
68
|
+
return value
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
After `vp run record` and `vp run judge`, `vp run questions` asks two questions about `src/clamp.ts` and one about each test's steps, each with the answers that settle it, shown here for the file and the first test:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
↳ 1. src/clamp.ts:2 Can any input tell `value < min` from `(value <= min)` in `clamp`?
|
|
76
|
+
id: tell|src/clamp.ts|clamp|0|value < min
|
|
77
|
+
yes: add that input
|
|
78
|
+
no: use `(value <= min)`
|
|
79
|
+
↳ 2. src/clamp.ts:3 Can any input make `value > max` true in `clamp`?
|
|
80
|
+
id: side|src/clamp.ts|clamp|1|value > max
|
|
81
|
+
yes: add that input
|
|
82
|
+
no: remove what runs when it is true
|
|
83
|
+
↳ 1. `raises a value below the range to its minimum` took 1 steps and its test states no count. Is that the work it needs?
|
|
84
|
+
yes: write `steps: 1` in the test's meta, then record again
|
|
85
|
+
no: make the code `raises a value below the range to its minimum` runs do less work
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Each takes a different answer:
|
|
89
|
+
|
|
90
|
+
- **A test:** no test passes a value above the range, so question 2 is answered by one that does, `expect(clamp(15n, 0n, 10n)).toBe(10n)`.
|
|
91
|
+
- **Steps:** each test states the work it takes as `meta: { steps: 1 }`, so a later change that makes it slower is asked about.
|
|
92
|
+
- **A justification:** at `value` equal to `min` both `<` and `<=` return `min`, and a `bigint` has no `-0` to tell them apart as a `number` would, so no input in the contract `min <= max` can answer question 1, and the same holds for `>` against `>=` at `max`, which judging asks once the test above reaches it. Each goes on the `describe` as written under Usage:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
describe('clamp', {
|
|
96
|
+
meta: {
|
|
97
|
+
justifies: [
|
|
98
|
+
{ id: 'tell|src/clamp.ts|clamp|0|value < min', basis: 'refresh', reason: 'Callers keep min <= max, and at value equal to min both sides return min with no -0 in a bigint, so no such input tells < from <=.' },
|
|
99
|
+
{ id: 'tell|src/clamp.ts|clamp|0|value > max', basis: 'refresh', reason: 'At value equal to max both sides return max, and a bigint has no -0, so no input tells > from >=.' },
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
}, () => {
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
A fresh record, judge and questions then prints that no question is open, and `vp run questions` has written each justification's basis in place of `refresh`.
|
|
106
|
+
Simpler code is the fourth answer: had both sides of a question behaved the same for every input that matters, as `no:` offers, the code would change to the one the question names instead.
|
|
107
|
+
|
|
60
108
|
### What each command prints last
|
|
61
109
|
|
|
62
110
|
Record, judge, questions and explore end with a blank line, then a `hint:` line, a `skill:` line, one or more `don't:` lines and a `next:` line, which names one command to run as printed.
|
package/dist/crush.tables.d.ts
CHANGED
|
@@ -3289,6 +3289,22 @@ export declare const exploreFindings: import("drizzle-orm/sqlite-core").SQLiteTa
|
|
|
3289
3289
|
identity: undefined;
|
|
3290
3290
|
generated: undefined;
|
|
3291
3291
|
}, {}>;
|
|
3292
|
+
plugin: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
3293
|
+
name: string;
|
|
3294
|
+
tableName: "explore_findings";
|
|
3295
|
+
dataType: "string";
|
|
3296
|
+
data: string;
|
|
3297
|
+
driverParam: string;
|
|
3298
|
+
notNull: true;
|
|
3299
|
+
hasDefault: true;
|
|
3300
|
+
isPrimaryKey: false;
|
|
3301
|
+
isAutoincrement: false;
|
|
3302
|
+
hasRuntimeDefault: false;
|
|
3303
|
+
enumValues: [string, ...string[]];
|
|
3304
|
+
baseColumn: never;
|
|
3305
|
+
identity: undefined;
|
|
3306
|
+
generated: undefined;
|
|
3307
|
+
}, {}>;
|
|
3292
3308
|
};
|
|
3293
3309
|
dialect: 'sqlite';
|
|
3294
3310
|
isAlias: false;
|
package/dist/crush.tables.js
CHANGED
|
@@ -415,9 +415,11 @@ export const exploreFindings = sqliteTable('explore_findings', {
|
|
|
415
415
|
target: text().notNull(),
|
|
416
416
|
// The hash of the file the finding asks at when explore found it, so an edit to that file drops the finding until an explore finds it again.
|
|
417
417
|
sourceHash: text().notNull(),
|
|
418
|
+
// The plugin that saved it, which its question names, so another plugin's findings are asked of apart from explore's own.
|
|
419
|
+
plugin: text().notNull().default('explore'),
|
|
418
420
|
}, (table) => [
|
|
419
421
|
enumConstraint('explore_findings_kind_check', table.kind, findingKinds),
|
|
420
|
-
primaryKey({ columns: [table.target, table.findingKey] }),
|
|
422
|
+
primaryKey({ columns: [table.plugin, table.target, table.findingKey] }),
|
|
421
423
|
]);
|
|
422
424
|
// Each call a test file's baseline made to an exported function, up to the counters' limit per test and export, in the order the calls began: the test that made it, the kept call it ran inside and how many it ran under, its arguments, how it ended and with what, and where a throw came from.
|
|
423
425
|
// Arguments and result are JSON, each value no JSON could hold, as a callback or a class instance, tagged uncloned; a null `parent` and `depth` 0 mark a call straight from the test.
|
|
@@ -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;
|
|
@@ -11,12 +11,17 @@ type ExploreRun = {
|
|
|
11
11
|
stopped: string | null;
|
|
12
12
|
};
|
|
13
13
|
export declare const setExploreRun: (db: Record, { key, ms, at, stopped }: ExploreRun) => void;
|
|
14
|
-
export type Finding = Omit<typeof exploreFindings.$inferInsert, 'findingKey'> & {
|
|
14
|
+
export type Finding = Omit<typeof exploreFindings.$inferInsert, 'findingKey' | 'plugin'> & {
|
|
15
15
|
key: string;
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
type StoredFinding = Finding & {
|
|
18
|
+
plugin: string;
|
|
19
|
+
};
|
|
20
|
+
type SetFindingsInput = {
|
|
21
|
+
plugin: string;
|
|
18
22
|
targets: readonly string[];
|
|
19
23
|
findings: Finding[];
|
|
20
|
-
}
|
|
21
|
-
export declare const
|
|
24
|
+
};
|
|
25
|
+
export declare const setFindings: (db: Record, { plugin, targets, findings }: SetFindingsInput) => void;
|
|
26
|
+
export declare const getFindings: (db: Record) => StoredFinding[];
|
|
22
27
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { asc, inArray, sql } from 'drizzle-orm';
|
|
1
|
+
import { and, asc, eq, inArray, sql } from 'drizzle-orm';
|
|
2
2
|
import { uncloned } from '../../capture/capture.operations.js';
|
|
3
3
|
import { exploreFindings, exploreRuns } from '../../crush.tables.js';
|
|
4
4
|
import { getExportCalls } from '../../record/edges/calls.db.js';
|
|
@@ -33,14 +33,16 @@ export const setExploreRun = (db, { key, ms, at, stopped }) => {
|
|
|
33
33
|
.onConflictDoUpdate({ target: exploreRuns.targetKey, set: { ms: sql `${exploreRuns.ms} + ${ms}`, exploredAt, stopped } })
|
|
34
34
|
.run();
|
|
35
35
|
};
|
|
36
|
-
// Replaces
|
|
37
|
-
export const setFindings = (db, { targets, findings }) => {
|
|
36
|
+
// Replaces one plugin's findings for the targets it ran with what it found, leaving every other plugin's and target's as they were, so a site two targets reach keeps the evidence of each.
|
|
37
|
+
export const setFindings = (db, { plugin, targets, findings }) => {
|
|
38
38
|
db.transaction((tx) => {
|
|
39
39
|
const targetChunks = chunksOf(targets.map((target) => ({ target }))).map((chunk) => chunk.map(({ target }) => target));
|
|
40
|
-
for (const chunk of targetChunks)
|
|
41
|
-
|
|
40
|
+
for (const chunk of targetChunks) {
|
|
41
|
+
const ran = and(eq(exploreFindings.plugin, plugin), inArray(exploreFindings.target, chunk));
|
|
42
|
+
tx.delete(exploreFindings).where(ran).run();
|
|
43
|
+
}
|
|
42
44
|
for (const chunk of chunksOf(findings)) {
|
|
43
|
-
const rows = chunk.map(({ key, ...finding }) => Object.assign(finding, { findingKey: key }));
|
|
45
|
+
const rows = chunk.map(({ key, ...finding }) => Object.assign(finding, { findingKey: key, plugin }));
|
|
44
46
|
tx.insert(exploreFindings).values(rows).run();
|
|
45
47
|
}
|
|
46
48
|
}, { behavior: 'immediate' });
|
|
@@ -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 {
|
|
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) => {
|
package/dist/judge/counters.d.ts
CHANGED
|
@@ -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;
|
package/dist/judge/counters.js
CHANGED
|
@@ -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 = [];
|
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
import type { ExportCallOutput } from '../../capture/capture.schema.ts';
|
|
2
2
|
import { type Finding } from '../../explore/edges/explore.db.ts';
|
|
3
|
+
import type { ReachEdgeOutput, ReachNodeOutput } from '../../graph/symbols/symbols.schema.ts';
|
|
3
4
|
import type { CrushError } from '../../utils/errors.ts';
|
|
4
5
|
import { type Safe } from '../../utils/safe.ts';
|
|
5
|
-
export { countedOn } from '
|
|
6
|
-
export {
|
|
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';
|
|
7
11
|
export type { ExportCallOutput, Finding };
|
|
12
|
+
export type { LoadedTestFile } from '../judge.schema.ts';
|
|
13
|
+
export declare const encodedValueOf: (value: unknown) => string;
|
|
8
14
|
export declare const capturedCallsOf: (root: string) => Safe<ExportCallOutput[], CrushError>;
|
|
15
|
+
type PlannedSource = {
|
|
16
|
+
path: string;
|
|
17
|
+
hash: string;
|
|
18
|
+
code: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const plannedSourcesOf: (root: string) => Safe<PlannedSource[], CrushError>;
|
|
21
|
+
type ReachGraph = {
|
|
22
|
+
nodes: ReachNodeOutput[];
|
|
23
|
+
edges: ReachEdgeOutput[];
|
|
24
|
+
};
|
|
25
|
+
export declare const reachGraphOf: (root: string) => Safe<ReachGraph, CrushError>;
|
|
9
26
|
type SaveFindingsInput = {
|
|
10
27
|
root: string;
|
|
28
|
+
plugin: string;
|
|
11
29
|
targets: readonly string[];
|
|
12
30
|
findings: Finding[];
|
|
13
31
|
};
|
|
14
|
-
export declare const saveFindings: ({ root, targets, findings }: SaveFindingsInput) => Error | null;
|
|
32
|
+
export declare const saveFindings: ({ root, plugin, targets, findings }: SaveFindingsInput) => Error | null;
|
package/dist/judge/edges/api.js
CHANGED
|
@@ -50,25 +50,37 @@ 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';
|
|
56
|
+
import { getPlanCodes } from '../../record/edges/plan.db.js';
|
|
57
|
+
import { getReachEdges, getReachNodes } from '../../record/edges/reach.db.js';
|
|
55
58
|
import { openCurrentRecord, readCurrentRecord } from '../../record/edges/record.db.js';
|
|
56
59
|
import { safe } from '../../utils/safe.js';
|
|
57
60
|
import { recordPathOf } from './vitest.js';
|
|
58
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.
|
|
59
|
-
export { countedOn } from '
|
|
60
|
-
export {
|
|
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));
|
|
61
69
|
// Every call the record's baseline captured to an exported function, with its arguments and how it ended.
|
|
62
70
|
export const capturedCallsOf = (root) => readCurrentRecord(recordPathOf(root), getExportCalls);
|
|
63
|
-
//
|
|
64
|
-
export const
|
|
71
|
+
// The code each source was instrumented with by the last plan, with the hash of the source it was made from.
|
|
72
|
+
export const plannedSourcesOf = (root) => readCurrentRecord(recordPathOf(root), getPlanCodes);
|
|
73
|
+
// The record's reach graph: every file, export and function, and which reaches which.
|
|
74
|
+
export const reachGraphOf = (root) => readCurrentRecord(recordPathOf(root), (record) => ({ nodes: getReachNodes(record), edges: getReachEdges(record) }));
|
|
75
|
+
// Replaces the findings of the named targets with these, which the next questions run asks about, naming the plugin that found each.
|
|
76
|
+
export const saveFindings = ({ root, plugin, targets, findings }) => {
|
|
65
77
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
66
78
|
try {
|
|
67
79
|
const { data: opened, error } = openCurrentRecord(recordPathOf(root));
|
|
68
80
|
if (error)
|
|
69
81
|
return error;
|
|
70
82
|
const record = __addDisposableResource(env_1, opened, false);
|
|
71
|
-
return safe(() => setFindings(record, { targets, findings })).error;
|
|
83
|
+
return safe(() => setFindings(record, { plugin, targets, findings })).error;
|
|
72
84
|
}
|
|
73
85
|
catch (e_1) {
|
|
74
86
|
env_1.error = e_1;
|
|
@@ -8,7 +8,7 @@ import { type MeasureWrite } from '../../record/edges/record.db.ts';
|
|
|
8
8
|
import type { CrushError } from '../../utils/errors.ts';
|
|
9
9
|
import type { Safe } from '../../utils/safe.ts';
|
|
10
10
|
import type { Candidate, Hold, Judged, Verified } from '../judge.schema.ts';
|
|
11
|
-
import {
|
|
11
|
+
import { getFindings } from '../../explore/edges/explore.db.ts';
|
|
12
12
|
export type JudgeEdges = {
|
|
13
13
|
getPlan: (input?: {
|
|
14
14
|
withRewrites?: boolean;
|
|
@@ -42,7 +42,7 @@ export type JudgeEdges = {
|
|
|
42
42
|
getReachNodes: () => ReachNodeOutput[];
|
|
43
43
|
getReachEdges: () => ReachEdgeOutput[];
|
|
44
44
|
getExportCalls: () => ExportCallOutput[];
|
|
45
|
-
getFindings: () =>
|
|
45
|
+
getFindings: () => ReturnType<typeof getFindings>;
|
|
46
46
|
getSeeds: () => Map<string, unknown[][]>;
|
|
47
47
|
marked: (name: string, work: () => Promise<Error | null>) => Promise<Error | null>;
|
|
48
48
|
settled: () => Promise<Error | null>;
|
|
@@ -128,5 +128,11 @@ export declare const questionsProject: ({ root, include, exclude, removableTests
|
|
|
128
128
|
export declare const stressesProject: ({ root }: CrushProjectsInput) => CrushProject;
|
|
129
129
|
export declare const recordProject: (input: CrushProjectsInput) => CrushProject;
|
|
130
130
|
export declare const judgeProject: (input: CrushProjectsInput) => CrushProject;
|
|
131
|
+
type PluginProjectInput = CrushProjectsInput & {
|
|
132
|
+
name: string;
|
|
133
|
+
coordinator: string;
|
|
134
|
+
metaKey: string;
|
|
135
|
+
};
|
|
136
|
+
export declare const pluginProject: ({ name, coordinator, metaKey, ...options }: PluginProjectInput) => CrushProject;
|
|
131
137
|
export declare const exploreProject: ({ root, include, exclude, entries, jsx, removableTests, steps, forks, mutation: written, explore }: CrushProjectsInput) => CrushProject;
|
|
132
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';
|
|
@@ -418,6 +418,11 @@ export const judgeProject = (input) => {
|
|
|
418
418
|
test: { ...project.test, name: 'judge', include: coordinators, exclude: [], provide: { ...Object(project.test.provide), [phaseProvideKey]: 'judge', [judgeRelatedProvideKey]: [] } },
|
|
419
419
|
};
|
|
420
420
|
};
|
|
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, metaKey, ...options }) => {
|
|
423
|
+
const project = exploreProject(options);
|
|
424
|
+
return { ...project, test: { ...project.test, name, root: options.root, include: [coordinator], exclude: [], provide: { ...Object(project.test.provide), [pluginMetaKeyProvideKey]: metaKey } } };
|
|
425
|
+
};
|
|
421
426
|
export const exploreProject = ({ root, include, exclude, entries, jsx = false, removableTests = 'all', steps = true, forks = [], mutation: written = {}, explore = {} }) => {
|
|
422
427
|
const plugins = forkPluginsInput.parse(forks);
|
|
423
428
|
const mutation = mutationSettingsInput.parse(written);
|
|
@@ -432,6 +437,7 @@ export const exploreProject = ({ root, include, exclude, entries, jsx = false, r
|
|
|
432
437
|
provide: {
|
|
433
438
|
[rootProvideKey]: root,
|
|
434
439
|
[phaseProvideKey]: 'property',
|
|
440
|
+
[pluginMetaKeyProvideKey]: null,
|
|
435
441
|
[exploreLimitsProvideKey]: exploreLimitsInput.parse(explore),
|
|
436
442
|
[removableTestsProvideKey]: removableTests,
|
|
437
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.
|
|
@@ -80,7 +80,7 @@ describe('crush:explore', () => {
|
|
|
80
80
|
spent.set(key, (spent.get(key) ?? 0) + ms);
|
|
81
81
|
}
|
|
82
82
|
if (explored.finding) {
|
|
83
|
-
setFindings(record, { targets: [key], findings: [explored.finding] });
|
|
83
|
+
setFindings(record, { plugin: 'explore', targets: [key], findings: [explored.finding] });
|
|
84
84
|
found.add(key);
|
|
85
85
|
}
|
|
86
86
|
else if (!reason && (explored.isSearched || budget.used() > used || now() - started >= limitMs))
|
|
@@ -88,7 +88,7 @@ describe('crush:explore', () => {
|
|
|
88
88
|
}
|
|
89
89
|
active = again;
|
|
90
90
|
}
|
|
91
|
-
setFindings(record, { targets: [...searched].filter((key) => !found.has(key)), findings: [] });
|
|
91
|
+
setFindings(record, { plugin: 'explore', targets: [...searched].filter((key) => !found.has(key)), findings: [] });
|
|
92
92
|
await annotate(`${searched.size} of ${targets.length} targets explored from seed ${seed}, ${budget.used()} runs, ${found.size} findings`, 'explore');
|
|
93
93
|
const isStopped = (key) => stopped.some((each) => each.key === key);
|
|
94
94
|
const unsearched = targets.map(({ key }) => key).filter((key) => !searched.has(key) && !isStopped(key));
|
|
@@ -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 {};
|