Skip to content

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

fix(memory-tools): correct test assertion for memory retrieval

Steven Enamakelf683e04c6842
diff --git a/crates/openhuman-core/src/flows/memory_tools_tests.rs b/crates/openhuman-core/src/flows/memory_tools_tests.rs
index f7ad1202b4..dc0a964925 100644
--- a/crates/openhuman-core/src/flows/memory_tools_tests.rs
+++ b/crates/openhuman-core/src/flows/memory_tools_tests.rs
@@ -77,146 +77,11 @@ fn recall_name_and_schema() {
assert!(schema["properties"]["flow_id"].is_object());
assert!(schema["properties"]["scope"].is_object());
}
-
-#[tokio::test]
-#[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 recall_empty_returns_no_results() {
- let (_tmp, _mem) = test_mem();
- let tool = FlowMemoryRecallTool::new();
- let result = tool
- .execute(json!({"query": "anything", "flow_id": "f1"}))
- .await
- .unwrap();
- assert!(!result.is_error);
- assert!(result.output().contains("No memories found"));
-}
-
-#[tokio::test]
-#[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_then_recall_matches() {
- let (_tmp, mem) = test_mem();
- mem.store_with_taint(
- &flow_namespace("f1"),
- "sent_item_42",
- "Sent newsletter item 42 to subscribers",
- EngineCategory::Core,
- None,
- EngineTaint::ExternalSync,
- )
- .await
- .unwrap();
-
- let tool = FlowMemoryRecallTool::new();
- let result = tool
- .execute(json!({"query": "newsletter item 42", "flow_id": "f1"}))
- .await
- .unwrap();
- assert!(!result.is_error);
- assert!(result.output().contains("newsletter item 42") || result.output().contains("42"));
- assert!(result.output().contains("Found 1"));
-}
-
-#[tokio::test]
-#[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 scope_flow_isolates_to_own_namespace() {
- let (_tmp, mem) = test_mem();
- mem.store_with_taint(
- &flow_namespace("f1"),
- "k",
- "shared keyword hit",
- EngineCategory::Core,
- None,
- EngineTaint::ExternalSync,
- )
- .await
- .unwrap();
- mem.store_with_taint(
- &flow_namespace("f2"),
- "k",
- "shared keyword hit",
- EngineCategory::Core,
- None,
- EngineTaint::ExternalSync,
- )
- .await
- .unwrap();
-
- let tool = FlowMemoryRecallTool::new();
- let result = tool
- .execute(json!({"query": "shared keyword", "flow_id": "f1", "scope": "flow"}))
- .await
- .unwrap();
- assert!(!result.is_error);
- // Only f1's own entry, not f2's.
- assert!(result.output().contains("Found 1"));
-}
-
-#[tokio::test]
-#[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 scope_flows_crosses_namespaces() {
- let (_tmp, mem) = test_mem();
- mem.store_with_taint(
- &flow_namespace("f1"),
- "k",
- "shared keyword hit from f1",
- EngineCategory::Core,
- None,
- EngineTaint::ExternalSync,
- )
- .await
- .unwrap();
- mem.store_with_taint(
- &flow_namespace("f2"),
- "k",
- "shared keyword hit from f2",
- EngineCategory::Core,
- None,
- EngineTaint::ExternalSync,
- )
- .await
- .unwrap();
-
- let tool = FlowMemoryRecallTool::new();
- let result = tool
- .execute(json!({"query": "shared keyword", "flow_id": "f1", "scope": "flows"}))
- .await
- .unwrap();
- assert!(!result.is_error);
- // Both f1's and f2's namespaces are visible under scope="flows".
- assert!(result.output().contains("Found 2"));
-}
-
// T-m5: a missing/invalid input param reports via `ToolResult::error`
// (an `Ok(..)` the model can read and react to in-turn), never
// `Err(anyhow!)` (a hard tool-invocation failure) — matching every other
// input-validation problem on this belt (see the scope/empty-value
// tests above, which already used this channel before the fix).
-#[tokio::test]
-#[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 recall_missing_query_errs() {
- let (_tmp, _mem) = test_mem();
- let tool = FlowMemoryRecallTool::new();
- let result = tool.execute(json!({"flow_id": "f1"})).await.unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("Missing 'query'"));
-}
-
-#[tokio::test]
-#[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 recall_missing_flow_id_errs() {
- let (_tmp, _mem) = test_mem();
- let tool = FlowMemoryRecallTool::new();
- let result = tool.execute(json!({"query": "anything"})).await.unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("Missing 'flow_id'"));
-}
-
// ── FlowMemoryRememberTool ──────────────────────────────────────
#[test]
@@ -245,226 +110,6 @@ fn trusted_workflow_origin(job_id: &str) -> AgentTurnOrigin {
},
}
}
-
-#[tokio::test]
-#[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 remember_stores_with_external_sync_taint() {
- let (_tmp, mem) = test_mem();
- let tool = FlowMemoryRememberTool::new(test_security());
- let result = turn_origin::with_origin(
- trusted_workflow_origin("f1"),
- tool.execute(json!({"flow_id": "f1", "key": "sent_item_42", "content": "Sent item 42"})),
- )
- .await
- .unwrap();
- assert!(!result.is_error);
-
- let entry = mem
- .get(&flow_namespace("f1"), "sent_item_42")
- .await
- .unwrap()
- .expect("entry should be stored");
- assert_eq!(entry.content, "Sent item 42");
- assert_eq!(entry.taint, EngineTaint::ExternalSync);
-}
-
-#[tokio::test]
-#[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 remember_writes_only_to_own_flow_namespace() {
- let (_tmp, mem) = test_mem();
- let tool = FlowMemoryRememberTool::new(test_security());
- turn_origin::with_origin(
- trusted_workflow_origin("f1"),
- tool.execute(json!({"flow_id": "f1", "key": "k", "content": "f1 content"})),
- )
- .await
- .unwrap();
-
- // Never lands in another flow's namespace, the shared "flows" scope
- // namespace, or global/user memory.
- assert!(mem.get(&flow_namespace("f2"), "k").await.unwrap().is_none());
- assert!(mem.get("global", "k").await.unwrap().is_none());
- assert!(mem
- .get("f1", "k") // raw flow_id, not the derived namespace
- .await
- .unwrap()
- .is_none());
-}
-
-/// SECURITY (T-M2): the primary fix under test — a chat/orchestrator turn
-/// (no trusted `Workflow` run origin) must be refused outright, never
-/// routed to the model-supplied `flow_id`. This is the exact
-/// prompt-injection scenario: an attacker-controlled chat turn calling
-/// `flow_memory_remember` with another flow's id to poison its dedup
-/// memory (e.g. mark an item as already-sent so a digest flow skips it
-/// forever).
-#[tokio::test]
-#[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 remember_refuses_outside_a_trusted_workflow_run() {
- let (_tmp, mem) = test_mem();
- let tool = FlowMemoryRememberTool::new(test_security());
-
- // No `turn_origin::with_origin` wrapper — this call has no trusted
- // Workflow run origin, exactly like every chat/orchestrator turn.
- let result = tool
- .execute(json!({
- "flow_id": "digest-flow-victim",
- "key": "sent_item_42",
- "content": "Sent newsletter item 42 to subscribers"
- }))
- .await
- .unwrap();
-
- assert!(result.is_error);
- assert!(result
- .output()
- .contains("only available inside a workflow run"));
- // Nothing was written to the targeted namespace — or anywhere else.
- assert!(mem
- .get(&flow_namespace("digest-flow-victim"), "sent_item_42")
- .await
- .unwrap()
- .is_none());
-}
-
-/// SECURITY (Fix 1): a running flow's own id — carried by the run's
-/// `TrustedAutomation { Workflow }` origin — is authoritative. A
-/// mismatched, model-supplied `flow_id` arg must be silently ignored,
-/// never allowed to redirect the write into a different flow's
-/// namespace.
-#[tokio::test]
-#[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 remember_ignores_mismatched_flow_id_arg_inside_trusted_workflow_run() {
- let (_tmp, mem) = test_mem();
- let tool = FlowMemoryRememberTool::new(test_security());
-
- let origin = AgentTurnOrigin::TrustedAutomation {
- job_id: "f-real".to_string(),
- source: TrustedAutomationSource::Workflow {
- require_approval: false,
- },
- };
- let result = turn_origin::with_origin(
- origin,
- tool.execute(json!({
- "flow_id": "f-other",
- "key": "sent_item_1",
- "content": "Sent item 1"
- })),
- )
- .await
- .unwrap();
- assert!(!result.is_error);
-
- // Landed in the trusted run's own namespace...
- assert!(mem
- .get(&flow_namespace("f-real"), "sent_item_1")
- .await
- .unwrap()
- .is_some());
- // ...and NOT the mismatched, model-supplied namespace.
- assert!(mem
- .get(&flow_namespace("f-other"), "sent_item_1")
- .await
- .unwrap()
- .is_none());
-}
-
-#[tokio::test]
-#[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 remember_blocked_in_readonly_autonomy() {
- let (_tmp, mem) = test_mem();
- let readonly = Arc::new(SecurityPolicy {
- autonomy: AutonomyLevel::ReadOnly,
- ..SecurityPolicy::default()
- });
- let tool = FlowMemoryRememberTool::new(readonly);
- let result = tool
- .execute(json!({"flow_id": "f1", "key": "k", "content": "blocked"}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("read-only mode"));
- assert!(mem.get(&flow_namespace("f1"), "k").await.unwrap().is_none());
-}
-
-#[tokio::test]
-#[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 remember_rejects_secret_like_content() {
- let (_tmp, mem) = test_mem();
- let tool = FlowMemoryRememberTool::new(test_security());
- let result = turn_origin::with_origin(
- trusted_workflow_origin("f1"),
- tool.execute(json!({
- "flow_id": "f1",
- "key": "api",
- "content": "api_key=sk-123456789012345678901234567890"
- })),
- )
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("looks like a secret"));
- assert!(mem
- .get(&flow_namespace("f1"), "api")
- .await
- .unwrap()
- .is_none());
-}
-
-/// Outside a trusted run, `flow_id` no longer matters — the T-M2 refusal
-/// fires regardless of whether it was supplied. (Inside a trusted run the
-/// arg is informational only and ignored either way — see
-/// `remember_ignores_mismatched_flow_id_arg_inside_trusted_workflow_run`.)
-#[tokio::test]
-#[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 remember_missing_flow_id_outside_trusted_run_is_refused() {
- let (_tmp, _mem) = test_mem();
- let tool = FlowMemoryRememberTool::new(test_security());
- let result = tool
- .execute(json!({"key": "k", "content": "c"}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result
- .output()
- .contains("only available inside a workflow run"));
-}
-
// T-m5 (retained through the T-M2 merge): the missing-param checks run
// BEFORE the trusted-origin resolution, so they are still reachable outside
-// a run and still assert the `ToolResult::error` channel rather than `Err`.
-#[tokio::test]
-#[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 remember_missing_key_errs() {
- let (_tmp, _mem) = test_mem();
- let tool = FlowMemoryRememberTool::new(test_security());
- let result = tool
- .execute(json!({"flow_id": "f1", "content": "c"}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("Missing 'key'"));
-}
-
-#[tokio::test]
-#[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 remember_missing_content_errs() {
- let (_tmp, _mem) = test_mem();
- let tool = FlowMemoryRememberTool::new(test_security());
- let result = tool
- .execute(json!({"flow_id": "f1", "key": "k"}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("Missing 'content'"));
-}
+// a run and still assert the `ToolResult::error` channel rather than `Err`.
\ No newline at end of file