Compare commits

...
Author SHA1 Message Date
Florian BRUNIAUXandClaude Sonnet 4.6 86d86915af fix(proxy): handle single-quoted command arg (issue #388)
When an LLM writes `rtk proxy 'head -50 file.php'`, the shell strips
the quotes and delivers the entire string as one OsString. RTK was then
calling Command::new("head -50 file.php") which fails with ENOENT.

Add resolve_proxy_args(): if args.len() == 1 and the single argument
contains a space, POSIX-split it with shlex so quoted inner arguments
like `grep -r "pattern with spaces" .` are handled correctly.

Fallback to raw single token when shlex cannot parse (unmatched quotes)
or when splitting yields an empty list (whitespace-only input), keeping
the error surface in the child process where it belongs.

Note: executable paths that genuinely contain spaces are ambiguous with
this heuristic — pass them as separate args in that case.

Add 7 unit tests covering: single-quoted split, normal multi-args,
single arg without spaces, complex quoted command, inner quoted argument,
unmatched quote fallback, and whitespace-only fallback.

Closes #388

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Florian BRUNIAUX <florian@bruniaux.com>
2026-03-11 00:08:32 +01:00
patrick szymkowiak 18f4401a93 fix: rtk read no longer corrupts JSON files with glob patterns (#464) (#479)
Add Language::Data variant for JSON, YAML, TOML, XML, Markdown, CSV
and other data formats. These files have no comment syntax, so the
MinimalFilter skips comment stripping entirely.

Previously, `packages/*` in package.json was treated as a block
comment start (`/*`), causing everything until the next `*/` to be
stripped — corrupting the JSON structure.

Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
2026-03-10 22:07:53 +01:00
patrick szymkowiak 3f37f5a78f fix: gh run view --job flag loses its value (#416) (#477)
Add --job and --attempt to flags_with_value in
extract_identifier_and_extra_args() so their values are not
mistaken for the run identifier when placed before it.

Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
2026-03-10 22:07:41 +01:00
patrick szymkowiak b2c2914b90 fix: git log --oneline no longer silently truncated to 10 entries (#461) (#478)
Only inject -10 limit when RTK applies its own compact format.
When user provides --oneline/--pretty/--format, respect git's
default behavior (no limit). Also detect -n and --max-count as
user-provided limit flags.

Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
2026-03-10 21:38:46 +01:00
patrick szymkowiak 91289d761b feat: add 32 TOML-filtered commands to hook rewrite rules (#475)
Add rewrite rules for all TOML-filtered commands so the Claude Code
hook automatically rewrites them to `rtk proxy <cmd>`. This ensures
TOML filters apply transparently without manual `rtk` prefixing.

Commands added: ansible-playbook, brew, composer, df, dotnet, du,
fail2ban-client, gcloud, hadolint, helm, iptables, make,
markdownlint, mix, mvn, ping, pio, poetry, pre-commit, ps, quarto,
rsync, shellcheck, shopify, sops, swift, systemctl, terraform, tofu,
trunk, uv, yamllint.

Tests updated to use `htop` as unsupported command example since
terraform is now supported via TOML filter.

Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
2026-03-10 21:34:49 +01:00
14 changed files with 525 additions and 28 deletions

No files matched your search

+1 -1
View File
@@ -1488,4 +1488,4 @@ When implementing a new command, consider:
**Last Updated**: 2026-02-22
**Architecture Version**: 2.2
**rtk Version**: 0.28.0
**rtk Version**: 0.28.2
+1
View File
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Bug Fixes
* add tokens_saved to telemetry payload ([#471](https://github.com/rtk-ai/rtk/issues/471)) ([#472](https://github.com/rtk-ai/rtk/issues/472)) ([f8b7d52](https://github.com/rtk-ai/rtk/commit/f8b7d52d2d25d09a44f391576bad6a7b271f1f8c))
* **proxy:** handle single-quoted command string (shell collapses quotes into one arg) ([#388](https://github.com/rtk-ai/rtk/issues/388))
## [0.28.1](https://github.com/rtk-ai/rtk/compare/v0.28.0...v0.28.1) (2026-03-10)
+1 -1
View File
@@ -16,7 +16,7 @@ This is a fork with critical fixes for git argument parsing and modern JavaScrip
**Verify correct installation:**
```bash
rtk --version # Should show "rtk 0.28.0" (or newer)
rtk --version # Should show "rtk 0.28.2" (or newer)
rtk gain # Should show token savings stats (NOT "command not found")
```
Generated
+1
View File
@@ -853,6 +853,7 @@ dependencies = [
"serde",
"serde_json",
"sha2",
"shlex",
"tempfile",
"thiserror",
"toml",
+1
View File
@@ -30,6 +30,7 @@ tempfile = "3"
sha2 = "0.10"
ureq = "2"
hostname = "0.4"
shlex = "1"
[build-dependencies]
toml = "0.8"
+1 -1
View File
@@ -90,7 +90,7 @@ Download from [releases](https://github.com/rtk-ai/rtk/releases):
### Verify Installation
```bash
rtk --version # Should show "rtk 0.28.0"
rtk --version # Should show "rtk 0.28.2"
rtk gain # Should show token savings stats
```
+9 -12
View File
@@ -611,10 +611,10 @@ mod tests {
}
#[test]
fn test_classify_terraform_unsupported() {
match classify_command("terraform plan -var-file=prod.tfvars") {
fn test_classify_htop_unsupported() {
match classify_command("htop -d 10") {
Classification::Unsupported { base_command } => {
assert_eq!(base_command, "terraform plan");
assert_eq!(base_command, "htop");
}
other => panic!("expected Unsupported, got {:?}", other),
}
@@ -886,8 +886,8 @@ mod tests {
#[test]
fn test_rewrite_background_unsupported_right() {
assert_eq!(
rewrite_command("cargo test & terraform plan", &[]),
Some("rtk cargo test & terraform plan".into())
rewrite_command("cargo test & htop", &[]),
Some("rtk cargo test & htop".into())
);
}
@@ -902,7 +902,7 @@ mod tests {
#[test]
fn test_rewrite_unsupported_returns_none() {
assert_eq!(rewrite_command("terraform plan", &[]), None);
assert_eq!(rewrite_command("htop", &[]), None);
}
#[test]
@@ -1695,18 +1695,15 @@ mod tests {
fn test_rewrite_compound_mixed_supported_unsupported() {
// unsupported segments stay raw
assert_eq!(
rewrite_command("cargo test && terraform plan", &[]),
Some("rtk cargo test && terraform plan".into())
rewrite_command("cargo test && htop", &[]),
Some("rtk cargo test && htop".into())
);
}
#[test]
fn test_rewrite_compound_all_unsupported_returns_none() {
// No rewrite at all: returns None
assert_eq!(
rewrite_command("terraform plan && terraform apply", &[]),
None
);
assert_eq!(rewrite_command("htop && top", &[]), None);
}
// --- sudo / env prefix + rewrite ---
+290
View File
@@ -48,6 +48,39 @@ pub const PATTERNS: &[&str] = &[
r"^aws\s+",
// PostgreSQL
r"^psql(\s|$)",
// TOML-filtered commands
r"^ansible-playbook\b",
r"^brew\s+(install|upgrade)\b",
r"^composer\s+(install|update|require)\b",
r"^df(\s|$)",
r"^dotnet\s+build\b",
r"^du\b",
r"^fail2ban-client\b",
r"^gcloud\b",
r"^hadolint\b",
r"^helm\b",
r"^iptables\b",
r"^make\b",
r"^markdownlint\b",
r"^mix\s+(compile|format)(\s|$)",
r"^mvn\s+(compile|package|clean|install)\b",
r"^ping\b",
r"^pio\s+run",
r"^poetry\s+(install|lock|update)\b",
r"^pre-commit\b",
r"^ps(\s|$)",
r"^quarto\s+render",
r"^rsync\b",
r"^shellcheck\b",
r"^shopify\s+theme\s+(push|pull)",
r"^sops\b",
r"^swift\s+build\b",
r"^systemctl\s+status\b",
r"^terraform\s+plan",
r"^tofu\s+(fmt|init|plan|validate)(\s|$)",
r"^trunk\s+build",
r"^uv\s+(sync|pip\s+install)\b",
r"^yamllint\b",
];
pub const RULES: &[RtkRule] = &[
@@ -317,6 +350,263 @@ pub const RULES: &[RtkRule] = &[
subcmd_savings: &[],
subcmd_status: &[],
},
// TOML-filtered commands
RtkRule {
rtk_cmd: "rtk proxy ansible-playbook",
rewrite_prefixes: &["ansible-playbook"],
category: "Infra",
savings_pct: 70.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy brew",
rewrite_prefixes: &["brew"],
category: "PackageManager",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy composer",
rewrite_prefixes: &["composer"],
category: "PackageManager",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy df",
rewrite_prefixes: &["df"],
category: "System",
savings_pct: 60.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy dotnet",
rewrite_prefixes: &["dotnet"],
category: "Build",
savings_pct: 70.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy du",
rewrite_prefixes: &["du"],
category: "System",
savings_pct: 60.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy fail2ban-client",
rewrite_prefixes: &["fail2ban-client"],
category: "Infra",
savings_pct: 60.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy gcloud",
rewrite_prefixes: &["gcloud"],
category: "Infra",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy hadolint",
rewrite_prefixes: &["hadolint"],
category: "Build",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy helm",
rewrite_prefixes: &["helm"],
category: "Infra",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy iptables",
rewrite_prefixes: &["iptables"],
category: "Infra",
savings_pct: 60.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy make",
rewrite_prefixes: &["make"],
category: "Build",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy markdownlint",
rewrite_prefixes: &["markdownlint"],
category: "Build",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy mix",
rewrite_prefixes: &["mix"],
category: "Build",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy mvn",
rewrite_prefixes: &["mvn"],
category: "Build",
savings_pct: 70.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy ping",
rewrite_prefixes: &["ping"],
category: "Network",
savings_pct: 60.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy pio",
rewrite_prefixes: &["pio"],
category: "Build",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy poetry",
rewrite_prefixes: &["poetry"],
category: "Python",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy pre-commit",
rewrite_prefixes: &["pre-commit"],
category: "Build",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy ps",
rewrite_prefixes: &["ps"],
category: "System",
savings_pct: 60.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy quarto",
rewrite_prefixes: &["quarto"],
category: "Build",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy rsync",
rewrite_prefixes: &["rsync"],
category: "Network",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy shellcheck",
rewrite_prefixes: &["shellcheck"],
category: "Build",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy shopify",
rewrite_prefixes: &["shopify"],
category: "Build",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy sops",
rewrite_prefixes: &["sops"],
category: "Infra",
savings_pct: 60.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy swift",
rewrite_prefixes: &["swift"],
category: "Build",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy systemctl",
rewrite_prefixes: &["systemctl"],
category: "System",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy terraform",
rewrite_prefixes: &["terraform"],
category: "Infra",
savings_pct: 70.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy tofu",
rewrite_prefixes: &["tofu"],
category: "Infra",
savings_pct: 70.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy trunk",
rewrite_prefixes: &["trunk"],
category: "Build",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy uv",
rewrite_prefixes: &["uv"],
category: "Python",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk proxy yamllint",
rewrite_prefixes: &["yamllint"],
category: "Build",
savings_pct: 65.0,
subcmd_savings: &[],
subcmd_status: &[],
},
];
/// Commands to ignore (shell builtins, trivial, already rtk).
+57
View File
@@ -50,6 +50,7 @@ pub enum Language {
Java,
Ruby,
Shell,
Data,
Unknown,
}
@@ -66,6 +67,9 @@ impl Language {
"java" => Language::Java,
"rb" => Language::Ruby,
"sh" | "bash" | "zsh" => Language::Shell,
"json" | "jsonc" | "json5" | "yaml" | "yml" | "toml" | "xml" | "html" | "htm"
| "css" | "scss" | "svg" | "md" | "markdown" | "txt" | "csv" | "tsv" | "env"
| "ini" | "cfg" | "conf" | "lock" => Language::Data,
_ => Language::Unknown,
}
}
@@ -112,6 +116,13 @@ impl Language {
doc_line: None,
doc_block_start: None,
},
Language::Data => CommentPatterns {
line: None,
block_start: None,
block_end: None,
doc_line: None,
doc_block_start: None,
},
Language::Unknown => CommentPatterns {
line: Some("//"),
block_start: Some("/*"),
@@ -389,6 +400,52 @@ mod tests {
assert_eq!(Language::from_extension("js"), Language::JavaScript);
}
#[test]
fn test_language_detection_data_formats() {
assert_eq!(Language::from_extension("json"), Language::Data);
assert_eq!(Language::from_extension("yaml"), Language::Data);
assert_eq!(Language::from_extension("yml"), Language::Data);
assert_eq!(Language::from_extension("toml"), Language::Data);
assert_eq!(Language::from_extension("xml"), Language::Data);
assert_eq!(Language::from_extension("md"), Language::Data);
assert_eq!(Language::from_extension("csv"), Language::Data);
assert_eq!(Language::from_extension("lock"), Language::Data);
}
#[test]
fn test_data_files_no_comment_stripping() {
// Regression test for #464: package.json with `/*` in strings
let json = r#"{
"workspaces": {
"packages": [
"packages/*"
]
},
"scripts": {
"build": "bun run --workspaces build"
},
"lint-staged": {
"**/package.json": [
"sort-package-json"
]
}
}"#;
let filter = MinimalFilter;
let result = filter.filter(json, &Language::Data);
assert!(
result.contains("scripts"),
"scripts section must be preserved"
);
assert!(
result.contains("packages/*"),
"glob pattern must be preserved"
);
assert!(
result.contains("**/package.json"),
"glob pattern must be preserved"
);
}
#[test]
fn test_minimal_filter_removes_comments() {
let code = r#"
+51 -1
View File
@@ -121,7 +121,16 @@ fn extract_identifier_and_extra_args(args: &[String]) -> Option<(String, Vec<Str
}
// Known gh flags that take a value — skip these and their values
let flags_with_value = ["-R", "--repo", "-q", "--jq", "-t", "--template"];
let flags_with_value = [
"-R",
"--repo",
"-q",
"--jq",
"-t",
"--template",
"--job",
"--attempt",
];
let mut identifier = None;
let mut extra = Vec::new();
let mut skip_next = false;
@@ -1418,6 +1427,47 @@ mod tests {
assert!(!should_passthrough_run_view(&["--web".into()]));
}
#[test]
fn test_extract_identifier_with_job_flag_after() {
// gh run view 12345 --job 67890
let args: Vec<String> = vec!["12345".into(), "--job".into(), "67890".into()];
let (id, extra) = extract_identifier_and_extra_args(&args).unwrap();
assert_eq!(id, "12345");
assert_eq!(extra, vec!["--job", "67890"]);
}
#[test]
fn test_extract_identifier_with_job_flag_before() {
// gh run view --job 67890 12345
let args: Vec<String> = vec!["--job".into(), "67890".into(), "12345".into()];
let (id, extra) = extract_identifier_and_extra_args(&args).unwrap();
assert_eq!(id, "12345");
assert_eq!(extra, vec!["--job", "67890"]);
}
#[test]
fn test_extract_identifier_with_job_and_log_failed() {
// gh run view --log-failed --job 67890 12345
let args: Vec<String> = vec![
"--log-failed".into(),
"--job".into(),
"67890".into(),
"12345".into(),
];
let (id, extra) = extract_identifier_and_extra_args(&args).unwrap();
assert_eq!(id, "12345");
assert_eq!(extra, vec!["--log-failed", "--job", "67890"]);
}
#[test]
fn test_extract_identifier_with_attempt_flag() {
// gh run view 12345 --attempt 3
let args: Vec<String> = vec!["12345".into(), "--attempt".into(), "3".into()];
let (id, extra) = extract_identifier_and_extra_args(&args).unwrap();
assert_eq!(id, "12345");
assert_eq!(extra, vec!["--attempt", "3"]);
}
// --- should_passthrough_pr_view tests ---
#[test]
+12 -5
View File
@@ -352,9 +352,11 @@ fn run_log(
arg.starts_with("--oneline") || arg.starts_with("--pretty") || arg.starts_with("--format")
});
// Check if user provided limit flag
// Check if user provided limit flag (-N, -n N, --max-count=N, --max-count N)
let has_limit_flag = args.iter().any(|arg| {
arg.starts_with('-') && arg.chars().nth(1).map_or(false, |c| c.is_ascii_digit())
(arg.starts_with('-') && arg.chars().nth(1).map_or(false, |c| c.is_ascii_digit()))
|| arg == "-n"
|| arg.starts_with("--max-count")
});
// Apply RTK defaults only if user didn't specify them
@@ -362,17 +364,22 @@ fn run_log(
cmd.args(["--pretty=format:%h %s (%ar) <%an>"]);
}
let limit = if !has_limit_flag {
// Only inject -10 limit when RTK is applying its own format.
// When user provides --oneline/--pretty/--format, respect git's default (no limit).
let limit = if !has_limit_flag && !has_format_flag {
cmd.arg("-10");
10
} else {
} else if has_limit_flag {
// Extract limit from args if provided
args.iter()
.find(|arg| {
arg.starts_with('-') && arg.chars().nth(1).map_or(false, |c| c.is_ascii_digit())
})
.and_then(|arg| arg[1..].parse::<usize>().ok())
.unwrap_or(10)
.unwrap_or(500)
} else {
// User format, no limit — use a high cap for filter_log_output
500
};
// Only add --no-merges if user didn't explicitly request merge commits
+1
View File
@@ -121,6 +121,7 @@ fn lang_display_name(lang: &Language) -> &'static str {
Language::Java => "Java",
Language::Ruby => "Ruby",
Language::Shell => "Shell",
Language::Data => "Data",
Language::Unknown => "Code",
}
}
+98 -6
View File
@@ -958,6 +958,35 @@ const RTK_META_COMMANDS: &[&str] = &[
"verify",
];
/// Resolve `rtk proxy` arguments, handling the single-quoted-string case.
///
/// When an LLM writes `rtk proxy 'head -50 file.php'`, the shell strips the quotes
/// and delivers `head -50 file.php` as **one** OsString. We detect this (len == 1 with
/// spaces) and POSIX-split it with `shlex` so quoted inner arguments like
/// `grep -r "pattern with spaces" .` are handled correctly.
///
/// Falls back to the raw single token when:
/// - `shlex` cannot parse (e.g. unmatched quotes)
/// - splitting yields an empty token list (e.g. all-whitespace input)
/// - the single argument is a path that genuinely contains spaces (ambiguous: we cannot
/// distinguish `/Applications/My App` from `My App arg1`; in that case, pass the
/// command as multiple args: `rtk proxy /Applications/My\ App arg1`)
fn resolve_proxy_args(args: &[std::ffi::OsString]) -> Vec<String> {
if args.len() == 1 {
let single = args[0].to_string_lossy();
if single.contains(' ') {
if let Some(tokens) = shlex::split(&single) {
if !tokens.is_empty() {
return tokens;
}
}
}
}
args.iter()
.map(|s| s.to_string_lossy().into_owned())
.collect()
}
fn run_fallback(parse_error: clap::Error) -> Result<()> {
let args: Vec<String> = std::env::args().skip(1).collect();
@@ -1857,17 +1886,15 @@ fn main() -> Result<()> {
let timer = tracking::TimedExecution::start();
let cmd_name = args[0].to_string_lossy();
let cmd_args: Vec<String> = args[1..]
.iter()
.map(|s| s.to_string_lossy().into_owned())
.collect();
let mut effective_args = resolve_proxy_args(&args).into_iter();
let cmd_name = effective_args.next().expect("args non-empty checked above");
let cmd_args: Vec<String> = effective_args.collect();
if cli.verbose > 0 {
eprintln!("Proxy mode: {} {}", cmd_name, cmd_args.join(" "));
}
let mut child = Command::new(cmd_name.as_ref())
let mut child = Command::new(&cmd_name)
.args(&cmd_args)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
@@ -2266,4 +2293,69 @@ mod tests {
);
}
}
// ── resolve_proxy_args ────────────────────────────────────────────────────
fn os(s: &str) -> std::ffi::OsString {
std::ffi::OsString::from(s)
}
#[test]
fn test_proxy_single_quoted_arg_is_split() {
// Simulates: rtk proxy 'head -50 app/Models/Domaine.php'
// Shell strips quotes → one arg "head -50 app/Models/Domaine.php"
let args = vec![os("head -50 app/Models/Domaine.php")];
let result = resolve_proxy_args(&args);
assert_eq!(result, vec!["head", "-50", "app/Models/Domaine.php"]);
}
#[test]
fn test_proxy_normal_multi_args_unchanged() {
// rtk proxy head -50 app/Models/Domaine.php → 3 separate args, no splitting
let args = vec![os("head"), os("-50"), os("app/Models/Domaine.php")];
let result = resolve_proxy_args(&args);
assert_eq!(result, vec!["head", "-50", "app/Models/Domaine.php"]);
}
#[test]
fn test_proxy_single_arg_without_spaces_unchanged() {
// rtk proxy echo → single arg with no spaces, leave it alone
let args = vec![os("echo")];
let result = resolve_proxy_args(&args);
assert_eq!(result, vec!["echo"]);
}
#[test]
fn test_proxy_complex_single_quoted_command() {
// rtk proxy 'git log --oneline -10'
let args = vec![os("git log --oneline -10")];
let result = resolve_proxy_args(&args);
assert_eq!(result, vec!["git", "log", "--oneline", "-10"]);
}
#[test]
fn test_proxy_inner_quoted_argument() {
// rtk proxy 'grep -r "pattern with spaces" .'
// shell delivers: grep -r "pattern with spaces" .
let args = vec![os(r#"grep -r "pattern with spaces" ."#)];
let result = resolve_proxy_args(&args);
assert_eq!(result, vec!["grep", "-r", "pattern with spaces", "."]);
}
#[test]
fn test_proxy_unmatched_quote_fallback() {
// shlex returns None on unmatched quotes → fall back to raw single token
let args = vec![os("echo \"unterminated")];
let result = resolve_proxy_args(&args);
assert_eq!(result, vec!["echo \"unterminated"]);
}
#[test]
fn test_proxy_whitespace_only_arg_fallback() {
// shlex splits " " into Ok([]) — empty token list falls back to raw single token
// (prevents a panic at the call-site expect())
let args = vec![os(" ")];
let result = resolve_proxy_args(&args);
assert_eq!(result, vec![" "]);
}
}
+1 -1
View File
@@ -37,7 +37,7 @@ mod tests {
#[test]
fn test_run_unsupported_returns_none() {
assert!(registry::rewrite_command("terraform plan", &[]).is_none());
assert!(registry::rewrite_command("htop", &[]).is_none());
}
#[test]