Files
gtk-ahfail/crates/ahfail-ui/tests/volume_tests.rs
Asger Geel Weirsøe 702f449d0e
Some checks failed
Test / test (push) Failing after 1m23s
fix: PID-based volume lock with state persistence and multiarch default path
Volume lock file now stores {pid}:{volume}:{muted} instead of "1":
- Allows recovery of saved volume state if the holder is SIGKILLed
- On stale lock detection (holder PID not alive), inherit saved volume state
  and take ownership — prevents permanent volume loss and infinite lockout

PAM module DEFAULT_PATH now baked in at build time via AHFAIL_LIBDIR env var
passed by Meson, fixing the wrong path on multiarch Debian/Ubuntu where libdir
is /usr/lib/x86_64-linux-gnu rather than /usr/lib.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 12:41:06 +02:00

20 lines
824 B
Rust

// Lock file behavior is tested via unit tests in src/volume.rs.
// Integration-level: verify that a fresh save_and_set_max() call creates the lock file.
// (pactl/osascript may not be available in CI — volume operations are best-effort.)
#[test]
fn save_and_set_max_creates_lock_file() {
// Override XDG_RUNTIME_DIR so we use a temp path, not the real user's runtime dir.
let dir = tempfile::tempdir().unwrap();
std::env::set_var("XDG_RUNTIME_DIR", dir.path());
let result = ahfail_ui::volume::save_and_set_max();
// Should succeed (lock file didn't exist).
assert!(result.is_some());
assert!(dir.path().join("ahfail.lock").exists());
// Cleanup: restore() removes the lock file.
ahfail_ui::volume::restore(result.unwrap());
assert!(!dir.path().join("ahfail.lock").exists());
}