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 memory tool handlers

Steven Enamakeldfd0c81e42cf
diff --git a/crates/openhuman-core/src/memory/tools_tests.rs b/crates/openhuman-core/src/memory/tools_tests.rs
index ca26d01d8d..ee95fd4681 100644
--- a/crates/openhuman-core/src/memory/tools_tests.rs
+++ b/crates/openhuman-core/src/memory/tools_tests.rs
@@ -668,3 +668,57 @@ async fn learning_is_durably_queued_even_when_the_backend_refuses_writes() {
assert_eq!(value["status"], "queued; not yet saved to memory");
assert_eq!(super::super::tool_writes::drain(&config).await, 0);
}
+
+/// The memory activity a tool call raises reaches the chat its own turn is in:
+/// the event carries the turn's thread and client, taken from the run context
+/// the tool was dispatched with, and a call outside a chat turn raises it
+/// unrouted.
+#[tokio::test]
+async fn memory_activity_carries_the_calling_turns_chat() {
+ crate::core::bus::init().await.expect("bus init");
+ let mut rx = crate::core::bus::BUS.get().unwrap().receiver();
+ let tmp = tempfile::tempdir().unwrap();
+ let config = config_in(&tmp);
+ let _engine = bind_reference(&config);
+ let tool = MemoryTool::new(Arc::new(config.clone()));
+
+ let context = crate::agent::tinyagents::host::run_context::tool_context_with_approval(
+ crate::security::approval::ApprovalTurnContext::chat(
+ crate::security::approval::ApprovalChatContext {
+ thread_id: "thread-activity".into(),
+ client_id: "client-activity".into(),
+ request_id: None,
+ },
+ ),
+ );
+ let routed = tool
+ .execute_with_context(
+ json!({"action": "learn", "text": "routed marker fact"}),
+ ToolCallOptions::default(),
+ Some(&context),
+ )
+ .await
+ .unwrap();
+ assert!(!routed.is_error, "{}", text(&routed));
+ let unrouted = tool
+ .execute(json!({"action": "learn", "text": "unrouted marker fact"}))
+ .await
+ .unwrap();
+ assert!(!unrouted.is_error, "{}", text(&unrouted));
+ super::super::tool_writes::drain(&config).await;
+
+ let mut seen = Vec::new();
+ while seen.len() < 2 {
+ match tokio::time::timeout(std::time::Duration::from_secs(5), rx.recv()).await {
+ Ok(Some(DomainEvent::MemoryStored {
+ thread_id,
+ client_id,
+ ..
+ })) => seen.push((thread_id, client_id)),
+ Ok(Some(_)) => continue,
+ other => panic!("expected two MemoryStored events, got {other:?}"),
+ }
+ }
+ assert!(seen.contains(&(Some("thread-activity".into()), Some("client-activity".into()))));
+ assert!(seen.contains(&(None, None)));
+}