Skip to content

Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.

feat(commands): suggest /download-dir reset when custom download folder is configured

Samir Hossainse830547af963
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9e60149..d300473 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,7 @@
### Added
- **Comprehensive QA & Regression Test Architecture**:
- - Introduced a 63-test automated suite covering critical algorithmic boundaries, end-to-end user journeys, active player session lifecycle & duplicate launch protection, error handling, addon manifest validation, mouse interactions, modal dismissals, TUI rendering across terminal size matrices, state reconciliation, crypto HMAC signing, download chunk arithmetic, and URL/stem security.
+ - Introduced a 69-test automated suite covering critical algorithmic boundaries, end-to-end user journeys, active player session lifecycle & duplicate launch protection, dynamic slash command autocomplete (`/download-dir reset`), error handling, addon manifest validation, mouse interactions, modal dismissals, TUI rendering across terminal size matrices, state reconciliation, crypto HMAC signing, download chunk arithmetic, and URL/stem security.
- Added structured integration tests in `tests/` (`error_handling.rs`, `tui_acceptance.rs`, `history_reconciliation.rs`, `cache_lifecycle.rs`, `player_integration.rs`, `m3u_integration.rs`, `addons_manifest.rs`, `download_integration.rs`, `url_security.rs`) and test fixtures (`tests/fixtures/`).
- Added [`docs/testing.md`](docs/testing.md) detailing test architecture, command references, and manual QA procedures.
- **Playback Tracking & Watch History Progress**:
diff --git a/docs/known-issues.md b/docs/known-issues.md
index 99bd88e..6afe546 100644
--- a/docs/known-issues.md
+++ b/docs/known-issues.md
@@ -26,6 +26,6 @@ Tracked here so future work and issue reports reference the same facts.
## Verification
-- Automated testing is enforced via `cargo test --locked` covering 63 unit and integration tests across 10 test suites (see [`docs/testing.md`](testing.md)).
+- Automated testing is enforced via `cargo test --locked` covering 69 unit and integration tests across 10 test suites (see [`docs/testing.md`](testing.md)).
- Static correctness is enforced by strict compiler type checking, the lint gate (`cargo clippy --all-targets --all-features -- -D warnings`), formatting (`cargo fmt --check`), dependency vulnerability scanning (`cargo audit`), and packaging verification (`cargo package --locked`).
- Runtime and platform-specific behavior (terminal resize, focus handling, external player launch, and Termux chooser) are verified through the release checklist in [`release-checklist.md`](release-checklist.md).
diff --git a/src/tui/app/keyboard.rs b/src/tui/app/keyboard.rs
index a07a120..640aa23 100644
--- a/src/tui/app/keyboard.rs
+++ b/src/tui/app/keyboard.rs
@@ -213,7 +213,7 @@ impl App {
let suggestions =
crate::tui::commands::SlashCommand::suggest(&self.state, &query);
if suggestions.len() == 1 {
- query = suggestions[0].name().to_string();
+ query = suggestions[0].clone();
}
}
@@ -241,10 +241,19 @@ impl App {
KeyCode::Tab => {
let trimmed = self.state.search_query.trim();
if trimmed.starts_with('/') {
- let suggestions =
- crate::tui::commands::SlashCommand::suggest(&self.state, trimmed);
- if let Some(first) = suggestions.first() {
- self.state.search_query = first.name().to_string();
+ let selected_or_first = self
+ .state
+ .suggest_index
+ .and_then(|idx| self.state.search_suggestions.get(idx).cloned())
+ .or_else(|| {
+ let suggestions = crate::tui::commands::SlashCommand::suggest(
+ &self.state,
+ trimmed,
+ );
+ suggestions.first().cloned()
+ });
+ if let Some(sug) = selected_or_first {
+ self.state.search_query = sug;
self.state.last_search_edit = std::time::Instant::now();
}
}
diff --git a/src/tui/app/requests.rs b/src/tui/app/requests.rs
index 9e3ae3c..448286c 100644
--- a/src/tui/app/requests.rs
+++ b/src/tui/app/requests.rs
@@ -17,7 +17,7 @@ impl App {
crate::tui::commands::SlashCommand::suggest(&self.state, &query);
let suggestions: Vec<serde_json::Value> = matching_commands
.into_iter()
- .map(|cmd| serde_json::json!({ "title": cmd.name() }))
+ .map(|cmd_name| serde_json::json!({ "title": cmd_name }))
.collect();
if !suggestions.is_empty() {
let fake_payload = serde_json::json!({
diff --git a/src/tui/commands.rs b/src/tui/commands.rs
index 4c4ad3e..450b570 100644
--- a/src/tui/commands.rs
+++ b/src/tui/commands.rs
@@ -160,22 +160,45 @@ impl SlashCommand {
}
}
- pub fn suggest(state: &AppState, query: &str) -> Vec<Self> {
+ pub fn suggest(state: &AppState, query: &str) -> Vec<String> {
let lower = query.to_ascii_lowercase();
- Self::ALL
- .iter()
- .copied()
- .filter(|cmd| cmd.is_available(state) && cmd.name().starts_with(&lower))
- .collect()
+ let mut results = Vec::new();
+
+ for cmd in Self::ALL {
+ if !cmd.is_available(state) {
+ continue;
+ }
+ let name = cmd.name();
+ if name.starts_with(&lower) {
+ results.push(name.to_string());
+ if cmd == Self::DownloadDir
+ && state.download_dir.is_some()
+ && "/download-dir reset".starts_with(&lower)
+ {
+ results.push("/download-dir reset".to_string());
+ }
+ } else if cmd == Self::DownloadDir
+ && state.download_dir.is_some()
+ && "/download-dir reset".starts_with(&lower)
+ {
+ results.push("/download-dir reset".to_string());
+ }
+ }
+
+ results
}
pub fn description_for(suggestion: &str, state: &AppState) -> Option<&'static str> {
let trimmed = if suggestion.starts_with('/') {
- suggestion
+ suggestion.trim()
} else {
return None;
};
+ if trimmed == "/download-dir reset" {
+ return Some("Reset download folder to default");
+ }
+
for cmd in Self::ALL {
if cmd.name() == trimmed {
return Some(cmd.description(state));
@@ -217,3 +240,88 @@ impl SlashCommand {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use std::path::PathBuf;
+
+ #[test]
+ fn test_download_dir_suggest_default_state() {
+ let state = AppState::default();
+ assert!(state.download_dir.is_none());
+
+ let suggestions = SlashCommand::suggest(&state, "/download-dir");
+ assert!(suggestions.contains(&"/download-dir".to_string()));
+ assert!(!suggestions.contains(&"/download-dir reset".to_string()));
+ }
+
+ #[test]
+ fn test_download_dir_suggest_custom_state() {
+ let state = AppState {
+ download_dir: Some(PathBuf::from("/custom/downloads")),
+ ..Default::default()
+ };
+
+ let suggestions = SlashCommand::suggest(&state, "/download-dir");
+ assert!(suggestions.contains(&"/download-dir".to_string()));
+ assert!(suggestions.contains(&"/download-dir reset".to_string()));
+
+ let d_suggestions = SlashCommand::suggest(&state, "/d");
+ assert!(d_suggestions.contains(&"/download-dir".to_string()));
+ assert!(d_suggestions.contains(&"/download-dir reset".to_string()));
+ }
+
+ #[test]
+ fn test_download_dir_suggest_subcommand_prefix() {
+ let state = AppState {
+ download_dir: Some(PathBuf::from("/custom/downloads")),
+ ..Default::default()
+ };
+
+ let suggestions = SlashCommand::suggest(&state, "/download-dir r");
+ assert_eq!(suggestions, vec!["/download-dir reset".to_string()]);
+
+ let suggestions_space = SlashCommand::suggest(&state, "/download-dir ");
+ assert_eq!(suggestions_space, vec!["/download-dir reset".to_string()]);
+ }
+
+ #[test]
+ fn test_download_dir_suggest_mode_parity() {
+ let mut state = AppState {
+ download_dir: Some(PathBuf::from("/custom/downloads")),
+ ..Default::default()
+ };
+
+ // 1. Streaming Mode
+ state.is_addon_mode = false;
+ state.is_tv_mode = false;
+ let stream_sug = SlashCommand::suggest(&state, "/download-dir");
+ assert!(stream_sug.contains(&"/download-dir reset".to_string()));
+
+ // 2. Addon Mode
+ state.is_addon_mode = true;
+ state.is_tv_mode = false;
+ let addon_sug = SlashCommand::suggest(&state, "/download-dir");
+ assert!(addon_sug.contains(&"/download-dir reset".to_string()));
+
+ // 3. TV Mode
+ state.is_addon_mode = false;
+ state.is_tv_mode = true;
+ let tv_sug = SlashCommand::suggest(&state, "/download-dir");
+ assert!(tv_sug.contains(&"/download-dir reset".to_string()));
+ }
+
+ #[test]
+ fn test_download_dir_reset_description() {
+ let state = AppState::default();
+ assert_eq!(
+ SlashCommand::description_for("/download-dir reset", &state),
+ Some("Reset download folder to default")
+ );
+ assert_eq!(
+ SlashCommand::description_for("/download-dir", &state),
+ Some("View or change download folder")
+ );
+ }
+}
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index 9ce1178..bd6812b 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -948,7 +948,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
if let Some(description) = desc {
let name_len = crate::tui::text::width(display_name);
- let pad = 22usize.saturating_sub(name_len).max(2);
+ let pad = 24usize.saturating_sub(name_len).max(2);
spans.push(Span::raw(" ".repeat(pad)));
spans.push(Span::styled(description, desc_style));
}
diff --git a/tests/tui_acceptance.rs b/tests/tui_acceptance.rs
index 49be4cd..d9a9c23 100644
--- a/tests/tui_acceptance.rs
+++ b/tests/tui_acceptance.rs
@@ -147,3 +147,23 @@ async fn test_full_user_journey_mode_switching_and_theme_selection() {
.await;
assert_eq!(app.state().active_theme_kind, "TokyoNight");
}
+
+#[tokio::test]
+async fn test_download_dir_reset_user_journey() {
+ let mut app = App::new();
+ let custom_path = std::path::PathBuf::from("/custom/moviebox/downloads");
+ app.state_mut().download_dir = Some(custom_path.clone());
+ assert_eq!(app.state().download_dir, Some(custom_path));
+
+ app.handle_action(Action::Search {
+ query: "/download-dir reset".to_string(),
+ force_refresh: false,
+ })
+ .await;
+
+ assert!(app.state().download_dir.is_none());
+ assert!(!app.state().notifications.is_empty());
+ let notif = app.state().notifications.back().unwrap();
+ assert_eq!(notif.title, "Download Directory");
+ assert!(notif.message.contains("Reset to default"));
+}