From bded9455f5419a0d1a1db5546e024af02aa3d4f9 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Wed, 11 Mar 2026 12:40:05 +0100 Subject: [PATCH] test(appd): add appd_socket_path tests; run appd tests single-threaded Two new tests cover appd_socket_path(): - appd_socket_path_uses_override_env: WEFT_APPD_SOCKET takes precedence - appd_socket_path_errors_without_xdg_and_no_override: returns error when both WEFT_APPD_SOCKET and XDG_RUNTIME_DIR are unset wsl-test.sh: add --test-threads=1 for weft-appd to prevent WEFT_RUNTIME_BIN races between the supervisor integration tests. --- crates/weft-appd/src/main.rs | 36 ++++++++++++++++++++++++++++++++++++ scripts/wsl-test.sh | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/crates/weft-appd/src/main.rs b/crates/weft-appd/src/main.rs index 897654e..b028b64 100644 --- a/crates/weft-appd/src/main.rs +++ b/crates/weft-appd/src/main.rs @@ -343,6 +343,42 @@ mod tests { Arc::new(Mutex::new(SessionRegistry::default())) } + #[test] + fn appd_socket_path_uses_override_env() { + let prior = std::env::var("WEFT_APPD_SOCKET").ok(); + unsafe { std::env::set_var("WEFT_APPD_SOCKET", "/tmp/custom.sock") }; + let path = appd_socket_path().unwrap(); + unsafe { + match prior { + Some(v) => std::env::set_var("WEFT_APPD_SOCKET", v), + None => std::env::remove_var("WEFT_APPD_SOCKET"), + } + } + assert_eq!(path, PathBuf::from("/tmp/custom.sock")); + } + + #[test] + fn appd_socket_path_errors_without_xdg_and_no_override() { + let prior_sock = std::env::var("WEFT_APPD_SOCKET").ok(); + let prior_xdg = std::env::var("XDG_RUNTIME_DIR").ok(); + unsafe { + std::env::remove_var("WEFT_APPD_SOCKET"); + std::env::remove_var("XDG_RUNTIME_DIR"); + } + let result = appd_socket_path(); + unsafe { + match prior_sock { + Some(v) => std::env::set_var("WEFT_APPD_SOCKET", v), + None => {} + } + match prior_xdg { + Some(v) => std::env::set_var("XDG_RUNTIME_DIR", v), + None => {} + } + } + assert!(result.is_err()); + } + #[tokio::test] async fn dispatch_launch_returns_ack() { let reg = make_registry(); diff --git a/scripts/wsl-test.sh b/scripts/wsl-test.sh index e57a245..8262efc 100644 --- a/scripts/wsl-test.sh +++ b/scripts/wsl-test.sh @@ -28,7 +28,7 @@ cargo test -p weft-compositor 2>&1 echo "" echo "==> cargo test -p weft-appd" -cargo test -p weft-appd 2>&1 +cargo test -p weft-appd -- --test-threads=1 2>&1 echo "" echo "==> cargo test -p weft-runtime"