diff --git a/crates/pi-ast/src/summary.rs b/crates/pi-ast/src/summary.rs index af58602a9..96e5f35e4 100644 --- a/crates/pi-ast/src/summary.rs +++ b/crates/pi-ast/src/summary.rs @@ -108,10 +108,13 @@ impl ElidableForest { /// BFS unfold. Start with every root span folded (matches the legacy /// outermost-only behavior) and progressively replace folded spans with /// their elidable children, breadth-first, until the visible line count -/// reaches `unfold_until`. A candidate unfold that would push the visible -/// count past `unfold_limit` is rejected and aborts the loop ("revert the -/// last unfold because it overflew"). `unfold_until == 0` short-circuits -/// to the legacy behavior. +/// reaches `unfold_until`. A candidate unfold whose revealed lines would +/// push the visible count past `unfold_limit` is skipped — that span stays +/// folded and its subtree is not explored — while the BFS keeps unfolding +/// the remaining queued siblings. A single oversized, un-unfoldable leaf +/// (e.g. a `\n\n\n
\n{sections}\n
\n\n\n" + ); + + let result = summarize_with_unfold(&code, "page.html", 50, 100); + assert!(result.parsed); + assert!(result.elided); + let kept_text = result + .segments + .iter() + .filter(|s| s.kind == "kept") + .filter_map(|s| s.text.as_deref()) + .collect::>() + .join("\n"); + // The body div was unfolded: its child
structure is visible. + assert!( + kept_text.contains("
"), + "body div should unfold to show sections" + ); + assert!( + kept_text.contains("
"), + "all sibling sections should surface" + ); + // The ` plus `
...
`, collapsing the document body into one dead `...`. An overflowing span is now skipped (left folded, its subtree unexplored) and the BFS keeps unfolding the remaining queued siblings, so structured siblings like the `` DOM are revealed up to `unfoldLimit` while the oversized leaf stays folded. + ## [16.0.2] - 2026-06-16 ### Added