diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-03 01:32:22 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-03 01:32:22 +0300 |
| commit | daf636fef7fd68bcb1e30cfb155883c3b831513c (patch) | |
| tree | e3f8403b964ebb16c54cf1d0650511179e713687 | |
| parent | a1ba035707cfb3c83fad541ecd32ccbd7be58815 (diff) | |
fix: preserve child argv flags after separator
refs #383
| -rw-r--r-- | src/remote.rs | 25 | ||||
| -rw-r--r-- | src/session.rs | 49 | ||||
| -rw-r--r-- | tests/cli_wrapper.rs | 4 |
3 files changed, 78 insertions, 0 deletions
diff --git a/src/remote.rs b/src/remote.rs index cd53344b..ce56ba8a 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -72,6 +72,10 @@ pub(crate) fn extract_remote_args( let mut index = 1; while index < args.len() { let arg = &args[index]; + if arg == "--" { + cleaned.extend_from_slice(&args[index..]); + break; + } if arg == "--handoff" { live_handoff = true; index += 1; @@ -1844,6 +1848,27 @@ mod tests { } #[test] + fn extract_remote_args_preserves_child_remote_options_after_separator() { + let args = vec![ + "herdr".into(), + "agent".into(), + "start".into(), + "repro".into(), + "--".into(), + "child".into(), + "--remote".into(), + "dev".into(), + "--remote-keybindings=server".into(), + "--handoff".into(), + ]; + + let (cleaned, remote) = extract_remote_args(&args).unwrap(); + + assert_eq!(cleaned, args); + assert!(remote.is_none()); + } + + #[test] fn extract_remote_args_preserves_handoff_without_remote() { let args = vec!["herdr".into(), "update".into(), "--handoff".into()]; diff --git a/src/session.rs b/src/session.rs index a4daf5e4..67b77dc0 100644 --- a/src/session.rs +++ b/src/session.rs @@ -52,6 +52,10 @@ pub fn configure_from_args(args: &[String]) -> Result<Vec<String>, String> { let mut index = 1; while index < args.len() { let arg = &args[index]; + if arg == "--" { + cleaned.extend_from_slice(&args[index..]); + break; + } if arg == "--session" { let Some(value) = args.get(index + 1) else { return Err("missing value for --session".to_string()); @@ -569,6 +573,51 @@ mod tests { } #[test] + fn configure_from_args_preserves_child_session_option_after_separator() { + let _guard = env_lock().lock().unwrap(); + std::env::remove_var(SESSION_ENV_VAR); + clear_explicit_session_for_test(); + let args = vec![ + "herdr".to_string(), + "agent".to_string(), + "start".to_string(), + "repro".to_string(), + "--".to_string(), + "/bin/echo".to_string(), + "--session".to_string(), + "child-session".to_string(), + ]; + + let cleaned = configure_from_args(&args).unwrap(); + + assert_eq!(cleaned, args); + assert!(std::env::var(SESSION_ENV_VAR).is_err()); + assert!(!explicit_session_requested()); + } + + #[test] + fn configure_from_args_preserves_child_session_equals_option_after_separator() { + let _guard = env_lock().lock().unwrap(); + std::env::remove_var(SESSION_ENV_VAR); + clear_explicit_session_for_test(); + let args = vec![ + "herdr".to_string(), + "agent".to_string(), + "start".to_string(), + "repro".to_string(), + "--".to_string(), + "/bin/echo".to_string(), + "--session=child-session".to_string(), + ]; + + let cleaned = configure_from_args(&args).unwrap(); + + assert_eq!(cleaned, args); + assert!(std::env::var(SESSION_ENV_VAR).is_err()); + assert!(!explicit_session_requested()); + } + + #[test] fn configure_from_args_rewrites_session_attach_to_default_launch() { let _guard = env_lock().lock().unwrap(); std::env::set_var(SESSION_ENV_VAR, "bad/name"); diff --git a/tests/cli_wrapper.rs b/tests/cli_wrapper.rs index 871cba64..bbe053a7 100644 --- a/tests/cli_wrapper.rs +++ b/tests/cli_wrapper.rs @@ -2117,11 +2117,15 @@ fn agent_start_command_works() { "/bin/sh", "-c", "printf cli-agent-start-ok; sleep 2", + "--session", + "child-session", ], ); assert_eq!(started["result"]["type"], "agent_started"); assert_eq!(started["result"]["agent"]["name"], "main"); assert_eq!(started["result"]["argv"][0], "/bin/sh"); + assert_eq!(started["result"]["argv"][3], "--session"); + assert_eq!(started["result"]["argv"][4], "child-session"); let terminal_id = started["result"]["agent"]["terminal_id"] .as_str() .unwrap() |
