(result)
| 254 | } |
| 255 | |
| 256 | export function computeSummary(result) { |
| 257 | const deductions = buildDeductions(result.checks); |
| 258 | const penalty = deductions.reduce((total, entry) => total + entry.penalty, 0); |
| 259 | |
| 260 | const score = Math.max(0, Math.round(100 - penalty)); |
| 261 | const grade = |
| 262 | score >= GRADE_THRESHOLDS.A |
| 263 | ? "A" |
| 264 | : score >= GRADE_THRESHOLDS.B |
| 265 | ? "B" |
| 266 | : score >= GRADE_THRESHOLDS.C |
| 267 | ? "C" |
| 268 | : score >= GRADE_THRESHOLDS.D |
| 269 | ? "D" |
| 270 | : "F"; |
| 271 | |
| 272 | const failedErrors = result.checks.filter( |
| 273 | (check) => check.status === "fail" && check.severity === "error", |
| 274 | ).length; |
| 275 | const warningSignals = result.checks.filter((check) => check.status === "warn").length; |
| 276 | const riskLevel = failedErrors > 0 || score < 70 ? "high" : warningSignals > 0 || score < 85 ? "medium" : "low"; |
| 277 | const checkCounts = summarizeChecks(result.checks); |
| 278 | const riskReasons = buildRiskReasons({ |
| 279 | score, |
| 280 | failedErrors, |
| 281 | warningSignals, |
| 282 | deductions, |
| 283 | checkSummary: checkCounts, |
| 284 | }); |
| 285 | |
| 286 | const topRecommendations = unique( |
| 287 | result.checks |
| 288 | .filter((check) => check.status === "fail" || check.status === "warn") |
| 289 | .flatMap((check) => check.remediation) |
| 290 | .slice(0, 5), |
| 291 | ); |
| 292 | |
| 293 | return enrichSummary(result, { |
| 294 | score, |
| 295 | grade, |
| 296 | riskLevel, |
| 297 | riskReasons, |
| 298 | scoreBreakdown: { |
| 299 | startingScore: 100, |
| 300 | totalDeductions: penalty, |
| 301 | finalScore: score, |
| 302 | gradeThresholds: GRADE_THRESHOLDS, |
| 303 | }, |
| 304 | checkCounts, |
| 305 | deductions, |
| 306 | categoryDeductions: buildCategoryDeductions(deductions), |
| 307 | topRecommendations, |
| 308 | }); |
| 309 | } |
| 310 | |
| 311 | export function enrichSummary(result, summary) { |
| 312 | const deductions = Array.isArray(summary?.deductions) ? summary.deductions : buildDeductions(result.checks); |
no test coverage detected