From daf636fef7fd68bcb1e30cfb155883c3b831513c Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Wed, 3 Jun 2026 01:32:22 +0300 Subject: fix: preserve child argv flags after separator refs #383 --- src/remote.rs | 25 +++++++++++++++++++++++++ src/session.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) (limited to 'src') 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; @@ -1843,6 +1847,27 @@ mod tests { assert!(remote.live_handoff); } + #[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, 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()); @@ -568,6 +572,51 @@ mod tests { clear_explicit_session_for_test(); } + #[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(); -- cgit v1.2.3