The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(memory): add coverage for confinement, lifecycle, and scope
Steven Enamakel5348e431073b
diff --git a/crates/openhuman-core/src/memory/confine_tests.rs b/crates/openhuman-core/src/memory/confine_tests.rsindex 857d9f6817..a026367cb1 100644--- a/crates/openhuman-core/src/memory/confine_tests.rs+++ b/crates/openhuman-core/src/memory/confine_tests.rs@@ -4,7 +4,7 @@ use tinymemory_api::{LearningKind, MemoryEngine, SourceKind, SourceRef, StoreIteuse crate::memory::error::INVALID_REQUEST;use crate::memory::explore::PathStep;-use crate::memory::scope::{within, MemoryIdentity};+use crate::memory::scope::MemoryIdentity;use crate::memory::test_fixtures::{bind_reference, config_in};fn ns(value: &str) -> Namespace {@@ -75,19 +75,18 @@ fn an_unset_reach_becomes_the_allowed_one_and_a_wider_one_is_refused() {fn the_allowed_reach_is_the_identity_roots_subtree() {let tmp = tempfile::tempdir().unwrap();let mut config = config_in(&tmp);- assert_eq!(allowed_reach(&config), Reach::subtree(Namespace::ROOT));+ assert_eq!(allowed_reach(&config, &MemoryIdentity::root()),+ Reach::subtree(Namespace::ROOT));config.memory.root = Some("project:q4".to_string());- assert_eq!(allowed_reach(&config), Reach::subtree(ns("project:q4")));+ assert_eq!(allowed_reach(&config, &MemoryIdentity::root()),+ Reach::subtree(ns("project:q4")));}-#[tokio::test]-async fn a_team_members_rpc_reach_is_its_teams_subtree() {+#[test]+fn a_team_members_reach_is_its_teams_subtree() {let tmp = tempfile::tempdir().unwrap();let config = config_in(&tmp);- let reach = within(MemoryIdentity::team_member("acme", "scout"), async {- allowed_reach(&config)- })- .await;+ let reach = allowed_reach(&config, &MemoryIdentity::team_member("acme", "scout"));assert_eq!(reach, Reach::subtree(ns("team:acme")));}@@ -96,13 +95,14 @@ async fn list_fetch_and_recall_never_read_another_root() {let tmp = tempfile::tempdir().unwrap();let (config, mine, theirs) = two_roots(&tmp).await;- let listed = items_list(&config, ItemsListParams::default())+ let listed = items_list(&config,&MemoryIdentity::root(), ItemsListParams::default()).await.unwrap();assert_eq!(ids(&listed.items), std::slice::from_ref(&mine));let page = fetch(&config,+ &MemoryIdentity::root(),FetchParams {refers_to: None,query: "plan".into(),@@ -118,6 +118,7 @@ async fn list_fetch_and_recall_never_read_another_root() {let answer = recall(&config,+ &MemoryIdentity::root(),RecallParams {refers_to: None,question: "secret plan".into(),@@ -144,6 +145,7 @@ async fn a_caller_reach_into_another_root_is_refused() {let error = items_list(&config,+ &MemoryIdentity::root(),ItemsListParams {filter: Some(elsewhere.clone()),..ItemsListParams::default()@@ -155,6 +157,7 @@ async fn a_caller_reach_into_another_root_is_refused() {let error = fetch(&config,+ &MemoryIdentity::root(),FetchParams {refers_to: None,query: "plan".into(),@@ -170,6 +173,7 @@ async fn a_caller_reach_into_another_root_is_refused() {let error = recall(&config,+ &MemoryIdentity::root(),RecallParams {refers_to: None,question: "plan".into(),@@ -193,6 +197,7 @@ async fn an_explorer_path_into_another_root_is_refused() {let error = items_list(&config,+ &MemoryIdentity::root(),ItemsListParams {path: path.clone(),..ItemsListParams::default()@@ -204,6 +209,7 @@ async fn an_explorer_path_into_another_root_is_refused() {let error = explore(&config,+ &MemoryIdentity::root(),ExploreParams {facet: tinymemory_api::Facet::Kind,path,@@ -219,6 +225,7 @@ async fn an_explorer_path_into_another_root_is_refused() {// Exploring inside the root still works and counts only its items.let page = explore(&config,+ &MemoryIdentity::root(),ExploreParams {facet: tinymemory_api::Facet::Kind,path: Vec::new(),@@ -239,6 +246,7 @@ async fn items_get_and_forget_leave_another_roots_items_alone() {let read = items_get(&config,+ &MemoryIdentity::root(),ItemsGetParams {ids: vec![mine.clone(), theirs.clone()],reach: None,@@ -250,6 +258,7 @@ async fn items_get_and_forget_leave_another_roots_items_alone() {let error = items_get(&config,+ &MemoryIdentity::root(),ItemsGetParams {ids: vec![theirs.clone()],reach: Some(Reach::subtree(Namespace::ROOT)),@@ -261,6 +270,7 @@ async fn items_get_and_forget_leave_another_roots_items_alone() {let forgotten = forget(&config,+ &MemoryIdentity::root(),ForgetParams {ids: vec![theirs.clone()],reach: None,@@ -272,6 +282,7 @@ async fn items_get_and_forget_leave_another_roots_items_alone() {let error = forget(&config,+ &MemoryIdentity::root(),ForgetParams {ids: vec![theirs.clone()],reach: Some(Reach::subtree(ns("team:other"))),@@ -298,6 +309,7 @@ async fn items_get_and_forget_leave_another_roots_items_alone() {// Its own items are forgotten as before.let forgotten = forget(&config,+ &MemoryIdentity::root(),ForgetParams {ids: vec![mine],reach: None,@@ -315,6 +327,7 @@ async fn learn_lands_inside_the_root_and_refuses_another() {let learned = learn(&config,+ &MemoryIdentity::root(),LearnParams {text: "acme prefers short standups".into(),kind: None,@@ -326,6 +339,7 @@ async fn learn_lands_inside_the_root_and_refuses_another() {.unwrap();let read = items_get(&config,+ &MemoryIdentity::root(),ItemsGetParams {ids: vec![learned.id],reach: None,@@ -338,6 +352,7 @@ async fn learn_lands_inside_the_root_and_refuses_another() {let error = learn(&config,+ &MemoryIdentity::root(),LearnParams {text: "planted in another team".into(),kind: None,diff --git a/crates/openhuman-core/src/memory/lifecycle/mod_tests.rs b/crates/openhuman-core/src/memory/lifecycle/mod_tests.rsindex 93d6fbeee5..9f6a6ffd04 100644--- a/crates/openhuman-core/src/memory/lifecycle/mod_tests.rs+++ b/crates/openhuman-core/src/memory/lifecycle/mod_tests.rs@@ -52,12 +52,10 @@ async fn agent_memory_needs_an_engine_and_follows_the_identity() {assert_eq!(memory.agent_id(), "writer");assert_eq!(memory.namespace().to_string(), "team:acme/agent:writer");- let (named, _) = named_agent_memory(&config, Some("auditor")).unwrap();+ let (named, _) = named_agent_memory(&config, &MemoryIdentity::root(), Some("auditor")).unwrap();assert_eq!(named.namespace().to_string(), "agent:auditor");- let (current, resolved) = crate::memory::scope::within_agent("planner", async {- current_agent_memory(&config).unwrap()- })- .await;+ let (current, resolved) =+ current_agent_memory(&config, &MemoryIdentity::root().child("planner")).unwrap();assert_eq!(current.agent_id(), "planner");assert_eq!(resolved.agent_id, "planner");}diff --git a/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs b/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rsindex bd7d776f71..0b0f8ca5d3 100644--- a/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs+++ b/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs@@ -340,7 +340,7 @@ async fn slow_engine_results_survive_the_manual_pre_turn_cutoff() {}#[tokio::test]-async fn queued_work_keeps_the_callers_core_and_memory_identity() {+async fn queued_work_keeps_the_callers_core_context() {let _guard = TEST_LOCK.lock().await;let tmp = tempfile::tempdir().unwrap();let config = config_in(&tmp);@@ -350,7 +350,7 @@ async fn queued_work_keeps_the_callers_core_and_memory_identity() {);crate::core::runtime::CoreContext::scope(ctx.clone(),- crate::memory::scope::within(MemoryIdentity::agent("scoped-agent"), async {+ async {let identity = MemoryIdentity::agent("scoped-agent").resolve(&config);let key = Key::new(&config, &identity, "t", false);let cache = cache();@@ -363,16 +363,12 @@ async fn queued_work_keeps_the_callers_core_and_memory_identity() {&crate::core::runtime::CoreContext::scoped().unwrap(),&expected));- assert_eq!(- crate::memory::scope::current().unwrap().agent_id.as_deref(),- Some("scoped-agent")- );Some(pack("scoped"))})),);drain(&cache, &key).await;assert_eq!(completed(&cache, &key).unwrap().markdown, "scoped");- }),+ },).await;}diff --git a/crates/openhuman-core/src/memory/scope_tests.rs b/crates/openhuman-core/src/memory/scope_tests.rsindex 8019870a77..3dac987698 100644--- a/crates/openhuman-core/src/memory/scope_tests.rs+++ b/crates/openhuman-core/src/memory/scope_tests.rs@@ -89,19 +89,17 @@ fn a_host_binding_beats_everything() {}}-#[tokio::test]-async fn within_agent_scopes_a_child_in_the_same_team() {- assert_eq!(current(), None);- let seen = within(MemoryIdentity::team_member("acme", "lead"), async {- within_agent("lead", async {- within_agent("scout", async { current().unwrap() }).await- })- .await- })- .await;- assert_eq!(seen, MemoryIdentity::team_member("acme", "scout"));- let alone = within_agent("solo", async { current().unwrap() }).await;- assert_eq!(alone, MemoryIdentity::agent("solo"));+#[test]+fn a_child_stays_in_the_parents_team() {+ let lead = MemoryIdentity::team_member("acme", "lead");+ assert_eq!(+ lead.child("lead").child("scout"),+ MemoryIdentity::team_member("acme", "scout")+ );+ assert_eq!(+ MemoryIdentity::root().child("solo"),+ MemoryIdentity::agent("solo")+ );}#[test]diff --git a/crates/openhuman-core/src/platform/cost/scope_tests.rs b/crates/openhuman-core/src/platform/cost/scope_tests.rsindex f25854e351..f2646bbf21 100644--- a/crates/openhuman-core/src/platform/cost/scope_tests.rs+++ b/crates/openhuman-core/src/platform/cost/scope_tests.rs@@ -54,7 +54,6 @@ fn each_origin_maps_to_its_thread_and_label() {#[tokio::test]async fn ambient_scope_reads_the_turn_and_prefers_the_subagent() {- use crate::memory::scope::{within, MemoryIdentity};let origin = AgentTurnOrigin::WebChat {thread_id: "thread-9".into(),client_id: "c".into(),@@ -67,12 +66,14 @@ async fn ambient_scope_reads_the_turn_and_prefers_the_subagent() {let (parent, child) = crate::core::runtime::CoreContext::scope(ctx,crate::agent::turn_origin::with_origin(origin, async {- within(MemoryIdentity::agent("orchestrator"), async {+ async {(- UsageScope::ambient(Some("openhuman"), None),- UsageScope::ambient(Some("openhuman"), Some(("researcher", "task-1"))),+ UsageScope::ambient(Some("openhuman"), None)+ .with_definition(Some("orchestrator")),+ UsageScope::ambient(Some("openhuman"), Some(("researcher", "task-1")))+ .with_definition(Some("orchestrator")),)- })+ }.await}),)