The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(config): cover v1 and v2 profile layout resolution
Steven Enamakeld010d43af1ca
diff --git a/crates/openhuman-core/src/config/schema/load_profile_layout_parity_tests.rs b/crates/openhuman-core/src/config/schema/load_profile_layout_parity_tests.rsindex eb0a1d7ca8..eae5490b69 100644--- a/crates/openhuman-core/src/config/schema/load_profile_layout_parity_tests.rs+++ b/crates/openhuman-core/src/config/schema/load_profile_layout_parity_tests.rs@@ -1,14 +1,19 @@//! The desktop resolver and the shared `ProfileLayout` must name the same-//! bytes: `users/<id>/{config.toml,workspace}` under the root.+//! bytes: `users/<id>/{config.toml,workspace}` (v1, an existing profile) or+//! `users/<id>/{config.toml,storage.db,files}` (v2, a brand-new one).use super::*;use crate::config::schema::ProfileLayout;#[tokio::test]-async fn an_active_user_resolves_to_its_profile_layout_byte_for_byte() {+async fn an_existing_active_user_resolves_to_its_v1_profile_layout_byte_for_byte() {let tmp = tempfile::tempdir().unwrap();let root = tmp.path();write_active_user_id(root, "65f1c0ffee0123456789abcd").unwrap();+ // An existing install: the profile already holds a config.toml.+ let user_dir = root.join("users").join("65f1c0ffee0123456789abcd");+ std::fs::create_dir_all(&user_dir).unwrap();+ std::fs::write(user_dir.join("config.toml"), "").unwrap();let (config_dir, workspace_dir, source) =resolve_runtime_config_dirs_with(root, &root.join("workspace"), &MapEnv::default())@@ -34,7 +39,7 @@ async fn an_active_user_resolves_to_its_profile_layout_byte_for_byte() {}#[tokio::test]-async fn the_pre_login_profile_resolves_to_its_profile_layout() {+async fn a_fresh_pre_login_profile_resolves_to_the_v2_layout() {let tmp = tempfile::tempdir().unwrap();let root = tmp.path();@@ -43,12 +48,35 @@ async fn the_pre_login_profile_resolves_to_its_profile_layout() {.await.unwrap();- let layout = ProfileLayout::new(root, PRE_LOGIN_USER_ID);+ let layout = ProfileLayout::resolve(root, PRE_LOGIN_USER_ID);assert_eq!(config_dir, layout.dir);assert_eq!(workspace_dir, layout.workspace_dir);assert_eq!(config_dir, root.join("users").join("local"));- assert_eq!(- workspace_dir,- root.join("users").join("local").join("workspace")- );+ assert_eq!(workspace_dir, root.join("users").join("local").join("files"));+ assert!(config_dir.join(".layout").is_file());+}++#[tokio::test]+async fn an_existing_pre_login_profile_stays_v1() {+ let tmp = tempfile::tempdir().unwrap();+ let root = tmp.path();+ let local = root.join("users").join("local");+ std::fs::create_dir_all(local.join("workspace")).unwrap();++ let (_, workspace_dir, _) =+ resolve_runtime_config_dirs_with(root, &root.join("workspace"), &MapEnv::default())+ .await+ .unwrap();++ assert_eq!(workspace_dir, local.join("workspace"));+ assert!(!local.join(".layout").exists(), "a v1 dir is never marked");+}++#[test]+fn a_v2_files_workspace_override_resolves_to_its_profile_directory() {+ let tmp = tempfile::tempdir().unwrap();+ let layout = ProfileLayout::resolve(tmp.path(), "alice");+ let (config_dir, workspace) = resolve_config_dir_for_workspace(&layout.workspace_dir);+ assert_eq!(config_dir, layout.dir);+ assert_eq!(workspace, layout.workspace_dir);}diff --git a/crates/openhuman-core/src/config/schema/profile_layout_tests.rs b/crates/openhuman-core/src/config/schema/profile_layout_tests.rsindex e483c16a78..824c10d8af 100644--- a/crates/openhuman-core/src/config/schema/profile_layout_tests.rs+++ b/crates/openhuman-core/src/config/schema/profile_layout_tests.rs@@ -1,4 +1,6 @@use super::*;+use crate::config::schema::user_openhuman_dir;+use std::path::PathBuf;#[test]fn every_path_sits_under_the_profile_directory() {@@ -37,3 +39,128 @@ fn the_layout_matches_the_desktop_user_directory() {super::super::user_openhuman_dir(root, "65f1c0ffee0123456789abcd"));}++fn tree(root: &Path) -> Vec<String> {+ fn walk(dir: &Path, root: &Path, out: &mut Vec<String>) {+ let mut entries: Vec<_> = std::fs::read_dir(dir).unwrap().flatten().collect();+ entries.sort_by_key(|e| e.path());+ for entry in entries {+ let path = entry.path();+ let rel = path.strip_prefix(root).unwrap().display().to_string();+ if path.is_dir() {+ out.push(format!("{rel}/"));+ walk(&path, root, out);+ } else {+ out.push(format!("{rel}={}", std::fs::read_to_string(&path).unwrap()));+ }+ }+ }+ let mut out = Vec::new();+ walk(root, root, &mut out);+ out+}++#[test]+fn v1_and_v2_resolve_each_accessor_under_the_same_profile_directory() {+ let dir = PathBuf::from("/srv/oh/users/alice");+ let v1 = ProfileLayout::with_version(dir.clone(), LayoutVersion::V1);+ let v2 = ProfileLayout::with_version(dir.clone(), LayoutVersion::V2);++ // Shared by both versions.+ assert_eq!(v1.dir, v2.dir);+ assert_eq!(v1.config_path, v2.config_path);+ assert_eq!(v1.meta_path, v2.meta_path);+ assert_eq!(v1.sandbox_dir, v2.sandbox_dir);+ assert_eq!(v1.storage_db, dir.join("storage.db"));+ assert_eq!(v2.storage_db, dir.join("storage.db"));+ assert_eq!(v1.files_dir, dir.join("files"));+ assert_eq!(v2.files_dir, dir.join("files"));++ // The workspace is the one thing that moves.+ assert_eq!(v1.workspace_dir, dir.join("workspace"));+ assert_eq!(v2.workspace_dir, dir.join("files"));+ assert_eq!(v1.version, LayoutVersion::V1);+ assert_eq!(v2.version, LayoutVersion::V2);+}++#[test]+fn the_pure_constructors_stay_v1() {+ assert_eq!(+ ProfileLayout::new(Path::new("/srv/oh"), "alice").version,+ LayoutVersion::V1+ );+ assert_eq!(+ ProfileLayout::at(PathBuf::from("/srv/oh/users/alice")).workspace_dir,+ Path::new("/srv/oh/users/alice/workspace")+ );+}++#[test]+fn a_missing_or_empty_profile_directory_is_v2_and_content_without_a_marker_is_v1() {+ let tmp = tempfile::tempdir().unwrap();+ assert_eq!(+ LayoutVersion::detect(&tmp.path().join("absent")),+ LayoutVersion::V2+ );+ assert_eq!(LayoutVersion::detect(tmp.path()), LayoutVersion::V2);++ std::fs::write(tmp.path().join("config.toml"), "").unwrap();+ assert_eq!(LayoutVersion::detect(tmp.path()), LayoutVersion::V1);++ LayoutVersion::mark_v2(tmp.path()).unwrap();+ assert_eq!(+ LayoutVersion::detect(tmp.path()),+ LayoutVersion::V2,+ "the marker wins over loose files"+ );+}++#[test]+fn resolving_a_fresh_profile_writes_the_marker_so_it_stays_v2() {+ let tmp = tempfile::tempdir().unwrap();+ let layout = ProfileLayout::resolve(tmp.path(), "alice");+ assert_eq!(layout.version, LayoutVersion::V2);+ assert_eq!(layout.workspace_dir, layout.dir.join("files"));+ assert_eq!(+ std::fs::read_to_string(layout.dir.join(".layout"))+ .unwrap()+ .trim(),+ "2"+ );++ // A config file appearing beside the marker does not flip it to V1.+ std::fs::write(&layout.config_path, "").unwrap();+ assert_eq!(+ ProfileLayout::resolve(tmp.path(), "alice").version,+ LayoutVersion::V2+ );+}++#[test]+fn resolving_a_v1_profile_changes_nothing_on_disk() {+ let tmp = tempfile::tempdir().unwrap();+ let dir = user_openhuman_dir(tmp.path(), "alice");+ std::fs::create_dir_all(dir.join("workspace/storage")).unwrap();+ std::fs::write(dir.join("config.toml"), "api_url = \"x\"\n").unwrap();+ std::fs::write(dir.join("workspace/threads.json"), "[]").unwrap();+ let before = tree(tmp.path());++ let layout = ProfileLayout::resolve(tmp.path(), "alice");++ assert_eq!(layout.version, LayoutVersion::V1);+ assert_eq!(layout.workspace_dir, dir.join("workspace"));+ assert_eq!(tree(tmp.path()), before, "no marker, no new directory");+}++#[test]+fn of_workspace_recognises_only_a_marked_v2_files_directory() {+ let tmp = tempfile::tempdir().unwrap();+ let v2 = ProfileLayout::resolve(tmp.path(), "alice");+ let found = ProfileLayout::of_workspace(&v2.workspace_dir).expect("a v2 files dir");+ assert_eq!(found, v2);++ let v1_dir = user_openhuman_dir(tmp.path(), "bob");+ std::fs::create_dir_all(v1_dir.join("files")).unwrap();+ assert!(ProfileLayout::of_workspace(&v1_dir.join("files")).is_none());+ assert!(ProfileLayout::of_workspace(&v1_dir.join("workspace")).is_none());+}diff --git a/crates/openhuman-core/src/storage/config_tests.rs b/crates/openhuman-core/src/storage/config_tests.rsindex 776db395f8..e166e368b6 100644--- a/crates/openhuman-core/src/storage/config_tests.rs+++ b/crates/openhuman-core/src/storage/config_tests.rs@@ -82,3 +82,73 @@ async fn the_default_url_opens_in_directory_mode() {// Directory mode: the directory holds the database file.assert!(dir.path().join(DEFAULT_DIR).exists());}++fn v2_layout(root: &Path) -> crate::config::schema::ProfileLayout {+ crate::config::schema::ProfileLayout::resolve(root, "alice")+}++#[test]+fn the_default_url_per_layout_version() {+ use crate::config::schema::profile_layout::{LayoutVersion, ProfileLayout};+ let dir = std::path::PathBuf::from("/srv/oh/users/alice");+ let v1 = ProfileLayout::with_version(dir.clone(), LayoutVersion::V1);+ let v2 = ProfileLayout::with_version(dir, LayoutVersion::V2);+ assert_eq!(+ default_url_for(&v1),+ "sqlite:/srv/oh/users/alice/workspace/storage"+ );+ assert_eq!(default_url_for(&v2), "sqlite:/srv/oh/users/alice/storage.db");+}++#[test]+fn a_v2_workspace_defaults_to_its_profiles_storage_db_and_a_v1_one_is_unchanged() {+ let tmp = tempfile::tempdir().unwrap();+ let layout = v2_layout(tmp.path());+ assert_eq!(+ default_url(&layout.workspace_dir),+ format!("sqlite:{}", layout.dir.join("storage.db").display())+ );+ // A `files` directory with no marker beside it is just a V1 workspace.+ assert_eq!(+ default_url(Path::new("/plain/files")),+ "sqlite:/plain/files/storage"+ );+}++#[test]+fn an_explicit_url_wins_over_the_v2_default() {+ let tmp = tempfile::tempdir().unwrap();+ let layout = v2_layout(tmp.path());+ let mut config = config_with(Some("memory"));+ config.workspace_dir = layout.workspace_dir.clone();+ assert_eq!(+ crate::storage::url_from(None, &config).as_deref(),+ Some("memory")+ );+ assert_eq!(+ crate::storage::url_from(Some("sqlite:/elsewhere.db".into()), &config).as_deref(),+ Some("sqlite:/elsewhere.db")+ );+ config.storage.url = None;+ assert_eq!(+ crate::storage::url_from(None, &config),+ Some(default_url_for(&layout))+ );+}++#[tokio::test]+async fn the_v2_default_opens_one_storage_db_file_beside_config_toml() {+ let tmp = tempfile::tempdir().unwrap();+ let layout = v2_layout(tmp.path());+ prepare_default_dir(&layout.workspace_dir).unwrap();+ let backend = crate::storage::open(&default_url(&layout.workspace_dir))+ .await+ .unwrap();+ assert_eq!(backend.driver(), "sqlite");+ assert!(+ layout.storage_db.is_file(),+ "{} should be a database file",+ layout.storage_db.display()+ );+ assert!(!layout.workspace_dir.join(DEFAULT_DIR).exists());+}