@whaaaley/crush 0.2.7 → 0.3.0-next.11

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.
Files changed (77) hide show
  1. package/README.md +54 -14
  2. package/SKILL.md +4 -19
  3. package/dist/crush.tables.d.ts +26 -122
  4. package/dist/crush.tables.js +8 -21
  5. package/dist/instrument/instrument.operations.js +1 -1
  6. package/dist/judge/counters.d.ts +6 -0
  7. package/dist/judge/counters.js +89 -1
  8. package/dist/judge/edges/api.d.ts +24 -4
  9. package/dist/judge/edges/api.js +20 -6
  10. package/dist/judge/edges/hints.reporter.js +2 -2
  11. package/dist/judge/edges/judge.edges.d.ts +2 -3
  12. package/dist/judge/edges/judge.edges.js +1 -2
  13. package/dist/judge/edges/plugin.d.ts +12 -9
  14. package/dist/judge/edges/plugin.js +34 -49
  15. package/dist/judge/edges/plugin.npm.d.ts +2 -0
  16. package/dist/judge/edges/plugin.npm.js +2 -0
  17. package/dist/judge/edges/vitest.d.ts +1 -3
  18. package/dist/judge/edges/vitest.js +2 -3
  19. package/dist/judge/hints.d.ts +1 -1
  20. package/dist/judge/hints.js +0 -3
  21. package/dist/judge/judge.schema.d.ts +10 -1
  22. package/dist/judge/judge.schema.js +0 -2
  23. package/dist/judge/provided.d.ts +31 -0
  24. package/dist/judge/provided.js +2 -0
  25. package/dist/judge/refusals.d.ts +2 -2
  26. package/dist/judge/refusals.js +2 -2
  27. package/dist/judge/report.test.js +11 -12
  28. package/dist/judge/runner.js +35 -58
  29. package/dist/judge/task-meta.d.ts +0 -6
  30. package/dist/questions/questions.operations.d.ts +4 -3
  31. package/dist/questions/questions.operations.js +11 -11
  32. package/dist/questions/questions.schema.d.ts +3 -3
  33. package/dist/questions/questions.schema.js +2 -2
  34. package/dist/record/edges/findings.db.d.ts +16 -0
  35. package/dist/record/edges/findings.db.js +25 -0
  36. package/dist/record/edges/parts.db.d.ts +1 -1
  37. package/dist/record/edges/parts.db.js +3 -15
  38. package/dist/record/edges/plan.db.d.ts +1 -0
  39. package/dist/record/edges/plan.db.js +5 -0
  40. package/dist/record/edges/record.db.d.ts +1 -1
  41. package/dist/record/edges/record.db.js +1 -1
  42. package/dist/record/parts.operations.d.ts +2 -3
  43. package/dist/record/parts.operations.js +1 -2
  44. package/migrations/main/20261206094906_plugin_findings/migration.sql +20 -0
  45. package/migrations/main/20261206094906_plugin_findings/snapshot.json +3652 -0
  46. package/migrations/main/20261206102548_drop_explore/migration.sql +17 -0
  47. package/migrations/main/20261206102548_drop_explore/snapshot.json +3550 -0
  48. package/package.json +3 -5
  49. package/references/consumer-setup.md +0 -1
  50. package/dist/explore/edges/explore.d.ts +0 -60
  51. package/dist/explore/edges/explore.db.d.ts +0 -22
  52. package/dist/explore/edges/explore.db.js +0 -55
  53. package/dist/explore/edges/explore.js +0 -305
  54. package/dist/explore/edges/random.d.ts +0 -2
  55. package/dist/explore/edges/random.js +0 -32
  56. package/dist/explore/explore.operations.d.ts +0 -30
  57. package/dist/explore/explore.operations.js +0 -117
  58. package/dist/explore/limits.operations.d.ts +0 -14
  59. package/dist/explore/limits.operations.js +0 -20
  60. package/dist/explore/targets.operations.d.ts +0 -36
  61. package/dist/explore/targets.operations.js +0 -32
  62. package/dist/explore/utils/draws.d.ts +0 -6
  63. package/dist/explore/utils/draws.js +0 -2
  64. package/dist/explore/utils/edits.d.ts +0 -15
  65. package/dist/explore/utils/edits.js +0 -151
  66. package/dist/explore/utils/guide.d.ts +0 -23
  67. package/dist/explore/utils/guide.js +0 -35
  68. package/dist/explore/utils/keep.d.ts +0 -10
  69. package/dist/explore/utils/keep.js +0 -61
  70. package/dist/explore/utils/pools.d.ts +0 -17
  71. package/dist/explore/utils/pools.js +0 -121
  72. package/dist/explore/utils/reads.d.ts +0 -19
  73. package/dist/explore/utils/reads.js +0 -118
  74. package/dist/explore/utils/twin.d.ts +0 -21
  75. package/dist/explore/utils/twin.js +0 -55
  76. package/dist/judge/explore.test.d.ts +0 -1
  77. package/dist/judge/explore.test.js +0 -101
package/README.md CHANGED
@@ -44,8 +44,6 @@ Run each from the root of the project crush is set up in, waiting for one to fin
44
44
  - `vp run judge:redundant` judges as `vp run judge` does, then reruns the other tests of each catch to find a second catcher, which is what shows a test redundant and asks whether it can go.
45
45
  - `vp run questions` lists the open questions.
46
46
  - `vp run questions:related <paths>` lists only the questions of the sources those paths reach.
47
- - `vp run explore` searches a property for inputs that break it, seeded from the record. Explore is experimental in 0.1: its findings can change between releases, and it may move to a plugin of its own.
48
- - `vp run explore:related <paths>` searches only the exports those paths reach.
49
47
  - `vp run stresses` prints how many tests each mutator and the crushes drive.
50
48
 
51
49
  A question no test can answer takes an inline literal `meta: { justifies: [{ id, basis, reason }] }` on the function's `describe` in its test file:
@@ -57,9 +55,57 @@ A justification whose code moves is reported apart from new questions; setting i
57
55
 
58
56
  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
57
 
58
+ ### A worked example
59
+
60
+ This `clamp` takes a range whose callers keep `min <= max`, and has one test below the range and one inside it:
61
+
62
+ ```ts
63
+ export const clamp = (value: bigint, min: bigint, max: bigint): bigint => {
64
+ if (value < min) return min
65
+ if (value > max) return max
66
+ return value
67
+ }
68
+ ```
69
+
70
+ 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:
71
+
72
+ ```
73
+ ↳ 1. src/clamp.ts:2 Can any input tell `value < min` from `(value <= min)` in `clamp`?
74
+ id: tell|src/clamp.ts|clamp|0|value < min
75
+ yes: add that input
76
+ no: use `(value <= min)`
77
+ ↳ 2. src/clamp.ts:3 Can any input make `value > max` true in `clamp`?
78
+ id: side|src/clamp.ts|clamp|1|value > max
79
+ yes: add that input
80
+ no: remove what runs when it is true
81
+ ↳ 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?
82
+ yes: write `steps: 1` in the test's meta, then record again
83
+ no: make the code `raises a value below the range to its minimum` runs do less work
84
+ ```
85
+
86
+ Each takes a different answer:
87
+
88
+ - **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)`.
89
+ - **Steps:** each test states the work it takes as `meta: { steps: 1 }`, so a later change that makes it slower is asked about.
90
+ - **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:
91
+
92
+ ```ts
93
+ describe('clamp', {
94
+ meta: {
95
+ justifies: [
96
+ { 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 <=.' },
97
+ { 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 >=.' },
98
+ ],
99
+ },
100
+ }, () => {
101
+ ```
102
+
103
+ 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`.
104
+ 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.
105
+
60
106
  ### What each command prints last
61
107
 
62
- 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.
108
+ Record, judge and questions 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.
63
109
  Stresses prints none, since its output is the work.
64
110
  A related run names the related task, as `vp run judge:related <paths>` after `vp run record:related <paths>`.
65
111
 
@@ -69,7 +115,6 @@ A related run names the related task, as `vp run judge:related <paths>` after `v
69
115
  | record, passed | `vp run judge` |
70
116
  | judge, a test failed | fixing each failure, then `vp run judge` again |
71
117
  | judge, passed | `vp run questions` |
72
- | explore | `vp run questions` |
73
118
  | questions, some open | answering the first open question, in its file, then `vp run record:related <file>`, `vp run judge:related <file>` and `vp run questions` |
74
119
  | questions, open, no file | answering them from the top, then `vp run record`, `vp run judge` and `vp run questions` |
75
120
  | questions, none open, failed | fixing each failure printed, then `vp run questions` again |
@@ -77,16 +122,12 @@ A related run names the related task, as `vp run judge:related <paths>` after `v
77
122
 
78
123
  The questions hint names asking the user, with the question's id and both readings, when the code's intent is unknown, and a `don't:` line says not to stop at such a question but to note it for the user and take the next.
79
124
 
80
- ### Explore and mutation
125
+ ### Plugins
81
126
 
82
127
  Judging checks whether your tests notice a change to your code: a mutant no test catches, or a branch no test needs, becomes a question.
83
128
  It can't find a bug the code and its tests agree on, as an input no test passes that the code gets wrong.
84
- Explore looks for those, with inputs generated from the calls your tests made, in two ways:
85
-
86
- - **Exports:** it calls each export with generated inputs, and a throw from a place no test covers becomes a question.
87
- - **Properties:** it calls a property, and each input it fails becomes a question. A property is an exported function in a test file that returns `'passed'`, `'discarded'` or `'failed'` for an input, a throw counting as failed, such as "decoding what was encoded gives back the input". A Vitest test names it in `meta: { explores }`.
88
-
89
- Properties pay off mostly for parsers, encoders and state machines, so judging alone is enough for most code.
129
+ A plugin such as crush-fuzz looks for those through `@whaaaley/crush/api`, and each finding it saves becomes a question that names the plugin.
130
+ A plugin declares `@whaaaley/crush` as a peer on the crush minor it was built against, so a crush minor that changes the API refuses the install.
90
131
 
91
132
  ## Why
92
133
 
@@ -122,14 +163,13 @@ crush can judge some code wrong, or not at all, in these cases:
122
163
  - **Module state between reruns:** a mutant's rerun can leave module state a later test reads, so a later site can read survived where a fresh load would catch it.
123
164
  - **Tests that leak globals:** a project's test files share one process per run with no isolation between files, so a test that sets a global and never restores it, as hono's `global.fetch` mock does, can change later files' verdicts.
124
165
  - **Unsteady tests:** a test whose work differs between runs with nothing forced, as one deciding with `Math.random`, gives verdicts that can differ between judges; crush marks it unsteady and asks about its steps.
125
- - **Generators:** an exported generator expression is captured by its arguments alone, since its body runs as the caller iterates, so explore seeds from its calls but the path checks never see them; an exported generator declaration isn't captured at all.
166
+ - **Generators:** an exported generator expression is captured by its arguments alone, since its body runs as the caller iterates, so a plugin can seed from its calls but the path checks never see them; an exported generator declaration isn't captured at all.
126
167
  - **Captured async exports:** reading an async export's result attaches a handler, so in crush's baseline a rejection the test leaves unhandled isn't reported; the project's own `vp test` still reports it.
127
- - **Explore is experimental:** its search, its findings and how it reports them may change, and nothing should gate on its output yet.
128
168
  - **ES modules only:** every file but a `.cjs` one is read as an ES module, as ESLint does, and CommonJS isn't supported.
129
169
 
130
170
  ## Project structure
131
171
 
132
- - `src/`: The engine, one folder per stage: `decisions/`, `crushes/`, `mutators/`, `graph/`, `collapse/`, `capture/`, `instrument/`, `record/`, `judge/`, `questions/`, `justify/`, `forks/`, `stresses/`, `explore/` and `parity/`, with shared helpers in `utils/`.
172
+ - `src/`: The engine, one folder per stage: `decisions/`, `crushes/`, `mutators/`, `graph/`, `collapse/`, `capture/`, `instrument/`, `record/`, `judge/`, `questions/`, `justify/`, `forks/`, `stresses/` and `parity/`, with shared helpers in `utils/`.
133
173
  - `docs/` and `references/`: The docs this README links and the consumer setup `SKILL.md` points to.
134
174
  - `scripts/`: The CI scripts the workflows run, and `check`, the format, lint and test gate.
135
175
  - `tools.config.json`: The settings crush's own tools read, such as the reviewer saga runs.
package/SKILL.md CHANGED
@@ -162,26 +162,11 @@ A related run keeps untouched results. Delete `.crush/record.db` when the check
162
162
  Finish the record loop with passing report tests and no open questions, invalid answers, invalid justifications, failing baselines, or tests failing their rerun
163
163
  The project report checks those items together, while coverage and mutation figures alone miss failures
164
164
 
165
- Declare an explore property through `meta.explores` on a Vitest test when the installed crush revision supports explore, naming the exported property function in that test module
166
- Explore uses the name to call the property with inputs generated from recorded calls
165
+ Reproduce a plugin's finding with a regression test before recording again
166
+ The finding supplies an input that breaks the code, and the regression test keeps that input checked on later runs
167
167
 
168
- Run `vp run explore` after a record, when the installed crush revision supports explore and the project defines the task
169
- Explore searches from whatever the record holds, and its findings come back as more questions
170
-
171
- Set `explore: { maxTotalTime, runs }` in `exploreProject` to bound Explore by seconds or target calls
172
- The defaults are `0` seconds and `-1` runs, leaving both limits open. When both are set, the first one reached ends the run
173
-
174
- In crush's own checkout set `explore.maxTotalTime` or `explore.runs` in the settings of its `vite.config.ts` before `vp run explore` or `vp run explore:related`
175
- Those tasks read the limits from the config, as a consumer's `exploreProject` settings set them
176
-
177
- Stop an unbounded run with Ctrl-C and read saved findings with `vp run questions`
178
- Explore saves each finding as it is found, so Questions can show those already found when the run stops
179
-
180
- Reproduce an explore finding with a regression test before recording again
181
- The finding supplies an input that breaks the property, and the regression test keeps that input checked on later runs
182
-
183
- Remove an explore finding's id from `meta.answers` once the finding closes
184
- Crush refuses a closed explore id because only open explore findings enter answer validation
168
+ Remove a finding's id from `meta.answers` once the finding closes
169
+ Crush refuses a closed finding id because only open findings enter answer validation
185
170
 
186
171
  Keep the worktree's `.crush/record.db` between runs
187
172
  Related runs reuse its evidence, and `vp run record` automatically rebuilds it when the version in `src/record/edges/record.db.ts` changes
@@ -2292,46 +2292,6 @@ export declare const testFileOutside: import("drizzle-orm/sqlite-core").SQLiteTa
2292
2292
  dialect: 'sqlite';
2293
2293
  isAlias: false;
2294
2294
  }>;
2295
- export declare const testFileProperties: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
2296
- name: "test_file_properties";
2297
- schema: undefined;
2298
- columns: {
2299
- testFile: import("drizzle-orm/sqlite-core").SQLiteColumn<{
2300
- name: string;
2301
- tableName: "test_file_properties";
2302
- dataType: "number int53";
2303
- data: number;
2304
- driverParam: number;
2305
- notNull: true;
2306
- hasDefault: false;
2307
- isPrimaryKey: false;
2308
- isAutoincrement: false;
2309
- hasRuntimeDefault: false;
2310
- enumValues: undefined;
2311
- baseColumn: never;
2312
- identity: undefined;
2313
- generated: undefined;
2314
- }, {}>;
2315
- name: import("drizzle-orm/sqlite-core").SQLiteColumn<{
2316
- name: string;
2317
- tableName: "test_file_properties";
2318
- dataType: "string";
2319
- data: string;
2320
- driverParam: string;
2321
- notNull: true;
2322
- hasDefault: false;
2323
- isPrimaryKey: false;
2324
- isAutoincrement: false;
2325
- hasRuntimeDefault: false;
2326
- enumValues: [string, ...string[]];
2327
- baseColumn: never;
2328
- identity: undefined;
2329
- generated: undefined;
2330
- }, {}>;
2331
- };
2332
- dialect: 'sqlite';
2333
- isAlias: false;
2334
- }>;
2335
2295
  export declare const testFileChanged: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
2336
2296
  name: "test_file_changed";
2337
2297
  schema: undefined;
@@ -3085,85 +3045,13 @@ export declare const reachEdges: import("drizzle-orm/sqlite-core").SQLiteTableWi
3085
3045
  isAlias: false;
3086
3046
  }>;
3087
3047
  export declare const findingKinds: readonly ['throw', 'property'];
3088
- export declare const exploreRuns: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
3089
- name: "explore_runs";
3090
- schema: undefined;
3091
- columns: {
3092
- targetKey: import("drizzle-orm/sqlite-core").SQLiteColumn<{
3093
- name: string;
3094
- tableName: "explore_runs";
3095
- dataType: "string";
3096
- data: string;
3097
- driverParam: string;
3098
- notNull: true;
3099
- hasDefault: false;
3100
- isPrimaryKey: true;
3101
- isAutoincrement: false;
3102
- hasRuntimeDefault: false;
3103
- enumValues: [string, ...string[]];
3104
- baseColumn: never;
3105
- identity: undefined;
3106
- generated: undefined;
3107
- }, {}>;
3108
- ms: import("drizzle-orm/sqlite-core").SQLiteColumn<{
3109
- name: string;
3110
- tableName: "explore_runs";
3111
- dataType: "number int53";
3112
- data: number;
3113
- driverParam: number;
3114
- notNull: true;
3115
- hasDefault: false;
3116
- isPrimaryKey: false;
3117
- isAutoincrement: false;
3118
- hasRuntimeDefault: false;
3119
- enumValues: undefined;
3120
- baseColumn: never;
3121
- identity: undefined;
3122
- generated: undefined;
3123
- }, {}>;
3124
- exploredAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
3125
- name: string;
3126
- tableName: "explore_runs";
3127
- dataType: "object date";
3128
- data: Date;
3129
- driverParam: number;
3130
- notNull: true;
3131
- hasDefault: false;
3132
- isPrimaryKey: false;
3133
- isAutoincrement: false;
3134
- hasRuntimeDefault: false;
3135
- enumValues: undefined;
3136
- baseColumn: never;
3137
- identity: undefined;
3138
- generated: undefined;
3139
- }, {}>;
3140
- stopped: import("drizzle-orm/sqlite-core").SQLiteColumn<{
3141
- name: string;
3142
- tableName: "explore_runs";
3143
- dataType: "string";
3144
- data: string;
3145
- driverParam: string;
3146
- notNull: false;
3147
- hasDefault: false;
3148
- isPrimaryKey: false;
3149
- isAutoincrement: false;
3150
- hasRuntimeDefault: false;
3151
- enumValues: [string, ...string[]];
3152
- baseColumn: never;
3153
- identity: undefined;
3154
- generated: undefined;
3155
- }, {}>;
3156
- };
3157
- dialect: 'sqlite';
3158
- isAlias: false;
3159
- }>;
3160
- export declare const exploreFindings: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
3161
- name: "explore_findings";
3048
+ export declare const pluginFindings: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
3049
+ name: "plugin_findings";
3162
3050
  schema: undefined;
3163
3051
  columns: {
3164
3052
  findingKey: import("drizzle-orm/sqlite-core").SQLiteColumn<{
3165
3053
  name: string;
3166
- tableName: "explore_findings";
3054
+ tableName: "plugin_findings";
3167
3055
  dataType: "string";
3168
3056
  data: string;
3169
3057
  driverParam: string;
@@ -3179,7 +3067,7 @@ export declare const exploreFindings: import("drizzle-orm/sqlite-core").SQLiteTa
3179
3067
  }, {}>;
3180
3068
  kind: import("drizzle-orm/sqlite-core").SQLiteColumn<{
3181
3069
  name: string;
3182
- tableName: "explore_findings";
3070
+ tableName: "plugin_findings";
3183
3071
  dataType: "string enum";
3184
3072
  data: "property" | "throw";
3185
3073
  driverParam: string;
@@ -3195,7 +3083,7 @@ export declare const exploreFindings: import("drizzle-orm/sqlite-core").SQLiteTa
3195
3083
  }, {}>;
3196
3084
  file: import("drizzle-orm/sqlite-core").SQLiteColumn<{
3197
3085
  name: string;
3198
- tableName: "explore_findings";
3086
+ tableName: "plugin_findings";
3199
3087
  dataType: "string";
3200
3088
  data: string;
3201
3089
  driverParam: string;
@@ -3211,7 +3099,7 @@ export declare const exploreFindings: import("drizzle-orm/sqlite-core").SQLiteTa
3211
3099
  }, {}>;
3212
3100
  line: import("drizzle-orm/sqlite-core").SQLiteColumn<{
3213
3101
  name: string;
3214
- tableName: "explore_findings";
3102
+ tableName: "plugin_findings";
3215
3103
  dataType: "number int53";
3216
3104
  data: number;
3217
3105
  driverParam: number;
@@ -3227,7 +3115,7 @@ export declare const exploreFindings: import("drizzle-orm/sqlite-core").SQLiteTa
3227
3115
  }, {}>;
3228
3116
  function: import("drizzle-orm/sqlite-core").SQLiteColumn<{
3229
3117
  name: string;
3230
- tableName: "explore_findings";
3118
+ tableName: "plugin_findings";
3231
3119
  dataType: "string";
3232
3120
  data: string;
3233
3121
  driverParam: string;
@@ -3243,7 +3131,7 @@ export declare const exploreFindings: import("drizzle-orm/sqlite-core").SQLiteTa
3243
3131
  }, {}>;
3244
3132
  input: import("drizzle-orm/sqlite-core").SQLiteColumn<{
3245
3133
  name: string;
3246
- tableName: "explore_findings";
3134
+ tableName: "plugin_findings";
3247
3135
  dataType: "string";
3248
3136
  data: string;
3249
3137
  driverParam: string;
@@ -3259,7 +3147,7 @@ export declare const exploreFindings: import("drizzle-orm/sqlite-core").SQLiteTa
3259
3147
  }, {}>;
3260
3148
  target: import("drizzle-orm/sqlite-core").SQLiteColumn<{
3261
3149
  name: string;
3262
- tableName: "explore_findings";
3150
+ tableName: "plugin_findings";
3263
3151
  dataType: "string";
3264
3152
  data: string;
3265
3153
  driverParam: string;
@@ -3275,7 +3163,23 @@ export declare const exploreFindings: import("drizzle-orm/sqlite-core").SQLiteTa
3275
3163
  }, {}>;
3276
3164
  sourceHash: import("drizzle-orm/sqlite-core").SQLiteColumn<{
3277
3165
  name: string;
3278
- tableName: "explore_findings";
3166
+ tableName: "plugin_findings";
3167
+ dataType: "string";
3168
+ data: string;
3169
+ driverParam: string;
3170
+ notNull: true;
3171
+ hasDefault: false;
3172
+ isPrimaryKey: false;
3173
+ isAutoincrement: false;
3174
+ hasRuntimeDefault: false;
3175
+ enumValues: [string, ...string[]];
3176
+ baseColumn: never;
3177
+ identity: undefined;
3178
+ generated: undefined;
3179
+ }, {}>;
3180
+ plugin: import("drizzle-orm/sqlite-core").SQLiteColumn<{
3181
+ name: string;
3182
+ tableName: "plugin_findings";
3279
3183
  dataType: "string";
3280
3184
  data: string;
3281
3185
  driverParam: string;
@@ -287,13 +287,6 @@ export const testFileOutside = sqliteTable('test_file_outside', {
287
287
  }, (table) => [
288
288
  primaryKey({ columns: [table.testFile, table.path] }),
289
289
  ]);
290
- // Each property a test file's tests declare for explore, by the export name its `meta.explores` gives, which a clean record reads to credit an answer to it.
291
- export const testFileProperties = sqliteTable('test_file_properties', {
292
- testFile: integer().notNull().references(() => testFiles.id, { onDelete: 'cascade' }),
293
- name: text().notNull(),
294
- }, (table) => [
295
- primaryKey({ columns: [table.testFile, table.name] }),
296
- ]);
297
290
  // Each source a test file's run loaded that changed during it, whose stale plan left the file's sites unjudged.
298
291
  export const testFileChanged = sqliteTable('test_file_changed', {
299
292
  testFile: integer().notNull().references(() => testFiles.id, { onDelete: 'cascade' }),
@@ -395,29 +388,23 @@ export const reachEdges = sqliteTable('reach_edges', {
395
388
  index('reach_edges_to_key_idx').on(table.toKey),
396
389
  ]);
397
390
  export const findingKinds = ['throw', 'property'];
398
- // When explore last ran each export or property and how long it spent, which orders the next budget and leaves the rest of the cap to the throw-only pass.
399
- export const exploreRuns = sqliteTable('explore_runs', {
400
- targetKey: text().primaryKey(),
401
- ms: integer().notNull(),
402
- exploredAt: integer({ mode: 'timestamp_ms' }).notNull(),
403
- // Why the target's search stopped short, as a call past its tick limit, null for a search that ran its course.
404
- stopped: text(),
405
- });
406
- // Each finding: a throw site no test covered, or a property a varied input failed, with the input that showed it and where to ask.
407
- export const exploreFindings = sqliteTable('explore_findings', {
391
+ // Each finding a plugin saved: a throw site no test covered, or a property a varied input failed, with the input that showed it and where to ask.
392
+ export const pluginFindings = sqliteTable('plugin_findings', {
408
393
  findingKey: text().notNull(),
409
394
  kind: text({ enum: findingKinds }).notNull(),
410
395
  file: text().notNull(),
411
396
  line: integer().notNull(),
412
397
  function: text().notNull(),
413
398
  input: text().notNull(),
414
- // The export or property whose explore found it, whose next explore replaces it; two targets reaching one site each keep their own row.
399
+ // The export or property whose search found it, whose next search replaces it; two targets reaching one site each keep their own row.
415
400
  target: text().notNull(),
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.
401
+ // The hash of the file the finding asks at when it was found, so an edit to that file drops the finding until a search finds it again.
417
402
  sourceHash: text().notNull(),
403
+ // The plugin that saved it, which its question names and whose rerun alone replaces it.
404
+ plugin: text().notNull(),
418
405
  }, (table) => [
419
- enumConstraint('explore_findings_kind_check', table.kind, findingKinds),
420
- primaryKey({ columns: [table.target, table.findingKey] }),
406
+ enumConstraint('plugin_findings_kind_check', table.kind, findingKinds),
407
+ primaryKey({ columns: [table.plugin, table.target, table.findingKey] }),
421
408
  ]);
422
409
  // 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
410
  // 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.
@@ -516,7 +516,7 @@ export const unitsOf = (source, parsed, paths, unitBase, edits = []) => {
516
516
  };
517
517
  // A test file's code with every function marking itself entered and the file marking itself loaded, through counters imported under names of crush's own, since a test of the counters imports their usual names itself.
518
518
  // A function nested in another closes its mark first where both end at once.
519
- // An exported function's capture wrap holds its entry mark, so it opens before and closes after every mark inside it, which keeps the calls a test makes to a property it declares for explore.
519
+ // An exported function's capture wrap holds its entry mark, so it opens before and closes after every mark inside it, which keeps the calls a test makes to an export of its own file.
520
520
  const markedTestOf = (path, source, parsed, entries, counters, justificationMarks) => {
521
521
  const capturedMarks = capturedOf(path, parsed, { value: '__crushCaptured', body: '__crushCapturedBody', isExact: true }).flatMap(({ open, close, opening, closing }) => [
522
522
  { at: open, order: -1, text: opening },
@@ -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 = [];
@@ -342,7 +430,7 @@ export const countersOf = (state) => {
342
430
  settle(kept.live, 'returned', snapshotOf(result), '');
343
431
  return result;
344
432
  };
345
- // Keeps a generator's call by its arguments alone: its body runs as the caller iterates, after the call returns, so no side it takes is its own and its path is cut, which keeps it out of the path checks while explore still seeds from it.
433
+ // Keeps a generator's call by its arguments alone: its body runs as the caller iterates, after the call returns, so no side it takes is its own and its path is cut, which keeps it out of the path checks while a plugin still seeds from it.
346
434
  // The generator is called as it is, so its body, its `finally` and its `arguments` stay as they were.
347
435
  const __g = (key, args, run) => {
348
436
  const kept = state.isCapturing ? begun(key, args) : null;
@@ -1,14 +1,34 @@
1
1
  import type { ExportCallOutput } from '../../capture/capture.schema.ts';
2
- import { type Finding } from '../../explore/edges/explore.db.ts';
2
+ import { type Finding } from '../../record/edges/findings.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 '../../explore/edges/explore.ts';
6
- export { stateOf } from '../counters.ts';
6
+ export { countedOn, countersOf, limitedRun, state as counters, stateOf, stepLimitOf } from '../counters.ts';
7
+ export { rootProvideKey } from './vitest.ts';
8
+ export { testFilePattern } from './plugin.ts';
9
+ export { throwLocationOf, uncloned } from '../../capture/capture.operations.ts';
10
+ export { hashOf, unitFieldsOf, unitKeyOf } from '../../record/record.operations.ts';
11
+ export { encodeReachKey } from '../../graph/symbols/keys.ts';
12
+ export { reachedFrom } from '../../graph/symbols/symbols.ts';
7
13
  export type { ExportCallOutput, Finding };
14
+ export type { LoadedTestFile } from '../judge.schema.ts';
15
+ export declare const encodedValueOf: (value: unknown) => string;
8
16
  export declare const capturedCallsOf: (root: string) => Safe<ExportCallOutput[], CrushError>;
17
+ type PlannedSource = {
18
+ path: string;
19
+ hash: string;
20
+ code: string;
21
+ };
22
+ export declare const plannedSourcesOf: (root: string) => Safe<PlannedSource[], CrushError>;
23
+ type ReachGraph = {
24
+ nodes: ReachNodeOutput[];
25
+ edges: ReachEdgeOutput[];
26
+ };
27
+ export declare const reachGraphOf: (root: string) => Safe<ReachGraph, CrushError>;
9
28
  type SaveFindingsInput = {
10
29
  root: string;
30
+ plugin: string;
11
31
  targets: readonly string[];
12
32
  findings: Finding[];
13
33
  };
14
- export declare const saveFindings: ({ root, targets, findings }: SaveFindingsInput) => Error | null;
34
+ export declare const saveFindings: ({ root, plugin, targets, findings }: SaveFindingsInput) => Error | null;
@@ -50,25 +50,39 @@ 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 { setFindings } from '../../explore/edges/explore.db.js';
53
+ import { encodedOf, snapshotOf } from '../../capture/capture.operations.js';
54
+ import { setFindings } from '../../record/edges/findings.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 '../../explore/edges/explore.js';
60
- export { stateOf } from '../counters.js';
62
+ export { countedOn, countersOf, limitedRun, state as counters, stateOf, stepLimitOf } from '../counters.js';
63
+ export { rootProvideKey } from './vitest.js';
64
+ export { testFilePattern } from './plugin.js';
65
+ export { throwLocationOf, uncloned } from '../../capture/capture.operations.js';
66
+ export { hashOf, unitFieldsOf, unitKeyOf } from '../../record/record.operations.js';
67
+ export { encodeReachKey } from '../../graph/symbols/keys.js';
68
+ export { reachedFrom } from '../../graph/symbols/symbols.js';
69
+ // A value as crush's questions print it, the form a finding's input takes.
70
+ export const encodedValueOf = (value) => encodedOf(snapshotOf(value));
61
71
  // Every call the record's baseline captured to an exported function, with its arguments and how it ended.
62
72
  export const capturedCallsOf = (root) => readCurrentRecord(recordPathOf(root), getExportCalls);
63
- // Replaces the findings of the named targets with these, which the next questions run asks about as explore's own.
64
- export const saveFindings = ({ root, targets, findings }) => {
73
+ // The code each source was instrumented with by the last plan, with the hash of the source it was made from.
74
+ export const plannedSourcesOf = (root) => readCurrentRecord(recordPathOf(root), getPlanCodes);
75
+ // The record's reach graph: every file, export and function, and which reaches which.
76
+ export const reachGraphOf = (root) => readCurrentRecord(recordPathOf(root), (record) => ({ nodes: getReachNodes(record), edges: getReachEdges(record) }));
77
+ // Replaces the findings of the named targets with these, which the next questions run asks about, naming the plugin that found each.
78
+ export const saveFindings = ({ root, plugin, targets, findings }) => {
65
79
  const env_1 = { stack: [], error: void 0, hasError: false };
66
80
  try {
67
81
  const { data: opened, error } = openCurrentRecord(recordPathOf(root));
68
82
  if (error)
69
83
  return error;
70
84
  const record = __addDisposableResource(env_1, opened, false);
71
- return safe(() => setFindings(record, { targets, findings })).error;
85
+ return safe(() => setFindings(record, { plugin, targets, findings })).error;
72
86
  }
73
87
  catch (e_1) {
74
88
  env_1.error = e_1;