abapgit-agent 1.17.7 → 1.17.8
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/package.json +1 -1
- package/src/commands/unit.js +26 -24
- package/src/config.js +16 -1
package/package.json
CHANGED
package/src/commands/unit.js
CHANGED
|
@@ -327,43 +327,45 @@ Examples:
|
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
-
// Coverage threshold enforcement —
|
|
331
|
-
//
|
|
330
|
+
// Coverage threshold enforcement — per file, runs BEFORE JUnit output
|
|
331
|
+
// so the injected failure testcase lands in the correct class's testsuite.
|
|
332
332
|
if (coverage && coverageThreshold > 0) {
|
|
333
|
-
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
333
|
+
let anyData = false;
|
|
334
|
+
for (const result of results) {
|
|
335
|
+
const stats = result.COVERAGE_STATS || result.coverage_stats;
|
|
336
|
+
if (!stats) continue;
|
|
337
|
+
anyData = true;
|
|
338
|
+
const totalLines = stats.TOTAL_LINES || stats.total_lines || 0;
|
|
339
|
+
const coveredLines = stats.COVERED_LINES || stats.covered_lines || 0;
|
|
340
|
+
if (totalLines === 0) continue;
|
|
339
341
|
const rate = Math.round((coveredLines / totalLines) * 100);
|
|
342
|
+
const className = result._className || 'UNKNOWN';
|
|
340
343
|
if (rate < coverageThreshold) {
|
|
341
|
-
const msg =
|
|
344
|
+
const msg = `${className}: coverage ${rate}% is below threshold ${coverageThreshold}%`;
|
|
342
345
|
if (coverageMode === 'warn') {
|
|
343
346
|
if (!jsonOutput) console.warn(`⚠️ ${msg}`);
|
|
344
347
|
} else {
|
|
345
348
|
if (!jsonOutput) console.error(`❌ ${msg}`);
|
|
346
349
|
hasErrors = true;
|
|
347
|
-
// Inject
|
|
348
|
-
//
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
ERRORS: [{
|
|
356
|
-
CLASS_NAME: 'Coverage',
|
|
357
|
-
METHOD_NAME: 'coverage_threshold',
|
|
358
|
-
ERROR_KIND: 'FAILURE',
|
|
359
|
-
ERROR_TEXT: msg
|
|
360
|
-
}]
|
|
350
|
+
// Inject failure into this class's own testsuite so Jenkins shows
|
|
351
|
+
// which class failed the gate and what its actual coverage was.
|
|
352
|
+
const errors = result.ERRORS || result.errors || [];
|
|
353
|
+
errors.push({
|
|
354
|
+
CLASS_NAME: className,
|
|
355
|
+
METHOD_NAME: 'coverage_threshold',
|
|
356
|
+
ERROR_KIND: 'FAILURE',
|
|
357
|
+
ERROR_TEXT: msg
|
|
361
358
|
});
|
|
359
|
+
result.ERRORS = errors;
|
|
360
|
+
result.FAILED_COUNT = (result.FAILED_COUNT || result.failed_count || 0) + 1;
|
|
362
361
|
}
|
|
363
362
|
} else {
|
|
364
|
-
if (!jsonOutput) console.log(`✅
|
|
363
|
+
if (!jsonOutput) console.log(`✅ ${className}: coverage ${rate}% meets threshold ${coverageThreshold}%`);
|
|
365
364
|
}
|
|
366
365
|
}
|
|
366
|
+
if (!anyData) {
|
|
367
|
+
if (!jsonOutput) console.warn('⚠️ Coverage data unavailable — threshold not enforced');
|
|
368
|
+
}
|
|
367
369
|
}
|
|
368
370
|
|
|
369
371
|
// JUnit output mode — write XML after threshold check so synthetic failure is included
|
package/src/config.js
CHANGED
|
@@ -233,6 +233,20 @@ function getScratchWorkspace() {
|
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
/**
|
|
237
|
+
* Get coverage policy from project-level config (.abapgit-agent.json)
|
|
238
|
+
* @returns {{ threshold: number, mode: string, excludes: string[] }}
|
|
239
|
+
*/
|
|
240
|
+
function getCoverageConfig() {
|
|
241
|
+
const projectConfig = loadProjectConfig();
|
|
242
|
+
const coverage = projectConfig?.coverage || {};
|
|
243
|
+
return {
|
|
244
|
+
threshold: coverage.threshold || 0,
|
|
245
|
+
mode: coverage.mode || 'fail',
|
|
246
|
+
excludes: Array.isArray(coverage.excludes) ? coverage.excludes : []
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
236
250
|
module.exports = {
|
|
237
251
|
loadConfig,
|
|
238
252
|
getAbapConfig,
|
|
@@ -246,5 +260,6 @@ module.exports = {
|
|
|
246
260
|
loadProjectConfig,
|
|
247
261
|
getTransportHookConfig,
|
|
248
262
|
getTransportSettings,
|
|
249
|
-
getScratchWorkspace
|
|
263
|
+
getScratchWorkspace,
|
|
264
|
+
getCoverageConfig
|
|
250
265
|
};
|