fix(boulder): support both structured and simple plan formats in getPlanProgress
Structured plans (with ## TODOs section) use strict numbered-label parsing. Simple plans (without sections) fall back to regex checkbox counting. This fixes 9 test failures from the #3066 merge.
This commit is contained in:
@@ -224,6 +224,24 @@ export function getPlanProgress(planPath: string): PlanProgress {
|
||||
try {
|
||||
const content = readFileSync(planPath, "utf-8")
|
||||
const lines = content.split(/\r?\n/)
|
||||
|
||||
// Check if the plan has structured sections (## TODOs / ## Final Verification Wave)
|
||||
const hasStructuredSections = lines.some((line) => TODO_HEADING_PATTERN.test(line))
|
||||
|
||||
if (hasStructuredSections) {
|
||||
// Structured plan: only count top-level checkboxes with numbered labels
|
||||
// under ## TODOs and ## Final Verification Wave sections
|
||||
return getStructuredPlanProgress(lines)
|
||||
}
|
||||
|
||||
// Simple plan: count all top-level checkboxes anywhere
|
||||
return getSimplePlanProgress(content)
|
||||
} catch {
|
||||
return { total: 0, completed: 0, isComplete: true }
|
||||
}
|
||||
}
|
||||
|
||||
function getStructuredPlanProgress(lines: string[]): PlanProgress {
|
||||
let section: ProgressSection = "other"
|
||||
let total = 0
|
||||
let completed = 0
|
||||
@@ -270,8 +288,19 @@ export function getPlanProgress(planPath: string): PlanProgress {
|
||||
completed,
|
||||
isComplete: total > 0 && completed === total,
|
||||
}
|
||||
} catch {
|
||||
return { total: 0, completed: 0, isComplete: true }
|
||||
}
|
||||
|
||||
function getSimplePlanProgress(content: string): PlanProgress {
|
||||
const uncheckedMatches = content.match(/^\s*[-*]\s*\[\s*\]/gm) || []
|
||||
const checkedMatches = content.match(/^\s*[-*]\s*\[[xX]\]/gm) || []
|
||||
|
||||
const total = uncheckedMatches.length + checkedMatches.length
|
||||
const completed = checkedMatches.length
|
||||
|
||||
return {
|
||||
total,
|
||||
completed,
|
||||
isComplete: total > 0 && completed === total,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user