Add named persistent sessions (#57)

* feat: add named persistent sessions

* feat: add session management commands

* fix: tighten named session stop and override precedence

* fix: handle session help and stop test race

* test: isolate default session env test

---------

Co-authored-by: Ogulcan Celik <ogulcancelik@gmail.com>
This commit is contained in:
Franz Bettag
2026-04-28 20:11:11 +03:00
committed by GitHub
co-authored by Ogulcan Celik
parent 22d7bef568
commit 5baf231e07
12 changed files with 1102 additions and 31 deletions
+25 -5
View File
@@ -95,11 +95,7 @@ impl EventHub {
}
pub fn socket_path() -> PathBuf {
if let Ok(path) = std::env::var(SOCKET_PATH_ENV_VAR) {
return PathBuf::from(path);
}
crate::config::config_dir().join("herdr.sock")
crate::session::active_api_socket_path()
}
pub struct ServerHandle {
@@ -1064,6 +1060,8 @@ mod tests {
fn socket_path_prefers_explicit_env_override() {
let _guard = env_lock().lock().unwrap();
let unique = format!("/tmp/herdr-test-{}.sock", std::process::id());
std::env::remove_var(crate::session::SESSION_ENV_VAR);
crate::session::clear_explicit_session_for_test();
std::env::set_var(SOCKET_PATH_ENV_VAR, &unique);
assert_eq!(socket_path(), PathBuf::from(&unique));
std::env::remove_var(SOCKET_PATH_ENV_VAR);
@@ -1075,6 +1073,8 @@ mod tests {
let config_home = unique_test_path("socket-default-config-home");
let runtime_dir = unique_test_path("socket-default-runtime");
std::env::remove_var(SOCKET_PATH_ENV_VAR);
std::env::remove_var(crate::session::SESSION_ENV_VAR);
crate::session::clear_explicit_session_for_test();
std::env::set_var("XDG_CONFIG_HOME", &config_home);
std::env::set_var("XDG_RUNTIME_DIR", &runtime_dir);
@@ -1087,6 +1087,26 @@ mod tests {
std::env::remove_var("XDG_RUNTIME_DIR");
}
#[test]
fn socket_path_uses_named_session_dir() {
let _guard = env_lock().lock().unwrap();
let config_home = unique_test_path("socket-named-config-home");
std::env::remove_var(SOCKET_PATH_ENV_VAR);
crate::session::clear_explicit_session_for_test();
std::env::set_var(crate::session::SESSION_ENV_VAR, "work");
std::env::set_var("XDG_CONFIG_HOME", &config_home);
let expected = config_home
.join(crate::config::app_dir_name())
.join("sessions")
.join("work")
.join("herdr.sock");
assert_eq!(socket_path(), expected);
std::env::remove_var(crate::session::SESSION_ENV_VAR);
std::env::remove_var("XDG_CONFIG_HOME");
}
#[test]
fn restrict_socket_permissions_sets_user_only_mode() {
let dir = unique_test_path("socket-perms");