#[cfg(test)]
mod khive_root_tests {
use super::khive_root_from;
use std::path::PathBuf;
#[test]
fn home_wins_when_set() {
assert_eq!(
khive_root_from(Some("/base/home".into()), Some("/other".into())),
PathBuf::from("/base/home/.khive")
);
}
#[test]
fn userprofile_backfills_missing_home() {
assert_eq!(
khive_root_from(None, Some("/profile/home".into())),
PathBuf::from("/profile/home/.khive")
);
}
#[test]
fn blank_values_are_skipped() {
assert_eq!(
khive_root_from(Some(" ".into()), Some("/profile/home".into())),
PathBuf::from("/profile/home/.khive")
);
}
#[cfg(not(unix))]
#[test]
fn fallback_is_never_cwd_relative() {
assert!(khive_root_from(None, None).is_absolute());
}
#[cfg(unix)]
#[test]
fn unix_fallback_stays_historical_not_shared_tmp() {
assert_eq!(khive_root_from(None, None), PathBuf::from("./.khive"));
}
#[test]
fn volume_lock_dir_without_a_home_is_an_error_not_the_relative_socket_root() {
let in_parent = khive_storage::test_support::run_exact_test_in_child(
"KHIVE_NO_HOME_LOCK_DIR_CHILD",
false,
|command| {
command
.env_remove("HOME")
.env_remove("USERPROFILE")
.env_remove("KHIVE_VOLUME_LOCK_DIR")
.env_remove("KHIVE_TEST_HARNESS");
},
);
if in_parent {
return;
}
let error =
super::volume_lock_dir().expect_err("no home must not resolve a lock directory");
assert!(
error.to_string().contains("KHIVE_VOLUME_LOCK_DIR"),
"{error}"
);
#[cfg(unix)]
assert_eq!(super::khive_dir(), PathBuf::from("./.khive"));
}
#[test]
fn volume_lock_dir_is_the_storage_layer_rule() {
assert_eq!(
super::volume_lock_dir().map_err(|error| error.to_string()),
khive_db::default_volume_lock_dir().map_err(|error| error.to_string())
);
}
}