From 0376abddae604e0cdba1597f65d6dd0c7dbfaeda Mon Sep 17 00:00:00 2001 From: vikingowl Date: Wed, 13 May 2026 02:35:13 +0200 Subject: [PATCH] feat(paths): OWLRY_SOCKET env var to override the IPC socket path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a one-shot override before XDG_RUNTIME_DIR resolution so smoke tests (and side-by-side daemon instances during dev) can run without disturbing a production daemon listening on the default socket. - OWLRY_SOCKET=/tmp/foo.sock owlry -d - OWLRY_SOCKET=/tmp/foo.sock owlry providers Test added (owlry_socket_env_overrides_xdg_runtime) verifying the env var takes precedence and restoring the previous value so it doesn't leak across other tests in the module. Used to verify Phase 1 live behavior across all 13 provider entry points — each returned expected results, including uuctl resolving to real systemd unit names ('dbus' -> dbus-broker, at-spi-dbus-bus). Issue #5 confirmed fixed end-to-end. --- crates/owlry/src/paths.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/owlry/src/paths.rs b/crates/owlry/src/paths.rs index 7da39a7..9079eb2 100644 --- a/crates/owlry/src/paths.rs +++ b/crates/owlry/src/paths.rs @@ -157,10 +157,17 @@ pub fn system_data_dirs() -> Vec { // Runtime files // ============================================================================= -/// IPC socket path: `$XDG_RUNTIME_DIR/owlry/owlry.sock` +/// IPC socket path. /// -/// Falls back to `/tmp` if `$XDG_RUNTIME_DIR` is not set. +/// Resolution order: +/// 1. `$OWLRY_SOCKET` — full path override (useful for tests and side-by-side +/// daemon instances). +/// 2. `$XDG_RUNTIME_DIR/owlry/owlry.sock` (the normal case). +/// 3. `/tmp/owlry/owlry.sock` as a last-resort fallback. pub fn socket_path() -> PathBuf { + if let Ok(custom) = std::env::var("OWLRY_SOCKET") { + return PathBuf::from(custom); + } let runtime_dir = std::env::var("XDG_RUNTIME_DIR") .map(PathBuf::from) .unwrap_or_else(|_| PathBuf::from("/tmp")); @@ -202,6 +209,22 @@ mod tests { } } + #[test] + fn owlry_socket_env_overrides_xdg_runtime() { + // SAFETY: tests in this binary do not run in parallel against the env. + // Save / restore so other tests in this module aren't affected. + let prev = std::env::var_os("OWLRY_SOCKET"); + unsafe { std::env::set_var("OWLRY_SOCKET", "/tmp/owlry-smoke/foo.sock") }; + assert_eq!( + socket_path(), + PathBuf::from("/tmp/owlry-smoke/foo.sock") + ); + match prev { + Some(v) => unsafe { std::env::set_var("OWLRY_SOCKET", v) }, + None => unsafe { std::env::remove_var("OWLRY_SOCKET") }, + } + } + #[test] fn test_frecency_in_data_dir() { if let Some(path) = frecency_file() {