diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-13 10:25:07 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-13 10:25:07 +0300 |
| commit | 62104fbcabf811b6cd31db15f0f72db1f9d3c6e6 (patch) | |
| tree | 9cdb813621bf9f4ecacdfc8db3aa8c365925230b /internal/tui/tui_test.go | |
| parent | d799f3f04da8067669c90a755e90cd723f9746e7 (diff) | |
cap filterStack undo history to 50 levels to prevent unbounded growth
Adds maxFilterHistory=50 and evicts the oldest entry from both the
history and label-stack slices in filterStack.push whenever the cap is
exceeded. Covers the fix with a new table-driven unit test.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/tui/tui_test.go')
| -rw-r--r-- | internal/tui/tui_test.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go index ba0f8ed..a685719 100644 --- a/internal/tui/tui_test.go +++ b/internal/tui/tui_test.go @@ -1725,6 +1725,27 @@ func TestDashboardFooterShowsGlobalFilterStack(t *testing.T) { } } +func TestFilterStackHistoryCapEvictsOldestEntries(t *testing.T) { + // Push maxFilterHistory+10 distinct filters and verify the slices never + // exceed the cap. The oldest entries must be evicted, and the most-recent + // maxFilterHistory entries must be retained. + fs := newFilterStack(globalfilter.Filter{}) + for i := 0; i < maxFilterHistory+10; i++ { + f := globalfilter.Filter{} + f.FD = globalfilter.NewEqFilter(int64(i + 1)) // unique per iteration + fs.push(f, "") + } + if len(fs.history) > maxFilterHistory { + t.Fatalf("history exceeds cap: got %d, want <= %d", len(fs.history), maxFilterHistory) + } + if len(fs.stack) > maxFilterHistory { + t.Fatalf("stack exceeds cap: got %d, want <= %d", len(fs.stack), maxFilterHistory) + } + if len(fs.history) != len(fs.stack) { + t.Fatalf("history and stack lengths must match: history=%d stack=%d", len(fs.history), len(fs.stack)) + } +} + func TestProcessesTabEnterAppliesSelectedProcessAsGlobalFilter(t *testing.T) { m := NewModel(-1, func(context.Context) error { return nil }) m.screen = ScreenDashboard |
