From c702065f36038f882f74cfe12d78b068cad4bd82 Mon Sep 17 00:00:00 2001 From: Max Hsu Date: Thu, 28 May 2026 23:43:57 +0800 Subject: [PATCH] fix(discover): rewrite dotnet test/restore/format, not just build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `rtk dotnet test`, `rtk dotnet restore`, and `rtk dotnet format` proxies already exist and route to dedicated handlers, but the rewrite rule only matched `dotnet build`, so the Claude Code hook silently passed the other three through unfiltered. Extend the rule's subcommand set; the output filters already handle all four — this is purely a routing fix. Fixes #1830 --- src/discover/registry.rs | 24 ++++++++++++++++++++++++ src/discover/rules.rs | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/discover/registry.rs b/src/discover/registry.rs index 4fd716828..f45894889 100644 --- a/src/discover/registry.rs +++ b/src/discover/registry.rs @@ -1283,6 +1283,30 @@ mod tests { ); } + #[test] + fn test_rewrite_dotnet_subcommands() { + // All four subcommands have dedicated `rtk dotnet` proxies, so the rewrite + // rule must route them (issue #1830 — only `build` was covered before). + for sub in ["build", "test", "restore", "format"] { + assert_eq!( + rewrite_command_no_prefixes(&format!("dotnet {}", sub), &[]), + Some(format!("rtk dotnet {}", sub)), + "dotnet {} should rewrite", + sub + ); + } + // Trailing args are preserved (the \b stops at the subcommand). + assert_eq!( + rewrite_command_no_prefixes("dotnet test --filter Category=Unit", &[]), + Some("rtk dotnet test --filter Category=Unit".into()) + ); + // Subcommands without a proxy must NOT be rewritten. + assert_eq!(rewrite_command_no_prefixes("dotnet publish", &[]), None); + assert_eq!(rewrite_command_no_prefixes("dotnet run", &[]), None); + // Word boundary guards against false prefixes. + assert_eq!(rewrite_command_no_prefixes("dotnet builder", &[]), None); + } + #[test] fn test_rewrite_compound_and() { assert_eq!( diff --git a/src/discover/rules.rs b/src/discover/rules.rs index df7c72d03..542cabd7f 100644 --- a/src/discover/rules.rs +++ b/src/discover/rules.rs @@ -591,7 +591,7 @@ pub const RULES: &[RtkRule] = &[ subcmd_status: &[], }, RtkRule { - pattern: r"^dotnet\s+build\b", + pattern: r"^dotnet\s+(build|test|restore|format)\b", rtk_cmd: "rtk dotnet", rewrite_prefixes: &["dotnet"], category: "Build",