Compare commits

...
Author SHA1 Message Date
Florian BRUNIAUX 4296fe04d0 feat(discover): track passthrough git/cargo/pnpm subcommands
Fix estimated_savings_pct=0 for passthrough, add missing rewrite tests.

Signed-off-by: Florian BRUNIAUX <florian@bruniaux.com>
2026-04-13 16:15:20 +02:00
2 changed files with 144 additions and 11 deletions

No files matched your search

+127 -5
View File
@@ -173,10 +173,17 @@ pub fn classify_command(cmd: &str) -> Classification {
(rule.savings_pct, super::report::RtkStatus::Existing)
};
// Passthrough commands have 0% savings (no filtering)
let final_savings = if status == super::report::RtkStatus::Passthrough {
0.0
} else {
savings
};
Classification::Supported {
rtk_equivalent: rule.rtk_cmd,
category: rule.category,
estimated_savings_pct: savings,
estimated_savings_pct: final_savings,
status,
}
} else {
@@ -919,7 +926,98 @@ mod tests {
Classification::Supported {
rtk_equivalent: "rtk cargo",
category: "Cargo",
estimated_savings_pct: 80.0,
estimated_savings_pct: 0.0,
status: RtkStatus::Passthrough,
}
);
}
#[test]
fn test_classify_cargo_run_passthrough() {
assert_eq!(
classify_command("cargo run"),
Classification::Supported {
rtk_equivalent: "rtk cargo",
category: "Cargo",
estimated_savings_pct: 0.0,
status: RtkStatus::Passthrough,
}
);
}
#[test]
fn test_classify_cargo_publish_passthrough() {
assert_eq!(
classify_command("cargo publish"),
Classification::Supported {
rtk_equivalent: "rtk cargo",
category: "Cargo",
estimated_savings_pct: 0.0,
status: RtkStatus::Passthrough,
}
);
}
#[test]
fn test_classify_git_checkout_passthrough() {
assert_eq!(
classify_command("git checkout main"),
Classification::Supported {
rtk_equivalent: "rtk git",
category: "Git",
estimated_savings_pct: 0.0,
status: RtkStatus::Passthrough,
}
);
}
#[test]
fn test_classify_git_merge_passthrough() {
assert_eq!(
classify_command("git merge feature-branch"),
Classification::Supported {
rtk_equivalent: "rtk git",
category: "Git",
estimated_savings_pct: 0.0,
status: RtkStatus::Passthrough,
}
);
}
#[test]
fn test_classify_git_rebase_passthrough() {
assert_eq!(
classify_command("git rebase origin/main"),
Classification::Supported {
rtk_equivalent: "rtk git",
category: "Git",
estimated_savings_pct: 0.0,
status: RtkStatus::Passthrough,
}
);
}
#[test]
fn test_classify_pnpm_build_passthrough() {
assert_eq!(
classify_command("pnpm build"),
Classification::Supported {
rtk_equivalent: "rtk pnpm",
category: "PackageManager",
estimated_savings_pct: 0.0,
status: RtkStatus::Passthrough,
}
);
}
#[test]
fn test_classify_pnpm_exec_passthrough() {
assert_eq!(
classify_command("pnpm exec playwright test"),
Classification::Supported {
rtk_equivalent: "rtk pnpm",
category: "PackageManager",
estimated_savings_pct: 0.0,
status: RtkStatus::Passthrough,
}
);
@@ -940,9 +1038,9 @@ mod tests {
#[test]
fn test_registry_covers_all_cargo_subcommands() {
// Verify that every CargoCommand variant (Build, Test, Clippy, Check, Fmt)
// Verify that every CargoCommand variant (Build, Test, Clippy, Check, Fmt, Run, Publish)
// except Other has a matching pattern in the registry
for subcmd in ["build", "test", "clippy", "check", "fmt"] {
for subcmd in ["build", "test", "clippy", "check", "fmt", "run", "publish"] {
let cmd = format!("cargo {subcmd}");
match classify_command(&cmd) {
Classification::Supported { .. } => {}
@@ -956,7 +1054,7 @@ mod tests {
// Verify that every GitCommand subcommand has a matching pattern
for subcmd in [
"status", "log", "diff", "show", "add", "commit", "push", "pull", "branch", "fetch",
"stash", "worktree",
"stash", "worktree", "checkout", "merge", "rebase",
] {
let cmd = format!("git {subcmd}");
match classify_command(&cmd) {
@@ -1121,6 +1219,30 @@ mod tests {
);
}
#[test]
fn test_rewrite_cargo_publish() {
assert_eq!(
rewrite_command("cargo publish", &[]),
Some("rtk cargo publish".into())
);
}
#[test]
fn test_rewrite_git_rebase() {
assert_eq!(
rewrite_command("git rebase origin/main", &[]),
Some("rtk git rebase origin/main".into())
);
}
#[test]
fn test_rewrite_pnpm_exec() {
assert_eq!(
rewrite_command("pnpm exec playwright test", &[]),
Some("rtk pnpm exec playwright test".into())
);
}
#[test]
fn test_rewrite_compound_and() {
assert_eq!(
+17 -6
View File
@@ -12,7 +12,7 @@ pub struct RtkRule {
pub const RULES: &[RtkRule] = &[
RtkRule {
pattern: r"^(?:git|yadm)\s+(?:-[Cc]\s+\S+\s+)*(status|log|diff|show|add|commit|push|pull|branch|fetch|stash|worktree)",
pattern: r"^(?:git|yadm)\s+(?:-[Cc]\s+\S+\s+)*(status|log|diff|show|add|commit|push|pull|branch|fetch|stash|worktree|checkout|merge|rebase)",
rtk_cmd: "rtk git",
rewrite_prefixes: &["git", "yadm"],
category: "Git",
@@ -23,7 +23,11 @@ pub const RULES: &[RtkRule] = &[
("add", 59.0),
("commit", 59.0),
],
subcmd_status: &[],
subcmd_status: &[
("checkout", RtkStatus::Passthrough),
("merge", RtkStatus::Passthrough),
("rebase", RtkStatus::Passthrough),
],
},
RtkRule {
pattern: r"^gh\s+(pr|issue|run|repo|api|release)",
@@ -35,22 +39,29 @@ pub const RULES: &[RtkRule] = &[
subcmd_status: &[],
},
RtkRule {
pattern: r"^cargo\s+(build|test|clippy|check|fmt|install)",
pattern: r"^cargo\s+(build|test|clippy|check|fmt|install|run|publish)",
rtk_cmd: "rtk cargo",
rewrite_prefixes: &["cargo"],
category: "Cargo",
savings_pct: 80.0,
subcmd_savings: &[("test", 90.0), ("check", 80.0)],
subcmd_status: &[("fmt", RtkStatus::Passthrough)],
subcmd_status: &[
("fmt", RtkStatus::Passthrough),
("run", RtkStatus::Passthrough),
("publish", RtkStatus::Passthrough),
],
},
RtkRule {
pattern: r"^pnpm\s+(list|ls|outdated|install)",
pattern: r"^pnpm\s+(list|ls|outdated|install|build|exec)",
rtk_cmd: "rtk pnpm",
rewrite_prefixes: &["pnpm"],
category: "PackageManager",
savings_pct: 80.0,
subcmd_savings: &[],
subcmd_status: &[],
subcmd_status: &[
("build", RtkStatus::Passthrough),
("exec", RtkStatus::Passthrough),
],
},
RtkRule {
pattern: r"^npm\s+(run|exec)",