From 69b93f8f69aac2b7e4dba851fdb7b25d156752d7 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Sun, 23 Aug 2026 11:00:38 +0800 Subject: [PATCH] test(layout): pin that a panel cap never lands under its own floor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three places spend `side_panel_max` on `clamp(own_floor, cap)` — the sidebar and right-panel widths and both drag handlers — and `f32::clamp` panics when its low bound is above its high one. A cap below the floor is therefore not a layout glitch but the render path going down, on the frame a window happens to get narrow enough. The existing tests pin the answer at three widths. This pins the property across every floor the callers pass and the degenerate widths a window reports while it is being made or taken apart — zero, negative, infinite, NaN — and makes the same clamp the callers make, so the test fails the way they would. Dropping the `.max(own_floor)` that guarantees it reports a cap of -360 against a floor of 180. No behaviour change; the guarantee was already there and already relied on. --- src/ui/app.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/ui/app.rs b/src/ui/app.rs index ad1442b8..3d1f07a4 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -8987,6 +8987,47 @@ mod tests { assert_eq!(side_panel_max(wide, PANEL_MIN, SIDEBAR_MIN), wide / 2.); } + /// The cap never lands under the floor it was given, for any viewport at + /// all. + /// + /// Three callers spend this on `clamp(own_floor, side_panel_max(..))` — + /// the sidebar and right panel widths, and both of their drag handlers — + /// and `f32::clamp` *panics* when its low bound is above its high one. So + /// a cap below the floor is not a layout glitch, it is the render path + /// going down, and it would go down on the frame a window got narrow + /// enough. The tests above pin the answer at three widths; this pins the + /// property, including the degenerate widths a window reports while it is + /// being made or taken apart. + #[test] + fn the_cap_is_never_below_the_floor_it_was_given() { + for viewport in [ + 0., + 1., + -100., + 320., + 719., + 720., + 1440., + f32::MAX, + f32::INFINITY, + f32::NEG_INFINITY, + f32::NAN, + ] { + for own in [SIDEBAR_MIN, PANEL_MIN, DOCUMENT_MIN_W] { + for others in [0., SIDEBAR_MIN, PANEL_MIN + DOCUMENT_MIN_W] { + let cap = side_panel_max(viewport, own, others); + assert!( + cap >= own, + "viewport {viewport}, floor {own}, others {others} capped at \ + {cap} — a clamp against this panics" + ); + // And the clamp those callers make really is well formed. + let _ = 0f32.clamp(own, cap); + } + } + } + } + /// Below the width where everything fits, the floor wins over the /// reservation: a cap under a panel's own minimum would be a panel drawn /// narrower than it can be read at, and the terminal — which can reflow —