From cd5ddf6f81192cbdb369a23ac67510684ac355a8 Mon Sep 17 00:00:00 2001 From: vvvomit Date: Thu, 29 Oct 2026 06:18:51 +0330 Subject: [PATCH] Review: no crash after scrolling a hidden preview; z makes room for DNS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the checks, ports and estimate Review got tall enough that the vars.yml preview doesn't fit a 45-row window and is hidden. ↑↓ still scrolled it, at a negative height, past its end, and the next taller window panicked drawing it. Its height and offset are now kept in range. z put the DNS records into that hidden preview, so it seemed to do nothing; now the left column is cut short to show them. choiceField panics when labels and choices differ in number, so an option that can't be picked (as Matrix room was) fails every test that opens its screen. Co-Authored-By: Claude Opus 5.5 --- internal/ui/form.go | 3 +++ internal/ui/review_scroll_test.go | 34 +++++++++++++++++++++++++++++++ internal/ui/screens_deploy.go | 15 ++++++++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 internal/ui/review_scroll_test.go diff --git a/internal/ui/form.go b/internal/ui/form.go index 5d566ac..8cd75b9 100644 --- a/internal/ui/form.go +++ b/internal/ui/form.go @@ -96,6 +96,9 @@ func toggleField(key, label string, on bool, help string) *field { } func choiceField(key, label string, choices, labels []string, value, help string) *field { + if labels != nil && len(labels) != len(choices) { + panic("choiceField " + key + ": the labels don't match the choices") // an unmatched one can't be picked + } f := &field{key: key, label: label, help: help, kind: fChoice, choices: choices, labels: labels} for i, c := range choices { if c == value { diff --git a/internal/ui/review_scroll_test.go b/internal/ui/review_scroll_test.go new file mode 100644 index 0000000..8888eb2 --- /dev/null +++ b/internal/ui/review_scroll_test.go @@ -0,0 +1,34 @@ +package ui + +import ( + "fmt" + "strings" + "testing" + + tea "github.com/charmbracelet/bubbletea" + + "interzone/internal/deploy" +) + +// With many checks the preview doesn't fit; scrolling it then must not +// crash once the window grows, and z still shows the DNS records. +func TestReviewHiddenPreview(t *testing.T) { + a := demoApp(t, 120, 45) + a.jump(a.index("Review")) + s := a.cur().(*reviewScreen) + for i := range 12 { + s.checks = append(s.checks, deploy.Finding{Group: "Clients", Name: fmt.Sprint("Check ", i), Level: deploy.Fail, + Detail: "a long reason that wraps onto a second line of the left column, as real failures do"}) + } + s.view(92, 40) + for range 40 { + s.update(tea.KeyMsg{Type: tea.KeyDown}) + } + s.view(92, 70) // panicked: the offset had run past the end + s.view(150, 70) + + s.update(zoneMsg{"matrix.example.org. 3600 IN A 203.0.113.7"}) + if out := s.view(92, 40); !strings.Contains(out, "IN A 203.0.113.7") || !strings.Contains(out, "a taller window shows them") { + t.Errorf("z shows no records:\n%s", out) + } +} diff --git a/internal/ui/screens_deploy.go b/internal/ui/screens_deploy.go index b46c168..60eb244 100644 --- a/internal/ui/screens_deploy.go +++ b/internal/ui/screens_deploy.go @@ -303,12 +303,23 @@ func (s *reviewScreen) view(w, h int) string { left := lipgloss.JoinVertical(lipgloss.Left, append(summary, append(gap, status...)...)...) if wide { s.vp.Width = w - lw - 4 - s.vp.Height = h - 4 + s.vp.Height = max(0, h-4) + s.vp.SetYOffset(s.vp.YOffset) // back in range after a resize right := sPanel.Width(w - lw - 2).Render(s.previewTitle() + "\n\n" + s.vp.View()) return lipgloss.JoinHorizontal(lipgloss.Top, lipgloss.NewStyle().Width(lw).Render(left), right) } s.vp.Width = w - 4 - s.vp.Height = h - lipgloss.Height(left) - 5 + room := h - lipgloss.Height(left) - 5 + if room < 3 && s.zone != nil { // the DNS records were asked for: cut the left short for them + lines := strings.Split(left, "\n") + if keep := max(4, h-5-10); len(lines) > keep { + left = strings.Join(lines[:keep-1], "\n") + "\n" + sFaint.Render(fmt.Sprintf(" ▼ %d more lines; a taller window shows them", len(lines)-keep+1)) + } + room = h - lipgloss.Height(left) - 5 + } + // ↑↓ scroll it even while it's hidden, so its height and offset stay in range. + s.vp.Height = max(0, room) + s.vp.SetYOffset(s.vp.YOffset) if s.vp.Height < 3 { return left }