refactor(tests): fix bugs, remove tech debt, add missing coverage#65
Conversation
Reviewer's GuideExtensive refactor of integration-style tests to reduce tech debt, fix several subtle behavioral bugs (search/selection, buffer rendering, history dedup, overwrite handling), and add missing coverage for viewer, pickers, history, overwrite, selection, compare, and user menu flows, plus a few small core changes (Cha::regular_file, CompareMode::label, shell history behavior). Sequence diagram for updated shell::push_history behaviorsequenceDiagram
actor User
participant Shell as shell
participant State as AppState
User->>Shell: push_history(state, cmd)
Shell->>Shell: cmd.trim().is_empty()
alt [cmd is empty]
Shell-->>User: return
else [cmd is non_empty]
Shell->>State: command_history.retain(entry != cmd)
Shell->>State: command_history.push_back(cmd.to_string())
Shell->>Shell: command_history.len() > MAX_HISTORY
alt [len > MAX_HISTORY]
Shell->>State: command_history.pop_front()
end
Shell-->>User: return
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
shell::push_historyimplementation usesretainon every call, which is O(n) and shifts all elements; if history grows large this may be unnecessarily expensive—consider scanning from the back and removing only the first matching entry (or using a small capped Vec) to keep dedup semantics while reducing per-call cost.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `shell::push_history` implementation uses `retain` on every call, which is O(n) and shifts all elements; if history grows large this may be unnecessarily expensive—consider scanning from the back and removing only the first matching entry (or using a small capped Vec) to keep dedup semantics while reducing per-call cost.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request refactors command history deduplication to move non-consecutive duplicate commands to the end of the history list, introduces a label helper method for CompareMode, and adds a regular_file constructor to Cha. Additionally, it extensively refactors the test suite to use cleaner helper patterns, removes redundant test setups, and adds comprehensive unit tests covering history navigation, viewer scrolling/searching, archive overwrite checks, and user menu picker boundaries. As there are no review comments, no additional feedback is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Greptile SummaryThis PR refactors the test suite across 14 test files: replacing
Confidence Score: 4/5Safe to merge. All production-code changes are small and well-tested; the test refactoring removes real false positives and adds meaningful coverage. The only finding is a design quirk in the new dispatch_test_event helper: it creates a local viewer and job that are dropped on return, so any state set through those pointers during event dispatch is silently lost. Existing tests avoid this by calling viewer handlers directly, but the contract is invisible to future test authors. Everything else — the push_history dedup change, Cha::regular_file, CompareMode::label, and the bulk test migration — is clean and correct. src/tests/helpers.rs — the dispatch_test_event function discards viewer and job state; worth a doc comment before the function grows more callers. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[push_history cmd] --> B{empty cmd?}
B -- Yes --> C[return early]
B -- No --> D[retain: remove all prior occurrences]
D --> E[push_back cmd]
E --> F{len over MAX_HISTORY?}
F -- Yes --> G[pop_front oldest]
F -- No --> H[done - MRU at end]
G --> H
subgraph PanelSetup["Panel Setup in Tests"]
P1[set_entries fills both entries and unfiltered_entries]
P2[Direct listing.entries assignment leaves unfiltered_entries empty]
P1 --> P3[Correct for navigation and selection tests]
P2 --> P4[Correct only where fallback logic handles empty unfiltered_entries]
end
Reviews (1): Last reviewed commit: "refactor(tests): fix bugs, remove tech d..." | Re-trigger Greptile |
| event: &Event, | ||
| ) -> Result<bool, std::convert::Infallible> { | ||
| let mut viewer: Option<viewer::ViewerState> = None; | ||
| let mut job: Option<RunningJob> = None; | ||
| let mut size = test_size(); | ||
| super::super::dispatch_event( | ||
| state, | ||
| &mut viewer, | ||
| &mut None, | ||
| &mut None, | ||
| &mut job, | ||
| terminal, | ||
| &mut size, | ||
| event, | ||
| ) | ||
| } | ||
|
|
||
| pub fn test_terminal() -> Terminal<TestBackend> { |
There was a problem hiding this comment.
dispatch_test_event silently discards viewer and job state
viewer and job are created as locals inside the function and dropped on return. Any state changes that dispatch_event writes through those pointers (e.g. F3 opening a ViewerState, or background jobs being spawned) are lost without error. A caller trying to verify that a key event results in a viewer being opened will silently see None and the test will behave as a false negative. The existing tests avoid this pitfall by calling viewer-mode handlers directly (e.g. handle_viewer_mode in viewer_close_via_escape), but this is a non-obvious contract that is easy to violate in future tests.
- Fix false positive tests (unfiltered_entries not set in search/selection) - Fix buffer_to_string missing newline separator between rows - Replace SystemTime::now() with UNIX_EPOCH in test builders - Add Cha::regular_file(size) constructor, TestEntry validation - Replace use crate::* with explicit imports in all 14 test files - Remove duplicate tests, extract shared helpers (dispatch_key, TestFixture, etc.) - Replace magic numbers with constants (TERMINAL_HEIGHT, VISIBLE_HEIGHT, TERMINAL_WIDTH) - Fix misleading test names (compare, history, selection, user_menu) - Add missing test coverage: viewer (scroll/page/search/hex/close), history (Home/End/dedup), overwrite (ExtractArchive/CreateArchive), pickers (early return/Home/End/ArchiveMenu), selection (toggle off/right panel/edge cases) - Fix shell::push_history non-consecutive dedup - Add CompareMode::label() method - Remove unnecessary tempfile operations from memory-only tests - Fix inconsistent import paths (app:: vs lc::app::) - Fix menu_rename test to actually verify rename via FS
Summary by Sourcery
Refine test utilities and interaction tests across selection, viewer, history, overwrite, pickers, menus, key handling, and search while introducing small core helpers for file metadata, comparison labeling, and shell history.
Bug Fixes:
Enhancements:
Tests: