deflake 1.2.31 → 1.2.33
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 +10 -23
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -116,10 +116,8 @@ async function analyzeAndFix(artifacts, client, argv, capturedOutput = '') {
|
|
|
116
116
|
return 0;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
//
|
|
120
|
-
const
|
|
121
|
-
const errorContextCount = (capturedOutput.match(/Error Context:/g) || []).length;
|
|
122
|
-
console.log(`${C.GRAY}📊 Captured output: ${capturedOutput.length} chars, Error Context lines: ${errorContextCount}, has 'at ': ${capturedOutput.includes(' at ')}${C.RESET}`);
|
|
119
|
+
// Strip ANSI escape codes from captured output — they break regex matching
|
|
120
|
+
const cleanOutput = capturedOutput.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '');
|
|
123
121
|
|
|
124
122
|
console.log(`${C.BRIGHT}🔍 Analyzing ${artifacts.length} failure(s)...${C.RESET}\n`);
|
|
125
123
|
let count = 0;
|
|
@@ -133,10 +131,11 @@ async function analyzeAndFix(artifacts, client, argv, capturedOutput = '') {
|
|
|
133
131
|
let loc = extractLoc(content);
|
|
134
132
|
let locSource = 'error-context.md';
|
|
135
133
|
|
|
136
|
-
if (!loc &&
|
|
134
|
+
if (!loc && cleanOutput) {
|
|
137
135
|
// Extract the relevant section from captured output for this artifact
|
|
138
|
-
const relevantOutput = extractRelevantOutput(
|
|
139
|
-
|
|
136
|
+
const relevantOutput = extractRelevantOutput(cleanOutput, art.name);
|
|
137
|
+
console.log(` ${C.GRAY}🔬 Relevant output: ${relevantOutput.length} chars for artifact${C.RESET}`);
|
|
138
|
+
loc = extractLoc(relevantOutput || cleanOutput);
|
|
140
139
|
locSource = 'console output';
|
|
141
140
|
}
|
|
142
141
|
|
|
@@ -262,13 +261,9 @@ async function applyFix(res, loc) {
|
|
|
262
261
|
}
|
|
263
262
|
|
|
264
263
|
function extractRelevantOutput(fullOutput, artifactName) {
|
|
265
|
-
//
|
|
266
|
-
// Each Playwright failure ends with: "Error Context: test-results/<artifact-name>/error-context.md"
|
|
267
|
-
// We find that line, then walk backwards to capture the full error + stack trace.
|
|
268
|
-
|
|
264
|
+
// Find the Error Context line for this artifact, then grab 30 lines before it
|
|
269
265
|
const lines = fullOutput.split('\n');
|
|
270
266
|
|
|
271
|
-
// Find the Error Context line that matches this artifact
|
|
272
267
|
let anchorIdx = -1;
|
|
273
268
|
for (let i = 0; i < lines.length; i++) {
|
|
274
269
|
if (lines[i].includes('Error Context:') && lines[i].includes(artifactName)) {
|
|
@@ -278,7 +273,7 @@ function extractRelevantOutput(fullOutput, artifactName) {
|
|
|
278
273
|
}
|
|
279
274
|
|
|
280
275
|
if (anchorIdx === -1) {
|
|
281
|
-
// Fallback:
|
|
276
|
+
// Fallback: partial match on artifact name parts
|
|
282
277
|
const nameParts = artifactName.split('-').filter(p => p.length > 3);
|
|
283
278
|
for (let i = 0; i < lines.length; i++) {
|
|
284
279
|
if (lines[i].includes('Error Context:') && nameParts.some(part => lines[i].includes(part))) {
|
|
@@ -290,16 +285,8 @@ function extractRelevantOutput(fullOutput, artifactName) {
|
|
|
290
285
|
|
|
291
286
|
if (anchorIdx === -1) return '';
|
|
292
287
|
|
|
293
|
-
//
|
|
294
|
-
|
|
295
|
-
let startIdx = anchorIdx;
|
|
296
|
-
for (let i = anchorIdx; i >= 0; i--) {
|
|
297
|
-
if (lines[i].match(/^\s*\d+\)\s+\[/)) {
|
|
298
|
-
startIdx = i;
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
288
|
+
// Grab 30 lines before the anchor — guaranteed to include the full stack trace
|
|
289
|
+
const startIdx = Math.max(0, anchorIdx - 30);
|
|
303
290
|
return lines.slice(startIdx, anchorIdx + 1).join('\n');
|
|
304
291
|
}
|
|
305
292
|
|