Skip to content

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

test(memory): add coverage for deletion, migration, and lifecycle jobs

Steven Enamakela7b94a168621
diff --git a/crates/openhuman-core/src/memory/deletion_tests.rs b/crates/openhuman-core/src/memory/deletion_tests.rs
index b54409133c..ed48c0d53b 100644
--- a/crates/openhuman-core/src/memory/deletion_tests.rs
+++ b/crates/openhuman-core/src/memory/deletion_tests.rs
@@ -76,13 +76,25 @@ async fn a_failed_forget_is_kept_for_the_next_drain() {
}
#[test]
-fn an_unparsable_queue_is_set_aside_not_lost() {
+fn an_unparsable_legacy_queue_is_ignored_and_left_in_place() {
let tmp = tempfile::tempdir().unwrap();
- let file = path(tmp.path());
+ let file = crate::memory::state_store::legacy_path(tmp.path(), "pending_deletions");
std::fs::create_dir_all(file.parent().unwrap()).unwrap();
std::fs::write(&file, "not json").unwrap();
assert!(pending(tmp.path()).is_empty());
- assert!(file.with_extension("json.corrupt").exists());
+ enqueue(tmp.path(), thread("t"));
+ assert_eq!(pending(tmp.path()), vec![thread("t")]);
+ assert_eq!(std::fs::read_to_string(&file).unwrap(), "not json");
+}
+
+#[test]
+fn a_legacy_queue_file_is_imported_once() {
+ let tmp = tempfile::tempdir().unwrap();
+ let file = crate::memory::state_store::legacy_path(tmp.path(), "pending_deletions");
+ std::fs::create_dir_all(file.parent().unwrap()).unwrap();
+ std::fs::write(&file, serde_json::to_vec(&vec![thread("old")]).unwrap()).unwrap();
+ assert_eq!(pending(tmp.path()), vec![thread("old")]);
+ assert!(file.exists(), "the legacy file is not touched");
}
#[tokio::test]
@@ -93,15 +105,3 @@ async fn a_blank_thread_id_queues_nothing() {
assert!(pending(&config.workspace_dir).is_empty());
}
-#[cfg(unix)]
-#[test]
-fn the_pending_queue_is_owner_only() {
- use std::os::unix::fs::PermissionsExt;
- let tmp = tempfile::tempdir().unwrap();
- enqueue(tmp.path(), thread("t"));
- let mode = std::fs::metadata(path(tmp.path()))
- .unwrap()
- .permissions()
- .mode();
- assert_eq!(mode & 0o077, 0, "{mode:o}");
-}
diff --git a/crates/openhuman-core/src/memory/layout_migration/service_tests.rs b/crates/openhuman-core/src/memory/layout_migration/service_tests.rs
index b365043735..600b4d1cc0 100644
--- a/crates/openhuman-core/src/memory/layout_migration/service_tests.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/service_tests.rs
@@ -207,7 +207,11 @@ async fn a_damaged_state_file_surfaces_as_the_hosts_engine_error() {
let tmp = tempfile::tempdir().unwrap();
let config = crate::memory::test_fixtures::config_in(&tmp);
std::fs::create_dir_all(config.workspace_dir.join("memory")).unwrap();
- std::fs::write(state::path(&config.workspace_dir), b"{ torn").unwrap();
+ std::fs::write(
+ crate::memory::state_store::legacy_path(&config.workspace_dir, "layout_migration"),
+ b"{ torn",
+ )
+ .unwrap();
let error = status(&config).unwrap_err();
assert_eq!(error.code(), "ENGINE");
let host = Arc::new(FakeHost::with(1, &config).await);
diff --git a/crates/openhuman-core/src/memory/layout_migration/state.rs b/crates/openhuman-core/src/memory/layout_migration/state.rs
index 6a24ab60f4..6734c7248a 100644
--- a/crates/openhuman-core/src/memory/layout_migration/state.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/state.rs
@@ -15,12 +15,12 @@ use crate::memory::error::{MemoryError, MemoryResult};
const STATE: &str = "layout_migration";
/// Whether a migration state exists in `workspace_dir`: the migration has
-/// begun there.
+/// begun there (a state that cannot be read counts: it was begun).
#[must_use]
pub fn exists(workspace_dir: &Path) -> bool {
crate::memory::state_store::load_strict::<serde_json::Value>(workspace_dir, STATE)
.map(|state| state.is_some())
- .unwrap_or(false)
+ .unwrap_or(true)
}
/// The migration state kept in one workspace.
diff --git a/crates/openhuman-core/src/memory/lifecycle/jobs_tests.rs b/crates/openhuman-core/src/memory/lifecycle/jobs_tests.rs
index 65af145fe2..9899ca1761 100644
--- a/crates/openhuman-core/src/memory/lifecycle/jobs_tests.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/jobs_tests.rs
@@ -27,7 +27,9 @@ async fn duplicates_merge_and_the_queue_survives_a_reload() {
let queue = snapshot(&config).await;
assert_eq!(queue.pending.len(), 3, "one per (root, job)");
- assert!(path(&config.workspace_dir).exists());
+ assert!(crate::memory::state_store::load::<JobQueue>(&config.workspace_dir, "jobs")
+ .unwrap()
+ .is_some());
}
#[tokio::test]
@@ -98,10 +100,10 @@ async fn the_build_delay_comes_from_the_recall_config_and_the_file_store_is_the_
config.memory.recall.build_delay_secs = 3600;
enqueue(&config, &Namespace::ROOT, vec![build("a")]).await;
assert!(has_pending(&config.workspace_dir));
- let on_disk: JobQueue =
- serde_json::from_str(&std::fs::read_to_string(path(&config.workspace_dir)).unwrap())
- .unwrap();
- assert_eq!(on_disk.pending.len(), 1, "persisted in memory/jobs.json");
+ let stored: JobQueue = crate::memory::state_store::load(&config.workspace_dir, "jobs")
+ .unwrap()
+ .unwrap();
+ assert_eq!(stored.pending.len(), 1, "persisted in the memory state store");
assert!(run(&config, Selection::Due).await.unwrap().is_empty());
}