@under18dev/veritas-mutation-adapter 0.0.0-stage → 0.1.1
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 +202 -0
- package/README.md +12 -2
- package/dist/detect.d.ts +27 -0
- package/dist/detect.d.ts.map +1 -0
- package/dist/detect.js +143 -0
- package/dist/detect.js.map +1 -0
- package/dist/import.d.ts +72 -0
- package/dist/import.d.ts.map +1 -0
- package/dist/import.js +164 -0
- package/dist/import.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/run.d.ts +49 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +303 -0
- package/dist/run.js.map +1 -0
- package/dist/schema.d.ts +126 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +50 -0
- package/dist/schema.js.map +1 -0
- package/dist/vitest-config.d.ts +14 -0
- package/dist/vitest-config.d.ts.map +1 -0
- package/dist/vitest-config.js +66 -0
- package/dist/vitest-config.js.map +1 -0
- package/package.json +26 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @under18dev/veritas-mutation-adapter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Mutation testing adapter (@mizchi/mutator) for Veritas
|
|
4
|
+
|
|
5
|
+
Part of [Veritas](https://github.com/under18dev/veritas), specification-aware test verification for TypeScript/JavaScript projects. Most users install the main package, which provides the `veritas` and `veritas-mcp` commands and the Node API:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D @under18dev/veritas
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This package is an internal building block of that package; its API may change between minor versions. Source: [`packages/mutation-adapter`](https://github.com/under18dev/veritas/tree/main/packages/mutation-adapter).
|
|
12
|
+
|
|
13
|
+
Licensed under Apache-2.0.
|
package/dist/detect.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MutatorDetection, MutatorOrigin } from './schema.js';
|
|
2
|
+
/** The mutator version this adapter is built and tested against. Others run with a warning. */
|
|
3
|
+
export declare const PINNED_MUTATOR_VERSION = "0.4.5";
|
|
4
|
+
/** Flags the adapter passes; a mutator whose `--help` lacks one of these is unsupported. */
|
|
5
|
+
export declare const REQUIRED_CAPABILITIES: readonly ["--root", "--reporter", "--report-dir"];
|
|
6
|
+
/** Flags used only when the caller asks for them. */
|
|
7
|
+
export declare const OPTIONAL_CAPABILITIES: readonly ["--since", "--include", "--kill-matrix", "--only", "--config", "--[no-]typecheck", "--time-budget", "agent", "json"];
|
|
8
|
+
export interface DetectOptions {
|
|
9
|
+
/** Explicit path to the mutator CLI script; skips resolution. */
|
|
10
|
+
binPath?: string;
|
|
11
|
+
/** Fall back to the mutator this adapter depends on when the project has none (default true). */
|
|
12
|
+
fallbackToAdapter?: boolean;
|
|
13
|
+
timeoutMs?: number;
|
|
14
|
+
}
|
|
15
|
+
interface Located {
|
|
16
|
+
binPath: string;
|
|
17
|
+
version: string | null;
|
|
18
|
+
origin: MutatorOrigin;
|
|
19
|
+
}
|
|
20
|
+
/** Locate the mutator CLI: the project's own installation first, then the adapter's dependency. */
|
|
21
|
+
export declare function locateMutator(root: string, options?: DetectOptions): Located | null;
|
|
22
|
+
/** Find mutator and confirm, from its own `--help`, which flags it supports. */
|
|
23
|
+
export declare function detectMutator(root: string, options?: DetectOptions): Promise<MutatorDetection>;
|
|
24
|
+
/** The last lines of a (already redacted) output stream, for diagnostics. */
|
|
25
|
+
export declare function summarize(text: string, maxLines?: number, maxChars?: number): string;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=detect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEnE,+FAA+F;AAC/F,eAAO,MAAM,sBAAsB,UAAU,CAAC;AAE9C,4FAA4F;AAC5F,eAAO,MAAM,qBAAqB,mDAAoD,CAAC;AAEvF,qDAAqD;AACrD,eAAO,MAAM,qBAAqB,gIAUxB,CAAC;AAEX,MAAM,WAAW,aAAa;IAC5B,iEAAiE;IACjE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iGAAiG;IACjG,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,OAAO;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,aAAa,CAAC;CACvB;AA2DD,mGAAmG;AACnG,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,GAAG,IAAI,CAiBvF;AAED,gFAAgF;AAChF,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAyDxG;AAED,6EAA6E;AAC7E,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,SAAK,EAAE,QAAQ,SAAO,GAAG,MAAM,CAK9E"}
|
package/dist/detect.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { runCommand } from '@under18dev/veritas-core';
|
|
5
|
+
/** The mutator version this adapter is built and tested against. Others run with a warning. */
|
|
6
|
+
export const PINNED_MUTATOR_VERSION = '0.4.5';
|
|
7
|
+
/** Flags the adapter passes; a mutator whose `--help` lacks one of these is unsupported. */
|
|
8
|
+
export const REQUIRED_CAPABILITIES = ['--root', '--reporter', '--report-dir'];
|
|
9
|
+
/** Flags used only when the caller asks for them. */
|
|
10
|
+
export const OPTIONAL_CAPABILITIES = [
|
|
11
|
+
'--since',
|
|
12
|
+
'--include',
|
|
13
|
+
'--kill-matrix',
|
|
14
|
+
'--only',
|
|
15
|
+
'--config',
|
|
16
|
+
'--[no-]typecheck',
|
|
17
|
+
'--time-budget',
|
|
18
|
+
'agent',
|
|
19
|
+
'json',
|
|
20
|
+
];
|
|
21
|
+
/** Walk up from `start` looking for `node_modules/@mizchi/mutator`, as Node's resolver would. */
|
|
22
|
+
function findPackageDir(start) {
|
|
23
|
+
let dir = path.resolve(start);
|
|
24
|
+
for (;;) {
|
|
25
|
+
const candidate = path.join(dir, 'node_modules', '@mizchi', 'mutator', 'package.json');
|
|
26
|
+
if (existsSync(candidate))
|
|
27
|
+
return path.dirname(candidate);
|
|
28
|
+
const parent = path.dirname(dir);
|
|
29
|
+
if (parent === dir)
|
|
30
|
+
return null;
|
|
31
|
+
dir = parent;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function adapterPackageDir() {
|
|
35
|
+
try {
|
|
36
|
+
const entry = createRequire(import.meta.url).resolve('@mizchi/mutator');
|
|
37
|
+
let dir = path.dirname(entry);
|
|
38
|
+
while (!existsSync(path.join(dir, 'package.json'))) {
|
|
39
|
+
const parent = path.dirname(dir);
|
|
40
|
+
if (parent === dir)
|
|
41
|
+
return null;
|
|
42
|
+
dir = parent;
|
|
43
|
+
}
|
|
44
|
+
return dir;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Not installed next to the adapter: the caller reports the binary as unavailable.
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function fromPackageDir(dir, origin) {
|
|
52
|
+
try {
|
|
53
|
+
const pkg = JSON.parse(readFileSync(path.join(dir, 'package.json'), 'utf8'));
|
|
54
|
+
if (pkg.name !== '@mizchi/mutator')
|
|
55
|
+
return null;
|
|
56
|
+
const bin = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin?.mutator;
|
|
57
|
+
if (!bin)
|
|
58
|
+
return null;
|
|
59
|
+
const binPath = path.resolve(dir, bin);
|
|
60
|
+
if (!existsSync(binPath))
|
|
61
|
+
return null;
|
|
62
|
+
return { binPath, version: typeof pkg.version === 'string' ? pkg.version : null, origin };
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// An unreadable or malformed package.json means this candidate is not a usable mutator.
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Locate the mutator CLI: the project's own installation first, then the adapter's dependency. */
|
|
70
|
+
export function locateMutator(root, options = {}) {
|
|
71
|
+
if (options.binPath !== undefined) {
|
|
72
|
+
if (!existsSync(options.binPath))
|
|
73
|
+
return null;
|
|
74
|
+
const pkgDir = path.dirname(path.dirname(options.binPath));
|
|
75
|
+
const fromPkg = fromPackageDir(pkgDir, 'explicit');
|
|
76
|
+
return { binPath: path.resolve(options.binPath), version: fromPkg?.version ?? null, origin: 'explicit' };
|
|
77
|
+
}
|
|
78
|
+
const projectDir = findPackageDir(root);
|
|
79
|
+
const project = projectDir ? fromPackageDir(projectDir, 'project') : null;
|
|
80
|
+
if (project)
|
|
81
|
+
return project;
|
|
82
|
+
if (options.fallbackToAdapter === false)
|
|
83
|
+
return null;
|
|
84
|
+
const adapterDir = adapterPackageDir();
|
|
85
|
+
return adapterDir ? fromPackageDir(adapterDir, 'adapter') : null;
|
|
86
|
+
}
|
|
87
|
+
/** Find mutator and confirm, from its own `--help`, which flags it supports. */
|
|
88
|
+
export async function detectMutator(root, options = {}) {
|
|
89
|
+
const located = locateMutator(root, options);
|
|
90
|
+
if (!located) {
|
|
91
|
+
return {
|
|
92
|
+
available: false,
|
|
93
|
+
version: null,
|
|
94
|
+
binPath: null,
|
|
95
|
+
origin: null,
|
|
96
|
+
capabilities: [],
|
|
97
|
+
detail: options.binPath !== undefined
|
|
98
|
+
? `mutator CLI not found at ${options.binPath}`
|
|
99
|
+
: `@mizchi/mutator is not installed in ${root} or its parents${options.fallbackToAdapter === false ? '' : ', nor next to @under18dev/veritas-mutation-adapter'}`,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const help = await runCommand(process.execPath, [located.binPath, '--help'], {
|
|
103
|
+
cwd: root,
|
|
104
|
+
timeoutMs: options.timeoutMs ?? 30_000,
|
|
105
|
+
});
|
|
106
|
+
const base = { version: located.version, binPath: located.binPath, origin: located.origin };
|
|
107
|
+
if (help.spawnError || help.timedOut || help.exitCode !== 0) {
|
|
108
|
+
const why = help.spawnError ?? (help.timedOut ? 'timed out' : `exit code ${help.exitCode}`);
|
|
109
|
+
return {
|
|
110
|
+
...base,
|
|
111
|
+
available: false,
|
|
112
|
+
capabilities: [],
|
|
113
|
+
detail: `mutator --help failed (${why}): ${summarize(help.stderr)}`,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const text = help.stdout + help.stderr;
|
|
117
|
+
const capabilities = [...REQUIRED_CAPABILITIES, ...OPTIONAL_CAPABILITIES].filter((flag) => new RegExp(`(^|[\\s,])${flag.replace(/[-[\]]/g, '\\$&')}(?=[\\s,)]|$)`, 'm').test(text));
|
|
118
|
+
const missing = REQUIRED_CAPABILITIES.filter((flag) => !capabilities.includes(flag));
|
|
119
|
+
const versionNote = located.version === PINNED_MUTATOR_VERSION
|
|
120
|
+
? `pinned version ${PINNED_MUTATOR_VERSION}`
|
|
121
|
+
: `version ${located.version ?? 'unknown'} differs from the pinned ${PINNED_MUTATOR_VERSION}`;
|
|
122
|
+
if (missing.length > 0) {
|
|
123
|
+
return {
|
|
124
|
+
...base,
|
|
125
|
+
available: false,
|
|
126
|
+
capabilities,
|
|
127
|
+
detail: `mutator at ${located.binPath} lacks required flags: ${missing.join(', ')} (${versionNote})`,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
...base,
|
|
132
|
+
available: true,
|
|
133
|
+
capabilities,
|
|
134
|
+
detail: `mutator resolved from the ${located.origin === 'project' ? 'project' : located.origin === 'adapter' ? 'adapter dependency' : 'explicit path'} at ${located.binPath} (${versionNote})`,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** The last lines of a (already redacted) output stream, for diagnostics. */
|
|
138
|
+
export function summarize(text, maxLines = 15, maxChars = 2000) {
|
|
139
|
+
const lines = text.trim().split('\n');
|
|
140
|
+
const tail = lines.slice(-maxLines).join('\n');
|
|
141
|
+
return tail.length > maxChars ? tail.slice(-maxChars) : tail;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=detect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,+FAA+F;AAC/F,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAE9C,4FAA4F;AAC5F,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,QAAQ,EAAE,YAAY,EAAE,cAAc,CAAU,CAAC;AAEvF,qDAAqD;AACrD,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,SAAS;IACT,WAAW;IACX,eAAe;IACf,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
export type ReportSource = 'mutator' | 'stryker' | 'mutation-testing-elements';
|
|
4
|
+
/** The subset of the mutation-testing-elements report (schemaVersion 2) this adapter reads. */
|
|
5
|
+
export declare const MutationTestingReport: z.ZodObject<{
|
|
6
|
+
schemaVersion: z.ZodString;
|
|
7
|
+
files: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
8
|
+
source: z.ZodOptional<z.ZodString>;
|
|
9
|
+
mutants: z.ZodArray<z.ZodObject<{
|
|
10
|
+
id: z.ZodString;
|
|
11
|
+
mutatorName: z.ZodString;
|
|
12
|
+
replacement: z.ZodOptional<z.ZodString>;
|
|
13
|
+
location: z.ZodObject<{
|
|
14
|
+
start: z.ZodObject<{
|
|
15
|
+
line: z.ZodNumber;
|
|
16
|
+
column: z.ZodNumber;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
end: z.ZodObject<{
|
|
19
|
+
line: z.ZodNumber;
|
|
20
|
+
column: z.ZodNumber;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
status: z.ZodString;
|
|
24
|
+
statusReason: z.ZodOptional<z.ZodString>;
|
|
25
|
+
killedBy: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
26
|
+
coveredBy: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
27
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
28
|
+
}, z.core.$strip>>;
|
|
29
|
+
}, z.core.$strip>>;
|
|
30
|
+
testFiles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
31
|
+
tests: z.ZodArray<z.ZodObject<{
|
|
32
|
+
id: z.ZodString;
|
|
33
|
+
name: z.ZodString;
|
|
34
|
+
}, z.core.$strip>>;
|
|
35
|
+
}, z.core.$strip>>>;
|
|
36
|
+
framework: z.ZodOptional<z.ZodObject<{
|
|
37
|
+
name: z.ZodString;
|
|
38
|
+
version: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, z.core.$strip>>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
export type MutationTestingReport = z.infer<typeof MutationTestingReport>;
|
|
42
|
+
/** Marker mutator puts in `statusReason` for mutants only a spawned child process may reach. */
|
|
43
|
+
export declare const CHILD_PROCESS_MARKER = "possibly reached in a child process";
|
|
44
|
+
/**
|
|
45
|
+
* Split a mutator test id (`<file>#<vitest fullName>`) into the parts test-inventory hashes.
|
|
46
|
+
* Vitest joins suite names with ` > `, so a test or suite name that itself contains ` > ` is split too;
|
|
47
|
+
* a multi-project prefix (`[name] `) is dropped.
|
|
48
|
+
*/
|
|
49
|
+
export declare function mutatorTestRef(name: string): {
|
|
50
|
+
file: string;
|
|
51
|
+
suitePath: string[];
|
|
52
|
+
name: string;
|
|
53
|
+
};
|
|
54
|
+
/** The test id test-inventory assigns to the test behind a mutator test name. */
|
|
55
|
+
export declare function mutatorTestId(name: string): string;
|
|
56
|
+
export interface ImportOptions {
|
|
57
|
+
root: string;
|
|
58
|
+
source: ReportSource;
|
|
59
|
+
/** Keys of mutants mutator flags as reachable only from a child process (agent report `childProcess`). */
|
|
60
|
+
childProcessKeys?: ReadonlySet<string>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Normalize a mutation-testing-elements report into core mutants. Survivors stay `survived`:
|
|
64
|
+
* equivalence is never inferred here.
|
|
65
|
+
*/
|
|
66
|
+
export declare function importMutationReport(json: unknown, options: ImportOptions): Mutant[];
|
|
67
|
+
/**
|
|
68
|
+
* POSIX-shell quoting for display of reproduction commands. The rule is the same on every OS:
|
|
69
|
+
* anything outside `[A-Za-z0-9_./:=@%+-]` (backslashes, spaces, quotes...) is single-quoted.
|
|
70
|
+
*/
|
|
71
|
+
export declare function shellQuote(arg: string): string;
|
|
72
|
+
//# sourceMappingURL=import.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../src/import.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EAOP,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,2BAA2B,CAAC;AAI/E,+FAA+F;AAC/F,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyBhC,CAAC;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAa1E,gGAAgG;AAChG,eAAO,MAAM,oBAAoB,wCAAwC,CAAC;AAE1E;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAQhG;AAED,iFAAiF;AACjF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,YAAY,CAAC;IACrB,0GAA0G;IAC1G,gBAAgB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACxC;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,EAAE,CAoEpF;AA8CD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C"}
|
package/dist/import.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { realpathSync } from 'node:fs';
|
|
2
|
+
import { Mutant, redact, resolveInsideRoot, stableId, toPosixRelative, VeritasError, } from '@under18dev/veritas-core';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
const Position = z.object({ line: z.number().int().positive(), column: z.number().int().nonnegative() });
|
|
5
|
+
/** The subset of the mutation-testing-elements report (schemaVersion 2) this adapter reads. */
|
|
6
|
+
export const MutationTestingReport = z.object({
|
|
7
|
+
schemaVersion: z.string().regex(/^2(\.|$)/, 'expected a mutation-testing-elements schemaVersion 2 report'),
|
|
8
|
+
files: z.record(z.string(), z.object({
|
|
9
|
+
source: z.string().optional(),
|
|
10
|
+
mutants: z.array(z.object({
|
|
11
|
+
id: z.string().min(1),
|
|
12
|
+
mutatorName: z.string(),
|
|
13
|
+
replacement: z.string().optional(),
|
|
14
|
+
location: z.object({ start: Position, end: Position }),
|
|
15
|
+
status: z.string(),
|
|
16
|
+
statusReason: z.string().optional(),
|
|
17
|
+
killedBy: z.array(z.string()).optional(),
|
|
18
|
+
coveredBy: z.array(z.string()).optional(),
|
|
19
|
+
duration: z.number().nonnegative().optional(),
|
|
20
|
+
})),
|
|
21
|
+
})),
|
|
22
|
+
testFiles: z
|
|
23
|
+
.record(z.string(), z.object({ tests: z.array(z.object({ id: z.string(), name: z.string() })) }))
|
|
24
|
+
.optional(),
|
|
25
|
+
framework: z.object({ name: z.string(), version: z.string().optional() }).optional(),
|
|
26
|
+
});
|
|
27
|
+
const STATUS_MAP = {
|
|
28
|
+
Killed: 'killed',
|
|
29
|
+
Survived: 'survived',
|
|
30
|
+
NoCoverage: 'no_coverage',
|
|
31
|
+
Timeout: 'timeout',
|
|
32
|
+
CompileError: 'compile_error',
|
|
33
|
+
RuntimeError: 'runtime_error',
|
|
34
|
+
Ignored: 'ignored',
|
|
35
|
+
Pending: 'pending',
|
|
36
|
+
};
|
|
37
|
+
/** Marker mutator puts in `statusReason` for mutants only a spawned child process may reach. */
|
|
38
|
+
export const CHILD_PROCESS_MARKER = 'possibly reached in a child process';
|
|
39
|
+
/**
|
|
40
|
+
* Split a mutator test id (`<file>#<vitest fullName>`) into the parts test-inventory hashes.
|
|
41
|
+
* Vitest joins suite names with ` > `, so a test or suite name that itself contains ` > ` is split too;
|
|
42
|
+
* a multi-project prefix (`[name] `) is dropped.
|
|
43
|
+
*/
|
|
44
|
+
export function mutatorTestRef(name) {
|
|
45
|
+
const hash = name.indexOf('#');
|
|
46
|
+
const file = hash < 0 ? '' : name.slice(0, hash).replaceAll('\\', '/');
|
|
47
|
+
const full = (hash < 0 ? name : name.slice(hash + 1)).replace(/^\[[^\]]*\] /, '');
|
|
48
|
+
const parts = full.split(' > ');
|
|
49
|
+
const testName = parts.pop() ?? '';
|
|
50
|
+
return { file, suitePath: parts, name: testName };
|
|
51
|
+
}
|
|
52
|
+
/** The test id test-inventory assigns to the test behind a mutator test name. */
|
|
53
|
+
export function mutatorTestId(name) {
|
|
54
|
+
return stableId('T', mutatorTestRef(name));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Normalize a mutation-testing-elements report into core mutants. Survivors stay `survived`:
|
|
58
|
+
* equivalence is never inferred here.
|
|
59
|
+
*/
|
|
60
|
+
export function importMutationReport(json, options) {
|
|
61
|
+
const parsed = MutationTestingReport.safeParse(json);
|
|
62
|
+
if (!parsed.success) {
|
|
63
|
+
throw new VeritasError('tool', 'MUTATION_REPORT_INVALID', `not a mutation-testing-elements report: ${parsed.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join('; ')}`);
|
|
64
|
+
}
|
|
65
|
+
const report = parsed.data;
|
|
66
|
+
const realRoot = realpathSync(options.root);
|
|
67
|
+
const testNames = new Map();
|
|
68
|
+
for (const [file, { tests }] of Object.entries(report.testFiles ?? {})) {
|
|
69
|
+
for (const t of tests)
|
|
70
|
+
testNames.set(t.id, options.source === 'mutator' ? t.id : `${file}#${t.name}`);
|
|
71
|
+
}
|
|
72
|
+
const testRef = (id) => {
|
|
73
|
+
if (options.source === 'mutator')
|
|
74
|
+
return mutatorTestId(id);
|
|
75
|
+
const raw = testNames.get(id) ?? id;
|
|
76
|
+
// Raw refs are exposed as-is, so redact them; long ones are hashed (the hash reveals nothing).
|
|
77
|
+
return raw.length <= 200 ? redact(raw) : stableId('TR', raw);
|
|
78
|
+
};
|
|
79
|
+
const mutants = [];
|
|
80
|
+
for (const fileKey of Object.keys(report.files).sort()) {
|
|
81
|
+
const entry = report.files[fileKey];
|
|
82
|
+
if (!entry)
|
|
83
|
+
continue;
|
|
84
|
+
const file = toPosixRelative(realRoot, resolveInsideRoot(realRoot, fileKey));
|
|
85
|
+
for (const m of entry.mutants) {
|
|
86
|
+
const { status, statusReason } = mapStatus(m.status, m.statusReason, options.childProcessKeys?.has(m.id));
|
|
87
|
+
mutants.push(Mutant.parse({
|
|
88
|
+
id: stableId('M', { file, key: m.id }),
|
|
89
|
+
backendKey: m.id,
|
|
90
|
+
location: {
|
|
91
|
+
file,
|
|
92
|
+
range: {
|
|
93
|
+
start: m.location.start.line,
|
|
94
|
+
end: Math.max(m.location.start.line, m.location.end.line),
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
// Every string taken from the report is untrusted and may carry secrets from the source.
|
|
98
|
+
operator: redact(m.mutatorName),
|
|
99
|
+
original: entry.source === undefined ? '' : redact(sliceSource(entry.source, m.location)),
|
|
100
|
+
replacement: redact(m.replacement ?? ''),
|
|
101
|
+
status,
|
|
102
|
+
...(statusReason === undefined ? {} : { statusReason: redact(statusReason) }),
|
|
103
|
+
killedBy: unique((m.killedBy ?? []).map(testRef)),
|
|
104
|
+
coveredBy: unique((m.coveredBy ?? []).map(testRef)),
|
|
105
|
+
propertyIds: [],
|
|
106
|
+
relevance: 'unknown',
|
|
107
|
+
...(m.duration === undefined ? {} : { durationMs: m.duration }),
|
|
108
|
+
reproduction: redact(reproductionFor(options.source, realRoot, file, m.id, m.location)),
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return mutants;
|
|
113
|
+
}
|
|
114
|
+
function mapStatus(raw, reason, childProcessFlag) {
|
|
115
|
+
const status = Object.hasOwn(STATUS_MAP, raw) ? STATUS_MAP[raw] : undefined;
|
|
116
|
+
if (status === undefined) {
|
|
117
|
+
return {
|
|
118
|
+
status: 'unknown',
|
|
119
|
+
statusReason: [`unrecognized backend status: ${raw}`, reason].filter(Boolean).join('; '),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const undetected = status === 'survived' || status === 'no_coverage';
|
|
123
|
+
if (undetected && (childProcessFlag || reason?.includes(CHILD_PROCESS_MARKER))) {
|
|
124
|
+
return { status: 'unknown', statusReason: reason ?? `${CHILD_PROCESS_MARKER} (backend status ${raw})` };
|
|
125
|
+
}
|
|
126
|
+
return reason === undefined ? { status } : { status, statusReason: reason };
|
|
127
|
+
}
|
|
128
|
+
/** Text between two 1-based (line, column) positions; the end column is exclusive. */
|
|
129
|
+
function sliceSource(source, loc) {
|
|
130
|
+
const lines = source.split('\n');
|
|
131
|
+
const offset = (line, column) => {
|
|
132
|
+
if (line > lines.length)
|
|
133
|
+
return undefined;
|
|
134
|
+
let at = 0;
|
|
135
|
+
for (let i = 0; i < line - 1; i++)
|
|
136
|
+
at += (lines[i]?.length ?? 0) + 1;
|
|
137
|
+
return at + Math.max(0, column - 1);
|
|
138
|
+
};
|
|
139
|
+
const start = offset(loc.start.line, loc.start.column);
|
|
140
|
+
const end = offset(loc.end.line, loc.end.column);
|
|
141
|
+
if (start === undefined || end === undefined || end < start)
|
|
142
|
+
return '';
|
|
143
|
+
return source.slice(start, end);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* POSIX-shell quoting for display of reproduction commands. The rule is the same on every OS:
|
|
147
|
+
* anything outside `[A-Za-z0-9_./:=@%+-]` (backslashes, spaces, quotes...) is single-quoted.
|
|
148
|
+
*/
|
|
149
|
+
export function shellQuote(arg) {
|
|
150
|
+
return /^[A-Za-z0-9_./:=@%+-]+$/.test(arg) ? arg : `'${arg.replaceAll("'", `'\\''`)}'`;
|
|
151
|
+
}
|
|
152
|
+
function reproductionFor(source, root, file, key, loc) {
|
|
153
|
+
if (source === 'mutator')
|
|
154
|
+
return ['mutator', '--root', root, '--only', key].map(shellQuote).join(' ');
|
|
155
|
+
if (source === 'stryker') {
|
|
156
|
+
const range = `${file}:${loc.start.line}:${loc.start.column}-${loc.end.line}:${loc.end.column}`;
|
|
157
|
+
return ['npx', 'stryker', 'run', '--mutate', range].map(shellQuote).join(' ');
|
|
158
|
+
}
|
|
159
|
+
return `unavailable: report from an unidentified backend (mutant ${key} in ${file})`;
|
|
160
|
+
}
|
|
161
|
+
function unique(values) {
|
|
162
|
+
return [...new Set(values)];
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=import.js.map
|