deflake 1.2.38 â 1.2.40
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/cli.js +55 -14
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -54,29 +54,35 @@ async function main() {
|
|
|
54
54
|
|
|
55
55
|
// Save backups of all source files before any modifications
|
|
56
56
|
const backups = new Map(); // path -> original content
|
|
57
|
-
let
|
|
57
|
+
let prevFailNames = new Set(); // Track specific failures by name
|
|
58
58
|
|
|
59
59
|
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
|
60
60
|
console.log(`\n${C.BRIGHT}${C.CYAN}đ Fix attempt ${attempt}/${MAX_ATTEMPTS}${C.RESET}`);
|
|
61
61
|
|
|
62
62
|
const artifacts = detectFailures();
|
|
63
|
-
const
|
|
63
|
+
const currentNames = new Set(artifacts.map(a => a.name));
|
|
64
64
|
|
|
65
|
-
if (
|
|
65
|
+
if (artifacts.length === 0) {
|
|
66
66
|
console.log(`${C.GREEN}đ All tests passing! No failures detected.${C.RESET}`);
|
|
67
67
|
break;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
//
|
|
71
|
-
if (attempt > 1
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
// Check for NEW failures (tests that weren't failing before)
|
|
71
|
+
if (attempt > 1) {
|
|
72
|
+
const newFailures = [...currentNames].filter(n => !prevFailNames.has(n));
|
|
73
|
+
if (newFailures.length > 0) {
|
|
74
|
+
console.log(`${C.RED}â ī¸ New failures detected after fix attempt! Rolling back all changes...${C.RESET}`);
|
|
75
|
+
for (const name of newFailures) {
|
|
76
|
+
console.log(` ${C.RED}đ ${name}${C.RESET}`);
|
|
77
|
+
}
|
|
78
|
+
for (const [filePath, originalContent] of backups) {
|
|
79
|
+
fs.writeFileSync(filePath, originalContent);
|
|
80
|
+
console.log(` ${C.YELLOW}âŠī¸ Restored: ${path.basename(filePath)}${C.RESET}`);
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
76
83
|
}
|
|
77
|
-
break;
|
|
78
84
|
}
|
|
79
|
-
|
|
85
|
+
prevFailNames = currentNames;
|
|
80
86
|
|
|
81
87
|
const applied = await analyzeAndFix(artifacts, client, argv, output, backups);
|
|
82
88
|
|
|
@@ -333,9 +339,44 @@ async function applyFix(res, loc, backups = new Map()) {
|
|
|
333
339
|
lines.splice(p.line, 0, cleanLine);
|
|
334
340
|
console.log(` ${C.GREEN}+ Line ${p.line + 1}: ${cleanLine.trim()}${C.RESET}`);
|
|
335
341
|
} else {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
342
|
+
// REPLACE action
|
|
343
|
+
// SMART: Handle multi-line expression replacement
|
|
344
|
+
// If the original line starts a multi-line expression (has unclosed parens)
|
|
345
|
+
// and the replacement is a complete statement, remove continuation lines
|
|
346
|
+
const origOpen = (originalLine.match(/\(/g) || []).length;
|
|
347
|
+
const origClose = (originalLine.match(/\)/g) || []).length;
|
|
348
|
+
const replOpen = (cleanLine.match(/\(/g) || []).length;
|
|
349
|
+
const replClose = (cleanLine.match(/\)/g) || []).length;
|
|
350
|
+
|
|
351
|
+
if (origOpen > origClose && replOpen <= replClose) {
|
|
352
|
+
// Original has unclosed parens, replacement is complete
|
|
353
|
+
// Find the closing of the multi-line expression
|
|
354
|
+
let depth = origOpen - origClose;
|
|
355
|
+
let endIdx = idx;
|
|
356
|
+
for (let j = idx + 1; j < lines.length && depth > 0; j++) {
|
|
357
|
+
const lo = (lines[j].match(/\(/g) || []).length;
|
|
358
|
+
const lc = (lines[j].match(/\)/g) || []).length;
|
|
359
|
+
depth += lo - lc;
|
|
360
|
+
endIdx = j;
|
|
361
|
+
}
|
|
362
|
+
if (endIdx > idx) {
|
|
363
|
+
const removedLines = endIdx - idx;
|
|
364
|
+
console.log(` ${C.GRAY}đ§ Expanding REPLACE to cover ${removedLines + 1}-line expression (lines ${p.line}-${endIdx + 1})${C.RESET}`);
|
|
365
|
+
for (let j = idx; j <= endIdx; j++) {
|
|
366
|
+
console.log(` ${C.RED}- Line ${j + 1}: ${lines[j].trim()}${C.RESET}`);
|
|
367
|
+
}
|
|
368
|
+
lines.splice(idx, endIdx - idx + 1, cleanLine);
|
|
369
|
+
console.log(` ${C.GREEN}+ Line ${p.line}: ${cleanLine.trim()}${C.RESET}`);
|
|
370
|
+
} else {
|
|
371
|
+
lines[idx] = cleanLine;
|
|
372
|
+
console.log(` ${C.RED}- Line ${p.line}: ${originalLine.trim()}${C.RESET}`);
|
|
373
|
+
console.log(` ${C.GREEN}+ Line ${p.line}: ${cleanLine.trim()}${C.RESET}`);
|
|
374
|
+
}
|
|
375
|
+
} else {
|
|
376
|
+
lines[idx] = cleanLine;
|
|
377
|
+
console.log(` ${C.RED}- Line ${p.line}: ${originalLine.trim()}${C.RESET}`);
|
|
378
|
+
console.log(` ${C.GREEN}+ Line ${p.line}: ${cleanLine.trim()}${C.RESET}`);
|
|
379
|
+
}
|
|
339
380
|
}
|
|
340
381
|
content = lines.join('\n');
|
|
341
382
|
appliedCount++;
|