@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/dist/judge/runner.js
CHANGED
|
@@ -73,8 +73,6 @@ import { eachInOrder, firstInOrder } from '../utils/order.js';
|
|
|
73
73
|
import { CrushError, failed, thrownToVitest } from '../utils/errors.js';
|
|
74
74
|
import { safeAsync } from '../utils/safe.js';
|
|
75
75
|
import { clearedCalls, isLiteralJustification, loadId, setObservations, state, stepLimitOf } from './counters.js';
|
|
76
|
-
import { exploreProperty, exploresMeta } from '../explore/edges/explore.js';
|
|
77
|
-
import { explorableOf, graphOf } from '../explore/targets.operations.js';
|
|
78
76
|
import { answerSitesOf, answeringRidersOf, backupRidersOf, candidatesHashOf, caughtOf, creditedOf, groupOf, fileFailureOf, runFailureOf, hookedOf, metaOf, pointKeyOf, ridersOf, ridingSidesOf, shareOf, suitedOf, stalePartsOf, runKeyOf, testDisplayNameOf, testFileOfKey, testKeyOf, testsUnderOf, timedOutPattern, } from './judge.operations.js';
|
|
79
77
|
import {} from './judge.schema.js';
|
|
80
78
|
import { droppedStrays } from './edges/strays.js';
|
|
@@ -82,7 +80,7 @@ import { hasRefusal, markRefusal, readJudgeSource, readJudgeSourceNullable } fro
|
|
|
82
80
|
import { mergeJudged } from './edges/merge.js';
|
|
83
81
|
import { browserModuleOutput, runnerModuleOutput, workerStateOutput } from './edges/vitest.schema.js';
|
|
84
82
|
import { judgeSpeedOf, now } from './edges/speed.js';
|
|
85
|
-
import {
|
|
83
|
+
import { pluginMetaKeyProvideKey, judgeCoordinators, judgeFilesProvideKey, judgeRedundantProvideKey, judgeRelatedProvideKey, judgeShardsProvideKey, phaseProvideKey, recordPathOf, rootProvideKey, rulesProvideKey, vitestProvideKey, } from './edges/vitest.js';
|
|
86
84
|
import { changedDuringRunOf, failedJudgingOf, stalePlanOf } from './refusals.js';
|
|
87
85
|
// This file loads natively from crush's own tree, where `vite-plus/test` names crush's copy, and the project's tests register with the copy the plugin resolved from the project, whose test functions only that copy can hand back.
|
|
88
86
|
// The values the command project provides reach the worker whichever copy reads them, so crush's own `inject` finds the project's copy.
|
|
@@ -379,7 +377,6 @@ export default function CrushRunner(config) {
|
|
|
379
377
|
keys: new Map(),
|
|
380
378
|
displaySeen: new Map(),
|
|
381
379
|
unfound: [],
|
|
382
|
-
properties: [],
|
|
383
380
|
loadTicks: 0,
|
|
384
381
|
refusal: null,
|
|
385
382
|
staleLoads: new Map(),
|
|
@@ -426,7 +423,6 @@ export default function CrushRunner(config) {
|
|
|
426
423
|
session.keys = testKeysIn(runner.config.root, files);
|
|
427
424
|
session.displaySeen.clear();
|
|
428
425
|
session.unfound = [];
|
|
429
|
-
session.properties = [];
|
|
430
426
|
};
|
|
431
427
|
// A suite's `beforeAll` and `afterAll` run under the suite's own id, which judging credits to every test under it.
|
|
432
428
|
const onBeforeRunSuite = async (suite) => {
|
|
@@ -493,10 +489,10 @@ export default function CrushRunner(config) {
|
|
|
493
489
|
const onBeforeRunTask = async (task) => {
|
|
494
490
|
await base.onBeforeRunTask(task);
|
|
495
491
|
if (phase === 'property') {
|
|
496
|
-
const { data, error } = await
|
|
497
|
-
if (
|
|
498
|
-
thrownToVitest(
|
|
499
|
-
task.context.
|
|
492
|
+
const { data: loaded, error: loadError } = await loadTestFilesDeclaring(inject(pluginMetaKeyProvideKey));
|
|
493
|
+
if (loadError)
|
|
494
|
+
thrownToVitest(loadError);
|
|
495
|
+
task.context.crushLoadedTestFiles = loaded;
|
|
500
496
|
return;
|
|
501
497
|
}
|
|
502
498
|
if (judgeFiles && !session.isRunningPass) {
|
|
@@ -522,13 +518,6 @@ export default function CrushRunner(config) {
|
|
|
522
518
|
const { data: stated, error: refusal } = metaOf(task.meta);
|
|
523
519
|
if (refusal)
|
|
524
520
|
thrownToVitest(new CrushError(`${key}: ${refusal.message}`));
|
|
525
|
-
// A property's declaration is refused here, where its meta enters, so a misspelled one never explores in silence.
|
|
526
|
-
if (task.meta.explores !== undefined) {
|
|
527
|
-
const declared = exploresMeta.safeParse(task.meta);
|
|
528
|
-
if (!declared.success)
|
|
529
|
-
thrownToVitest(new CrushError(`${key}: its explore meta is no property declaration: ${declared.error.message}`));
|
|
530
|
-
session.properties.push({ meta: declared.data, key });
|
|
531
|
-
}
|
|
532
521
|
const fn = TestRunner.getTestFn(task);
|
|
533
522
|
// The copy that registered the test hands its function back, so another copy gives none.
|
|
534
523
|
if (fn === undefined) {
|
|
@@ -966,7 +955,6 @@ export default function CrushRunner(config) {
|
|
|
966
955
|
assignees: [],
|
|
967
956
|
sequence: { generation: 0, units: [] },
|
|
968
957
|
failure: fileFailureOf(testFile),
|
|
969
|
-
properties: session.properties.map(({ meta }) => meta.explores),
|
|
970
958
|
};
|
|
971
959
|
};
|
|
972
960
|
// Writes the parts of this shard's files with the verdicts each holds, once every shard saved the verdicts of its sites.
|
|
@@ -1441,59 +1429,48 @@ export default function CrushRunner(config) {
|
|
|
1441
1429
|
assignees: [],
|
|
1442
1430
|
sequence: { generation, units: [] },
|
|
1443
1431
|
failure: refusal.message,
|
|
1444
|
-
properties: session.properties.map(({ meta }) => meta.explores),
|
|
1445
1432
|
}, { calls: [], clearVerification: false, clearFailure: session.pass === 'record' && session.ran.size > 0 });
|
|
1446
1433
|
return refusal;
|
|
1447
1434
|
};
|
|
1448
|
-
//
|
|
1449
|
-
|
|
1435
|
+
// Loads one test file through Vitest's own loader without running its tests, so a plugin reads each test's meta and calls what the module exports.
|
|
1436
|
+
// Vitest's shared runner collects one file at a time, so a caller loads files in turn.
|
|
1437
|
+
const loadTestFile = async (file) => {
|
|
1438
|
+
const root = inject(rootProvideKey);
|
|
1439
|
+
const path = join(root, file);
|
|
1440
|
+
const { data: files, error: collectError } = await safeAsync(() => collectTests([path], runner));
|
|
1441
|
+
if (collectError)
|
|
1442
|
+
return { data: null, error: collectError };
|
|
1443
|
+
const loaded = itemAt(files, 0);
|
|
1444
|
+
const failure = runFailureOf(loaded);
|
|
1445
|
+
if (failure)
|
|
1446
|
+
return { data: null, error: new CrushError(failure) };
|
|
1447
|
+
// The module was just collected by the same Vitest loader, so importing it again loads nothing new.
|
|
1448
|
+
const { data: module, error: loadError } = await safeAsync(async () => await runner.importFile(path, 'collect'));
|
|
1449
|
+
if (loadError)
|
|
1450
|
+
return { data: null, error: loadError };
|
|
1451
|
+
const tests = testsOf(loaded).map(({ name, meta }) => ({ name, meta }));
|
|
1452
|
+
return { data: { file, source: readJudgeSource(root, file), module, tests }, error: null };
|
|
1453
|
+
};
|
|
1454
|
+
// Loads each recorded test file whose source names a plugin's meta key, in turn, for that plugin's coordinator to read.
|
|
1455
|
+
const loadTestFilesDeclaring = async (metaKey) => {
|
|
1450
1456
|
const { data: edges, error } = currentEdgesOf();
|
|
1451
1457
|
if (error)
|
|
1452
1458
|
return { data: null, error };
|
|
1453
|
-
const targets = [];
|
|
1454
1459
|
const root = inject(rootProvideKey);
|
|
1455
|
-
const
|
|
1456
|
-
const
|
|
1457
|
-
|
|
1458
|
-
const seedsOf = edges.getSeeds();
|
|
1459
|
-
// Vitest's shared runner collects one file at a time, so the files load in turn, stopping at the first that cannot.
|
|
1460
|
-
const collectTargets = async ({ file, properties }) => {
|
|
1461
|
-
const keys = properties.map((name) => unitKeyOf(file, name)).filter((key) => seedsOf.has(key));
|
|
1462
|
-
const allowed = new Set(explorableOf({ ...graph, keys, paths: related }).map(({ key }) => key));
|
|
1463
|
-
if (!allowed.size)
|
|
1460
|
+
const files = [];
|
|
1461
|
+
const loadDeclaring = async ({ file }) => {
|
|
1462
|
+
if (!readJudgeSource(root, file).includes(metaKey))
|
|
1464
1463
|
return null;
|
|
1465
|
-
const
|
|
1466
|
-
const { data: files, error: collectError } = await safeAsync(() => collectTests([path], runner));
|
|
1467
|
-
if (collectError)
|
|
1468
|
-
return collectError;
|
|
1469
|
-
const loaded = itemAt(files, 0);
|
|
1470
|
-
const failure = runFailureOf(loaded);
|
|
1471
|
-
if (failure)
|
|
1472
|
-
return new CrushError(failure);
|
|
1473
|
-
// The module was just collected by the same Vitest loader, so importing it again loads nothing new.
|
|
1474
|
-
const { data: module, error: loadError } = await safeAsync(async () => await runner.importFile(path, 'collect'));
|
|
1464
|
+
const { data: loaded, error: loadError } = await loadTestFile(file);
|
|
1475
1465
|
if (loadError)
|
|
1476
1466
|
return loadError;
|
|
1477
|
-
|
|
1478
|
-
for (const task of testsOf(loaded)) {
|
|
1479
|
-
const declaration = exploresMeta.safeParse(task.meta);
|
|
1480
|
-
if (!declaration.success)
|
|
1481
|
-
continue;
|
|
1482
|
-
const meta = declaration.data;
|
|
1483
|
-
const key = unitKeyOf(file, meta.explores);
|
|
1484
|
-
if (!allowed.has(key))
|
|
1485
|
-
continue;
|
|
1486
|
-
if (meta.twin && !explorableOf({ ...graph, keys: [unitKeyOf(file, meta.twin.related)], paths: null }).length)
|
|
1487
|
-
continue;
|
|
1488
|
-
const seeds = entryAt(seedsOf, key, 'the recorded property arguments');
|
|
1489
|
-
targets.push({ key, search: exploreProperty({ file, source, module, meta, seeds, seed: runner.config.sequence.seed }) });
|
|
1490
|
-
}
|
|
1467
|
+
files.push(loaded);
|
|
1491
1468
|
return null;
|
|
1492
1469
|
};
|
|
1493
|
-
const
|
|
1494
|
-
if (
|
|
1495
|
-
return { data: null, error:
|
|
1496
|
-
return { data:
|
|
1470
|
+
const loadError = await firstInOrder(edges.getJudged({ withHits: false }), loadDeclaring);
|
|
1471
|
+
if (loadError)
|
|
1472
|
+
return { data: null, error: loadError };
|
|
1473
|
+
return { data: files, error: null };
|
|
1497
1474
|
};
|
|
1498
1475
|
// Reruns this file's passing tests with every candidate crush forced together, and when one fails, keeps the candidates one at a time in order, dropping each that a test fails with.
|
|
1499
1476
|
const verifyFile = async (edges, first, candidates, candidateHash) => {
|
|
@@ -52,14 +52,15 @@ export declare const unusedQuestionsOf: (nodes: ReachNodeOutput[]) => {
|
|
|
52
52
|
all: Asked[];
|
|
53
53
|
open: Asked[];
|
|
54
54
|
};
|
|
55
|
-
export type
|
|
55
|
+
export type PluginFinding = {
|
|
56
56
|
key: string;
|
|
57
57
|
file: string;
|
|
58
58
|
line: number;
|
|
59
59
|
function: string;
|
|
60
60
|
input: string;
|
|
61
|
+
plugin: string;
|
|
61
62
|
};
|
|
62
|
-
export declare const
|
|
63
|
+
export declare const findingQuestionsOf: (all: readonly PluginFinding[]) => Asked[];
|
|
63
64
|
type PathFinding = Pick<QuestionInput, 'file' | 'function' | 'code'> & {
|
|
64
65
|
kind: 'same-result' | 'no-split';
|
|
65
66
|
siteKey: string;
|
|
@@ -76,7 +77,7 @@ type CaughtInput = {
|
|
|
76
77
|
calls: readonly CaughtCall[];
|
|
77
78
|
properties: ReadonlySet<string>;
|
|
78
79
|
};
|
|
79
|
-
export declare const
|
|
80
|
+
export declare const findingCaughtOf: ({ calls, properties }: CaughtInput) => Map<string, Set<string>>;
|
|
80
81
|
export declare const reachingKinds: ReadonlySet<string>;
|
|
81
82
|
export type Answer = {
|
|
82
83
|
test: string;
|
|
@@ -58,10 +58,10 @@ const wordings = {
|
|
|
58
58
|
};
|
|
59
59
|
},
|
|
60
60
|
untested: ({ file, code }) => ({ ask: `No test reads the pattern ${quote(code)} in ${quote(file)}. Test it?`, answers: ['yes: add a test that reads it', 'no: drop its `export`'] }),
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
ask: `
|
|
64
|
-
answers: ['yes: fix the code, with a test that fails before the fix, then run
|
|
61
|
+
// A finding names the input that failed and what it failed, a throw site or a property, since a varied seed made it; findingQuestionsOf names the plugin that found it.
|
|
62
|
+
finding: ({ function: name, code, replacement: input }) => ({
|
|
63
|
+
ask: `A plugin called ${ownerOf(name)} with ${quote(input)} and it failed ${quote(code)}, which no test covers. Is that input one a caller can send?`,
|
|
64
|
+
answers: ['yes: fix the code, with a test that fails before the fix, then run the plugin again', 'no: refuse the input where it enters with a parse or guard, or justify it'],
|
|
65
65
|
}),
|
|
66
66
|
behavior: ({ function: name, code }) => ({ ask: `What should ${ownerOf(name)} give at ${quote(code)}?`, answers: ['yes: add a case answering this question with its output', 'no: remove that outcome'] }),
|
|
67
67
|
'same-result': ({ function: name, code }) => ({
|
|
@@ -274,16 +274,16 @@ export const unusedQuestionsOf = (nodes) => {
|
|
|
274
274
|
});
|
|
275
275
|
return { all: asks.flatMap(({ all }) => all), open: asks.flatMap(({ open }) => open) };
|
|
276
276
|
};
|
|
277
|
-
// One question per finding's site, open until
|
|
277
|
+
// One question per finding's site, open until its plugin no longer finds it or a justification answers it; a site two targets found is asked once, of the first, naming the plugin that found it.
|
|
278
278
|
// Its id names the site alone, never the function that found it, so refreshing which target found a shared site keeps the id an answer names.
|
|
279
|
-
export const
|
|
279
|
+
export const findingQuestionsOf = (all) => {
|
|
280
280
|
const seen = new Set();
|
|
281
281
|
const findings = all.filter(({ key }) => !seen.has(key) && Boolean(seen.add(key)));
|
|
282
|
-
const inputs = findings.map((finding) => ({ kind: '
|
|
282
|
+
const inputs = findings.map((finding) => ({ kind: 'finding', file: finding.file, function: finding.function, code: finding.key, replacement: finding.input.slice(0, 1024) }));
|
|
283
283
|
const ids = questionsOf(inputs.map((input) => ({ ...input, function: '' })));
|
|
284
284
|
return questionsOf(inputs).map((question, index) => {
|
|
285
285
|
const finding = itemAt(findings, index);
|
|
286
|
-
return Object.assign(question, { id: itemAt(ids, index).id, sites: [finding.key], file: finding.file, line: finding.line });
|
|
286
|
+
return Object.assign(question, { id: itemAt(ids, index).id, ask: question.ask.replace(/^A plugin/, finding.plugin), sites: [finding.key], file: finding.file, line: finding.line });
|
|
287
287
|
});
|
|
288
288
|
};
|
|
289
289
|
export const pathQuestionsOf = (findings) => {
|
|
@@ -295,9 +295,9 @@ export const pathQuestionsOf = (findings) => {
|
|
|
295
295
|
return Object.assign(question, { file, line, sites: [siteKey], answers });
|
|
296
296
|
});
|
|
297
297
|
};
|
|
298
|
-
// Which tests catch each
|
|
299
|
-
// Only an export
|
|
300
|
-
export const
|
|
298
|
+
// Which tests catch each finding's key: a throw finding by a test whose call threw from its site, as a regression test for it does, and a property finding by a test that calls the property.
|
|
299
|
+
// Only an export a plugin found failing as a property counts as one, so a test calling a helper of its own file answers nothing.
|
|
300
|
+
export const findingCaughtOf = ({ calls, properties }) => {
|
|
301
301
|
const caught = new Map();
|
|
302
302
|
const note = (key, test) => {
|
|
303
303
|
caught.set(key, (caught.get(key) ?? new Set()).add(test));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const questionKinds: readonly ['crush', 'reach', 'call', 'side', 'tell', 'matter', 'behavior', 'test', 'unused', 'unexport', 'untested', 'testonly', 'steps', 'answers', '
|
|
2
|
+
export declare const questionKinds: readonly ['crush', 'reach', 'call', 'side', 'tell', 'matter', 'behavior', 'test', 'unused', 'unexport', 'untested', 'testonly', 'steps', 'answers', 'finding', 'same-result', 'no-split'];
|
|
3
3
|
export declare const questionIdPattern: RegExp;
|
|
4
4
|
export declare const encodedQuestionIdLength: number;
|
|
5
5
|
export declare const questionId: z.ZodString;
|
|
@@ -9,7 +9,7 @@ export declare const questionInput: z.ZodObject<{
|
|
|
9
9
|
behavior: "behavior";
|
|
10
10
|
call: "call";
|
|
11
11
|
crush: "crush";
|
|
12
|
-
|
|
12
|
+
finding: "finding";
|
|
13
13
|
matter: "matter";
|
|
14
14
|
"no-split": "no-split";
|
|
15
15
|
reach: "reach";
|
|
@@ -35,7 +35,7 @@ declare const questionOutput: z.ZodObject<{
|
|
|
35
35
|
behavior: "behavior";
|
|
36
36
|
call: "call";
|
|
37
37
|
crush: "crush";
|
|
38
|
-
|
|
38
|
+
finding: "finding";
|
|
39
39
|
matter: "matter";
|
|
40
40
|
"no-split": "no-split";
|
|
41
41
|
reach: "reach";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export const questionKinds = ['crush', 'reach', 'call', 'side', 'tell', 'matter', 'behavior', 'test', 'unused', 'unexport', 'untested', 'testonly', 'steps', 'answers', '
|
|
2
|
+
export const questionKinds = ['crush', 'reach', 'call', 'side', 'tell', 'matter', 'behavior', 'test', 'unused', 'unexport', 'untested', 'testonly', 'steps', 'answers', 'finding', 'same-result', 'no-split'];
|
|
3
3
|
// Matches a question id with pipes and percent signs escaped inside its fields.
|
|
4
|
-
export const questionIdPattern = /^(crush|reach|call|side|tell|matter|behavior|test|unused|unexport|untested|testonly|steps|answers|
|
|
4
|
+
export const questionIdPattern = /^(crush|reach|call|side|tell|matter|behavior|test|unused|unexport|untested|testonly|steps|answers|finding|same-result|no-split)\|(?:[^|%]|%25|%7C)+\|(?:[^|%]|%25|%7C)*\|\d+\|(?:[^|%]|%25|%7C)+$/;
|
|
5
5
|
const questionIdLength = 2048;
|
|
6
6
|
export const encodedQuestionIdLength = questionIdLength * 3;
|
|
7
7
|
// A question id names its kind, file, function and code, never a line, so edits around the code leave it as it was.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { pluginFindings } from '../../crush.tables.ts';
|
|
2
|
+
import { type Record } from './record.db.ts';
|
|
3
|
+
export type Finding = Omit<typeof pluginFindings.$inferInsert, 'findingKey' | 'plugin'> & {
|
|
4
|
+
key: string;
|
|
5
|
+
};
|
|
6
|
+
type StoredFinding = Finding & {
|
|
7
|
+
plugin: string;
|
|
8
|
+
};
|
|
9
|
+
type SetFindingsInput = {
|
|
10
|
+
plugin: string;
|
|
11
|
+
targets: readonly string[];
|
|
12
|
+
findings: Finding[];
|
|
13
|
+
};
|
|
14
|
+
export declare const setFindings: (db: Record, { plugin, targets, findings }: SetFindingsInput) => void;
|
|
15
|
+
export declare const getFindings: (db: Record) => StoredFinding[];
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { and, asc, eq, inArray } from 'drizzle-orm';
|
|
2
|
+
import { pluginFindings } from '../../crush.tables.js';
|
|
3
|
+
import { chunksOf } from './record.db.js';
|
|
4
|
+
// Replaces one plugin's findings for the targets it ran with what it found, leaving every other plugin's and target's as they were, so a site two targets reach keeps the evidence of each.
|
|
5
|
+
export const setFindings = (db, { plugin, targets, findings }) => {
|
|
6
|
+
db.transaction((tx) => {
|
|
7
|
+
const targetChunks = chunksOf(targets.map((target) => ({ target }))).map((chunk) => chunk.map(({ target }) => target));
|
|
8
|
+
for (const chunk of targetChunks) {
|
|
9
|
+
const ran = and(eq(pluginFindings.plugin, plugin), inArray(pluginFindings.target, chunk));
|
|
10
|
+
tx.delete(pluginFindings).where(ran).run();
|
|
11
|
+
}
|
|
12
|
+
for (const chunk of chunksOf(findings)) {
|
|
13
|
+
const rows = chunk.map(({ key, ...finding }) => Object.assign(finding, { findingKey: key, plugin }));
|
|
14
|
+
tx.insert(pluginFindings).values(rows).run();
|
|
15
|
+
}
|
|
16
|
+
}, { behavior: 'immediate' });
|
|
17
|
+
};
|
|
18
|
+
export const getFindings = (db) => {
|
|
19
|
+
return db
|
|
20
|
+
.select()
|
|
21
|
+
.from(pluginFindings)
|
|
22
|
+
.orderBy(asc(pluginFindings.findingKey), asc(pluginFindings.target))
|
|
23
|
+
.all()
|
|
24
|
+
.map(({ findingKey, ...finding }) => Object.assign(finding, { key: findingKey }));
|
|
25
|
+
};
|
|
@@ -17,7 +17,7 @@ export type CapturedPart = {
|
|
|
17
17
|
clearVerification: boolean;
|
|
18
18
|
clearFailure?: boolean;
|
|
19
19
|
};
|
|
20
|
-
export declare const setJudged: (db: Record, { file, hash, reused, tests, justifications, failure,
|
|
20
|
+
export declare const setJudged: (db: Record, { file, hash, reused, tests, justifications, failure, hits: taken, entered, verdicts: judged, reads, rerunFailing, passes, outside, changed, assignees, sequence }: Judged, captured?: CapturedPart) => void;
|
|
21
21
|
export declare const clearJudged: (db: Record, path: string) => void;
|
|
22
22
|
export declare const clearFileFailure: (db: Record, path: string, ranTests: boolean) => void;
|
|
23
23
|
export declare const setFileFailure: (db: Record, path: string, failure: string) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { and, asc, desc, eq, inArray, isNull, notInArray, sql, sum } from 'drizzle-orm';
|
|
3
|
-
import { entries, hits, judgedState, partAssignees, readSequences, sidePasses, sites, testFileChanged, testFileOutside,
|
|
3
|
+
import { entries, hits, judgedState, partAssignees, readSequences, sidePasses, sites, testFileChanged, testFileOutside, testFileReads, testFiles, testRuns, verdicts, verifiedFiles } from '../../crush.tables.js';
|
|
4
4
|
import { byPath, hitTextOf, partFrom, partTextOf } from '../parts.operations.js';
|
|
5
5
|
import { entryAt, itemAt } from '../../utils/lookup.js';
|
|
6
6
|
import { prepareExportCalls, writeExportCalls } from './calls.db.js';
|
|
@@ -67,10 +67,9 @@ const partOf = (db, testFile) => {
|
|
|
67
67
|
reads: db.select({ path: testFileReads.path, hash: testFileReads.hash }).from(testFileReads).where(eq(testFileReads.testFile, testFile)).all(),
|
|
68
68
|
outside: db.select({ path: testFileOutside.path }).from(testFileOutside).where(eq(testFileOutside.testFile, testFile)).all(),
|
|
69
69
|
changed: db.select({ path: testFileChanged.path }).from(testFileChanged).where(eq(testFileChanged.testFile, testFile)).all(),
|
|
70
|
-
properties: db.select({ name: testFileProperties.name }).from(testFileProperties).where(eq(testFileProperties.testFile, testFile)).all(),
|
|
71
70
|
});
|
|
72
71
|
};
|
|
73
|
-
export const setJudged = (db, { file, hash, reused, tests, justifications, failure,
|
|
72
|
+
export const setJudged = (db, { file, hash, reused, tests, justifications, failure, hits: taken, entered, verdicts: judged, reads, rerunFailing, passes, outside, changed, assignees, sequence }, captured) => {
|
|
74
73
|
const calls = captured && prepareExportCalls(captured.calls);
|
|
75
74
|
const isRerunFailing = new Set(rerunFailing);
|
|
76
75
|
const runs = tests.map(({ key, name, passed, isSteady, answers, ...test }) => ({
|
|
@@ -129,7 +128,7 @@ export const setJudged = (db, { file, hash, reused, tests, justifications, failu
|
|
|
129
128
|
.where(and(eq(readSequences.testFile, file), notInArray(readSequences.generation, kept)))
|
|
130
129
|
.run();
|
|
131
130
|
};
|
|
132
|
-
if (before?.hash === hash && partOf(tx, testFile) === partFrom({ runs, taken, entered, reads, passes, outside, changed,
|
|
131
|
+
if (before?.hash === hash && partOf(tx, testFile) === partFrom({ runs, taken, entered, reads, passes, outside, changed, siteOf })) {
|
|
133
132
|
// Every test key is already this file's, so the upsert only moves each test's timing.
|
|
134
133
|
for (const chunk of chunksOf(testRows)) {
|
|
135
134
|
tx.insert(testRuns)
|
|
@@ -150,10 +149,6 @@ export const setJudged = (db, { file, hash, reused, tests, justifications, failu
|
|
|
150
149
|
tx.delete(testFileOutside).where(eq(testFileOutside.testFile, testFile)).run();
|
|
151
150
|
for (const chunk of chunksOf(outside.map((path) => ({ testFile, path }))))
|
|
152
151
|
tx.insert(testFileOutside).values(chunk).run();
|
|
153
|
-
tx.delete(testFileProperties).where(eq(testFileProperties.testFile, testFile)).run();
|
|
154
|
-
// Two tests may declare one property, which the file holds once.
|
|
155
|
-
for (const chunk of chunksOf([...new Set(properties)].map((name) => ({ testFile, name }))))
|
|
156
|
-
tx.insert(testFileProperties).values(chunk).run();
|
|
157
152
|
tx.delete(testFileChanged).where(eq(testFileChanged.testFile, testFile)).run();
|
|
158
153
|
for (const chunk of chunksOf(changed.map((path) => ({ testFile, path }))))
|
|
159
154
|
tx.insert(testFileChanged).values(chunk).run();
|
|
@@ -271,12 +266,6 @@ const partsIn = (db, { withHits, path: only }) => {
|
|
|
271
266
|
.where(fileId === null ? undefined : eq(testFileOutside.testFile, fileId))
|
|
272
267
|
.orderBy(asc(testFileOutside.path))
|
|
273
268
|
.all(), ({ testFile }) => testFile);
|
|
274
|
-
const declared = Map.groupBy(tx
|
|
275
|
-
.select()
|
|
276
|
-
.from(testFileProperties)
|
|
277
|
-
.where(fileId === null ? undefined : eq(testFileProperties.testFile, fileId))
|
|
278
|
-
.orderBy(asc(testFileProperties.name))
|
|
279
|
-
.all(), ({ testFile }) => testFile);
|
|
280
269
|
const changedDuring = Map.groupBy(tx
|
|
281
270
|
.select()
|
|
282
271
|
.from(testFileChanged)
|
|
@@ -365,7 +354,6 @@ const partsIn = (db, { withHits, path: only }) => {
|
|
|
365
354
|
passes: (counted.get(id) ?? []).map(({ site, side, passes: count }) => ({ siteKey: entryAt(keyOf, site, 'a passed site'), side, passes: count })),
|
|
366
355
|
outside: (loadedOutside.get(id) ?? []).map(({ path: loaded }) => loaded),
|
|
367
356
|
changed: (changedDuring.get(id) ?? []).map(({ path: source }) => source),
|
|
368
|
-
properties: (declared.get(id) ?? []).map(({ name }) => name),
|
|
369
357
|
assignees: (judgedUnder.get(id) ?? []).map(({ source, assignee }) => ({ source, assignee })),
|
|
370
358
|
}));
|
|
371
359
|
return byPath(parts);
|
|
@@ -14,6 +14,7 @@ export type PlanCode = {
|
|
|
14
14
|
code: string;
|
|
15
15
|
};
|
|
16
16
|
export declare const setPlanCodes: (db: Record, planKey: string, codes: readonly PlanCode[]) => void;
|
|
17
|
+
export declare const getPlanCodes: (db: Reader) => PlanCode[];
|
|
17
18
|
export declare const getPlanCodesNullable: (db: Record, planKey: string) => PlanCode[] | null;
|
|
18
19
|
export declare const getPlan: (db: Record, { withRewrites }?: {
|
|
19
20
|
withRewrites?: boolean;
|
|
@@ -105,6 +105,11 @@ export const setPlanCodes = (db, planKey, codes) => {
|
|
|
105
105
|
tx.insert(planCodes).values(chunk).run();
|
|
106
106
|
}, { behavior: 'immediate' });
|
|
107
107
|
};
|
|
108
|
+
// The instrumented code the last plan kept, in path order, whatever its plan key.
|
|
109
|
+
export const getPlanCodes = (db) => {
|
|
110
|
+
const rows = db.select().from(planCodes).orderBy(asc(planCodes.path)).all();
|
|
111
|
+
return rows.map(({ path, hash, code }) => ({ path, hash, code }));
|
|
112
|
+
};
|
|
108
113
|
// The instrumented code kept under a plan key, in path order, or null when the last plan kept was another.
|
|
109
114
|
export const getPlanCodesNullable = (db, planKey) => {
|
|
110
115
|
const rows = db.select().from(planCodes).orderBy(asc(planCodes.path)).all();
|
|
@@ -2,7 +2,7 @@ import { DatabaseSync } from 'node:sqlite';
|
|
|
2
2
|
import { type NodeSQLiteDatabase } from 'drizzle-orm/node-sqlite';
|
|
3
3
|
import { CrushError } from '../../utils/errors.ts';
|
|
4
4
|
import { type Safe } from '../../utils/safe.ts';
|
|
5
|
-
export declare const recordVersion = "
|
|
5
|
+
export declare const recordVersion = "59";
|
|
6
6
|
export declare const memoryPath = ":memory:";
|
|
7
7
|
export type Record = NodeSQLiteDatabase & {
|
|
8
8
|
$client: DatabaseSync;
|
|
@@ -60,7 +60,7 @@ import { safe } from '../../utils/safe.js';
|
|
|
60
60
|
import { ensureRecordFolder, recordFileExists, removeRecordFile } from './record.fs.js';
|
|
61
61
|
import { unreadableRecordOf } from '../../judge/refusals.js';
|
|
62
62
|
// The record's shape; a record of any other version is deleted and rebuilt, since every row can be recorded again.
|
|
63
|
-
export const recordVersion = '
|
|
63
|
+
export const recordVersion = '59';
|
|
64
64
|
// How long a connection waits on the record while another holds its write lock, as every test file's worker writes its own part at once.
|
|
65
65
|
const busyMs = 30_000;
|
|
66
66
|
const migrationsFolder = join(import.meta.dirname, '../../../migrations/main');
|
|
@@ -10,11 +10,10 @@ type PartRows = {
|
|
|
10
10
|
reads: object[];
|
|
11
11
|
outside: object[];
|
|
12
12
|
changed: object[];
|
|
13
|
-
properties: object[];
|
|
14
13
|
};
|
|
15
14
|
export declare const partTextOf: ({ taken, ...rows }: PartRows) => string;
|
|
16
15
|
export declare const hitTextOf: (site: number, side: Judged['hits'][number]['side'], testKey: string | undefined) => string;
|
|
17
|
-
type PartFromInput = Pick<Judged, 'entered' | 'reads' | 'passes' | 'outside' | 'changed'
|
|
16
|
+
type PartFromInput = Pick<Judged, 'entered' | 'reads' | 'passes' | 'outside' | 'changed'> & {
|
|
18
17
|
runs: {
|
|
19
18
|
testKey: string;
|
|
20
19
|
ns: number;
|
|
@@ -22,5 +21,5 @@ type PartFromInput = Pick<Judged, 'entered' | 'reads' | 'passes' | 'outside' | '
|
|
|
22
21
|
taken: Judged['hits'];
|
|
23
22
|
siteOf: ReadonlyMap<string, number>;
|
|
24
23
|
};
|
|
25
|
-
export declare const partFrom: ({ runs, taken, entered, reads, passes, outside, changed,
|
|
24
|
+
export declare const partFrom: ({ runs, taken, entered, reads, passes, outside, changed, siteOf }: PartFromInput) => string;
|
|
26
25
|
export {};
|
|
@@ -10,7 +10,7 @@ export const partTextOf = ({ taken, ...rows }) => JSON.stringify([taken.toSorted
|
|
|
10
10
|
// Hits have a fixed shape. Comparing tuples avoids sorting three property names for every hit in both copies of a part.
|
|
11
11
|
export const hitTextOf = (site, side, testKey) => JSON.stringify([site, side, testKey]);
|
|
12
12
|
// The part a run is about to write without its verdicts, which `setJudged` writes apart, leaving out a row for a site no plan names and a hit by a test this file did not run.
|
|
13
|
-
export const partFrom = ({ runs, taken, entered, reads, passes, outside, changed,
|
|
13
|
+
export const partFrom = ({ runs, taken, entered, reads, passes, outside, changed, siteOf }) => {
|
|
14
14
|
const keys = new Set(runs.map(({ testKey }) => testKey));
|
|
15
15
|
return partTextOf({
|
|
16
16
|
runs: runs.map(({ ns: _ns, ...run }) => run),
|
|
@@ -26,6 +26,5 @@ export const partFrom = ({ runs, taken, entered, reads, passes, outside, changed
|
|
|
26
26
|
reads: reads.map(({ path, hash }) => ({ path, hash })),
|
|
27
27
|
outside: outside.map((path) => ({ path })),
|
|
28
28
|
changed: changed.map((path) => ({ path })),
|
|
29
|
-
properties: [...new Set(properties)].map((name) => ({ name })),
|
|
30
29
|
});
|
|
31
30
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
ALTER TABLE `explore_findings` ADD `plugin` text DEFAULT 'explore' NOT NULL;--> statement-breakpoint
|
|
2
|
+
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
|
3
|
+
CREATE TABLE `__new_explore_findings` (
|
|
4
|
+
`finding_key` text NOT NULL,
|
|
5
|
+
`kind` text NOT NULL,
|
|
6
|
+
`file` text NOT NULL,
|
|
7
|
+
`line` integer NOT NULL,
|
|
8
|
+
`function` text NOT NULL,
|
|
9
|
+
`input` text NOT NULL,
|
|
10
|
+
`target` text NOT NULL,
|
|
11
|
+
`source_hash` text NOT NULL,
|
|
12
|
+
`plugin` text DEFAULT 'explore' NOT NULL,
|
|
13
|
+
CONSTRAINT `explore_findings_pk` PRIMARY KEY(`plugin`, `target`, `finding_key`),
|
|
14
|
+
CONSTRAINT "explore_findings_kind_check" CHECK("kind" in ('throw', 'property'))
|
|
15
|
+
);
|
|
16
|
+
--> statement-breakpoint
|
|
17
|
+
INSERT INTO `__new_explore_findings`(`finding_key`, `kind`, `file`, `line`, `function`, `input`, `target`, `source_hash`) SELECT `finding_key`, `kind`, `file`, `line`, `function`, `input`, `target`, `source_hash` FROM `explore_findings`;--> statement-breakpoint
|
|
18
|
+
DROP TABLE `explore_findings`;--> statement-breakpoint
|
|
19
|
+
ALTER TABLE `__new_explore_findings` RENAME TO `explore_findings`;--> statement-breakpoint
|
|
20
|
+
PRAGMA foreign_keys=ON;
|