fix: clamp progress bar percent to prevent RangeError crash (#715)
When orphaned SUMMARY.md files cause totalSummaries > totalPlans, the progress percentage exceeds 100%, making String.repeat() throw RangeError on negative arguments. Clamp percent to Math.min(100, ...) at all three computation sites (state, commands, roadmap). Closes #633 Co-authored-by: vinicius-tersi <vinicius-tersi@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -421,7 +421,7 @@ function cmdProgressRender(cwd, format, raw) {
|
||||
}
|
||||
} catch {}
|
||||
|
||||
const percent = totalPlans > 0 ? Math.round((totalSummaries / totalPlans) * 100) : 0;
|
||||
const percent = totalPlans > 0 ? Math.min(100, Math.round((totalSummaries / totalPlans) * 100)) : 0;
|
||||
|
||||
if (format === 'table') {
|
||||
// Render markdown table
|
||||
|
||||
@@ -208,7 +208,7 @@ function cmdRoadmapAnalyze(cwd, raw) {
|
||||
completed_phases: completedPhases,
|
||||
total_plans: totalPlans,
|
||||
total_summaries: totalSummaries,
|
||||
progress_percent: totalPlans > 0 ? Math.round((totalSummaries / totalPlans) * 100) : 0,
|
||||
progress_percent: totalPlans > 0 ? Math.min(100, Math.round((totalSummaries / totalPlans) * 100)) : 0,
|
||||
current_phase: currentPhase ? currentPhase.number : null,
|
||||
next_phase: nextPhase ? nextPhase.number : null,
|
||||
missing_phase_details: missingDetails.length > 0 ? missingDetails : null,
|
||||
|
||||
@@ -238,7 +238,7 @@ function cmdStateUpdateProgress(cwd, raw) {
|
||||
}
|
||||
}
|
||||
|
||||
const percent = totalPlans > 0 ? Math.round(totalSummaries / totalPlans * 100) : 0;
|
||||
const percent = totalPlans > 0 ? Math.min(100, Math.round(totalSummaries / totalPlans * 100)) : 0;
|
||||
const barWidth = 10;
|
||||
const filled = Math.round(percent / 100 * barWidth);
|
||||
const bar = '\u2588'.repeat(filled) + '\u2591'.repeat(barWidth - filled);
|
||||
|
||||
Reference in New Issue
Block a user