@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
@@ -1,118 +0,0 @@
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
2
- import { itemAt, present } from '../../utils/lookup.js';
3
- // Only an array or a plain object holds fields an edit walks into; a Set, Map, Date or class instance is one value, so an edit never turns it into a plain object no typed caller could pass.
4
- export const isHolder = (value) => {
5
- if (Array.isArray(value))
6
- return true;
7
- if (typeof value !== 'object' || value === null)
8
- return false;
9
- const prototype = Object.getPrototypeOf(value);
10
- return prototype === Object.prototype || prototype === null;
11
- };
12
- export const fieldOf = (holder, key) => {
13
- if (!isHolder(holder))
14
- return undefined;
15
- const field = Reflect.get(holder, key);
16
- return field;
17
- };
18
- export const readsOf = (value, run) => {
19
- const wrap = (target) => {
20
- const node = { keys: new Set(), children: new Map(), proxy: undefined };
21
- node.proxy = new Proxy(target, {
22
- get: (object, key) => {
23
- const inner = Reflect.get(object, key);
24
- if (typeof key !== 'string')
25
- return inner;
26
- node.keys.add(key);
27
- if (!isHolder(inner))
28
- return inner;
29
- let child = node.children.get(key);
30
- if (!child) {
31
- child = wrap(inner);
32
- node.children.set(key, child);
33
- }
34
- return child.proxy;
35
- },
36
- });
37
- return node;
38
- };
39
- const root = wrap(value);
40
- run(Object(root.proxy));
41
- return root;
42
- };
43
- // The reads of two runs over one shape, as one tree.
44
- export const merged = (a, b) => {
45
- if (!a || !b)
46
- return a ?? b;
47
- const node = { keys: new Set([...a.keys, ...b.keys]), children: new Map(), proxy: undefined };
48
- // A key both trees reached merges once per tree, which gives the same child again.
49
- for (const key of [...a.children.keys(), ...b.children.keys()])
50
- node.children.set(key, present(merged(a.children.get(key), b.children.get(key))));
51
- return node;
52
- };
53
- // The path to every number and string a run read.
54
- export const leafPathsOf = (value, node, path, found) => {
55
- for (const key of node.keys) {
56
- const inner = fieldOf(value, key);
57
- if (typeof inner === 'number' || typeof inner === 'string') {
58
- if (key !== 'length')
59
- found.push([...path, key]);
60
- }
61
- else {
62
- // A run that read a holder entered it, so only a holder has a child.
63
- const child = node.children.get(key);
64
- if (child)
65
- leafPathsOf(inner, child, [...path, key], found);
66
- }
67
- }
68
- return found;
69
- };
70
- export const valueAtPath = (value, path) => {
71
- let at = value;
72
- for (const key of path)
73
- at = fieldOf(at, key);
74
- return at;
75
- };
76
- export const copyOf = (value) => (Array.isArray(value) ? value.slice() : { ...Object(value) });
77
- // A value with the field at a path replaced, copying only the objects along the path.
78
- export const withAt = (value, path, depth, change) => {
79
- const key = itemAt(path, depth);
80
- const copy = copyOf(value);
81
- Reflect.set(copy, key, depth === path.length - 1 ? change(value, key) : withAt(fieldOf(value, key), path, depth + 1, change));
82
- return copy;
83
- };
84
- export const isIndex = (key) => !Number.isNaN(Number(key));
85
- // The nearest named holder, with a top-level argument index as the fallback for a positional seed.
86
- export const holderKeyOf = (path) => {
87
- let holderKey = path[0] ?? '';
88
- for (const each of path)
89
- if (!isIndex(each))
90
- holderKey = each;
91
- return holderKey;
92
- };
93
- export const sizeOf = (value) => {
94
- const root = Object(value);
95
- const stack = [{ value: root, fields: Object.values(root).values() }];
96
- const ancestors = new Set([root]);
97
- let size = 1;
98
- while (stack.length) {
99
- const frame = itemAt(stack, stack.length - 1);
100
- const field = frame.fields.next();
101
- if (field.done) {
102
- ancestors.delete(frame.value);
103
- stack.pop();
104
- continue;
105
- }
106
- size++;
107
- const inner = field.value;
108
- if (!isHolder(inner))
109
- continue;
110
- // Only ancestors form a cycle. A shared field still counts at each place it occurs.
111
- if (ancestors.has(inner))
112
- return Infinity;
113
- ancestors.add(inner);
114
- stack.push({ value: inner, fields: Object.values(inner).values() });
115
- }
116
- return size;
117
- };
118
- export const keysOf = (value) => Object.keys(Object(value));
@@ -1,21 +0,0 @@
1
- import type { Pools } from './pools.ts';
2
- import type { Random } from './draws.ts';
3
- import { type Path, type ReadNode } from './reads.ts';
4
- export type Plan = {
5
- numbers: [string, number][];
6
- strings: string[];
7
- children: [string, Plan][];
8
- resizes: string | undefined;
9
- free: number;
10
- };
11
- type TwinInput = {
12
- r: Random;
13
- pools: Pools;
14
- resized: (array: unknown[], key: string, holder?: unknown) => unknown[];
15
- };
16
- export type Twin = {
17
- planOf: (value: unknown, node: ReadNode | undefined, key: string, path: Path) => Plan | undefined;
18
- vary: (value: unknown, plan: Plan, holderKey?: string, holder?: unknown) => unknown;
19
- };
20
- export declare const twinOf: ({ r, pools, resized }: TwinInput) => Twin;
21
- export {};
@@ -1,55 +0,0 @@
1
- import { copyOf, fieldOf, isIndex, keysOf } from './reads.js';
2
- // The chance in a thousand each free field of the second side is redrawn.
3
- const varyChance = 500;
4
- // The chance in a hundred a free array of the second side changes length.
5
- const growChance = 25;
6
- export const twinOf = ({ r, pools, resized }) => {
7
- // The path is where the value sits in the input, so its last step names the field a resize keys on.
8
- const planOf = (value, node, key, path) => {
9
- const field = path.at(-1) ?? key;
10
- const isResizable = Array.isArray(value) && !node?.keys.has('length') && !pools.isTuple(path);
11
- const plan = { numbers: [], strings: [], children: [], resizes: isResizable ? field : undefined, free: 0 };
12
- for (const each of keysOf(value)) {
13
- const inner = fieldOf(value, each);
14
- if (typeof inner === 'number') {
15
- if (!node?.keys.has(each))
16
- plan.numbers.push([each, inner]);
17
- }
18
- else if (typeof inner === 'string') {
19
- if (!pools.isTag(key, each) && !node?.keys.has(each))
20
- plan.strings.push(each);
21
- }
22
- else {
23
- // Only a holder has fields to free, so a boolean or null plans nothing.
24
- const child = planOf(inner, node?.children.get(each), isIndex(each) ? key : each, path.concat(each));
25
- if (child) {
26
- plan.children.push([each, child]);
27
- plan.free += child.free;
28
- }
29
- }
30
- }
31
- plan.free += plan.numbers.length + plan.strings.length + (plan.resizes === undefined ? 0 : 1);
32
- return plan.free ? plan : undefined;
33
- };
34
- const vary = (value, plan, holderKey = '', holder) => {
35
- let copy;
36
- const set = (key, next) => {
37
- copy ??= copyOf(value);
38
- Reflect.set(copy, key, next);
39
- };
40
- for (const [key, current] of plan.numbers)
41
- if (r.int(0, 999) < varyChance)
42
- set(key, pools.drawNumber(key, current));
43
- for (const key of plan.strings)
44
- if (r.int(0, 999) < varyChance)
45
- set(key, pools.drawString(key, fieldOf(value, key), holderKey));
46
- for (const [key, child] of plan.children) {
47
- set(key, vary(fieldOf(value, key), child, isIndex(key) ? holderKey : key, value));
48
- }
49
- const varied = copy ?? value;
50
- if (plan.resizes !== undefined && Array.isArray(varied) && r.int(0, 99) < growChance)
51
- return resized(varied, plan.resizes, holder);
52
- return varied;
53
- };
54
- return { planOf, vary };
55
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,101 +0,0 @@
1
- var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
- if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
- return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
- return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
- });
6
- }
7
- return path;
8
- };
9
- import { join } from 'node:path';
10
- import { describe, expect, inject, it } from 'vite-plus/test';
11
- import { exploreExport } from '../explore/edges/explore.js';
12
- import { getCovered, getSeeds, getUnreplayable, setExploreRun, setFindings } from '../explore/edges/explore.db.js';
13
- import { explorableOf, graphOf, skippedOf, unexploredOf } from '../explore/targets.operations.js';
14
- import { shareOf } from '../explore/explore.operations.js';
15
- import { exploreBudgetOf } from '../explore/limits.operations.js';
16
- import { getReachEdges, getReachNodes } from '../record/edges/reach.db.js';
17
- import { openRecord } from '../record/edges/record.db.js';
18
- import { unitFieldsOf } from '../record/record.operations.js';
19
- import { exploreLimitsProvideKey, explorePathsProvideKey, exploreSeedProvideKey, recordPathOf, rootProvideKey } from './edges/vitest.js';
20
- import { testFilePattern } from './edges/plugin.js';
21
- // Crush's explore of every export the record's baselines called with data it kept, each for a throw from a site no test covered, in what the step's cap leaves after the property pass.
22
- const root = inject(rootProvideKey);
23
- const seed = inject(exploreSeedProvideKey);
24
- const record = openRecord(recordPathOf(root));
25
- const seeds = getSeeds(record);
26
- const covered = getCovered(record);
27
- const limits = inject(exploreLimitsProvideKey);
28
- // The paths a related explore names, or null for a full one, as the plugin provides them.
29
- const paths = inject(explorePathsProvideKey);
30
- const graph = graphOf({ nodes: getReachNodes(record), edges: getReachEdges(record) });
31
- // The runner collects properties before this test. Export search excludes edge-reaching targets and respects related paths.
32
- const candidates = [...seeds.keys()].filter((key) => !testFilePattern.test(unitFieldsOf(key)[0]));
33
- const explorable = new Set(explorableOf({ ...graph, keys: candidates, paths: paths && new Set(paths) }).map(({ key }) => key));
34
- const exports = [...seeds].filter(([key]) => explorable.has(key));
35
- describe('crush:explore', () => {
36
- it('explores every replayable export', { timeout: 0 }, async ({ annotate, crushExploreProperties }) => {
37
- const now = () => performance.now();
38
- const budget = exploreBudgetOf(limits, now);
39
- const targets = [
40
- ...(crushExploreProperties ?? []),
41
- ...exports.map(([key, lists]) => {
42
- let resume;
43
- return {
44
- key,
45
- search: async (slice) => {
46
- resume ??= exploreExport({ root, key, module: await import(__rewriteRelativeImportExtension(join(root, unitFieldsOf(key)[0]))), seeds: lists, covered, seed });
47
- return resume(slice);
48
- },
49
- };
50
- }),
51
- ];
52
- const found = new Set();
53
- const stopped = [];
54
- const spent = new Map();
55
- const searched = new Set();
56
- let active = targets;
57
- while (active.length && budget.isLeft()) {
58
- const again = [];
59
- for (const [index, target] of active.entries()) {
60
- if (!budget.isLeft())
61
- break;
62
- const { key } = target;
63
- const started = now();
64
- const used = budget.used();
65
- // A finite run shares its remaining time. An unlimited one uses slices so every target gets a turn.
66
- const leftMs = budget.remainingMs();
67
- const limitMs = Number.isFinite(leftMs) ? Math.max(1, shareOf({ leftMs, count: active.length - index })) : 2000;
68
- const takeRun = () => now() - started < limitMs && budget.takeRun();
69
- // oxlint-disable-next-line no-await-in-loop -- each target shares the same budget and saves its own result before the next one runs
70
- const explored = await target.search({ limitMs, now, takeRun });
71
- const ms = Math.round(now() - started);
72
- const reason = explored instanceof Error ? explored.message : explored.stopped;
73
- setExploreRun(record, { key, ms, at: Temporal.Now.instant().epochMilliseconds, stopped: reason });
74
- if (explored instanceof Error)
75
- throw explored;
76
- if (reason)
77
- stopped.push({ key, reason });
78
- if (explored.isSearched) {
79
- searched.add(key);
80
- spent.set(key, (spent.get(key) ?? 0) + ms);
81
- }
82
- if (explored.finding) {
83
- setFindings(record, { targets: [key], findings: [explored.finding] });
84
- found.add(key);
85
- }
86
- else if (!reason && (explored.isSearched || budget.used() > used || now() - started >= limitMs))
87
- again.push(target);
88
- }
89
- active = again;
90
- }
91
- setFindings(record, { targets: [...searched].filter((key) => !found.has(key)), findings: [] });
92
- await annotate(`${searched.size} of ${targets.length} targets explored from seed ${seed}, ${budget.used()} runs, ${found.size} findings`, 'explore');
93
- const isStopped = (key) => stopped.some((each) => each.key === key);
94
- const unsearched = targets.map(({ key }) => key).filter((key) => !searched.has(key) && !isStopped(key));
95
- const unexplorable = candidates.filter((key) => !explorable.has(key));
96
- const skipped = { unreplayable: getUnreplayable(record), unexplorable, stopped, unsearched };
97
- await annotate(['explored:', ...[...spent].map(([key, ms]) => `${key}: ${ms} ms`), 'skipped:', ...skippedOf(skipped)].join('\n'), 'targets');
98
- if (limits.runs !== 0)
99
- expect(searched.size || budget.used(), unexploredOf(skipped)).toBeGreaterThan(0);
100
- });
101
- });