From d3f356876a09316fd49cdabd7b3637bf4fe7ea35 Mon Sep 17 00:00:00 2001 From: WaleWangPW <396218656@qq.com> Date: Thu, 20 Aug 2026 20:00:13 +0800 Subject: [PATCH] fix(desktop): preserve inherited KANDEV_SERVER_HOST for embedded backend (#2838) Co-authored-by: Carlos Florencio --- apps/desktop/src-tauri/src/backend.rs | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/apps/desktop/src-tauri/src/backend.rs b/apps/desktop/src-tauri/src/backend.rs index 2445cb82d8..17da701f23 100644 --- a/apps/desktop/src-tauri/src/backend.rs +++ b/apps/desktop/src-tauri/src/backend.rs @@ -849,6 +849,36 @@ mod tests { assert!(!env.contains_key(OsStr::new("kandev_desktop_native_notifications"))); } + #[test] + fn desktop_environment_overrides_inherited_server_host_with_loopback() { + // Desktop launches must keep the embedded backend on the loopback host. + let mut inherited = BTreeMap::new(); + inherited.insert( + OsString::from("KANDEV_SERVER_HOST"), + OsString::from("10.0.0.42"), + ); + + let env = desktop_environment(Path::new("/opt/kandev"), inherited, None); + + assert_eq!( + env.get(OsStr::new("KANDEV_SERVER_HOST")), + Some(&OsString::from(LOOPBACK_HOST)), + "desktop_environment must force the loopback server host", + ); + } + + #[test] + fn desktop_environment_falls_back_to_loopback_when_server_host_unset() { + // The default production path: no inherited KANDEV_SERVER_HOST, + // desktop_environment must inject the loopback default. + let env = desktop_environment(Path::new("/opt/kandev"), BTreeMap::new(), None); + + assert_eq!( + env.get(OsStr::new("KANDEV_SERVER_HOST")), + Some(&OsString::from(LOOPBACK_HOST)) + ); + } + #[test] fn missing_launcher_returns_readable_error() { let dir = temp_root("missing-launcher");