Skip to content

Commit f3a1b0f

Browse files
committed
test(gui): eliminate APPIMAGE env race in autostart tests
Parallel tests mutating process-wide APPIMAGE could interleave and cause resolve_exe_path_appimage_env to fail on macOS CI. Refactor resolve_exe_path to accept an injected env getter so tests exercise the precedence logic without touching process state.
1 parent 8d9862b commit f3a1b0f

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

crates/vykar-gui/src/autostart.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@ pub fn should_start_hidden(start_in_background: Option<bool>, autostart_enabled:
2222
}
2323

2424
fn resolve_exe_path() -> Result<String, Box<dyn std::error::Error>> {
25+
resolve_exe_path_with(|k| std::env::var(k))
26+
}
27+
28+
fn resolve_exe_path_with<F>(env_get: F) -> Result<String, Box<dyn std::error::Error>>
29+
where
30+
F: Fn(&str) -> Result<String, std::env::VarError>,
31+
{
2532
// AppImage: the FUSE mount path is transient; use the real .AppImage path.
26-
if let Ok(appimage) = std::env::var("APPIMAGE") {
33+
if let Ok(appimage) = env_get("APPIMAGE") {
2734
return Ok(appimage);
2835
}
2936
Ok(std::env::current_exe()?.display().to_string())
@@ -43,30 +50,23 @@ mod tests {
4350

4451
#[test]
4552
fn resolve_exe_path_appimage_env() {
46-
// Temporarily set APPIMAGE and verify it takes precedence.
47-
let key = "APPIMAGE";
48-
let prev = std::env::var(key).ok();
49-
std::env::set_var(key, "/opt/Vykar-1.0.AppImage");
50-
let result = resolve_exe_path().unwrap();
51-
assert_eq!(result, "/opt/Vykar-1.0.AppImage");
52-
// Restore.
53-
match prev {
54-
Some(v) => std::env::set_var(key, v),
55-
None => std::env::remove_var(key),
56-
}
53+
let get = |k: &str| {
54+
if k == "APPIMAGE" {
55+
Ok("/opt/Vykar-1.0.AppImage".to_string())
56+
} else {
57+
Err(std::env::VarError::NotPresent)
58+
}
59+
};
60+
assert_eq!(
61+
resolve_exe_path_with(get).unwrap(),
62+
"/opt/Vykar-1.0.AppImage"
63+
);
5764
}
5865

5966
#[test]
6067
fn resolve_exe_path_fallback() {
61-
let key = "APPIMAGE";
62-
let prev = std::env::var(key).ok();
63-
std::env::remove_var(key);
64-
let result = resolve_exe_path().unwrap();
65-
// Should return something non-empty (the test binary path).
66-
assert!(!result.is_empty());
67-
if let Some(v) = prev {
68-
std::env::set_var(key, v);
69-
}
68+
let get = |_: &str| Err(std::env::VarError::NotPresent);
69+
assert!(!resolve_exe_path_with(get).unwrap().is_empty());
7070
}
7171

7272
#[test]

0 commit comments

Comments
 (0)