Repository navigation
fix(tui): the Brokers tab keeps its cursor on a broker when a refresh returns fewer - #389
Merged
Merged
Conversation
… returns fewer The Brokers tab refreshes every 10 s and stored the new broker list without looking at the cursor. With the cursor on the last broker and that broker gone (it died, or was scaled away), View indexed past the end and the dashboard died with "index out of range [2] with length 2", exactly when it was wanted. A refresh now clamps the cursor to the last broker, or 0 with none. View already handles a nil or empty list. TestBrokersRefreshWithFewerBrokers shrinks 3 brokers to 2 with the cursor on the third, then to none.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item 1.3 of the CLI performance and stability plan (finding F8). Independent of the other Wave 1 PRs.
Why
kates tui's Brokers tab panics when the broker list shrinks. On main (6f4cf61),cli/tui/brokers.go:45-48stores a refresh without looking at the cursor,cli/tui/tui.go:57refreshes every 10 s, andView()indexesm.info.Brokers[m.cursor](:116). With the cursor on the last broker and that broker gone, because it died or was scaled away, the next refresh ends the dashboard withindex out of range [2] with length 2. That is exactly when the dashboard is wanted.Changes
cli/tui/brokers.go: thebrokersLoadedMsgcase clamps the cursor to the last broker, or 0 when there are none. The nil-check the plan asks for is already there:View()returns "No brokers found." for a nil or empty list before it indexes, and the key handler skips a nilinfo.brokers.go's import block is not gofmt-sorted on main. It is left as it is, to keep the diff to the fix.Tests
Added
TestBrokersRefreshWithFewerBrokers:View()renders broker 1.On main's
brokers.gothe test panics withindex out of range [2] with length 2.Run locally, passing:
cd cli && go test ./...,go test -race ./tui,go vet ./....golangci-lint run --new-from-rev=origin/main ./...: 0 issues.scripts/check-cli-style.shandscripts/check-cli-compat.sh: OK.cli/**triggers (Build & Test): this PR touches nothing underkates/../mvnw teston main'skates/tree ran 1,254 tests with 0 failures and 0 errors, once for all of Wave 1.Skipped locally:
govulncheck, asgo.modis unchanged.CI only:
./mvnw verifywith the*ITtests, the Kind and Docker jobs, CodeQL and Trivy.