Skip to content

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

test(composio): cover document store updates and require Send

Steven Enamakelbbca365452e2
diff --git a/crates/openhuman-core/src/agent/artifacts/store_documents_tests.rs b/crates/openhuman-core/src/agent/artifacts/store_documents_tests.rs
index 9719b07e70..4411677414 100644
--- a/crates/openhuman-core/src/agent/artifacts/store_documents_tests.rs
+++ b/crates/openhuman-core/src/agent/artifacts/store_documents_tests.rs
@@ -101,7 +101,7 @@ async fn the_store_dispatches_to_documents_when_a_backend_is_pinned() {
let docs = docs_in(&storage, "local");
let workspace = tempfile::tempdir().unwrap();
let ws = workspace.path();
- store_documents::TEST_OVERRIDE.with(|slot| *slot.borrow_mut() = Some(docs.clone()));
+ super::TEST_OVERRIDE.with(|slot| *slot.borrow_mut() = Some(docs.clone()));
save_artifact_meta(ws, &meta("a", 1, Some("t1")))
.await
@@ -125,7 +125,7 @@ async fn the_store_dispatches_to_documents_when_a_backend_is_pinned() {
delete_artifact(ws, FileRoots::from(ws.to_path_buf()), "a")
.await
.unwrap();
- store_documents::TEST_OVERRIDE.with(|slot| *slot.borrow_mut() = None);
+ super::TEST_OVERRIDE.with(|slot| *slot.borrow_mut() = None);
assert!(docs.get_meta("a").unwrap().is_none());
assert!(docs.get_meta("b").unwrap().is_some());
diff --git a/crates/openhuman-core/src/integrations/composio/file_store.rs b/crates/openhuman-core/src/integrations/composio/file_store.rs
index 49a1103b18..50670ac810 100644
--- a/crates/openhuman-core/src/integrations/composio/file_store.rs
+++ b/crates/openhuman-core/src/integrations/composio/file_store.rs
@@ -88,7 +88,7 @@ pub(crate) async fn update<T, R>(
change: impl Fn(&mut T) -> (R, bool) + Send + 'static,
) -> Result<R, String>
where
- T: DeserializeOwned + Serialize + Default + 'static,
+ T: DeserializeOwned + Serialize + Default + Send + 'static,
R: Send + 'static,
{
if let Some(docs) =
diff --git a/crates/openhuman-core/src/integrations/composio/file_store_documents.rs b/crates/openhuman-core/src/integrations/composio/file_store_documents.rs
index 9e52d792d7..882a05499f 100644
--- a/crates/openhuman-core/src/integrations/composio/file_store_documents.rs
+++ b/crates/openhuman-core/src/integrations/composio/file_store_documents.rs
@@ -83,7 +83,7 @@ impl Docs {
change: impl Fn(&mut T) -> (R, bool) + Send + 'static,
) -> Result<R>
where
- T: DeserializeOwned + Serialize + Default,
+ T: DeserializeOwned + Serialize + Default + Send + 'static,
R: Send + 'static,
{
let id = id_of(path)?;
diff --git a/crates/openhuman-core/src/integrations/composio/file_store_documents_tests.rs b/crates/openhuman-core/src/integrations/composio/file_store_documents_tests.rs
index 83670f49e6..ccd6b54cb1 100644
--- a/crates/openhuman-core/src/integrations/composio/file_store_documents_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/file_store_documents_tests.rs
@@ -72,3 +72,69 @@ async fn the_file_path_still_works_with_no_backend() {
super::super::file_store::save(&path, &value).await.unwrap();
assert!(path.exists());
}
+
+#[test]
+fn update_creates_applies_and_skips_unchanged() {
+ let docs = docs_in(&MemoryStorage::new(), "local");
+ let added = docs
+ .update(&path(), |v: &mut BTreeMap<String, u32>| {
+ v.insert("gmail".into(), 1);
+ (v.len(), true)
+ })
+ .unwrap();
+ assert_eq!(added, 1);
+ let unchanged = docs
+ .update(&path(), |v: &mut BTreeMap<String, u32>| (v.len(), false))
+ .unwrap();
+ assert_eq!(unchanged, 1);
+ let loaded: BTreeMap<String, u32> = docs.load(&path()).unwrap();
+ assert_eq!(loaded.get("gmail"), Some(&1));
+}
+
+#[test]
+fn concurrent_updates_do_not_lose_each_other() {
+ let docs = docs_in(&MemoryStorage::new(), "local");
+ let handles: Vec<_> = (0..8u32)
+ .map(|n| {
+ let docs = docs.clone();
+ std::thread::spawn(move || {
+ docs.update(&path(), move |v: &mut BTreeMap<String, u32>| {
+ v.insert(format!("k{n}"), n);
+ ((), true)
+ })
+ .unwrap();
+ })
+ })
+ .collect();
+ for handle in handles {
+ handle.join().unwrap();
+ }
+ let loaded: BTreeMap<String, u32> = docs.load(&path()).unwrap();
+ assert_eq!(loaded.len(), 8);
+}
+
+#[tokio::test]
+async fn file_store_update_uses_the_file_with_no_backend_and_documents_when_pinned() {
+ let dir = tempfile::tempdir().unwrap();
+ let file = dir.path().join("state.json");
+ let bump = |v: &mut BTreeMap<String, u32>| {
+ *v.entry("n".into()).or_default() += 1;
+ ((), true)
+ };
+ super::super::file_store::update(&file, bump).await.unwrap();
+ super::super::file_store::update(&file, bump).await.unwrap();
+ let loaded: BTreeMap<String, u32> = super::super::file_store::load(&file).await.unwrap();
+ assert_eq!(loaded["n"], 2);
+ assert!(file.exists());
+
+ let docs = docs_in(&MemoryStorage::new(), "local");
+ let pinned = dir.path().join("pinned.json");
+ super::TEST_OVERRIDE.with(|slot| *slot.borrow_mut() = Some(docs.clone()));
+ super::super::file_store::update(&pinned, bump)
+ .await
+ .unwrap();
+ super::TEST_OVERRIDE.with(|slot| *slot.borrow_mut() = None);
+ let stored: BTreeMap<String, u32> = docs.load(&pinned).unwrap();
+ assert_eq!(stored["n"], 1);
+ assert!(!pinned.exists());
+}