From fe2d66e7bf422134e485d595b427395fb639bf0d Mon Sep 17 00:00:00 2001 From: hoklims Date: Sun, 22 Feb 2026 00:36:44 +0100 Subject: [PATCH] fix(registry): "fi" in IGNORED_PREFIXES shadows find commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The shell keyword "fi" was listed as a bare prefix in IGNORED_PREFIXES, causing classify_command("find ...") to return Ignored because "find".starts_with("fi") is true. This prevented find commands from being rewritten by rtk rewrite and the hook system. Move "fi" and "done" from IGNORED_PREFIXES to IGNORED_EXACT so they only match as exact standalone keywords, not as prefixes of other commands. Fixes #170, #204, #236 (partially — find classification was the root blocker for rtk rewrite). Co-Authored-By: Claude Opus 4.6 --- src/discover/registry.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/discover/registry.rs b/src/discover/registry.rs index 7ef375cd..da0406fe 100644 --- a/src/discover/registry.rs +++ b/src/discover/registry.rs @@ -272,17 +272,15 @@ const IGNORED_PREFIXES: &[&str] = &[ "then ", "else\n", "else ", - "fi", "do\n", "do ", - "done", "for ", "while ", "if ", "case ", ]; -const IGNORED_EXACT: &[&str] = &["cd", "echo", "true", "false", "wait", "pwd", "bash", "sh"]; +const IGNORED_EXACT: &[&str] = &["cd", "echo", "true", "false", "wait", "pwd", "bash", "sh", "fi", "done"]; lazy_static! { static ref REGEX_SET: RegexSet = RegexSet::new(PATTERNS).expect("invalid regex patterns"); @@ -699,6 +697,33 @@ mod tests { } } + #[test] + fn test_classify_find_not_blocked_by_fi() { + // Regression: "fi" in IGNORED_PREFIXES used to shadow "find" commands + // because "find".starts_with("fi") is true. "fi" should only match exactly. + assert_eq!( + classify_command("find . -name foo"), + Classification::Supported { + rtk_equivalent: "rtk find", + category: "Files", + estimated_savings_pct: 70.0, + status: RtkStatus::Existing, + } + ); + } + + #[test] + fn test_fi_still_ignored_exact() { + // Bare "fi" (shell keyword) should still be ignored + assert_eq!(classify_command("fi"), Classification::Ignored); + } + + #[test] + fn test_done_still_ignored_exact() { + // Bare "done" (shell keyword) should still be ignored + assert_eq!(classify_command("done"), Classification::Ignored); + } + #[test] fn test_split_chain_and() { assert_eq!(split_command_chain("a && b"), vec!["a", "b"]);