Assert list_state is selected in Detail movement methods#52
Merged
Conversation
Adds precondition assertions to all four Detail-arm movement methods (move_up, move_down, move_page_up, move_page_down) so that an unselected list_state in the Detail screen panics immediately rather than silently computing movement from index 0. Closes #48
There was a problem hiding this comment.
Pull request overview
This PR adds precondition assertions to App’s Screen::Detail movement methods to fail fast when DetailView.list_state is unexpectedly unselected, instead of silently defaulting to index 0.
Changes:
- Added
assert!(view.list_state.selected().is_some(), ...)tomove_up,move_down,move_page_up, andmove_page_downin theScreen::Detailarms. - Intended to treat an unselected
Detaillist state as a programmer error (per issue #48).
Comments suppressed due to low confidence (2)
ui/tui/src/state/mod.rs:82
- Same issue as in
move_up:apply_enter_actionleavesDetailView.list_stateunselected whenitem_count == 0(ui/tui/src/state/update.rs:297-306). With the new unconditional assert,move_downwill panic instead of being a no-op for an empty detail list. Consider asserting only whenlen > 0, or ensure the detail screen always selects an index.
assert!(
view.list_state.selected().is_some(),
"list_state must be selected in Detail screen"
);
let sel = view.list_state.selected().unwrap_or(0);
ui/tui/src/state/mod.rs:120
- This assertion will also fire for an empty detail list, but
apply_enter_actioncan constructScreen::Detailwithlist_stateleft unselected whenitem_count == 0(ui/tui/src/state/update.rs:297-306). If empty groups are allowed,move_page_upshould probably no-op rather than panic; otherwise make the invariant true by always selecting when entering Detail.
assert!(
view.list_state.selected().is_some(),
"list_state must be selected in Detail screen"
);
let sel = view.list_state.selected().unwrap_or(0);
view.list_state.select(Some(sel.saturating_sub(PAGE)));
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The file was removed in aa09a73 when it was moved to dotfiles, but workflows/src/implement.rs still references it via include_str! at compile time, breaking the build. Restoring it as a short-term fix until implement.rs is updated to read the prompt from a runtime path.
The four Detail-arm movement methods (move_up, move_down, move_page_up, move_page_down) had no test coverage. Adds a #[cfg(test)] module in state/mod.rs with eight rstest cases covering interior movement and boundary clamping for each method. These tests were surfaced by the copilot review of PR #52, which questioned whether the new precondition asserts could fire on real user input. The asserts are correct — an empty Detail list is unreachable in production — but the gap in coverage made the asserts unverifiable by the suite.
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.
Adds precondition assertions to all four
Detail-arm movement methods (move_up,move_down,move_page_up,move_page_down) so that an unselectedlist_statein theDetailscreen panics immediately rather than silently computing movement from index 0.Since
apply_enter_actionalways callsds.select(Some(0))when entering the detail screen, an unselected state here is a programmer error, not a recoverable case.Closes #48
Generated by Claude Code