From bf76cef889257a56b29f892816cff827b34c23da Mon Sep 17 00:00:00 2001 From: akbash Date: Thu, 10 Sep 2026 16:10:44 +0300 Subject: fix: accept machine add options before the SSH target (#3897) refs #3883 Co-authored-by: akbash-bot <300245827+akbash-bot@users.noreply.github.com> --- tests/machine_setup.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/machine_setup.rs b/tests/machine_setup.rs index 5fce2865..3b577f4e 100644 --- a/tests/machine_setup.rs +++ b/tests/machine_setup.rs @@ -5,7 +5,7 @@ use std::io::{Read, Write}; use std::os::unix::fs::PermissionsExt; use std::process::Command; use std::sync::mpsc; -use std::time::Duration; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; use portable_pty::{native_pty_system, CommandBuilder, PtySize}; @@ -205,6 +205,59 @@ fn setup_with_strict_host_key_failure( } } +#[test] +fn machine_add_accepts_help_argument_order() { + let nonce = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_nanos(); + let root = std::env::temp_dir().join(format!( + "herdr-machine-add-order-{}-{nonce}", + std::process::id() + )); + fs::create_dir(&root).unwrap(); + let app = if cfg!(debug_assertions) { + "herdr-dev" + } else { + "herdr" + }; + fs::create_dir_all(root.join("config").join(app)).unwrap(); + fs::write( + root.join("config").join(app).join("config.toml"), + "onboarding = false\n[remote]\nmanage_ssh_config = false\n", + ) + .unwrap(); + let mut command = Command::new(env!("CARGO_BIN_EXE_herdr")); + command.args(["machine", "add", "--label", "coder", "workstation.coder"]); + // Reach remote preparation, but never execute SSH or start a server. + command.env("PATH", root.join("no-executables")); + command.env("HOME", &root); + command.env("XDG_CONFIG_HOME", root.join("config")); + command.env("XDG_STATE_HOME", root.join("state")); + command.env("XDG_RUNTIME_DIR", &root); + for name in [ + "HERDR_ENV", + "HERDR_SESSION", + "HERDR_SOCKET_PATH", + "HERDR_CLIENT_SOCKET_PATH", + "HERDR_REMOTE_BINARY", + "HERDR_CONFIG_PATH", + ] { + command.env_remove(name); + } + let output = command.output().unwrap(); + let saved = root + .join("state") + .join(app) + .join("client/endpoints.json") + .exists(); + fs::remove_dir_all(root).unwrap(); + let stderr = String::from_utf8_lossy(&output.stderr); + assert_eq!(output.status.code(), Some(1), "{stderr}"); + assert!(stderr.contains("machine was not saved"), "{stderr}"); + assert!(!saved, "failed preparation must not save a machine"); +} + #[test] fn machine_add_reports_strict_host_key_failure() { let result = setup_with_strict_host_key_failure("new", "", false, true); -- cgit v1.2.3