Skip to content

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

chore(memory): add tests for layout migration and local root

Steven Enamakelb5487cf96c9e
diff --git a/crates/openhuman-core/src/memory/layout_migration/state_tests.rs b/crates/openhuman-core/src/memory/layout_migration/state_tests.rs
index cfe5cfeccc..74ede5c890 100644
--- a/crates/openhuman-core/src/memory/layout_migration/state_tests.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/state_tests.rs
@@ -9,7 +9,7 @@ fn a_missing_file_is_a_fresh_state() {
}
#[test]
-fn a_saved_state_loads_back_and_leaves_no_temporary_file() {
+fn a_saved_state_loads_back() {
let tmp = tempfile::tempdir().unwrap();
let state = MigrationState {
phase: Phase::Paused,
@@ -31,14 +31,16 @@ fn a_saved_state_loads_back_and_leaves_no_temporary_file() {
};
save(tmp.path(), &state).unwrap();
assert_eq!(load(tmp.path()).unwrap(), state);
- assert!(!path(tmp.path()).with_extension("json.tmp").exists());
+ assert!(exists(tmp.path()));
}
#[test]
-fn a_damaged_file_is_an_error_not_a_fresh_start() {
+fn a_damaged_legacy_file_is_an_error_not_a_fresh_start() {
let tmp = tempfile::tempdir().unwrap();
std::fs::create_dir_all(tmp.path().join("memory")).unwrap();
- std::fs::write(path(tmp.path()), b"{ not json").unwrap();
+ let legacy = crate::memory::state_store::legacy_path(tmp.path(), "layout_migration");
+ std::fs::write(&legacy, b"{ not json").unwrap();
+ assert!(exists(tmp.path()), "a state that cannot be read was begun");
assert!(load(tmp.path()).is_err());
// Through the port the host hands the module, too.
assert!(FileStateStore::new(tmp.path()).load().is_err());
@@ -56,3 +58,18 @@ fn the_port_saves_where_the_status_reads() {
store.save(&state).unwrap();
assert_eq!(load(tmp.path()).unwrap(), state);
}
+
+#[test]
+fn a_legacy_state_file_is_imported_and_left_in_place() {
+ let tmp = tempfile::tempdir().unwrap();
+ std::fs::create_dir_all(tmp.path().join("memory")).unwrap();
+ let legacy = crate::memory::state_store::legacy_path(tmp.path(), "layout_migration");
+ let state = MigrationState {
+ phase: Phase::Paused,
+ copied: 4,
+ ..MigrationState::default()
+ };
+ std::fs::write(&legacy, serde_json::to_vec_pretty(&state).unwrap()).unwrap();
+ assert_eq!(load(tmp.path()).unwrap(), state);
+ assert!(legacy.exists());
+}
diff --git a/crates/openhuman-core/src/memory/local_root_tests.rs b/crates/openhuman-core/src/memory/local_root_tests.rs
index e3435bd830..7b027affa1 100644
--- a/crates/openhuman-core/src/memory/local_root_tests.rs
+++ b/crates/openhuman-core/src/memory/local_root_tests.rs
@@ -92,7 +92,6 @@ fn the_legacy_root_is_the_old_hashed_user_dir_name() {
fn a_record_already_written_wins_a_race() {
let tmp = tempfile::tempdir().unwrap();
let config = local_config(&tmp, "a");
- let file = path(&config.workspace_dir);
let first = LocalRoot {
root: format!("{LOCAL_ROOT_PREFIX}aaaa"),
origin: Origin::Minted,
@@ -101,8 +100,8 @@ fn a_record_already_written_wins_a_race() {
root: format!("{LOCAL_ROOT_PREFIX}bbbb"),
origin: Origin::Minted,
};
- assert_eq!(record_once(&file, &first).unwrap(), first);
- assert_eq!(record_once(&file, &second).unwrap(), first);
+ assert_eq!(record_once(&config.workspace_dir, &first).unwrap(), first);
+ assert_eq!(record_once(&config.workspace_dir, &second).unwrap(), first);
assert_eq!(resolve(&config, HOST_ID), Some(first.root));
}