targeted-mutation 0.0.0-stage → 0.1.0
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/LICENSE +201 -0
- package/NOTICE +21 -0
- package/README.md +111 -2
- package/bin/tmt-compile.mjs +46 -0
- package/bin/tmt.mjs +117 -0
- package/build/typescript-syntax/LICENSE.txt +55 -0
- package/build/typescript-syntax/ThirdPartyNoticeText.txt +193 -0
- package/build/typescript-syntax/typescript-syntax.cjs +43 -0
- package/docs/analysis.md +218 -0
- package/docs/compiler.md +462 -0
- package/docs/development.md +61 -0
- package/docs/how-it-works.svg +188 -0
- package/docs/l1.md +94 -0
- package/docs/performance.md +647 -0
- package/docs/releasing.md +48 -0
- package/package.json +49 -4
- package/src/analysis.mjs +689 -0
- package/src/assertion-session.mjs +93 -0
- package/src/assertion-strength.mjs +795 -0
- package/src/builtin-mutations.mjs +755 -0
- package/src/builtin-switches.mjs +642 -0
- package/src/change-undone.mjs +524 -0
- package/src/cli-output.mjs +166 -0
- package/src/compiler-compat.cjs +108 -0
- package/src/compiler-maps.cjs +60 -0
- package/src/compiler-routes.cjs +391 -0
- package/src/compiler.cjs +98 -0
- package/src/compiler.mjs +1 -0
- package/src/conventional.mjs +172 -0
- package/src/displacement.mjs +19 -0
- package/src/extract.mjs +135 -0
- package/src/fallback-process.mjs +14 -0
- package/src/in-parallel.mjs +20 -0
- package/src/lean-replay.mjs +39 -0
- package/src/operator-analysis.mjs +123 -0
- package/src/playwright.mjs +139 -0
- package/src/probe-runtime.mjs +50 -0
- package/src/probe.mjs +170 -0
- package/src/prototype.mjs +230 -0
- package/src/regex-mutations.mjs +102 -0
- package/src/runner-process.mjs +59 -0
- package/src/runtime-binaries.mjs +50 -0
- package/src/scope.mjs +202 -0
- package/src/source-text.mjs +49 -0
- package/src/standard-plan.mjs +308 -0
- package/src/standard-runner.mjs +185 -0
- package/src/standard-session.mjs +362 -0
- package/src/standard-setup.mjs +20 -0
- package/src/targeted-gaps.mjs +85 -0
- package/src/threshold.mjs +185 -0
- package/src/trace-buffer.mjs +126 -0
- package/src/typescript-bindings.mjs +243 -0
- package/src/typescript-compiler.mjs +59 -0
- package/src/typescript-extraction.mjs +354 -0
- package/src/typescript-grammar.mjs +923 -0
- package/src/vitest-reporter.mjs +64 -0
- package/src/vitest.mjs +262 -0
- package/src/witness-analysis.mjs +234 -0
- package/src/witness-contracts.mjs +110 -0
- package/src/witness-discovery.mjs +239 -0
- package/src/witness-fixtures.mjs +148 -0
- package/src/witness-order.mjs +83 -0
- package/src/witness-rules.mjs +254 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { pathToFileURL } from 'node:url';
|
|
6
|
+
import { inside } from './vitest.mjs';
|
|
7
|
+
|
|
8
|
+
// Warm Vitest 4 child process for `--suggest-assertions`: runs with `cwd: workspace` in an isolated process
|
|
9
|
+
// communicating over a dedicated Node IPC channel (so config stdout cannot corrupt protocol messages, Vitest's
|
|
10
|
+
// `process.exitCode` mutations never leak to the CLI, and timeouts can terminate the entire process group).
|
|
11
|
+
const [, , workspace, configArg] = process.argv;
|
|
12
|
+
const config = configArg ? inside(workspace, configArg) : undefined;
|
|
13
|
+
const applyEdit = (input, [start, end], replacement) => Buffer.concat([input.subarray(0, start), Buffer.from(replacement), input.subarray(end)]);
|
|
14
|
+
|
|
15
|
+
function reply(message) {
|
|
16
|
+
if (typeof process.send === 'function' && process.connected) process.send(message);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let vitest;
|
|
20
|
+
try {
|
|
21
|
+
const req = createRequire(resolve(workspace, 'package.json'));
|
|
22
|
+
const version = req('vitest/package.json').version;
|
|
23
|
+
if (!version.startsWith('4.')) {
|
|
24
|
+
reply({ ready: false, reason: `Requires Vitest 4, found ${version}` });
|
|
25
|
+
process.exit(0);
|
|
26
|
+
}
|
|
27
|
+
const { createVitest } = await import(pathToFileURL(req.resolve('vitest/node')).href);
|
|
28
|
+
vitest = await createVitest('test', {
|
|
29
|
+
root: workspace, config, watch: false, api: false, ui: false, cache: false,
|
|
30
|
+
pool: 'threads', isolate: true, maxConcurrency: 1, maxWorkers: 1, fileParallelism: false,
|
|
31
|
+
coverage: { enabled: false }, onConsoleLog: () => false,
|
|
32
|
+
reporters: [{ onInit() {} }],
|
|
33
|
+
});
|
|
34
|
+
for (const project of vitest.projects) {
|
|
35
|
+
if (project.config.browser?.enabled || project.config.typecheck?.enabled || project.config.runner) {
|
|
36
|
+
reply({ ready: false, reason: 'Unsupported Vitest project configuration for warm session' });
|
|
37
|
+
await vitest.close();
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const specCache = new Map();
|
|
42
|
+
let queue = Promise.resolve();
|
|
43
|
+
let doneResolve;
|
|
44
|
+
const done = new Promise(resolveDone => { doneResolve = resolveDone; });
|
|
45
|
+
process.on('disconnect', () => doneResolve());
|
|
46
|
+
process.on('message', reqMsg => {
|
|
47
|
+
if (!reqMsg || typeof reqMsg !== 'object') return;
|
|
48
|
+
if (reqMsg.close) { doneResolve(); return; }
|
|
49
|
+
queue = queue.then(async () => {
|
|
50
|
+
const { id, testFile, rewriteContent, collect, trial, subjectFile, subjectDigest } = reqMsg;
|
|
51
|
+
const absTest = inside(workspace, testFile);
|
|
52
|
+
const origTest = readFileSync(absTest);
|
|
53
|
+
const absSubject = subjectFile ? inside(workspace, subjectFile) : null;
|
|
54
|
+
const origSubject = absSubject ? readFileSync(absSubject) : null;
|
|
55
|
+
const absCollect = resolve(workspace, collect);
|
|
56
|
+
try {
|
|
57
|
+
if (absSubject && subjectDigest && createHash('sha256').update(origSubject).digest('hex') !== subjectDigest) {
|
|
58
|
+
reply({ id, error: `Source changed during analysis: ${subjectFile}` });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!specCache.has(absTest)) {
|
|
62
|
+
const specs = await vitest.globTestSpecifications([absTest]);
|
|
63
|
+
if (!specs.length) {
|
|
64
|
+
reply({ id, unsupported: true });
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
specCache.set(absTest, specs);
|
|
68
|
+
}
|
|
69
|
+
writeFileSync(absTest, rewriteContent);
|
|
70
|
+
if (absSubject && trial) writeFileSync(absSubject, applyEdit(origSubject, trial.edit, trial.replacement));
|
|
71
|
+
vitest.vite?.moduleGraph?.invalidateAll();
|
|
72
|
+
for (const project of vitest.projects) project.vite?.moduleGraph?.invalidateAll();
|
|
73
|
+
await vitest.runTestSpecifications(specCache.get(absTest));
|
|
74
|
+
const collected = existsSync(absCollect) ? readFileSync(absCollect, 'utf8') : '';
|
|
75
|
+
reply({ id, collected });
|
|
76
|
+
} catch (error) {
|
|
77
|
+
reply({ id, error: error?.message ?? String(error) });
|
|
78
|
+
} finally {
|
|
79
|
+
rmSync(absCollect, { force: true });
|
|
80
|
+
writeFileSync(absTest, origTest);
|
|
81
|
+
if (absSubject && origSubject) writeFileSync(absSubject, origSubject);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
reply({ ready: true });
|
|
86
|
+
await done;
|
|
87
|
+
await queue;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
reply({ ready: false, reason: error?.message ?? String(error) });
|
|
90
|
+
} finally {
|
|
91
|
+
if (vitest) await Promise.race([vitest.close().catch(() => {}), new Promise(resolveClose => setTimeout(resolveClose, 5_000))]);
|
|
92
|
+
process.exit(0);
|
|
93
|
+
}
|