@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.
- package/README.md +54 -14
- package/SKILL.md +4 -19
- package/dist/crush.tables.d.ts +26 -122
- package/dist/crush.tables.js +8 -21
- package/dist/instrument/instrument.operations.js +1 -1
- package/dist/judge/counters.d.ts +6 -0
- package/dist/judge/counters.js +89 -1
- package/dist/judge/edges/api.d.ts +24 -4
- package/dist/judge/edges/api.js +20 -6
- package/dist/judge/edges/hints.reporter.js +2 -2
- package/dist/judge/edges/judge.edges.d.ts +2 -3
- package/dist/judge/edges/judge.edges.js +1 -2
- package/dist/judge/edges/plugin.d.ts +12 -9
- package/dist/judge/edges/plugin.js +34 -49
- package/dist/judge/edges/plugin.npm.d.ts +2 -0
- package/dist/judge/edges/plugin.npm.js +2 -0
- package/dist/judge/edges/vitest.d.ts +1 -3
- package/dist/judge/edges/vitest.js +2 -3
- package/dist/judge/hints.d.ts +1 -1
- package/dist/judge/hints.js +0 -3
- package/dist/judge/judge.schema.d.ts +10 -1
- package/dist/judge/judge.schema.js +0 -2
- package/dist/judge/provided.d.ts +31 -0
- package/dist/judge/provided.js +2 -0
- package/dist/judge/refusals.d.ts +2 -2
- package/dist/judge/refusals.js +2 -2
- package/dist/judge/report.test.js +11 -12
- package/dist/judge/runner.js +35 -58
- package/dist/judge/task-meta.d.ts +0 -6
- package/dist/questions/questions.operations.d.ts +4 -3
- package/dist/questions/questions.operations.js +11 -11
- package/dist/questions/questions.schema.d.ts +3 -3
- package/dist/questions/questions.schema.js +2 -2
- package/dist/record/edges/findings.db.d.ts +16 -0
- package/dist/record/edges/findings.db.js +25 -0
- package/dist/record/edges/parts.db.d.ts +1 -1
- package/dist/record/edges/parts.db.js +3 -15
- 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/dist/record/parts.operations.d.ts +2 -3
- package/dist/record/parts.operations.js +1 -2
- package/migrations/main/20261206094906_plugin_findings/migration.sql +20 -0
- package/migrations/main/20261206094906_plugin_findings/snapshot.json +3652 -0
- package/migrations/main/20261206102548_drop_explore/migration.sql +17 -0
- package/migrations/main/20261206102548_drop_explore/snapshot.json +3550 -0
- package/package.json +3 -5
- package/references/consumer-setup.md +0 -1
- package/dist/explore/edges/explore.d.ts +0 -60
- package/dist/explore/edges/explore.db.d.ts +0 -22
- package/dist/explore/edges/explore.db.js +0 -55
- package/dist/explore/edges/explore.js +0 -305
- package/dist/explore/edges/random.d.ts +0 -2
- package/dist/explore/edges/random.js +0 -32
- package/dist/explore/explore.operations.d.ts +0 -30
- package/dist/explore/explore.operations.js +0 -117
- package/dist/explore/limits.operations.d.ts +0 -14
- package/dist/explore/limits.operations.js +0 -20
- package/dist/explore/targets.operations.d.ts +0 -36
- package/dist/explore/targets.operations.js +0 -32
- package/dist/explore/utils/draws.d.ts +0 -6
- package/dist/explore/utils/draws.js +0 -2
- package/dist/explore/utils/edits.d.ts +0 -15
- package/dist/explore/utils/edits.js +0 -151
- package/dist/explore/utils/guide.d.ts +0 -23
- package/dist/explore/utils/guide.js +0 -35
- package/dist/explore/utils/keep.d.ts +0 -10
- package/dist/explore/utils/keep.js +0 -61
- package/dist/explore/utils/pools.d.ts +0 -17
- package/dist/explore/utils/pools.js +0 -121
- package/dist/explore/utils/reads.d.ts +0 -19
- package/dist/explore/utils/reads.js +0 -118
- package/dist/explore/utils/twin.d.ts +0 -21
- package/dist/explore/utils/twin.js +0 -55
- package/dist/judge/explore.test.d.ts +0 -1
- package/dist/judge/explore.test.js +0 -101
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whaaaley/crush",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-next.11",
|
|
4
4
|
"description": "Mutation testing for TypeScript inside Vitest, built for agent loops",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"types": "./dist/judge/edges/plugin.d.ts",
|
|
14
|
-
"default": "./dist/judge/edges/plugin.js"
|
|
13
|
+
"types": "./dist/judge/edges/plugin.npm.d.ts",
|
|
14
|
+
"default": "./dist/judge/edges/plugin.npm.js"
|
|
15
15
|
},
|
|
16
16
|
"./reporter": {
|
|
17
17
|
"types": "./dist/judge/edges/completion.reporter.d.ts",
|
|
@@ -54,8 +54,6 @@
|
|
|
54
54
|
"judge": "vp test --run --mode judge --project judge --reporter ./src/judge/edges/completion.reporter.ts",
|
|
55
55
|
"judge:related": "vp test related --run --mode judge --project judge --reporter ./src/judge/edges/completion.reporter.ts",
|
|
56
56
|
"judge:redundant": "vp test --run --mode redundant --project judge --reporter ./src/judge/edges/completion.reporter.ts",
|
|
57
|
-
"explore": "vp test --run --mode explore --project explore --reporter default --reporter ./src/judge/edges/hints.reporter.ts",
|
|
58
|
-
"explore:related": "vp test related --run --mode explore --project explore --reporter default --reporter ./src/judge/edges/hints.reporter.ts",
|
|
59
57
|
"questions": "vp test --run --mode questions --project questions --reporter default --reporter ./src/judge/edges/hints.reporter.ts",
|
|
60
58
|
"questions:related": "vp test related --run --mode questions --project questions --reporter default --reporter ./src/judge/edges/hints.reporter.ts",
|
|
61
59
|
"stresses": "vp test --run --mode stresses --project stresses",
|
|
@@ -77,7 +77,6 @@ declare module 'vite-plus/test' {
|
|
|
77
77
|
```
|
|
78
78
|
|
|
79
79
|
crush's declaration gives `steps` a numeric type, `answers` a string or a list of strings, and `keeps` and `stepsReason` string types.
|
|
80
|
-
Revisions that support explore also declare `explores` as a string.
|
|
81
80
|
|
|
82
81
|
## Justifications
|
|
83
82
|
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { type stateOf } from '../../judge/counters.ts';
|
|
3
|
-
import { type Safe } from '../../utils/safe.ts';
|
|
4
|
-
export type Finding = {
|
|
5
|
-
key: string;
|
|
6
|
-
kind: 'throw' | 'property';
|
|
7
|
-
target: string;
|
|
8
|
-
file: string;
|
|
9
|
-
line: number;
|
|
10
|
-
function: string;
|
|
11
|
-
input: string;
|
|
12
|
-
sourceHash: string;
|
|
13
|
-
};
|
|
14
|
-
export declare const exploresMeta: z.ZodObject<{
|
|
15
|
-
explores: z.ZodString;
|
|
16
|
-
twin: z.ZodOptional<z.ZodObject<{
|
|
17
|
-
first: z.ZodString;
|
|
18
|
-
second: z.ZodString;
|
|
19
|
-
related: z.ZodString;
|
|
20
|
-
}, z.core.$strip>>;
|
|
21
|
-
}, z.core.$strip>;
|
|
22
|
-
export type Explored = {
|
|
23
|
-
finding: Finding | null;
|
|
24
|
-
isSearched: boolean;
|
|
25
|
-
stopped: string | null;
|
|
26
|
-
};
|
|
27
|
-
export type ExploreSlice = {
|
|
28
|
-
limitMs: number;
|
|
29
|
-
now: () => number;
|
|
30
|
-
takeRun?: () => boolean;
|
|
31
|
-
};
|
|
32
|
-
export type ExploreTarget = {
|
|
33
|
-
key: string;
|
|
34
|
-
search: (slice: ExploreSlice) => Explored | Error;
|
|
35
|
-
};
|
|
36
|
-
type Counted<T> = Safe<T, Error> & {
|
|
37
|
-
ticks: number;
|
|
38
|
-
isPastLimit: boolean;
|
|
39
|
-
};
|
|
40
|
-
export declare const countedOn: (counters: ReturnType<typeof stateOf>) => <T>(counts: Map<string, number>, call: () => T, limit: number) => Counted<T>;
|
|
41
|
-
export declare const lineOf: (source: string, name: string, file?: string) => number;
|
|
42
|
-
type PropertyInput = {
|
|
43
|
-
file: string;
|
|
44
|
-
source: string;
|
|
45
|
-
module: unknown;
|
|
46
|
-
meta: z.infer<typeof exploresMeta>;
|
|
47
|
-
seeds: unknown[][];
|
|
48
|
-
seed: number;
|
|
49
|
-
};
|
|
50
|
-
export declare const exploreProperty: ({ file, source, module, meta, seeds, seed }: PropertyInput) => ExploreTarget['search'];
|
|
51
|
-
type ExportInput = {
|
|
52
|
-
root: string;
|
|
53
|
-
key: string;
|
|
54
|
-
module: unknown;
|
|
55
|
-
seeds: unknown[][];
|
|
56
|
-
covered: ReadonlySet<string>;
|
|
57
|
-
seed: number;
|
|
58
|
-
};
|
|
59
|
-
export declare const exploreExport: ({ root, key, module, seeds, covered, seed }: ExportInput) => ((slice: ExploreSlice) => Explored);
|
|
60
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { exploreFindings } from '../../crush.tables.ts';
|
|
2
|
-
import { type Record } from '../../record/edges/record.db.ts';
|
|
3
|
-
export declare const getSeeds: (db: Record) => Map<string, unknown[][]>;
|
|
4
|
-
export declare const getUnreplayable: (db: Record) => string[];
|
|
5
|
-
export declare const getCovered: (db: Record) => Set<string>;
|
|
6
|
-
export declare const clearExploreRuns: (db: Record) => void;
|
|
7
|
-
type ExploreRun = {
|
|
8
|
-
key: string;
|
|
9
|
-
ms: number;
|
|
10
|
-
at: number;
|
|
11
|
-
stopped: string | null;
|
|
12
|
-
};
|
|
13
|
-
export declare const setExploreRun: (db: Record, { key, ms, at, stopped }: ExploreRun) => void;
|
|
14
|
-
export type Finding = Omit<typeof exploreFindings.$inferInsert, 'findingKey'> & {
|
|
15
|
-
key: string;
|
|
16
|
-
};
|
|
17
|
-
export declare const setFindings: (db: Record, { targets, findings }: {
|
|
18
|
-
targets: readonly string[];
|
|
19
|
-
findings: Finding[];
|
|
20
|
-
}) => void;
|
|
21
|
-
export declare const getFindings: (db: Record) => Finding[];
|
|
22
|
-
export {};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { asc, inArray, sql } from 'drizzle-orm';
|
|
2
|
-
import { uncloned } from '../../capture/capture.operations.js';
|
|
3
|
-
import { exploreFindings, exploreRuns } from '../../crush.tables.js';
|
|
4
|
-
import { getExportCalls } from '../../record/edges/calls.db.js';
|
|
5
|
-
import { chunksOf } from '../../record/edges/record.db.js';
|
|
6
|
-
// Replayable argument lists in baseline order, leaving out only calls with an uncloned argument.
|
|
7
|
-
export const getSeeds = (db) => {
|
|
8
|
-
const seeds = new Map();
|
|
9
|
-
for (const { exportKey, args } of getExportCalls(db)) {
|
|
10
|
-
if (args.includes(uncloned))
|
|
11
|
-
continue;
|
|
12
|
-
const lists = seeds.get(exportKey) ?? [];
|
|
13
|
-
lists.push(args);
|
|
14
|
-
seeds.set(exportKey, lists);
|
|
15
|
-
}
|
|
16
|
-
return seeds;
|
|
17
|
-
};
|
|
18
|
-
// Exports with captured calls and no replayable argument list.
|
|
19
|
-
export const getUnreplayable = (db) => {
|
|
20
|
-
const byExport = Map.groupBy(getExportCalls(db), ({ exportKey }) => exportKey);
|
|
21
|
-
return [...byExport].flatMap(([key, calls]) => (calls.every(({ args }) => args.includes(uncloned)) ? [key] : [])).toSorted();
|
|
22
|
-
};
|
|
23
|
-
// Each throw site a baseline's call raised, as `path:line`, which explore counts as covered; a thrown value that is no Error has no site.
|
|
24
|
-
export const getCovered = (db) => new Set(getExportCalls(db).flatMap(({ thrownAt }) => thrownAt ?? []));
|
|
25
|
-
// The timing table describes the current Explore invocation.
|
|
26
|
-
export const clearExploreRuns = (db) => {
|
|
27
|
-
db.delete(exploreRuns).run();
|
|
28
|
-
};
|
|
29
|
-
export const setExploreRun = (db, { key, ms, at, stopped }) => {
|
|
30
|
-
const exploredAt = new Date(at);
|
|
31
|
-
db.insert(exploreRuns)
|
|
32
|
-
.values({ targetKey: key, ms, exploredAt, stopped })
|
|
33
|
-
.onConflictDoUpdate({ target: exploreRuns.targetKey, set: { ms: sql `${exploreRuns.ms} + ${ms}`, exploredAt, stopped } })
|
|
34
|
-
.run();
|
|
35
|
-
};
|
|
36
|
-
// Replaces the findings of the targets an explore ran with what it found, leaving every other target's as they were, so a site two targets reach keeps the evidence of each.
|
|
37
|
-
export const setFindings = (db, { targets, findings }) => {
|
|
38
|
-
db.transaction((tx) => {
|
|
39
|
-
const targetChunks = chunksOf(targets.map((target) => ({ target }))).map((chunk) => chunk.map(({ target }) => target));
|
|
40
|
-
for (const chunk of targetChunks)
|
|
41
|
-
tx.delete(exploreFindings).where(inArray(exploreFindings.target, chunk)).run();
|
|
42
|
-
for (const chunk of chunksOf(findings)) {
|
|
43
|
-
const rows = chunk.map(({ key, ...finding }) => Object.assign(finding, { findingKey: key }));
|
|
44
|
-
tx.insert(exploreFindings).values(rows).run();
|
|
45
|
-
}
|
|
46
|
-
}, { behavior: 'immediate' });
|
|
47
|
-
};
|
|
48
|
-
export const getFindings = (db) => {
|
|
49
|
-
return db
|
|
50
|
-
.select()
|
|
51
|
-
.from(exploreFindings)
|
|
52
|
-
.orderBy(asc(exploreFindings.findingKey), asc(exploreFindings.target))
|
|
53
|
-
.all()
|
|
54
|
-
.map(({ findingKey, ...finding }) => Object.assign(finding, { key: findingKey }));
|
|
55
|
-
};
|
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
-
if (value !== null && value !== void 0) {
|
|
3
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose, inner;
|
|
5
|
-
if (async) {
|
|
6
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
-
dispose = value[Symbol.asyncDispose];
|
|
8
|
-
}
|
|
9
|
-
if (dispose === void 0) {
|
|
10
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
-
dispose = value[Symbol.dispose];
|
|
12
|
-
if (async) inner = dispose;
|
|
13
|
-
}
|
|
14
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
-
}
|
|
18
|
-
else if (async) {
|
|
19
|
-
env.stack.push({ async: true });
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
-
return function (env) {
|
|
25
|
-
function fail(e) {
|
|
26
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
-
env.hasError = true;
|
|
28
|
-
}
|
|
29
|
-
var r, s = 0;
|
|
30
|
-
function next() {
|
|
31
|
-
while (r = env.stack.pop()) {
|
|
32
|
-
try {
|
|
33
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
-
if (r.dispose) {
|
|
35
|
-
var result = r.dispose.call(r.value);
|
|
36
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
-
}
|
|
38
|
-
else s |= 1;
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
fail(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
-
if (env.hasError) throw env.error;
|
|
46
|
-
}
|
|
47
|
-
return next();
|
|
48
|
-
};
|
|
49
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
-
var e = new Error(message);
|
|
51
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
-
});
|
|
53
|
-
// oxlint-disable typescript/no-unsafe-argument, typescript/no-unsafe-assignment, typescript/no-unsafe-return -- this file handles values the code under test makes, passes or throws, which no static type names
|
|
54
|
-
import { readFileSync } from 'node:fs';
|
|
55
|
-
import { join } from 'node:path';
|
|
56
|
-
import { parseSync } from 'oxc-parser';
|
|
57
|
-
import { z } from 'zod';
|
|
58
|
-
import { encodedOf, snapshotOf, throwLocationOf } from '../../capture/capture.operations.js';
|
|
59
|
-
import { hashOf, unitFieldsOf, unitKeyOf } from '../../record/record.operations.js';
|
|
60
|
-
import { limitedRun, state, stepLimitOf } from '../../judge/counters.js';
|
|
61
|
-
import { safe, ThrownValue } from '../../utils/safe.js';
|
|
62
|
-
import { locate } from '../../utils/ast.js';
|
|
63
|
-
import { itemAt } from '../../utils/lookup.js';
|
|
64
|
-
import { drawsOf } from '../utils/draws.js';
|
|
65
|
-
import { seededDraw } from './random.js';
|
|
66
|
-
import { searchOf } from '../explore.operations.js';
|
|
67
|
-
// The id the counters credit an explored call's sides to, so a run reads its sides off the passes as a test's baseline does.
|
|
68
|
-
const exploreId = 'crush:explore';
|
|
69
|
-
// A property's two sides and the export holding the relation between them, as a test's meta declares it.
|
|
70
|
-
const twinMeta = z.object({ first: z.string(), second: z.string(), related: z.string() });
|
|
71
|
-
// What a test's `meta` declares for explore: the export of its own file that maps an input to a verdict, and for a two-run property its twin.
|
|
72
|
-
export const exploresMeta = z.object({ explores: z.string(), twin: twinMeta.optional() });
|
|
73
|
-
const verdictOutput = z.enum(['passed', 'discarded', 'failed']);
|
|
74
|
-
// A property's verdict, a throw from it reading as failed, and an answer that is no verdict as an error the search ends on.
|
|
75
|
-
const verdictOf = (result) => {
|
|
76
|
-
if (result.error)
|
|
77
|
-
return 'failed';
|
|
78
|
-
const parsed = verdictOutput.safeParse(result.data);
|
|
79
|
-
return parsed.success ? parsed.data : new Error(`an explore property answered ${encodedOf(snapshotOf(result.data))}, which is no verdict`);
|
|
80
|
-
};
|
|
81
|
-
// Whether a call handed back a thenable, a promise of any realm among them, whose work explore cannot wait on, so both its outcomes are handled here rather than a rejection left unhandled.
|
|
82
|
-
// A `then` that cannot be read leaves the answer no thenable, while one that throws as it is attached is a thenable all the same.
|
|
83
|
-
const isPromised = (data) => {
|
|
84
|
-
if ((typeof data !== 'object' && typeof data !== 'function') || data === null)
|
|
85
|
-
return false;
|
|
86
|
-
const { data: then } = safe(() => ('then' in data ? data.then : undefined));
|
|
87
|
-
if (typeof then !== 'function')
|
|
88
|
-
return false;
|
|
89
|
-
safe(() => Reflect.apply(then, data, [() => null, () => null]));
|
|
90
|
-
return true;
|
|
91
|
-
};
|
|
92
|
-
// `limit` is the most ticks the call may take, as a rerun's is, 0 for none, so a call that would run past the cap stops.
|
|
93
|
-
export const countedOn = (counters) => {
|
|
94
|
-
return (counts, call, limit) => {
|
|
95
|
-
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
96
|
-
try {
|
|
97
|
-
const { current, isCapturing, isLimitHit } = counters;
|
|
98
|
-
const started = counters.ticks;
|
|
99
|
-
// The counters go back however the call ends, so a judging run after it credits its own test and captures again.
|
|
100
|
-
const restored = __addDisposableResource(env_1, new DisposableStack(), false);
|
|
101
|
-
restored.defer(() => {
|
|
102
|
-
counters.passes.clear();
|
|
103
|
-
counters.current = current;
|
|
104
|
-
counters.isCapturing = isCapturing;
|
|
105
|
-
counters.isLimitHit = isLimitHit;
|
|
106
|
-
});
|
|
107
|
-
counters.current = exploreId;
|
|
108
|
-
// An explored call is no test's, so capture keeps none of the calls it makes.
|
|
109
|
-
counters.isCapturing = false;
|
|
110
|
-
counters.passes.clear();
|
|
111
|
-
counters.isLimitHit = false;
|
|
112
|
-
const result = safe(() => limitedRun(counters, limit, call));
|
|
113
|
-
for (const [key, passes] of counters.passes)
|
|
114
|
-
counts.set(String(key), passes);
|
|
115
|
-
return Object.assign(result, { ticks: counters.ticks - started, isPastLimit: counters.isLimitHit });
|
|
116
|
-
}
|
|
117
|
-
catch (e_1) {
|
|
118
|
-
env_1.error = e_1;
|
|
119
|
-
env_1.hasError = true;
|
|
120
|
-
}
|
|
121
|
-
finally {
|
|
122
|
-
__disposeResources(env_1);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
const counted = countedOn(state);
|
|
127
|
-
// The rerun limit of the longest seed, each seed run once with no limit as the tests ran it, so every search call, the first variation included, runs within it; null when a seed answers with a promise.
|
|
128
|
-
const seedLimitOf = (seeds, call) => {
|
|
129
|
-
let mostTicks = 0;
|
|
130
|
-
let next = 0;
|
|
131
|
-
return (takeRun) => {
|
|
132
|
-
while (next < seeds.length) {
|
|
133
|
-
if (takeRun && !takeRun())
|
|
134
|
-
return undefined;
|
|
135
|
-
const each = itemAt(seeds, next++);
|
|
136
|
-
const { data, ticks } = counted(new Map(), () => call(structuredClone(each)), 0);
|
|
137
|
-
if (isPromised(data))
|
|
138
|
-
return null;
|
|
139
|
-
mostTicks = Math.max(mostTicks, ticks);
|
|
140
|
-
}
|
|
141
|
-
return stepLimitOf(mostTicks);
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
// An export a module holds under a name, or null when it is no function, since only a function can be explored.
|
|
145
|
-
const functionOf = (module, name) => {
|
|
146
|
-
const found = Reflect.get(Object(module), name);
|
|
147
|
-
if (typeof found !== 'function')
|
|
148
|
-
return null;
|
|
149
|
-
return (...args) => Reflect.apply(found, undefined, args);
|
|
150
|
-
};
|
|
151
|
-
// The line where a runtime export is named, including an export specifier or alias.
|
|
152
|
-
export const lineOf = (source, name, file = 'property.ts') => {
|
|
153
|
-
const { module } = parseSync(file, source);
|
|
154
|
-
for (const { entries } of module.staticExports) {
|
|
155
|
-
for (const { exportName, isType } of entries) {
|
|
156
|
-
const exported = exportName.kind === 'Default' ? 'default' : exportName.name;
|
|
157
|
-
if (!isType && exported === name && exportName.start !== null)
|
|
158
|
-
return locate(source)(exportName.start).line;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return 0;
|
|
162
|
-
};
|
|
163
|
-
// Explores a property a test file exports and its test declares, from the inputs its own test passed it, failing on a verdict of failed or a throw.
|
|
164
|
-
// A property or relation its test names but its file does not export as a function is refused as an error, so a misspelled one never explores in silence.
|
|
165
|
-
export const exploreProperty = ({ file, source, module, meta, seeds, seed }) => {
|
|
166
|
-
const property = functionOf(module, meta.explores);
|
|
167
|
-
const related = meta.twin ? functionOf(module, meta.twin.related) : null;
|
|
168
|
-
if (!property)
|
|
169
|
-
return () => new Error(`${file} exports no function ${meta.explores} for explore`);
|
|
170
|
-
if (meta.twin && !related)
|
|
171
|
-
return () => new Error(`${file} exports no function ${meta.twin?.related} for explore`);
|
|
172
|
-
// A two-run property reads its sides as fields of its input, so its input must be an object; any other property's input is held under one field, so a number or a string reaches it as it was passed.
|
|
173
|
-
if (meta.twin && seeds.some(([input]) => typeof input !== 'object' || input === null))
|
|
174
|
-
return () => new Error(`${file} declares ${meta.explores} a two-run property, but its test passed it an input that is no object`);
|
|
175
|
-
const inputOf = (held) => (meta.twin ? held : 'input' in held ? held.input : undefined);
|
|
176
|
-
const counts = new Map();
|
|
177
|
-
// An answer that is no verdict, or a relation that throws, ends the search with it, as the first such answer refuses the property.
|
|
178
|
-
const refused = { error: null };
|
|
179
|
-
const promised = new Error(`${file}'s property ${meta.explores} answered a promise, which explore cannot wait on`);
|
|
180
|
-
// Every call, its relation's too, runs within the rerun limit of the longest seed, so one past it stops the search as an export's does.
|
|
181
|
-
const calibrate = seedLimitOf(seeds, ([input]) => property(input));
|
|
182
|
-
let limit = 0;
|
|
183
|
-
let calls = 0;
|
|
184
|
-
let stopped = null;
|
|
185
|
-
const judged = (held) => {
|
|
186
|
-
if (refused.error || stopped)
|
|
187
|
-
return 'stopped';
|
|
188
|
-
calls++;
|
|
189
|
-
const answered = counted(counts, () => property(inputOf(held)), limit);
|
|
190
|
-
if (answered.isPastLimit) {
|
|
191
|
-
stopped = 'a call ran past its limit';
|
|
192
|
-
return 'stopped';
|
|
193
|
-
}
|
|
194
|
-
if (isPromised(answered.data)) {
|
|
195
|
-
refused.error ??= promised;
|
|
196
|
-
return 'stopped';
|
|
197
|
-
}
|
|
198
|
-
const verdict = verdictOf(answered);
|
|
199
|
-
if (!(verdict instanceof Error))
|
|
200
|
-
return verdict;
|
|
201
|
-
refused.error = verdict;
|
|
202
|
-
return 'stopped';
|
|
203
|
-
};
|
|
204
|
-
const target = { seeds: seeds.map(([input]) => (meta.twin ? Object(input) : { input })), property: judged, counts };
|
|
205
|
-
if (meta.twin && related) {
|
|
206
|
-
const relation = meta.twin.related;
|
|
207
|
-
const relatedOf = (input) => {
|
|
208
|
-
if (refused.error || stopped)
|
|
209
|
-
return false;
|
|
210
|
-
const { data, error, isPastLimit } = counted(new Map(), () => related(input), limit);
|
|
211
|
-
if (isPastLimit)
|
|
212
|
-
stopped = 'a call ran past its limit';
|
|
213
|
-
else if (error)
|
|
214
|
-
refused.error ??= new Error(`${file}'s relation ${relation} threw: ${error.message}`);
|
|
215
|
-
else if (isPromised(data))
|
|
216
|
-
refused.error ??= new Error(`${file}'s relation ${relation} answered a promise, which explore cannot wait on`);
|
|
217
|
-
return !refused.error && !stopped && Boolean(data);
|
|
218
|
-
};
|
|
219
|
-
target.twin = { first: meta.twin.first, second: meta.twin.second, related: relatedOf };
|
|
220
|
-
}
|
|
221
|
-
let resume;
|
|
222
|
-
return (slice) => {
|
|
223
|
-
if (slice.limitMs <= 0)
|
|
224
|
-
return { finding: null, isSearched: false, stopped: null };
|
|
225
|
-
const calibrated = calibrate(slice.takeRun);
|
|
226
|
-
if (calibrated === undefined)
|
|
227
|
-
return { finding: null, isSearched: false, stopped: null };
|
|
228
|
-
if (calibrated === null)
|
|
229
|
-
return promised;
|
|
230
|
-
limit = calibrated;
|
|
231
|
-
resume ??= searchOf({ target, random: drawsOf(seededDraw(seed)) });
|
|
232
|
-
const was = calls;
|
|
233
|
-
const found = resume(slice);
|
|
234
|
-
if (refused.error)
|
|
235
|
-
return refused.error;
|
|
236
|
-
if (stopped)
|
|
237
|
-
return { finding: null, isSearched: false, stopped };
|
|
238
|
-
if (!found)
|
|
239
|
-
return { finding: null, isSearched: calls > was, stopped: null };
|
|
240
|
-
const key = unitKeyOf(file, meta.explores);
|
|
241
|
-
const finding = { key, kind: 'property', target: key, file, line: lineOf(source, meta.explores, file), function: meta.explores, input: encodedOf(snapshotOf(inputOf(found.input))), sourceHash: hashOf(source) };
|
|
242
|
-
return { finding, isSearched: true, stopped: null };
|
|
243
|
-
};
|
|
244
|
-
};
|
|
245
|
-
// Explores an export for a throw from a site no test covered, varying the argument lists the tests passed it; a covered throw is a refusal the tests already expect.
|
|
246
|
-
export const exploreExport = ({ root, key, module, seeds, covered, seed }) => {
|
|
247
|
-
const [, name] = unitFieldsOf(key);
|
|
248
|
-
const fn = functionOf(module, name);
|
|
249
|
-
// An export the capture saw called is a function, unless its module changed since, which leaves nothing to explore.
|
|
250
|
-
if (!fn)
|
|
251
|
-
return () => ({ finding: null, isSearched: false, stopped: null });
|
|
252
|
-
const counts = new Map();
|
|
253
|
-
// The uncovered site the failing call threw from, which names the finding, with the file and line it is asked at.
|
|
254
|
-
const failed = { site: '', file: '', line: 0 };
|
|
255
|
-
// A thrown value that is no Error carries no stack of its own, so it names no site and is no finding.
|
|
256
|
-
const siteOf = (error) => {
|
|
257
|
-
if (error instanceof ThrownValue)
|
|
258
|
-
return null;
|
|
259
|
-
const location = throwLocationOf({ stack: error.stack ?? '', root });
|
|
260
|
-
return location && { ...location, site: `${location.file}:${location.line}` };
|
|
261
|
-
};
|
|
262
|
-
// Only a call that answered synchronously within its limit was judged, so an export that answers with a promise, or runs past its limit, is stopped and named with why.
|
|
263
|
-
const promised = 'it answers with a promise, which explore cannot wait on';
|
|
264
|
-
const calibrate = seedLimitOf(seeds, (args) => fn(...args));
|
|
265
|
-
let limit = 0;
|
|
266
|
-
let calls = 0;
|
|
267
|
-
let stopped = null;
|
|
268
|
-
const judged = (input) => {
|
|
269
|
-
const args = Object.values(input);
|
|
270
|
-
const { data, error, isPastLimit } = counted(counts, () => fn(...args), limit);
|
|
271
|
-
// An export that answers with a promise does its work where explore cannot wait, so its first promise stops the search.
|
|
272
|
-
if (isPromised(data))
|
|
273
|
-
stopped = promised;
|
|
274
|
-
else if (isPastLimit)
|
|
275
|
-
stopped = 'a call ran past its limit';
|
|
276
|
-
if (stopped)
|
|
277
|
-
return 'stopped';
|
|
278
|
-
calls++;
|
|
279
|
-
const thrown = error ? siteOf(error) : null;
|
|
280
|
-
if (!thrown || covered.has(thrown.site))
|
|
281
|
-
return 'passed';
|
|
282
|
-
Object.assign(failed, thrown);
|
|
283
|
-
return 'failed';
|
|
284
|
-
};
|
|
285
|
-
const target = { seeds: seeds.map((args) => Object.fromEntries(args.entries())), property: judged, counts };
|
|
286
|
-
let resume;
|
|
287
|
-
return (slice) => {
|
|
288
|
-
if (slice.limitMs <= 0)
|
|
289
|
-
return { finding: null, isSearched: false, stopped: null };
|
|
290
|
-
const calibrated = calibrate(slice.takeRun);
|
|
291
|
-
if (calibrated === undefined)
|
|
292
|
-
return { finding: null, isSearched: false, stopped: null };
|
|
293
|
-
if (calibrated === null)
|
|
294
|
-
return { finding: null, isSearched: false, stopped: promised };
|
|
295
|
-
limit = calibrated;
|
|
296
|
-
resume ??= searchOf({ target, random: drawsOf(seededDraw(seed)) });
|
|
297
|
-
const was = calls;
|
|
298
|
-
const found = resume(slice);
|
|
299
|
-
if (!found)
|
|
300
|
-
return { finding: null, isSearched: calls > was && !stopped, stopped };
|
|
301
|
-
const atSource = readFileSync(join(root, failed.file), 'utf8');
|
|
302
|
-
const finding = { key: failed.site, kind: 'throw', target: key, file: failed.file, line: failed.line, function: name, input: encodedOf(snapshotOf(Object.values(found.input))), sourceHash: hashOf(atSource) };
|
|
303
|
-
return { finding, isSearched: true, stopped: null };
|
|
304
|
-
};
|
|
305
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const rotated = (word, by) => (word << by) | (word >>> (32 - by));
|
|
2
|
-
// One step of splitmix32, which spreads a small seed over the four words xoshiro128** needs, since an all-zero state would draw only zeros.
|
|
3
|
-
const splitmixOf = (seed) => {
|
|
4
|
-
let at = seed;
|
|
5
|
-
return () => {
|
|
6
|
-
at = (at + 0x9e3779b9) | 0;
|
|
7
|
-
let mixed = at;
|
|
8
|
-
mixed = Math.imul(mixed ^ (mixed >>> 16), 0x85ebca6b);
|
|
9
|
-
mixed = Math.imul(mixed ^ (mixed >>> 13), 0xc2b2ae35);
|
|
10
|
-
return mixed ^ (mixed >>> 16);
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
// A seeded xoshiro128** over 32-bit words, every operation wrapping as an integer one does, so one seed draws one sequence on every machine.
|
|
14
|
-
export const seededDraw = (seed) => {
|
|
15
|
-
const spread = splitmixOf(seed);
|
|
16
|
-
let a = spread();
|
|
17
|
-
let b = spread();
|
|
18
|
-
let c = spread();
|
|
19
|
-
let d = spread();
|
|
20
|
-
const next = () => {
|
|
21
|
-
const drawn = Math.imul(rotated(Math.imul(b, 5), 7), 9) >>> 0;
|
|
22
|
-
const shifted = b << 9;
|
|
23
|
-
c ^= a;
|
|
24
|
-
d ^= b;
|
|
25
|
-
b ^= c;
|
|
26
|
-
a ^= d;
|
|
27
|
-
c ^= shifted;
|
|
28
|
-
d = rotated(d, 11);
|
|
29
|
-
return drawn;
|
|
30
|
-
};
|
|
31
|
-
return (min, max) => min + Math.floor((next() / 0x1_0000_0000) * (max - min + 1));
|
|
32
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Random } from './utils/draws.ts';
|
|
2
|
-
export type Verdict = 'passed' | 'discarded' | 'failed' | 'stopped';
|
|
3
|
-
export type Target = {
|
|
4
|
-
seeds: object[];
|
|
5
|
-
property: (input: object) => Verdict;
|
|
6
|
-
counts: Map<string, number>;
|
|
7
|
-
twin?: {
|
|
8
|
-
first: string;
|
|
9
|
-
second: string;
|
|
10
|
-
related: (input: object) => boolean;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export type Found = {
|
|
14
|
-
input: object;
|
|
15
|
-
} | undefined;
|
|
16
|
-
type SearchBudget = {
|
|
17
|
-
limitMs: number;
|
|
18
|
-
now: () => number;
|
|
19
|
-
takeRun?: () => boolean;
|
|
20
|
-
};
|
|
21
|
-
type SearchInput = {
|
|
22
|
-
target: Target;
|
|
23
|
-
random: Random;
|
|
24
|
-
} & SearchBudget;
|
|
25
|
-
export declare const searchOf: ({ target, random: r }: Pick<SearchInput, 'target' | 'random'>) => ((budget: SearchBudget) => Found);
|
|
26
|
-
export declare const shareOf: ({ leftMs, count }: {
|
|
27
|
-
leftMs: number;
|
|
28
|
-
count: number;
|
|
29
|
-
}) => number;
|
|
30
|
-
export {};
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { editsOf } from './utils/edits.js';
|
|
2
|
-
import { readPathsOf, sizeLimitOf, twinReadsOf } from './utils/guide.js';
|
|
3
|
-
import { keptInputsOf } from './utils/keep.js';
|
|
4
|
-
import { poolsOf } from './utils/pools.js';
|
|
5
|
-
import { twinOf } from './utils/twin.js';
|
|
6
|
-
import { fieldOf, holderKeyOf, withAt } from './utils/reads.js';
|
|
7
|
-
import { itemAt } from '../utils/lookup.js';
|
|
8
|
-
// The settings crush+fable's were frozen at, from generic.ts.
|
|
9
|
-
// `most` is the most second sides one edited input gets, `tries` how often an edit the property discards is drawn again.
|
|
10
|
-
const settings = { most: 12, tries: 16 };
|
|
11
|
-
// A port of generic.ts, crush+fable with nothing of one target in it: every name, value and shape it uses is read off the seeds and the inputs it keeps.
|
|
12
|
-
export const searchOf = ({ target, random: r }) => {
|
|
13
|
-
const { counts } = target;
|
|
14
|
-
// A target with no seed has nothing to vary, so the search finds nothing.
|
|
15
|
-
if (!target.seeds.length)
|
|
16
|
-
return () => undefined;
|
|
17
|
-
// Every call of the target counts against the budget, its relation's and the seeds' first runs included, so the clock starts before any and is read before each; a spent budget or a stopped target calls neither again.
|
|
18
|
-
let isSpent = false;
|
|
19
|
-
let isDone = false;
|
|
20
|
-
let take = () => false;
|
|
21
|
-
// An input a run on the plain input failed on, whichever step ran it, a seed's path, an edit's discard check or its test, so no failure seen is lost; once one is seen the target runs no more, and the search returns it.
|
|
22
|
-
let failedOn = null;
|
|
23
|
-
// Guidance runs the target on a proxy that tracks its reads, which the target may refuse where it accepts the plain input, as `structuredClone` does, so only a plain run's failure is kept as a finding.
|
|
24
|
-
// Run on a copy so writes cannot change the corpus or the input saved with a finding.
|
|
25
|
-
const runOn = (input, isPlain) => {
|
|
26
|
-
if (isDone || failedOn || !take())
|
|
27
|
-
return 'stopped';
|
|
28
|
-
const verdict = target.property(isPlain ? structuredClone(input) : input);
|
|
29
|
-
if (verdict === 'stopped')
|
|
30
|
-
isDone = true;
|
|
31
|
-
if (isPlain && verdict === 'failed')
|
|
32
|
-
failedOn = input;
|
|
33
|
-
return verdict;
|
|
34
|
-
};
|
|
35
|
-
const property = (input) => runOn(input, true);
|
|
36
|
-
const guided = (input) => runOn(input, false);
|
|
37
|
-
const ownTwin = target.twin;
|
|
38
|
-
const twin = ownTwin && { ...ownTwin, related: (input) => !isDone && !failedOn && take() && ownTwin.related(input) };
|
|
39
|
-
// An input without its second side, which is what gets kept and edited, and the same with its first side standing on both.
|
|
40
|
-
const baseOf = (input) => (twin ? withAt(input, [twin.second], 0, () => null) : input);
|
|
41
|
-
const mirrored = (base) => (twin ? withAt(base, [twin.second], 0, (holder) => fieldOf(holder, twin.first)) : base);
|
|
42
|
-
const forRead = (base) => structuredClone(mirrored(base));
|
|
43
|
-
const pools = poolsOf(r);
|
|
44
|
-
const { learnInput } = pools;
|
|
45
|
-
const seedBases = target.seeds.map(baseOf);
|
|
46
|
-
const kept = keptInputsOf(r, learnInput, sizeLimitOf(seedBases));
|
|
47
|
-
const { queue, groupList, join } = kept;
|
|
48
|
-
const check = (base) => {
|
|
49
|
-
counts.clear();
|
|
50
|
-
return property(mirrored(base));
|
|
51
|
-
};
|
|
52
|
-
// The seeds are learned twice, since which fields are tags is known only once every seed has been seen.
|
|
53
|
-
for (const base of seedBases)
|
|
54
|
-
learnInput(base);
|
|
55
|
-
pools.forget();
|
|
56
|
-
// Only the seeds teach lengths, since a kept input repeats its seed's arrays and would make every list look fixed.
|
|
57
|
-
for (const base of seedBases) {
|
|
58
|
-
learnInput(base);
|
|
59
|
-
pools.learnLengths(base);
|
|
60
|
-
}
|
|
61
|
-
let nextSeed = 0;
|
|
62
|
-
const pathsOf = readPathsOf({ property: guided, mirrored: forRead, twin });
|
|
63
|
-
// A two-run input's sides and what its relation read of them, together, so one check stands for both.
|
|
64
|
-
const twinned = twin ? { twin, readsOf: twinReadsOf({ twin, mirrored: forRead }) } : null;
|
|
65
|
-
const { edit, resized } = editsOf({ r, pools, readPathsOf: pathsOf, kept: () => queue });
|
|
66
|
-
const { planOf, vary } = twinOf({ r, pools, resized });
|
|
67
|
-
const canContinue = () => !isSpent && !isDone && !failedOn;
|
|
68
|
-
return ({ limitMs, now, takeRun }) => {
|
|
69
|
-
const start = now();
|
|
70
|
-
isSpent = false;
|
|
71
|
-
take = () => {
|
|
72
|
-
if (isSpent || now() - start >= limitMs || (takeRun && !takeRun()))
|
|
73
|
-
isSpent = true;
|
|
74
|
-
return !isSpent;
|
|
75
|
-
};
|
|
76
|
-
while (nextSeed < seedBases.length && canContinue()) {
|
|
77
|
-
const base = itemAt(seedBases, nextSeed);
|
|
78
|
-
check(base);
|
|
79
|
-
if (isSpent)
|
|
80
|
-
break;
|
|
81
|
-
nextSeed++;
|
|
82
|
-
join(base, kept.pathOf(counts.keys()), true);
|
|
83
|
-
queue.push(base);
|
|
84
|
-
}
|
|
85
|
-
// A failure ends the search at once, before any more guidance or relation calls, so nothing run after it can replace it.
|
|
86
|
-
while (canContinue()) {
|
|
87
|
-
const parent = r.pick(r.pick(groupList));
|
|
88
|
-
// A discarded edit is redrawn up to the retry limit. The last check also supplies the base's path and verdict.
|
|
89
|
-
let base = edit(parent);
|
|
90
|
-
let verdict = check(base);
|
|
91
|
-
for (let tries = 0; tries < settings.tries && verdict === 'discarded'; tries++) {
|
|
92
|
-
base = edit(parent);
|
|
93
|
-
verdict = check(base);
|
|
94
|
-
}
|
|
95
|
-
if (!canContinue())
|
|
96
|
-
break;
|
|
97
|
-
const path = kept.pathOf(counts.keys());
|
|
98
|
-
const plan = twinned && planOf(fieldOf(base, twinned.twin.first), twinned.readsOf(base), holderKeyOf([twinned.twin.first]), [twinned.twin.first]);
|
|
99
|
-
if (!twinned || !plan) {
|
|
100
|
-
kept.keep(base, path, counts);
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
const { first, second } = twinned.twin;
|
|
104
|
-
const variants = Math.min(settings.most, 1 + plan.free);
|
|
105
|
-
for (let index = 0; index < variants && canContinue(); index++) {
|
|
106
|
-
const input = withAt(base, [second], 0, (holder) => vary(fieldOf(holder, first), plan, holderKeyOf([first]), holder));
|
|
107
|
-
counts.clear();
|
|
108
|
-
property(input);
|
|
109
|
-
if (canContinue())
|
|
110
|
-
kept.keep(base, path, counts);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return failedOn ? { input: failedOn } : undefined;
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
|
-
// One target's share of what is left, split evenly over the `count` targets still to search, so a target stopped at once leaves its time to the rest.
|
|
117
|
-
export const shareOf = ({ leftMs, count }) => Math.floor(leftMs / count);
|