Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(storage): verify directory mode persistence and CAS capabilities

Steven Enamakel1ef55e95e40a
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle_storage_adoption_tests.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle_storage_adoption_tests.rs
index 4c2c53ac9a..368541ad70 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_storage_adoption_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_storage_adoption_tests.rs
@@ -150,7 +150,7 @@ fn legacy_host_kv_pause_is_converted_without_rewriting_the_source_record() {
fn owner_file_pause_is_imported_and_the_original_bytes_stay_unchanged() {
let workspace = tempfile::tempdir().unwrap();
let key = task();
- let adapter = super::super::persistence::OpenHumanPersistence::new(workspace.path());
+ let adapter = super::super::persistence::OpenHumanPersistence::new(workspace.path().to_path_buf());
let file = adapter.legacy_pause_path(&key);
std::fs::create_dir_all(file.parent().unwrap()).unwrap();
let bytes = serde_json::to_vec(&paused(&key)).unwrap();
diff --git a/crates/openhuman-core/src/storage/config_tests.rs b/crates/openhuman-core/src/storage/config_tests.rs
index a41c6364b9..b3c68eef20 100644
--- a/crates/openhuman-core/src/storage/config_tests.rs
+++ b/crates/openhuman-core/src/storage/config_tests.rs
@@ -75,11 +75,38 @@ fn the_default_differs_per_workspace() {
#[tokio::test]
async fn the_default_url_opens_in_directory_mode() {
let dir = tempfile::tempdir().unwrap();
- let backend = crate::storage::open(&default_url(dir.path()))
+ let url = default_url(dir.path());
+ let backend = crate::storage::open(&url).await.unwrap();
+ let scoped = backend.for_scope(&crate::storage::Scope::local()).unwrap();
+ let docs = scoped.documents();
+ docs.ensure_collection(&crate::storage::CollectionSpec::new("reopen_probe"))
.await
.unwrap();
+ docs.put(
+ "reopen_probe",
+ "persisted",
+ serde_json::json!({"ok": true}),
+ crate::storage::Precondition::Absent,
+ )
+ .await
+ .unwrap();
+ drop(docs);
+ drop(scoped);
+ drop(backend);
// Directory mode: the directory holds the database file.
assert!(dir.path().join(DEFAULT_DIR).exists());
+ let reopened = crate::storage::open(&url).await.unwrap();
+ let scoped = reopened.for_scope(&crate::storage::Scope::local()).unwrap();
+ assert_eq!(
+ scoped
+ .documents()
+ .get("reopen_probe", "persisted")
+ .await
+ .unwrap()
+ .unwrap()
+ .doc["ok"],
+ true
+ );
}
fn v2_layout(root: &Path) -> crate::config::schema::ProfileLayout {
diff --git a/crates/openhuman-core/src/storage/mod_tests.rs b/crates/openhuman-core/src/storage/mod_tests.rs
index 2d32a67a48..def9e8e444 100644
--- a/crates/openhuman-core/src/storage/mod_tests.rs
+++ b/crates/openhuman-core/src/storage/mod_tests.rs
@@ -238,15 +238,15 @@ fn only_mongodb_and_sqlite_have_cross_process_cas() {
#[tokio::test]
async fn local_drivers_do_not_claim_cross_process_cas() {
let dir = tempfile::tempdir().unwrap();
- for url in [
- "memory".to_string(),
- format!("sqlite:{}", dir.path().join("cas.db").display()),
- format!("file:{}", dir.path().join("files").display()),
+ for (url, expected) in [
+ ("memory".to_string(), false),
+ (format!("sqlite:{}", dir.path().join("cas.db").display()), true),
+ (format!("file:{}", dir.path().join("files").display()), false),
] {
let backend = open(&url).await.unwrap();
assert!(
- !backend_has_cross_process_cas(backend.as_ref()),
- "{url} is a local driver"
+ backend_has_cross_process_cas(backend.as_ref()) == expected,
+ "unexpected CAS capability for {url}"
);
}
}