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(memory): cover corrupt state files being set aside
Steven Enamakel009fd55f752f
diff --git a/crates/openhuman-core/src/memory/channels_tests.rs b/crates/openhuman-core/src/memory/channels_tests.rsindex bdb3e5c2fe..c57ed34d29 100644--- a/crates/openhuman-core/src/memory/channels_tests.rs+++ b/crates/openhuman-core/src/memory/channels_tests.rs@@ -12,6 +12,21 @@ fn records_threads_per_channel_case_insensitively() {assert!(threads_of(tmp.path(), "web").is_empty());}+#[test]+fn corrupt_channel_thread_file_is_set_aside() {+ let tmp = tempfile::tempdir().unwrap();+ let file = path(tmp.path());+ std::fs::create_dir_all(file.parent().unwrap()).unwrap();+ std::fs::write(&file, b"{\"telegram\":[").unwrap();++ assert!(threads_of(tmp.path(), "telegram").is_empty());+ assert!(!file.exists(), "corrupt state must not be silently replaced");+ assert_eq!(+ std::fs::read(file.with_extension("json.corrupt")).unwrap(),+ b"{\"telegram\":["+ );+}+#[tokio::test]async fn a_channel_forgotten_while_signed_out_queues_each_thread_it_owned() {use crate::memory::deletion::{pending, PendingDeletion};diff --git a/crates/openhuman-core/src/memory/lifecycle/jobs_tests.rs b/crates/openhuman-core/src/memory/lifecycle/jobs_tests.rsindex 65af145fe2..287b1b18c6 100644--- a/crates/openhuman-core/src/memory/lifecycle/jobs_tests.rs+++ b/crates/openhuman-core/src/memory/lifecycle/jobs_tests.rs@@ -11,6 +11,22 @@ fn build(agent: &str) -> BackgroundJob {}}+#[test]+fn corrupt_job_queue_file_is_set_aside() {+ let tmp = tempfile::tempdir().unwrap();+ let file = path(tmp.path());+ std::fs::create_dir_all(file.parent().unwrap()).unwrap();+ std::fs::write(&file, b"{\"pending\":[").unwrap();+ let store = FileQueueStore { file: file.clone() };++ assert_eq!(store.load(), QueueState::default());+ assert!(!file.exists(), "corrupt queue must not be silently replaced");+ assert_eq!(+ std::fs::read(file.with_extension("json.corrupt")).unwrap(),+ b"{\"pending\":["+ );+}+#[tokio::test]async fn duplicates_merge_and_the_queue_survives_a_reload() {let tmp = tempfile::tempdir().unwrap();diff --git a/crates/openhuman-core/src/memory/sources/state.rs b/crates/openhuman-core/src/memory/sources/state.rsindex ec77123717..9940567d68 100644--- a/crates/openhuman-core/src/memory/sources/state.rs+++ b/crates/openhuman-core/src/memory/sources/state.rs@@ -125,3 +125,7 @@ pub fn remove_orphaned_connector_files(workspace_dir: &Path) {}}}++#[cfg(test)]+#[path = "state_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/memory/sources/state_tests.rs b/crates/openhuman-core/src/memory/sources/state_tests.rsnew file mode 100644index 0000000000..28a5c3e073--- /dev/null+++ b/crates/openhuman-core/src/memory/sources/state_tests.rs@@ -0,0 +1,16 @@+use super::*;++#[test]+fn corrupt_source_state_file_is_set_aside() {+ let tmp = tempfile::tempdir().unwrap();+ let file = path(tmp.path());+ std::fs::create_dir_all(file.parent().unwrap()).unwrap();+ std::fs::write(&file, b"{\"source-1\":").unwrap();++ assert!(load(tmp.path()).is_empty());+ assert!(!file.exists(), "corrupt state must not be silently replaced");+ assert_eq!(+ std::fs::read(file.with_extension("json.corrupt")).unwrap(),+ b"{\"source-1\":"+ );+}