aboutsummaryrefslogtreecommitdiff
path: root/tests/machine_setup.rs
diff options
context:
space:
mode:
authorakbash <akbash@herdr.dev>2026-09-10 16:10:44 +0300
committerGitHub <noreply@github.com>2026-09-10 16:10:44 +0300
commitbf76cef889257a56b29f892816cff827b34c23da (patch)
tree7c24a5dba2963dc31c1e39f8ae7ffa68e0f50598 /tests/machine_setup.rs
parent241a1e0fad651f441d97b8373f14ef193b3d9faf (diff)
fix: accept machine add options before the SSH target (#3897)
refs #3883 Co-authored-by: akbash-bot <300245827+akbash-bot@users.noreply.github.com>
Diffstat (limited to 'tests/machine_setup.rs')
-rw-r--r--tests/machine_setup.rs55
1 files changed, 54 insertions, 1 deletions
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};
@@ -206,6 +206,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);
assert!(!result.success, "{}", result.output);