@whaaaley/crush 0.2.6 → 0.3.0-next.8
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.db.d.ts +9 -4
- package/dist/explore/edges/explore.db.js +8 -6
- package/dist/judge/edges/api.d.ts +15 -2
- package/dist/judge/edges/api.js +10 -4
- package/dist/judge/edges/judge.edges.d.ts +2 -2
- package/dist/judge/edges/plugin.d.ts +5 -0
- package/dist/judge/edges/plugin.js +5 -0
- package/dist/judge/edges/plugin.npm.d.ts +2 -0
- package/dist/judge/edges/plugin.npm.js +2 -0
- package/dist/judge/explore.test.js +2 -2
- package/dist/judge/provided.d.ts +37 -0
- package/dist/judge/provided.js +2 -0
- package/dist/judge/report.test.js +4 -3
- package/dist/judge/task-meta.d.ts +0 -37
- package/dist/judge/task-meta.js +1 -3
- 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.
|
|
@@ -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,14 +1,27 @@
|
|
|
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
6
|
export { countedOn } from '../../explore/edges/explore.ts';
|
|
6
|
-
export { stateOf } from '../counters.ts';
|
|
7
|
+
export { state as counters, stateOf } from '../counters.ts';
|
|
7
8
|
export type { ExportCallOutput, Finding };
|
|
8
9
|
export declare const capturedCallsOf: (root: string) => Safe<ExportCallOutput[], CrushError>;
|
|
10
|
+
type PlannedSource = {
|
|
11
|
+
path: string;
|
|
12
|
+
hash: string;
|
|
13
|
+
code: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const plannedSourcesOf: (root: string) => Safe<PlannedSource[], CrushError>;
|
|
16
|
+
type ReachGraph = {
|
|
17
|
+
nodes: ReachNodeOutput[];
|
|
18
|
+
edges: ReachEdgeOutput[];
|
|
19
|
+
};
|
|
20
|
+
export declare const reachGraphOf: (root: string) => Safe<ReachGraph, CrushError>;
|
|
9
21
|
type SaveFindingsInput = {
|
|
10
22
|
root: string;
|
|
23
|
+
plugin: string;
|
|
11
24
|
targets: readonly string[];
|
|
12
25
|
findings: Finding[];
|
|
13
26
|
};
|
|
14
|
-
export declare const saveFindings: ({ root, targets, findings }: SaveFindingsInput) => Error | null;
|
|
27
|
+
export declare const saveFindings: ({ root, plugin, targets, findings }: SaveFindingsInput) => Error | null;
|
package/dist/judge/edges/api.js
CHANGED
|
@@ -52,23 +52,29 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
52
52
|
});
|
|
53
53
|
import { setFindings } from '../../explore/edges/explore.db.js';
|
|
54
54
|
import { getExportCalls } from '../../record/edges/calls.db.js';
|
|
55
|
+
import { getPlanCodes } from '../../record/edges/plan.db.js';
|
|
56
|
+
import { getReachEdges, getReachNodes } from '../../record/edges/reach.db.js';
|
|
55
57
|
import { openCurrentRecord, readCurrentRecord } from '../../record/edges/record.db.js';
|
|
56
58
|
import { safe } from '../../utils/safe.js';
|
|
57
59
|
import { recordPathOf } from './vitest.js';
|
|
58
60
|
// 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
61
|
export { countedOn } from '../../explore/edges/explore.js';
|
|
60
|
-
export { stateOf } from '../counters.js';
|
|
62
|
+
export { state as counters, stateOf } from '../counters.js';
|
|
61
63
|
// Every call the record's baseline captured to an exported function, with its arguments and how it ended.
|
|
62
64
|
export const capturedCallsOf = (root) => readCurrentRecord(recordPathOf(root), getExportCalls);
|
|
63
|
-
//
|
|
64
|
-
export const
|
|
65
|
+
// The code each source was instrumented with by the last plan, with the hash of the source it was made from.
|
|
66
|
+
export const plannedSourcesOf = (root) => readCurrentRecord(recordPathOf(root), getPlanCodes);
|
|
67
|
+
// The record's reach graph: every file, export and function, and which reaches which.
|
|
68
|
+
export const reachGraphOf = (root) => readCurrentRecord(recordPathOf(root), (record) => ({ nodes: getReachNodes(record), edges: getReachEdges(record) }));
|
|
69
|
+
// Replaces the findings of the named targets with these, which the next questions run asks about, naming the plugin that found each.
|
|
70
|
+
export const saveFindings = ({ root, plugin, targets, findings }) => {
|
|
65
71
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
66
72
|
try {
|
|
67
73
|
const { data: opened, error } = openCurrentRecord(recordPathOf(root));
|
|
68
74
|
if (error)
|
|
69
75
|
return error;
|
|
70
76
|
const record = __addDisposableResource(env_1, opened, false);
|
|
71
|
-
return safe(() => setFindings(record, { targets, findings })).error;
|
|
77
|
+
return safe(() => setFindings(record, { plugin, targets, findings })).error;
|
|
72
78
|
}
|
|
73
79
|
catch (e_1) {
|
|
74
80
|
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,10 @@ 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
|
+
};
|
|
135
|
+
export declare const pluginProject: ({ name, coordinator, ...options }: PluginProjectInput) => CrushProject;
|
|
131
136
|
export declare const exploreProject: ({ root, include, exclude, entries, jsx, removableTests, steps, forks, mutation: written, explore }: CrushProjectsInput) => CrushProject;
|
|
132
137
|
export {};
|
|
@@ -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, ...options }) => {
|
|
423
|
+
const project = exploreProject(options);
|
|
424
|
+
return { ...project, test: { ...project.test, name, root: options.root, include: [coordinator], exclude: [] } };
|
|
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);
|
|
@@ -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));
|
|
@@ -0,0 +1,37 @@
|
|
|
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';
|
|
4
|
+
import { type BaselineSpeed, type JudgeSpeed, type PlanSpeed, planSpeedKey } from './edges/speed.ts';
|
|
5
|
+
import type { CrushTaskMeta } from './task-meta.ts';
|
|
6
|
+
declare module 'vite-plus/test' {
|
|
7
|
+
interface TestContext {
|
|
8
|
+
crushExploreProperties?: ExploreTarget[];
|
|
9
|
+
}
|
|
10
|
+
interface TaskMeta extends CrushTaskMeta {
|
|
11
|
+
crushBaselineSpeed?: BaselineSpeed;
|
|
12
|
+
crushJudgeSpeed?: JudgeSpeed;
|
|
13
|
+
crushOpen?: number;
|
|
14
|
+
crushOpenIn?: string;
|
|
15
|
+
}
|
|
16
|
+
interface ProvidedContext {
|
|
17
|
+
[vitestProvideKey]: string;
|
|
18
|
+
[phaseProvideKey]: 'record' | 'judge' | 'verify' | 'property';
|
|
19
|
+
[rulesProvideKey]: string;
|
|
20
|
+
[rootProvideKey]: string;
|
|
21
|
+
[removableTestsProvideKey]: RemovableTests;
|
|
22
|
+
[stepsProvideKey]: boolean;
|
|
23
|
+
[recordTestFilesProvideKey]: string[];
|
|
24
|
+
[explorePathsProvideKey]: string[] | null;
|
|
25
|
+
[exploreSeedProvideKey]: number;
|
|
26
|
+
[exploreLimitsProvideKey]: {
|
|
27
|
+
maxTotalTime: number;
|
|
28
|
+
runs: number;
|
|
29
|
+
};
|
|
30
|
+
[judgeFilesProvideKey]: string[];
|
|
31
|
+
[judgeShardsProvideKey]: number;
|
|
32
|
+
[judgeRelatedProvideKey]: string[];
|
|
33
|
+
[questionsRelatedProvideKey]: string[];
|
|
34
|
+
[judgeRedundantProvideKey]: boolean;
|
|
35
|
+
[planSpeedKey]: PlanSpeed;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { exploreLimitsProvideKey, explorePathsProvideKey, exploreSeedProvideKey, judgeRedundantProvideKey, judgeFilesProvideKey, judgeRelatedProvideKey, questionsRelatedProvideKey, judgeShardsProvideKey, phaseProvideKey, recordTestFilesProvideKey, removableTestsProvideKey, rootProvideKey, rulesProvideKey, stepsProvideKey, vitestProvideKey, } from './edges/vitest.js';
|
|
2
|
+
import { planSpeedKey } from './edges/speed.js';
|
|
@@ -57,7 +57,7 @@ import { describe, expect, inject, it } from 'vite-plus/test';
|
|
|
57
57
|
import { readJustifications } from '../justify/edges/load.js';
|
|
58
58
|
import { refreshEntry } from '../justify/edges/refresh.fs.js';
|
|
59
59
|
import { basisOf, justifiedOf } from '../justify/justify.operations.js';
|
|
60
|
-
import { answerChoicesOf, answerProblemsOf, exploreCaughtOf, exploreQuestionsOf, pathQuestionsOf, siteQuestionsOf, stepsQuestionsOf, testQuestionsOf, unusedQuestionsOf } from '../questions/questions.operations.js';
|
|
60
|
+
import { answerChoicesOf, answerProblemsOf, exploreCaughtOf, exploreQuestionsOf, findingQuestionsOf, pathQuestionsOf, siteQuestionsOf, stepsQuestionsOf, testQuestionsOf, unusedQuestionsOf } from '../questions/questions.operations.js';
|
|
61
61
|
import { readJudgeEdges } from './edges/judge.edges.js';
|
|
62
62
|
import { hasRefusal, readJudgeSourceNullable } from './edges/judge.fs.js';
|
|
63
63
|
import { recordPathOf, questionsRelatedProvideKey, recordTestFilesProvideKey, removableTestsProvideKey, rootProvideKey, stepsProvideKey } from './edges/vitest.js';
|
|
@@ -80,7 +80,7 @@ const recordPath = recordPathOf(root);
|
|
|
80
80
|
const opened = readJudgeEdges(recordPath);
|
|
81
81
|
if (opened.error)
|
|
82
82
|
throw opened.error;
|
|
83
|
-
var edges, stillWorking, plan, runs, testFiles, currentHashOf, stale, merged, statusOf, candidates, candidatesHash, checks, drops, dropped, basis, isCurrent, checkedFiles, isVerified, falling, liveSources, liveSourceOf, isLive, isLiveVerified, collapses, holding, heldNow, heldKeys, isAnyLeft, takenPoints, covered, observed, sites, judged, reachNodes, plannedTests, unused, plannedHashOf, explored, exportCalls, loopSites, pathFindingsOf, pathQuestions, all, entries, justifyError, sourceHashes, bases, justified, refreshProblems, refreshedIds, acceptedEntries, staleEntries, acceptedIds, staleIds, asked, open, acceptedQuestions, reasonOf, positions, basisFor, liveIds, justifyProblems, caughtBy, reachedBy, note, crushesByDecision, catchingTests, properties, answers, graphIds, graphAnswers, answerFiles, answerReach, graphOutOf, graphOut, pathArgs, paths, visibleFiles, visible, isVisible, noteGraphReach, evidence, problems, refusedChoices, unsettledTests, tests, names, labelOf, measured, measuredTests, removableTests, keyOfLabel, readers, patternReaders, removalReach, shieldedFiles, isAskable, removable, testQuestions, outsideOf, counted, testMetaQuestions, justifiedSites, taken, figureLineOf;
|
|
83
|
+
var edges, stillWorking, plan, runs, testFiles, currentHashOf, stale, merged, statusOf, candidates, candidatesHash, checks, drops, dropped, basis, isCurrent, checkedFiles, isVerified, falling, liveSources, liveSourceOf, isLive, isLiveVerified, collapses, holding, heldNow, heldKeys, isAnyLeft, takenPoints, covered, observed, sites, judged, reachNodes, plannedTests, unused, plannedHashOf, currentFindings, explored, exportCalls, loopSites, pathFindingsOf, pathQuestions, all, entries, justifyError, sourceHashes, bases, justified, refreshProblems, refreshedIds, acceptedEntries, staleEntries, acceptedIds, staleIds, asked, open, acceptedQuestions, reasonOf, positions, basisFor, liveIds, justifyProblems, caughtBy, reachedBy, note, crushesByDecision, catchingTests, properties, answers, graphIds, graphAnswers, answerFiles, answerReach, graphOutOf, graphOut, pathArgs, paths, visibleFiles, visible, isVisible, noteGraphReach, evidence, problems, refusedChoices, unsettledTests, tests, names, labelOf, measured, measuredTests, removableTests, keyOfLabel, readers, patternReaders, removalReach, shieldedFiles, isAskable, removable, testQuestions, outsideOf, counted, testMetaQuestions, justifiedSites, taken, figureLineOf;
|
|
84
84
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
85
85
|
try {
|
|
86
86
|
edges = __addDisposableResource(env_1, opened.data, false);
|
|
@@ -166,7 +166,8 @@ try {
|
|
|
166
166
|
plannedTests = new Set(plan.tests.map(({ path }) => path));
|
|
167
167
|
unused = unusedQuestionsOf(reachNodes.filter(({ file }) => !plannedTests.has(file) && !testRootPattern.test(file)));
|
|
168
168
|
plannedHashOf = new Map([...plan.files, ...plan.tests].map(({ path, hash }) => [path, hash]));
|
|
169
|
-
|
|
169
|
+
currentFindings = edges.getFindings().filter(({ file, sourceHash }) => plannedHashOf.get(file) === sourceHash);
|
|
170
|
+
explored = [...exploreQuestionsOf(currentFindings.filter(({ plugin }) => plugin === 'explore')), ...findingQuestionsOf(currentFindings.filter(({ plugin }) => plugin !== 'explore'))];
|
|
170
171
|
exportCalls = edges.getExportCalls();
|
|
171
172
|
// The fork points that test a loop, which no-split never asks of, by the same key a call's steps name their site with.
|
|
172
173
|
loopSites = new Set(plan.files.flatMap(({ path, points }) => points.filter(({ kind }) => loopKinds.has(kind)).map(({ decision }) => pointKeyOf(path, decision))));
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import 'vite-plus/test';
|
|
2
1
|
import type { Justification } from '../justify/justify.schema.ts';
|
|
3
|
-
import type { ExploreTarget } from '../explore/edges/explore.ts';
|
|
4
|
-
import { exploreLimitsProvideKey, explorePathsProvideKey, exploreSeedProvideKey, judgeRedundantProvideKey, judgeFilesProvideKey, judgeRelatedProvideKey, questionsRelatedProvideKey, judgeShardsProvideKey, phaseProvideKey, recordTestFilesProvideKey, removableTestsProvideKey, rootProvideKey, rulesProvideKey, stepsProvideKey, vitestProvideKey } from './edges/vitest.ts';
|
|
5
|
-
import type { RemovableTests } from './judge.schema.ts';
|
|
6
|
-
import { type BaselineSpeed, type JudgeSpeed, type PlanSpeed, planSpeedKey } from './edges/speed.ts';
|
|
7
2
|
export type CrushTaskMeta = {
|
|
8
3
|
answers?: string | string[];
|
|
9
4
|
justifies?: Justification[];
|
|
@@ -17,35 +12,3 @@ export type CrushTaskMeta = {
|
|
|
17
12
|
related: string;
|
|
18
13
|
};
|
|
19
14
|
};
|
|
20
|
-
declare module 'vite-plus/test' {
|
|
21
|
-
interface TestContext {
|
|
22
|
-
crushExploreProperties?: ExploreTarget[];
|
|
23
|
-
}
|
|
24
|
-
interface TaskMeta extends CrushTaskMeta {
|
|
25
|
-
crushBaselineSpeed?: BaselineSpeed;
|
|
26
|
-
crushJudgeSpeed?: JudgeSpeed;
|
|
27
|
-
crushOpen?: number;
|
|
28
|
-
crushOpenIn?: string;
|
|
29
|
-
}
|
|
30
|
-
interface ProvidedContext {
|
|
31
|
-
[vitestProvideKey]: string;
|
|
32
|
-
[phaseProvideKey]: 'record' | 'judge' | 'verify' | 'property';
|
|
33
|
-
[rulesProvideKey]: string;
|
|
34
|
-
[rootProvideKey]: string;
|
|
35
|
-
[removableTestsProvideKey]: RemovableTests;
|
|
36
|
-
[stepsProvideKey]: boolean;
|
|
37
|
-
[recordTestFilesProvideKey]: string[];
|
|
38
|
-
[explorePathsProvideKey]: string[] | null;
|
|
39
|
-
[exploreSeedProvideKey]: number;
|
|
40
|
-
[exploreLimitsProvideKey]: {
|
|
41
|
-
maxTotalTime: number;
|
|
42
|
-
runs: number;
|
|
43
|
-
};
|
|
44
|
-
[judgeFilesProvideKey]: string[];
|
|
45
|
-
[judgeShardsProvideKey]: number;
|
|
46
|
-
[judgeRelatedProvideKey]: string[];
|
|
47
|
-
[questionsRelatedProvideKey]: string[];
|
|
48
|
-
[judgeRedundantProvideKey]: boolean;
|
|
49
|
-
[planSpeedKey]: PlanSpeed;
|
|
50
|
-
}
|
|
51
|
-
}
|
package/dist/judge/task-meta.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { exploreLimitsProvideKey, explorePathsProvideKey, exploreSeedProvideKey, judgeRedundantProvideKey, judgeFilesProvideKey, judgeRelatedProvideKey, questionsRelatedProvideKey, judgeShardsProvideKey, phaseProvideKey, recordTestFilesProvideKey, removableTestsProvideKey, rootProvideKey, rulesProvideKey, stepsProvideKey, vitestProvideKey, } from './edges/vitest.js';
|
|
3
|
-
import { planSpeedKey } from './edges/speed.js';
|
|
1
|
+
export {};
|
|
@@ -59,7 +59,11 @@ export type ExploreFinding = {
|
|
|
59
59
|
function: string;
|
|
60
60
|
input: string;
|
|
61
61
|
};
|
|
62
|
-
export declare const exploreQuestionsOf: (all: readonly ExploreFinding[]) => Asked[];
|
|
62
|
+
export declare const exploreQuestionsOf: (all: readonly ExploreFinding[], kind?: 'explore' | 'finding') => Asked[];
|
|
63
|
+
type PluginFinding = ExploreFinding & {
|
|
64
|
+
plugin: string;
|
|
65
|
+
};
|
|
66
|
+
export declare const findingQuestionsOf: (all: readonly PluginFinding[]) => Asked[];
|
|
63
67
|
type PathFinding = Pick<QuestionInput, 'file' | 'function' | 'code'> & {
|
|
64
68
|
kind: 'same-result' | 'no-split';
|
|
65
69
|
siteKey: string;
|
|
@@ -63,6 +63,11 @@ const wordings = {
|
|
|
63
63
|
ask: `Explore called ${ownerOf(name)} with ${quote(input)} and it failed ${quote(code)}, which no test covers. Is that input one a caller can send?`,
|
|
64
64
|
answers: ['yes: fix the code, with a test that fails before the fix, then run explore again', 'no: refuse the input where it enters with a parse or guard, or justify it'],
|
|
65
65
|
}),
|
|
66
|
+
// Another plugin's finding is worded as explore's, and findingQuestionsOf names the plugin in place of explore.
|
|
67
|
+
finding: ({ function: name, code, replacement: input }) => ({
|
|
68
|
+
ask: `A plugin called ${ownerOf(name)} with ${quote(input)} and it failed ${quote(code)}, which no test covers. Is that input one a caller can send?`,
|
|
69
|
+
answers: ['yes: fix the code, with a test that fails before the fix, then run the plugin again', 'no: refuse the input where it enters with a parse or guard, or justify it'],
|
|
70
|
+
}),
|
|
66
71
|
behavior: ({ function: name, code }) => ({ ask: `What should ${ownerOf(name)} give at ${quote(code)}?`, answers: ['yes: add a case answering this question with its output', 'no: remove that outcome'] }),
|
|
67
72
|
'same-result': ({ function: name, code }) => ({
|
|
68
73
|
ask: `The recorded paths parting at ${quote(code)} in ${ownerOf(name)} give the same result. Can any input tell them apart?`,
|
|
@@ -276,16 +281,27 @@ export const unusedQuestionsOf = (nodes) => {
|
|
|
276
281
|
};
|
|
277
282
|
// One question per finding's site, open until an explore no longer finds it or a justification answers it; a site two targets found is asked once, of the first.
|
|
278
283
|
// Its id names the site alone, never the function that found it, so refreshing which target found a shared site keeps the id an answer names.
|
|
279
|
-
export const exploreQuestionsOf = (all) => {
|
|
284
|
+
export const exploreQuestionsOf = (all, kind = 'explore') => {
|
|
280
285
|
const seen = new Set();
|
|
281
286
|
const findings = all.filter(({ key }) => !seen.has(key) && Boolean(seen.add(key)));
|
|
282
|
-
const inputs = findings.map((finding) => ({ kind
|
|
287
|
+
const inputs = findings.map((finding) => ({ kind, file: finding.file, function: finding.function, code: finding.key, replacement: finding.input.slice(0, 1024) }));
|
|
283
288
|
const ids = questionsOf(inputs.map((input) => ({ ...input, function: '' })));
|
|
284
289
|
return questionsOf(inputs).map((question, index) => {
|
|
285
290
|
const finding = itemAt(findings, index);
|
|
286
291
|
return Object.assign(question, { id: itemAt(ids, index).id, sites: [finding.key], file: finding.file, line: finding.line });
|
|
287
292
|
});
|
|
288
293
|
};
|
|
294
|
+
// Another plugin's findings, asked as explore's are under their own kind, each naming the plugin that found it.
|
|
295
|
+
export const findingQuestionsOf = (all) => {
|
|
296
|
+
const pluginOf = new Map();
|
|
297
|
+
for (const { key, plugin } of all)
|
|
298
|
+
if (!pluginOf.has(key))
|
|
299
|
+
pluginOf.set(key, plugin);
|
|
300
|
+
return exploreQuestionsOf(all, 'finding').map((question) => {
|
|
301
|
+
const [site] = question.sites;
|
|
302
|
+
return Object.assign(question, { ask: question.ask.replace(/^A plugin/, pluginOf.get(site ?? '') ?? 'A plugin') });
|
|
303
|
+
});
|
|
304
|
+
};
|
|
289
305
|
export const pathQuestionsOf = (findings) => {
|
|
290
306
|
return questionsOf(findings.map(({ kind, file, function: name, code }) => ({ kind, file, function: name, code, replacement: '' }))).map((question, index) => {
|
|
291
307
|
const { file, line, siteKey, uncompared } = itemAt(findings, index);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const questionKinds: readonly ['crush', 'reach', 'call', 'side', 'tell', 'matter', 'behavior', 'test', 'unused', 'unexport', 'untested', 'testonly', 'steps', 'answers', 'explore', 'same-result', 'no-split'];
|
|
2
|
+
export declare const questionKinds: readonly ['crush', 'reach', 'call', 'side', 'tell', 'matter', 'behavior', 'test', 'unused', 'unexport', 'untested', 'testonly', 'steps', 'answers', 'explore', 'finding', 'same-result', 'no-split'];
|
|
3
3
|
export declare const questionIdPattern: RegExp;
|
|
4
4
|
export declare const encodedQuestionIdLength: number;
|
|
5
5
|
export declare const questionId: z.ZodString;
|
|
@@ -10,6 +10,7 @@ export declare const questionInput: z.ZodObject<{
|
|
|
10
10
|
call: "call";
|
|
11
11
|
crush: "crush";
|
|
12
12
|
explore: "explore";
|
|
13
|
+
finding: "finding";
|
|
13
14
|
matter: "matter";
|
|
14
15
|
"no-split": "no-split";
|
|
15
16
|
reach: "reach";
|
|
@@ -36,6 +37,7 @@ declare const questionOutput: z.ZodObject<{
|
|
|
36
37
|
call: "call";
|
|
37
38
|
crush: "crush";
|
|
38
39
|
explore: "explore";
|
|
40
|
+
finding: "finding";
|
|
39
41
|
matter: "matter";
|
|
40
42
|
"no-split": "no-split";
|
|
41
43
|
reach: "reach";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export const questionKinds = ['crush', 'reach', 'call', 'side', 'tell', 'matter', 'behavior', 'test', 'unused', 'unexport', 'untested', 'testonly', 'steps', 'answers', 'explore', 'same-result', 'no-split'];
|
|
2
|
+
export const questionKinds = ['crush', 'reach', 'call', 'side', 'tell', 'matter', 'behavior', 'test', 'unused', 'unexport', 'untested', 'testonly', 'steps', 'answers', 'explore', 'finding', 'same-result', 'no-split'];
|
|
3
3
|
// Matches a question id with pipes and percent signs escaped inside its fields.
|
|
4
4
|
export const questionIdPattern = /^(crush|reach|call|side|tell|matter|behavior|test|unused|unexport|untested|testonly|steps|answers|explore|same-result|no-split)\|(?:[^|%]|%25|%7C)+\|(?:[^|%]|%25|%7C)*\|\d+\|(?:[^|%]|%25|%7C)+$/;
|
|
5
5
|
const questionIdLength = 2048;
|
|
@@ -14,6 +14,7 @@ export type PlanCode = {
|
|
|
14
14
|
code: string;
|
|
15
15
|
};
|
|
16
16
|
export declare const setPlanCodes: (db: Record, planKey: string, codes: readonly PlanCode[]) => void;
|
|
17
|
+
export declare const getPlanCodes: (db: Reader) => PlanCode[];
|
|
17
18
|
export declare const getPlanCodesNullable: (db: Record, planKey: string) => PlanCode[] | null;
|
|
18
19
|
export declare const getPlan: (db: Record, { withRewrites }?: {
|
|
19
20
|
withRewrites?: boolean;
|
|
@@ -105,6 +105,11 @@ export const setPlanCodes = (db, planKey, codes) => {
|
|
|
105
105
|
tx.insert(planCodes).values(chunk).run();
|
|
106
106
|
}, { behavior: 'immediate' });
|
|
107
107
|
};
|
|
108
|
+
// The instrumented code the last plan kept, in path order, whatever its plan key.
|
|
109
|
+
export const getPlanCodes = (db) => {
|
|
110
|
+
const rows = db.select().from(planCodes).orderBy(asc(planCodes.path)).all();
|
|
111
|
+
return rows.map(({ path, hash, code }) => ({ path, hash, code }));
|
|
112
|
+
};
|
|
108
113
|
// The instrumented code kept under a plan key, in path order, or null when the last plan kept was another.
|
|
109
114
|
export const getPlanCodesNullable = (db, planKey) => {
|
|
110
115
|
const rows = db.select().from(planCodes).orderBy(asc(planCodes.path)).all();
|
|
@@ -2,7 +2,7 @@ import { DatabaseSync } from 'node:sqlite';
|
|
|
2
2
|
import { type NodeSQLiteDatabase } from 'drizzle-orm/node-sqlite';
|
|
3
3
|
import { CrushError } from '../../utils/errors.ts';
|
|
4
4
|
import { type Safe } from '../../utils/safe.ts';
|
|
5
|
-
export declare const recordVersion = "
|
|
5
|
+
export declare const recordVersion = "58";
|
|
6
6
|
export declare const memoryPath = ":memory:";
|
|
7
7
|
export type Record = NodeSQLiteDatabase & {
|
|
8
8
|
$client: DatabaseSync;
|
|
@@ -60,7 +60,7 @@ import { safe } from '../../utils/safe.js';
|
|
|
60
60
|
import { ensureRecordFolder, recordFileExists, removeRecordFile } from './record.fs.js';
|
|
61
61
|
import { unreadableRecordOf } from '../../judge/refusals.js';
|
|
62
62
|
// The record's shape; a record of any other version is deleted and rebuilt, since every row can be recorded again.
|
|
63
|
-
export const recordVersion = '
|
|
63
|
+
export const recordVersion = '58';
|
|
64
64
|
// How long a connection waits on the record while another holds its write lock, as every test file's worker writes its own part at once.
|
|
65
65
|
const busyMs = 30_000;
|
|
66
66
|
const migrationsFolder = join(import.meta.dirname, '../../../migrations/main');
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
ALTER TABLE `explore_findings` ADD `plugin` text DEFAULT 'explore' NOT NULL;--> statement-breakpoint
|
|
2
|
+
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
|
3
|
+
CREATE TABLE `__new_explore_findings` (
|
|
4
|
+
`finding_key` text NOT NULL,
|
|
5
|
+
`kind` text NOT NULL,
|
|
6
|
+
`file` text NOT NULL,
|
|
7
|
+
`line` integer NOT NULL,
|
|
8
|
+
`function` text NOT NULL,
|
|
9
|
+
`input` text NOT NULL,
|
|
10
|
+
`target` text NOT NULL,
|
|
11
|
+
`source_hash` text NOT NULL,
|
|
12
|
+
`plugin` text DEFAULT 'explore' NOT NULL,
|
|
13
|
+
CONSTRAINT `explore_findings_pk` PRIMARY KEY(`plugin`, `target`, `finding_key`),
|
|
14
|
+
CONSTRAINT "explore_findings_kind_check" CHECK("kind" in ('throw', 'property'))
|
|
15
|
+
);
|
|
16
|
+
--> statement-breakpoint
|
|
17
|
+
INSERT INTO `__new_explore_findings`(`finding_key`, `kind`, `file`, `line`, `function`, `input`, `target`, `source_hash`) SELECT `finding_key`, `kind`, `file`, `line`, `function`, `input`, `target`, `source_hash` FROM `explore_findings`;--> statement-breakpoint
|
|
18
|
+
DROP TABLE `explore_findings`;--> statement-breakpoint
|
|
19
|
+
ALTER TABLE `__new_explore_findings` RENAME TO `explore_findings`;--> statement-breakpoint
|
|
20
|
+
PRAGMA foreign_keys=ON;
|