Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(host): keep unit tests away from the real host's data

leepokai9a9f58d868c2
diff --git a/host/src/service/mod.rs b/host/src/service/mod.rs
index 779a635e..6ac69a5e 100644
--- a/host/src/service/mod.rs
+++ b/host/src/service/mod.rs
@@ -80,8 +80,18 @@ pub(crate) fn home() -> PathBuf {
}
pub fn data_dir() -> PathBuf {
- std::env::var_os("CODYNC_HOME")
- .map_or_else(|| home().join(crate::environment::Environment::current().data_folder()), PathBuf::from)
+ std::env::var_os("CODYNC_HOME").map_or_else(default_data_dir, PathBuf::from)
+}
+
+#[cfg(not(test))]
+fn default_data_dir() -> PathBuf {
+ home().join(crate::environment::Environment::current().data_folder())
+}
+
+/// Unit tests never see a real host's data: tests that start a hub run its start-up clean-up, which deletes files.
+#[cfg(test)]
+fn default_data_dir() -> PathBuf {
+ std::env::temp_dir().join(format!("codync-unit-{}", std::process::id()))
}
fn create_parent(file: &Path) -> Result<()> {
@@ -368,6 +378,15 @@ mod tests {
serde_json::from_str(&std::fs::read_to_string(f).unwrap()).unwrap()
}
+ #[test]
+ fn unit_tests_keep_out_of_the_real_data_folder() {
+ assert!(
+ std::env::var_os("CODYNC_HOME").is_some() || !data_dir().starts_with(home()),
+ "{}",
+ data_dir().display()
+ );
+ }
+
#[test]
fn mac_models_map_to_devices() {
assert_eq!(mac_device("MacBook Pro"), Device::Laptop);