Skip to content

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

test(memory-tools): read stored memories back through the tool's own seam

Shanua2629f0dff75
diff --git a/src/openhuman/memory/tools/store.rs b/src/openhuman/memory/tools/store.rs
index ccad6085cf..839077702e 100644
--- a/src/openhuman/memory/tools/store.rs
+++ b/src/openhuman/memory/tools/store.rs
@@ -153,6 +153,7 @@ mod tests {
// could be bound without translating). Naming the contract here rather
// than the engine keeps that true at the import as well as the type, and
// is one fewer reference holding the crate in the build (#5560).
+ use crate::openhuman::memory::api::types::MemoryEntry;
use tinymemory_api::types::MemoryCategory as EngineMemoryCategory;
fn test_security() -> Arc<SecurityPolicy> {
@@ -168,6 +169,26 @@ mod tests {
(tmp, Arc::new(mem))
}
+ /// Read a memory back through the seam the tool wrote it through.
+ ///
+ /// [`test_mem`] hands out an in-process [`UnifiedMemory`] over a fresh
+ /// tempdir, and the tool holds no handle at all — it resolves the *bound*
+ /// driver per call. Under a real module that driver is the process-global
+ /// test workspace, a different store entirely, so asking `test_mem`'s
+ /// handle can never see the write. It is not a flake, and it does not
+ /// depend on the engine version: the two stores were never the same one.
+ ///
+ /// The guard is the tool's own door, so a read through it proves the write
+ /// landed where a caller would look for it.
+ async fn stored(namespace: &str, key: &str) -> Option<MemoryEntry> {
+ active_memory_guard()
+ .await
+ .expect("a bound memory guard")
+ .get(namespace, key)
+ .await
+ .expect("read back through the guard")
+ }
+
#[test]
fn name_and_schema() {
let (_tmp, _mem) = test_mem();
@@ -189,7 +210,7 @@ mod tests {
#[ignore = "needs a built tinymemory module (OPENHUMAN_MODULE_PATH) and its own process: \
the tool resolves the bound driver rather than being handed a memory handle"]
async fn store_core() {
- let (_tmp, mem) = test_mem();
+ let (_tmp, _mem) = test_mem();
let tool = MemoryStoreTool::new(test_security());
let result = tool
.execute(json!({"namespace": "global", "key": "lang", "content": "Prefers Rust"}))
@@ -198,8 +219,11 @@ the tool resolves the bound driver rather than being handed a memory handle"]
assert!(!result.is_error);
assert!(result.output().contains("lang"));
- let entry = mem.get("global", "lang").await.unwrap();
- assert!(entry.is_some());
+ let entry = stored("global", "lang").await;
+ assert!(
+ entry.is_some(),
+ "the write is visible through the tool's own seam"
+ );
assert_eq!(entry.unwrap().content, "Prefers Rust");
}
@@ -222,7 +246,7 @@ the tool resolves the bound driver rather than being handed a memory handle"]
#[ignore = "needs a built tinymemory module (OPENHUMAN_MODULE_PATH) and its own process: \
the tool resolves the bound driver rather than being handed a memory handle"]
async fn store_with_custom_category() {
- let (_tmp, mem) = test_mem();
+ let (_tmp, _mem) = test_mem();
let tool = MemoryStoreTool::new(test_security());
let result = tool
.execute(
@@ -232,7 +256,9 @@ the tool resolves the bound driver rather than being handed a memory handle"]
.unwrap();
assert!(!result.is_error);
- let entry = mem.get("global", "proj_note").await.unwrap().unwrap();
+ let entry = stored("global", "proj_note")
+ .await
+ .expect("the stored memory is readable through the guard");
assert_eq!(entry.content, "Uses async runtime");
assert_eq!(
entry.category,
@@ -248,12 +274,12 @@ the tool resolves the bound driver rather than being handed a memory handle"]
#[ignore = "needs a built tinymemory module (OPENHUMAN_MODULE_PATH) and its own process: \
the tool resolves the bound driver rather than being handed a memory handle"]
async fn store_strips_custom_prefix_from_wire_category() {
- let (_tmp, mem) = test_mem();
+ let (_tmp, _mem) = test_mem();
let tool = MemoryStoreTool::new(test_security());
let result = tool
.execute(json!({
"namespace": "global",
- "key": "proj_note",
+ "key": "wire_prefixed_note",
"content": "Uses async runtime",
"category": "custom:project"
}))
@@ -261,7 +287,9 @@ the tool resolves the bound driver rather than being handed a memory handle"]
.unwrap();
assert!(!result.is_error);
- let entry = mem.get("global", "proj_note").await.unwrap().unwrap();
+ let entry = stored("global", "wire_prefixed_note")
+ .await
+ .expect("the stored memory is readable through the guard");
assert_eq!(
entry.category,
EngineMemoryCategory::Custom("project".into()),