Skip to content

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

chore(memory): add tests for memory tools

Steven Enamakel0964bf6feb70
diff --git a/crates/openhuman-core/src/memory/tools_tests.rs b/crates/openhuman-core/src/memory/tools_tests.rs
index a51a27d62b..6e9cdd1204 100644
--- a/crates/openhuman-core/src/memory/tools_tests.rs
+++ b/crates/openhuman-core/src/memory/tools_tests.rs
@@ -1,4 +1,8 @@
use super::*;
+
+fn ambient() -> DispatchCtx {
+ DispatchCtx::ambient()
+}
use crate::memory::scope::MemoryIdentity;
use crate::memory::test_fixtures::{bind_reference, config_in, stored};
use std::collections::HashSet;
@@ -88,13 +92,7 @@ async fn every_action_reports_memory_off_as_a_tool_error() {
json!({"action": "learn", "text": "t"}),
json!({"action": "forget", "ids": ["a"]}),
] {
- let result = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &args,
- &facts(),
- )
- .await;
+ let result = run_action(&ambient(), &config, &args, &facts()).await;
assert!(result.is_error, "{args}");
assert!(text(&result).contains("MEMORY_OFF"), "{}", text(&result));
}
@@ -106,33 +104,15 @@ async fn bad_arguments_and_unknown_actions_are_model_visible_errors() {
let config = config_in(&tmp);
bind_reference(&config);
- let unknown = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &json!({"action": "explode"}),
- &facts(),
- )
- .await;
+ let unknown = run_action(&ambient(), &config, &json!({"action": "explode"}), &facts()).await;
assert!(unknown.is_error);
assert!(text(&unknown).contains("unknown action `explode`"));
- let missing = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &json!({}),
- &facts(),
- )
- .await;
+ let missing = run_action(&ambient(), &config, &json!({}), &facts()).await;
assert!(missing.is_error);
for action in ["recall", "fetch", "learn", "forget"] {
- let result = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &json!({ "action": action }),
- &facts(),
- )
- .await;
+ let result = run_action(&ambient(), &config, &json!({ "action": action }), &facts()).await;
assert!(result.is_error, "{action}");
assert!(text(&result).contains("invalid arguments"), "{action}");
}
@@ -152,13 +132,7 @@ async fn learn_stamps_what_the_host_knows_and_ignores_model_meta() {
// The model must not be able to forge host-owned fields.
"meta": {"thread_id": "forged", "agent_id": "forged"},
});
- let result = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &args,
- &facts(),
- )
- .await;
+ let result = run_action(&ambient(), &config, &args, &facts()).await;
assert!(!result.is_error, "{}", text(&result));
let id = serde_json::from_str::<Value>(&text(&result)).unwrap()["id"]
.as_str()
@@ -196,7 +170,7 @@ async fn recall_fetch_and_forget_round_trip_and_recall_records_citations() {
};
let learned = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "learn", "text": "The user likes oolong tea"}),
&facts,
@@ -208,29 +182,22 @@ async fn recall_fetch_and_forget_round_trip_and_recall_records_citations() {
.to_string();
let recalled = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "recall", "question": "oolong tea"}),
&facts,
)
.await;
assert!(!recalled.is_error, "{}", text(&recalled));
- let cites = take_turn_citations(
- &crate::core::runtime::DispatchCtx::ambient(),
- "thread-citations",
- );
+ let cites = take_turn_citations(&ambient(), "thread-citations");
assert!(cites.iter().any(|c| c.id == id), "{cites:?}");
assert!(
- take_turn_citations(
- &crate::core::runtime::DispatchCtx::ambient(),
- "thread-citations"
- )
- .is_empty(),
+ take_turn_citations(&ambient(), "thread-citations").is_empty(),
"draining empties the thread's citations"
);
let fetched = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "fetch", "query": "oolong", "mode": "keyword", "limit": 5}),
&facts,
@@ -246,7 +213,7 @@ async fn recall_fetch_and_forget_round_trip_and_recall_records_citations() {
);
let forgotten = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "forget", "ids": [id]}),
&facts,
@@ -266,14 +233,14 @@ async fn recall_without_a_thread_records_no_citations() {
..facts()
};
run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "learn", "text": "fact one"}),
&no_thread,
)
.await;
let result = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "recall", "question": "fact one"}),
&no_thread,
@@ -296,7 +263,7 @@ async fn fetch_with_an_undeclared_mode_is_unsupported() {
)
.unwrap();
let result = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "fetch", "query": "x", "mode": "keyword"}),
&facts(),
@@ -317,14 +284,10 @@ fn turn_citations_are_capped_and_deduplicated() {
};
let thread = "thread-cap";
let many: Vec<_> = (0..MAX_TURN_CITATIONS + 10).map(citation).collect();
- record_turn_citations(&crate::core::runtime::DispatchCtx::ambient(), thread, &many);
- record_turn_citations(
- &crate::core::runtime::DispatchCtx::ambient(),
- thread,
- &many[..2],
- );
- record_turn_citations(&crate::core::runtime::DispatchCtx::ambient(), thread, &[]);
- let drained = take_turn_citations(&crate::core::runtime::DispatchCtx::ambient(), thread);
+ record_turn_citations(&ambient(), thread, &many);
+ record_turn_citations(&ambient(), thread, &many[..2]);
+ record_turn_citations(&ambient(), thread, &[]);
+ let drained = take_turn_citations(&ambient(), thread);
assert_eq!(drained.len(), MAX_TURN_CITATIONS);
assert_eq!(
drained
@@ -409,7 +372,7 @@ async fn learnings_are_shared_under_a_root_and_a_team_root_is_kept_apart() {
let config = config.clone();
async move {
let result = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "learn", "text": text, "share": true}),
&facts,
@@ -444,7 +407,7 @@ async fn learnings_are_shared_under_a_root_and_a_team_root_is_kept_apart() {
let config = config.clone();
async move {
run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "fetch", "query": "the", "limit": 50, "filter": {"reach": null}}),
&facts,
@@ -468,7 +431,7 @@ async fn learnings_are_shared_under_a_root_and_a_team_root_is_kept_apart() {
.find(|hit| hit.text.contains("deploy day"))
.unwrap();
let forgot = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "forget", "ids": [main_item.id.0.clone()]}),
&member(),
@@ -557,7 +520,7 @@ async fn learn_returns_on_accept_and_says_recall_may_lag() {
crate::memory::engine::install_test_engine(&config.workspace_dir, engine.clone());
let learned = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "learn", "text": "The user drinks oolong"}),
&facts(),
@@ -600,7 +563,7 @@ async fn a_failed_learn_is_reported_to_the_model() {
crate::memory::test_fixtures::RefusingEngine::out_of_credits().bind(&config);
let learned = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "learn", "text": "The user drinks oolong"}),
&facts(),
@@ -675,7 +638,7 @@ async fn refers_to_reaches_the_engine_in_the_users_time_zone() {
crate::memory::engine::install_test_engine(&config.workspace_dir, engine.clone());
let fetched = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "fetch", "query": "dinner", "refers_to": {"from": "2026-10-03", "to": "2026-10-04"}}),
&facts(),
@@ -683,7 +646,7 @@ async fn refers_to_reaches_the_engine_in_the_users_time_zone() {
.await;
assert!(!fetched.is_error, "{}", text(&fetched));
let recalled = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "recall", "question": "dinner", "refers_to": {"from": "2026-10-03"}}),
&facts(),
@@ -691,7 +654,7 @@ async fn refers_to_reaches_the_engine_in_the_users_time_zone() {
.await;
assert!(!recalled.is_error, "{}", text(&recalled));
let bad = run_action(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ambient(),
&config,
&json!({"action": "fetch", "query": "dinner", "refers_to": {"from": "last Saturday"}}),
&facts(),