From a4cb33b995f29cc119c06f5a57a1ae32e425b43b Mon Sep 17 00:00:00 2001 From: Yunare Maia Date: Thu, 10 Sep 2026 00:52:20 +0000 Subject: [PATCH 1/2] fix: filter empty lines in apt generator callbacks list_all_packages and list_all_deb_files_in_cwd were not filtering empty lines, causing blank suggestions to appear in completions when dpkg-query or find output had trailing newlines. Fixes warpdotdev/command-signatures#380 --- command-signatures/src/generators/apt.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/command-signatures/src/generators/apt.rs b/command-signatures/src/generators/apt.rs index e4199a51..8fd3d35f 100644 --- a/command-signatures/src/generators/apt.rs +++ b/command-signatures/src/generators/apt.rs @@ -17,10 +17,12 @@ const LIST_ALL_DEB_FILES_COMMAND: &str = r#"find . -maxdepth 1 -type f -name '*. pub fn list_all_packages(output: &str) -> GeneratorResults { let mut targets = Vec::new(); for package_name in output.lines() { - targets.push(Suggestion::with_description( - package_name.to_string(), - "package", - )); + if !package_name.is_empty() { + targets.push(Suggestion::with_description( + package_name.to_string(), + "package", + )); + } } targets.into_iter().collect_unordered_results() } @@ -41,11 +43,13 @@ pub fn list_available_packages(output: &str) -> GeneratorResults { pub fn list_all_deb_files_in_cwd(output: &str) -> GeneratorResults { let mut targets = Vec::new(); for file in output.lines() { - targets.push( - // We should prioritize .deb files over the already installed packages. - Suggestion::with_description(file.to_string(), ".deb file") - .with_priority(Priority::most_important()), - ) + if !file.is_empty() { + targets.push( + // We should prioritize .deb files over the already installed packages. + Suggestion::with_description(file.to_string(), ".deb file") + .with_priority(Priority::most_important()), + ); + } } targets.into_iter().collect_unordered_results() } From 97f325ab58fe02d646019d450e2f1d1fba09ddba Mon Sep 17 00:00:00 2001 From: Yunare Maia Date: Thu, 10 Sep 2026 14:32:59 +0000 Subject: [PATCH 2/2] test: add regression tests for apt generator empty-line filtering Add tests verifying that list_all_packages and list_all_deb_files_in_cwd properly filter empty lines from dpkg-query and find output. --- .../src/generators/apt_tests.rs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 command-signatures/src/generators/apt_tests.rs diff --git a/command-signatures/src/generators/apt_tests.rs b/command-signatures/src/generators/apt_tests.rs new file mode 100644 index 00000000..d7cce053 --- /dev/null +++ b/command-signatures/src/generators/apt_tests.rs @@ -0,0 +1,38 @@ +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_list_all_packages_filters_empty_lines() { + let output = "vim\ngit\n\n"; + let results = list_all_packages(output); + let suggestions: Vec<_> = results.into_iter().collect(); + assert_eq!(suggestions.len(), 2); + assert_eq!(suggestions[0].name, "vim"); + assert_eq!(suggestions[1].name, "git"); + } + + #[test] + fn test_list_all_packages_empty_input() { + let results = list_all_packages(""); + let suggestions: Vec<_> = results.into_iter().collect(); + assert_eq!(suggestions.len(), 0); + } + + #[test] + fn test_list_all_deb_files_filters_empty_lines() { + let output = "./foo.deb\n./bar.deb\n\n"; + let results = list_all_deb_files_in_cwd(output); + let suggestions: Vec<_> = results.into_iter().collect(); + assert_eq!(suggestions.len(), 2); + assert_eq!(suggestions[0].name, "./foo.deb"); + assert_eq!(suggestions[1].name, "./bar.deb"); + } + + #[test] + fn test_list_all_deb_files_empty_input() { + let results = list_all_deb_files_in_cwd(""); + let suggestions: Vec<_> = results.into_iter().collect(); + assert_eq!(suggestions.len(), 0); + } +}