tribunal-kit 5.7.0 → 5.8.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/.agent/ARCHITECTURE.md +6 -7
- package/.agent/agents/frontend-reviewer.md +13 -0
- package/.agent/agents/frontend-specialist.md +14 -0
- package/.agent/agents/logic-reviewer.md +11 -0
- package/.agent/agents/orchestrator.md +15 -0
- package/.agent/agents/security-auditor.md +13 -0
- package/.agent/agents/ui-ux-auditor.md +7 -31
- package/.agent/history/memory/.memory.idx +766 -0
- package/.agent/history/memory/MEMORY.md +62 -0
- package/.agent/routing_index.json +694 -714
- package/.agent/rules/GEMINI.md +58 -8
- package/.agent/scripts/_colors.js +131 -89
- package/.agent/scripts/_utils.js +163 -128
- package/.agent/scripts/auto_preview.js +207 -197
- package/.agent/scripts/bundle_analyzer.js +227 -192
- package/.agent/scripts/case_law_manager.js +991 -689
- package/.agent/scripts/checklist.js +233 -190
- package/.agent/scripts/context_broker.js +930 -605
- package/.agent/scripts/dependency_analyzer.js +275 -184
- package/.agent/scripts/graph_builder.js +412 -341
- package/.agent/scripts/graph_visualizer.js +392 -390
- package/.agent/scripts/graph_zoom.js +198 -156
- package/.agent/scripts/inner_loop_validator.js +523 -445
- package/.agent/scripts/lint_runner.js +199 -157
- package/.agent/scripts/marathon_harness.js +819 -661
- package/.agent/scripts/minify_context.js +115 -100
- package/.agent/scripts/mutation_runner.js +321 -280
- package/.agent/scripts/prompt_compiler.js +62 -42
- package/.agent/scripts/schema_validator.js +373 -280
- package/.agent/scripts/security_scan.js +333 -190
- package/.agent/scripts/session_manager.js +306 -270
- package/.agent/scripts/skill_evolution.js +810 -637
- package/.agent/scripts/skill_integrator.js +327 -307
- package/.agent/scripts/strengthen_skills.js +203 -193
- package/.agent/scripts/swarm_dispatcher.js +558 -457
- package/.agent/scripts/test_runner.js +178 -152
- package/.agent/scripts/verify_all.js +200 -168
- package/.agent/skills/fabel-protocol/SKILL.md +235 -0
- package/.agent/skills/thinking-protocol/SKILL.md +27 -0
- package/.agent/workflows/generate.md +1 -1
- package/.agent/workflows/tribunal-speed.md +1 -1
- package/README.md +53 -53
- package/bin/mcp-server.js +460 -175
- package/bin/tribunal-kit.js +1245 -987
- package/bin/wrapper.js +104 -74
- package/dist/cli.js +31 -0
- package/dist/commands/case.js +23 -0
- package/dist/commands/compile.js +84 -0
- package/dist/commands/init.js +42 -0
- package/dist/commands/learn.js +57 -0
- package/dist/commands/memory.js +456 -0
- package/package.json +2 -2
- package/scripts/benchmark.js +162 -125
- package/scripts/changelog.js +196 -168
- package/scripts/sync-version.js +94 -81
- package/scripts/validate-payload.js +85 -78
|
@@ -1,280 +1,321 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tribunal-Kit: Testing Patterns 2.0 (Mutation Engine)
|
|
3
|
-
*
|
|
4
|
-
* Safely mutates source code and runs tests to detect false positives.
|
|
5
|
-
* Includes absolute safety net for file restoration.
|
|
6
|
-
*
|
|
7
|
-
* v2.1 — Context-aware mutations (skips strings/comments),
|
|
8
|
-
* line number reporting, configurable --max-mutants.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const fs = require(
|
|
12
|
-
const path = require(
|
|
13
|
-
const { spawnSync } = require(
|
|
14
|
-
|
|
15
|
-
// ── Mutation Definitions ──────────────────────────────────────────────────────
|
|
16
|
-
const MUTATIONS = [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
console.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Tribunal-Kit: Testing Patterns 2.0 (Mutation Engine)
|
|
3
|
+
*
|
|
4
|
+
* Safely mutates source code and runs tests to detect false positives.
|
|
5
|
+
* Includes absolute safety net for file restoration.
|
|
6
|
+
*
|
|
7
|
+
* v2.1 — Context-aware mutations (skips strings/comments),
|
|
8
|
+
* line number reporting, configurable --max-mutants.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const fs = require("fs");
|
|
12
|
+
const path = require("path");
|
|
13
|
+
const { spawnSync } = require("child_process");
|
|
14
|
+
|
|
15
|
+
// ── Mutation Definitions ──────────────────────────────────────────────────────
|
|
16
|
+
const MUTATIONS = [
|
|
17
|
+
{ name: "Strict Equality", pattern: /===/g, replacement: "!==" },
|
|
18
|
+
{ name: "Strict Inequality", pattern: /!==/g, replacement: "===" },
|
|
19
|
+
{ name: "Logical AND", pattern: /&&/g, replacement: "||" },
|
|
20
|
+
{ name: "Logical OR", pattern: /\|\|/g, replacement: "&&" },
|
|
21
|
+
{ name: "True -> False", pattern: /\btrue\b/g, replacement: "false" },
|
|
22
|
+
{ name: "False -> True", pattern: /\bfalse\b/g, replacement: "true" },
|
|
23
|
+
{ name: "Greater Than", pattern: /(?<!=)>(?!=)/g, replacement: "<" },
|
|
24
|
+
{ name: "Less Than", pattern: /(?<!=)<(?!=)/g, replacement: ">" },
|
|
25
|
+
{
|
|
26
|
+
name: "Return Early Removal",
|
|
27
|
+
pattern: /\breturn\b/g,
|
|
28
|
+
replacement: "/* return */",
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
// ── Context-Aware Token Map ───────────────────────────────────────────────────
|
|
33
|
+
// Builds a boolean mask: true = "live code", false = "inside string or comment"
|
|
34
|
+
function buildCodeMask(source) {
|
|
35
|
+
const mask = new Array(source.length).fill(true);
|
|
36
|
+
let inString = false;
|
|
37
|
+
let stringChar = "";
|
|
38
|
+
let inBlockComment = false;
|
|
39
|
+
let inLineComment = false;
|
|
40
|
+
|
|
41
|
+
for (let i = 0; i < source.length; i++) {
|
|
42
|
+
const ch = source[i];
|
|
43
|
+
const next = source[i + 1] || "";
|
|
44
|
+
|
|
45
|
+
if (inBlockComment) {
|
|
46
|
+
mask[i] = false;
|
|
47
|
+
if (ch === "*" && next === "/") {
|
|
48
|
+
mask[i + 1] = false;
|
|
49
|
+
inBlockComment = false;
|
|
50
|
+
i++;
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (inLineComment) {
|
|
56
|
+
mask[i] = false;
|
|
57
|
+
if (ch === "\n") {
|
|
58
|
+
inLineComment = false;
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (inString) {
|
|
64
|
+
mask[i] = false;
|
|
65
|
+
if (ch === "\\") {
|
|
66
|
+
i++;
|
|
67
|
+
if (i < source.length) mask[i] = false;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (ch === stringChar) {
|
|
71
|
+
inString = false;
|
|
72
|
+
}
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Entering block comment
|
|
77
|
+
if (ch === "/" && next === "*") {
|
|
78
|
+
mask[i] = false;
|
|
79
|
+
mask[i + 1] = false;
|
|
80
|
+
inBlockComment = true;
|
|
81
|
+
i++;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Entering line comment
|
|
86
|
+
if (ch === "/" && next === "/") {
|
|
87
|
+
mask[i] = false;
|
|
88
|
+
mask[i + 1] = false;
|
|
89
|
+
inLineComment = true;
|
|
90
|
+
i++;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Entering string
|
|
95
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
96
|
+
mask[i] = false;
|
|
97
|
+
inString = true;
|
|
98
|
+
stringChar = ch;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Everything else is live code
|
|
103
|
+
mask[i] = true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return mask;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ── Line Number Lookup ────────────────────────────────────────────────────────
|
|
110
|
+
function getLineNumber(source, charIndex) {
|
|
111
|
+
let line = 1;
|
|
112
|
+
for (let i = 0; i < charIndex && i < source.length; i++) {
|
|
113
|
+
if (source[i] === "\n") line++;
|
|
114
|
+
}
|
|
115
|
+
return line;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ── Safe Restore Globals ──────────────────────────────────────────────────────
|
|
119
|
+
let targetFile = null;
|
|
120
|
+
let originalContent = null;
|
|
121
|
+
let backupPath = null;
|
|
122
|
+
|
|
123
|
+
function safeRestore() {
|
|
124
|
+
if (targetFile && originalContent) {
|
|
125
|
+
try {
|
|
126
|
+
fs.writeFileSync(targetFile, originalContent, "utf-8");
|
|
127
|
+
} catch {
|
|
128
|
+
// Last resort: tell user where the backup is
|
|
129
|
+
if (backupPath) {
|
|
130
|
+
console.error(
|
|
131
|
+
`[Tribunal] CRITICAL: Could not restore file. Manual backup at: ${backupPath}`,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (backupPath && fs.existsSync(backupPath)) {
|
|
136
|
+
try {
|
|
137
|
+
fs.unlinkSync(backupPath);
|
|
138
|
+
} catch {}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 🛑 ABSOLUTE SAFETY NET
|
|
144
|
+
process.on("SIGINT", () => {
|
|
145
|
+
safeRestore();
|
|
146
|
+
console.error("\n[Tribunal] Mutation Engine aborted. Target file restored.");
|
|
147
|
+
process.exit(1);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
process.on("uncaughtException", (err) => {
|
|
151
|
+
safeRestore();
|
|
152
|
+
console.error("\n[Tribunal] Critical error. File restored.", err);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
process.on("exit", safeRestore);
|
|
157
|
+
|
|
158
|
+
// ── CLI Argument Parsing ──────────────────────────────────────────────────────
|
|
159
|
+
function parseCliArgs(argv) {
|
|
160
|
+
const args = argv.slice(2);
|
|
161
|
+
let maxMutants = 5; // default per mutation type
|
|
162
|
+
let fileToMutate = null;
|
|
163
|
+
let testCommandParts = [];
|
|
164
|
+
|
|
165
|
+
for (let i = 0; i < args.length; i++) {
|
|
166
|
+
if (args[i] === "--max-mutants" && args[i + 1]) {
|
|
167
|
+
maxMutants = parseInt(args[i + 1], 10) || 5;
|
|
168
|
+
i++; // skip next
|
|
169
|
+
} else if (!fileToMutate) {
|
|
170
|
+
fileToMutate = args[i];
|
|
171
|
+
} else {
|
|
172
|
+
testCommandParts.push(args[i]);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return { fileToMutate, testCommand: testCommandParts.join(" "), maxMutants };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ── Main Engine ───────────────────────────────────────────────────────────────
|
|
180
|
+
function runMutationTesting(fileToMutate, testCommand, maxMutantsPerType) {
|
|
181
|
+
targetFile = path.resolve(fileToMutate);
|
|
182
|
+
|
|
183
|
+
if (!fs.existsSync(targetFile)) {
|
|
184
|
+
console.error(`ERROR: File not found: ${targetFile}`);
|
|
185
|
+
process.exit(1);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
originalContent = fs.readFileSync(targetFile, "utf-8");
|
|
189
|
+
backupPath = targetFile + ".bak";
|
|
190
|
+
fs.writeFileSync(backupPath, originalContent, "utf-8");
|
|
191
|
+
|
|
192
|
+
console.log(`\n━━━ Tribunal Mutation Engine v2.1 ━━━`);
|
|
193
|
+
console.log(`Target: ${fileToMutate}`);
|
|
194
|
+
console.log(`Test cmd: ${testCommand}`);
|
|
195
|
+
console.log(`Max/type: ${maxMutantsPerType}`);
|
|
196
|
+
console.log(`\nExecuting baseline test run...`);
|
|
197
|
+
|
|
198
|
+
const baseline = spawnSync(testCommand, { shell: true, stdio: "pipe" });
|
|
199
|
+
if (baseline.status !== 0) {
|
|
200
|
+
console.error(
|
|
201
|
+
`ERROR: Baseline test failed! Fix your tests before mutating.`,
|
|
202
|
+
);
|
|
203
|
+
console.error(baseline.stderr.toString());
|
|
204
|
+
safeRestore();
|
|
205
|
+
process.exit(1);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
console.log(`Baseline passed. Building code mask & generating mutants...\n`);
|
|
209
|
+
|
|
210
|
+
// Build the context mask once
|
|
211
|
+
const codeMask = buildCodeMask(originalContent);
|
|
212
|
+
|
|
213
|
+
let totalMutants = 0;
|
|
214
|
+
let killedMutants = 0;
|
|
215
|
+
let survivedMutants = 0;
|
|
216
|
+
const survivors = []; // Track survivors for the report
|
|
217
|
+
|
|
218
|
+
for (const mutation of MUTATIONS) {
|
|
219
|
+
const regex = new RegExp(mutation.pattern.source, mutation.pattern.flags);
|
|
220
|
+
const matchIndices = [];
|
|
221
|
+
let m;
|
|
222
|
+
|
|
223
|
+
while (
|
|
224
|
+
(m = regex.exec(originalContent)) !== null &&
|
|
225
|
+
matchIndices.length < maxMutantsPerType
|
|
226
|
+
) {
|
|
227
|
+
// Context-aware: skip matches that are inside strings or comments
|
|
228
|
+
const matchStart = m.index;
|
|
229
|
+
const matchEnd = m.index + m[0].length - 1;
|
|
230
|
+
const isLiveCode = codeMask[matchStart] && codeMask[matchEnd];
|
|
231
|
+
|
|
232
|
+
if (isLiveCode) {
|
|
233
|
+
matchIndices.push({
|
|
234
|
+
index: m.index,
|
|
235
|
+
length: m[0].length,
|
|
236
|
+
string: m[0],
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
for (const { index, length, string } of matchIndices) {
|
|
242
|
+
totalMutants++;
|
|
243
|
+
const lineNum = getLineNumber(originalContent, index);
|
|
244
|
+
const mutatedString = string.replace(
|
|
245
|
+
new RegExp(mutation.pattern.source),
|
|
246
|
+
mutation.replacement,
|
|
247
|
+
);
|
|
248
|
+
const mutatedContent =
|
|
249
|
+
originalContent.substring(0, index) +
|
|
250
|
+
mutatedString +
|
|
251
|
+
originalContent.substring(index + length);
|
|
252
|
+
|
|
253
|
+
fs.writeFileSync(targetFile, mutatedContent, "utf-8");
|
|
254
|
+
|
|
255
|
+
process.stdout.write(
|
|
256
|
+
` [Mutant #${totalMutants}] ${mutation.name} (L${lineNum}) ... `,
|
|
257
|
+
);
|
|
258
|
+
const run = spawnSync(testCommand, { shell: true, stdio: "pipe" });
|
|
259
|
+
|
|
260
|
+
if (run.status !== 0) {
|
|
261
|
+
console.log(`✅ KILLED`);
|
|
262
|
+
killedMutants++;
|
|
263
|
+
} else {
|
|
264
|
+
console.log(`❌ SURVIVED`);
|
|
265
|
+
survivedMutants++;
|
|
266
|
+
survivors.push({
|
|
267
|
+
type: mutation.name,
|
|
268
|
+
line: lineNum,
|
|
269
|
+
original: string,
|
|
270
|
+
mutated: mutatedString,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Restore immediately after each mutant
|
|
275
|
+
fs.writeFileSync(targetFile, originalContent, "utf-8");
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const score =
|
|
280
|
+
totalMutants > 0 ? Math.round((killedMutants / totalMutants) * 100) : 100;
|
|
281
|
+
|
|
282
|
+
console.log(`\n━━━ Mutation Summary ━━━`);
|
|
283
|
+
console.log(` Total Mutants: ${totalMutants}`);
|
|
284
|
+
console.log(` Killed: ${killedMutants}`);
|
|
285
|
+
console.log(` Survived: ${survivedMutants}`);
|
|
286
|
+
console.log(` Score: ${score}%`);
|
|
287
|
+
|
|
288
|
+
if (survivors.length > 0) {
|
|
289
|
+
console.log(`\n━━━ Surviving Mutants (Weak Test Coverage) ━━━`);
|
|
290
|
+
survivors.forEach((s, i) => {
|
|
291
|
+
console.log(
|
|
292
|
+
` ${i + 1}. Line ${s.line}: ${s.type} (${s.original} → ${s.mutated})`,
|
|
293
|
+
);
|
|
294
|
+
});
|
|
295
|
+
console.log(`\n ⚠ These lines have no test that catches the mutation.`);
|
|
296
|
+
console.log(
|
|
297
|
+
` Add assertions that would FAIL if the operator were swapped.`,
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
process.exit(score < 80 ? 1 : 0);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// ── Entry Point ───────────────────────────────────────────────────────────────
|
|
305
|
+
const { fileToMutate, testCommand, maxMutants } = parseCliArgs(process.argv);
|
|
306
|
+
|
|
307
|
+
if (!fileToMutate || !testCommand) {
|
|
308
|
+
console.log(
|
|
309
|
+
`Usage: node mutation_runner.js <target_file> [--max-mutants N] <test_command>`,
|
|
310
|
+
);
|
|
311
|
+
console.log(`\nExamples:`);
|
|
312
|
+
console.log(
|
|
313
|
+
` node mutation_runner.js src/math.js "npx jest src/math.test.js"`,
|
|
314
|
+
);
|
|
315
|
+
console.log(
|
|
316
|
+
` node mutation_runner.js src/auth.js --max-mutants 10 "npx jest test/auth.test.js"`,
|
|
317
|
+
);
|
|
318
|
+
process.exit(1);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
runMutationTesting(fileToMutate, testCommand, maxMutants);
|