Skip to content

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

chore: files changed crates/openhuman-core/src/core/runtime/agent_scope_tests.rs,crates/openhuman-co

Steven Enamakela534116348a5
diff --git a/crates/openhuman-core/src/core/runtime/agent_scope_tests.rs b/crates/openhuman-core/src/core/runtime/agent_scope_tests.rs
index 97359b4016..1232467209 100644
--- a/crates/openhuman-core/src/core/runtime/agent_scope_tests.rs
+++ b/crates/openhuman-core/src/core/runtime/agent_scope_tests.rs
@@ -181,3 +181,22 @@ fn current_slot_without_a_context_uses_the_unscoped_state() {
let second = current_slot::<Counter>();
assert!(Arc::ptr_eq(&first, &second));
}
+
+#[test]
+fn an_unscoped_saas_task_never_meets_shared_slots() {
+ let first = slot_in::<Counter>(true, None);
+ *first.0.lock().unwrap() = 5;
+ let second = slot_in::<Counter>(true, None);
+ assert_eq!(*second.0.lock().unwrap(), 0, "a throwaway slot each time");
+ assert!(!Arc::ptr_eq(&first, &second));
+ // Single-user processes keep the one shared unscoped slot.
+ assert!(Arc::ptr_eq(
+ &slot_in::<Counter>(false, None),
+ &slot_in::<Counter>(false, None)
+ ));
+ let ctx = root("/tmp/x");
+ assert!(Arc::ptr_eq(
+ &slot_in::<Counter>(true, Some(&ctx)),
+ &ctx.agent_state().slot::<Counter>()
+ ));
+}
diff --git a/crates/openhuman-core/src/platform/cost/global_tests.rs b/crates/openhuman-core/src/platform/cost/global_tests.rs
index 6196e6e6fd..baa574abd0 100644
--- a/crates/openhuman-core/src/platform/cost/global_tests.rs
+++ b/crates/openhuman-core/src/platform/cost/global_tests.rs
@@ -248,3 +248,28 @@ fn token_usage_row_shape_is_stable_and_old_rows_load() {
assert_eq!(parsed.input_tokens, 10);
assert_eq!(parsed.cost_usd, 0.25);
}
+
+#[test]
+fn a_tenant_tracker_belongs_to_its_profile_alone() {
+ use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};
+ let tmp = tempfile::tempdir().unwrap();
+ let config = crate::config::Config {
+ workspace_dir: tmp.path().to_path_buf(),
+ ..crate::config::Config::default()
+ };
+ let root = CoreContext::for_test(DomainSet::full(), None);
+ let derive = |id: &str| {
+ root.derive_with(
+ ContextOverlay::new(config.clone(), DomainSet::kernel(), Default::default())
+ .profile(id),
+ )
+ };
+ let (alice, bob) = (derive("u-alice"), derive("u-bob"));
+ assert!(tracker_in(Some(&alice)).is_none());
+ seed_tenant_tracker(&alice, &config);
+ let tracker = tracker_in(Some(&alice)).expect("seeded at open");
+ assert_eq!(tracker.workspace_dir(), tmp.path());
+ assert!(tracker_in(Some(&bob)).is_none(), "never another profile's");
+ assert!(tracker_in(Some(&root)).is_none(), "nor the operator's");
+ assert!(tracker_in(None).is_none(), "an unscoped task has none");
+}
diff --git a/crates/openhuman-core/src/web_chat/event_bus_tests.rs b/crates/openhuman-core/src/web_chat/event_bus_tests.rs
index 5dacc98e92..76cacf6d82 100644
--- a/crates/openhuman-core/src/web_chat/event_bus_tests.rs
+++ b/crates/openhuman-core/src/web_chat/event_bus_tests.rs
@@ -589,7 +589,8 @@ async fn published_events_carry_the_publishing_agent() {
DomainSet::full(),
Default::default(),
)
- .session_agent("u-alice"),
+ .session_agent("u-alice")
+ .profile("p-alice"),
);
CoreContext::scope(ctx, async {
publish_web_channel_event(WebChannelEvent {
@@ -615,9 +616,11 @@ async fn published_events_carry_the_publishing_agent() {
let scoped = seen.iter().find(|e| e.thread_id == marker).unwrap();
assert!(scoped.belongs_to("u-alice"));
assert!(!scoped.belongs_to("u-bob"));
+ assert!(scoped.belongs_to_profile("p-alice"));
+ assert!(!scoped.belongs_to_profile("p-bob"));
let unscoped = seen.iter().find(|e| e.thread_id != marker).unwrap();
assert!(
- !unscoped.belongs_to("u-alice"),
+ !unscoped.belongs_to("u-alice") && !unscoped.belongs_to_profile("p-alice"),
"unstamped events belong to no user"
);
assert!(
diff --git a/crates/openhuman-core/src/web_chat/ops/state_tests.rs b/crates/openhuman-core/src/web_chat/ops/state_tests.rs
index 84e1c03223..c70f8da1d1 100644
--- a/crates/openhuman-core/src/web_chat/ops/state_tests.rs
+++ b/crates/openhuman-core/src/web_chat/ops/state_tests.rs
@@ -35,3 +35,35 @@ async fn each_agent_context_owns_its_turn_tables() {
assert!(!Arc::ptr_eq(&alpha_parallel, &beta_parallel));
assert!(Arc::ptr_eq(&alpha_in_flight, &alpha_again));
}
+
+#[tokio::test]
+async fn two_profiles_on_the_same_thread_id_hold_two_keys() {
+ let root = CoreContext::for_test(DomainSet::full(), None);
+ let profile = |id: &str| {
+ root.derive_with(
+ ContextOverlay::new(
+ crate::config::Config::default(),
+ DomainSet::kernel(),
+ ToolGroups::none(),
+ )
+ .profile(id)
+ .session_agent(id),
+ )
+ };
+ let (alice, bob) = (profile("u-alice"), profile("u-bob"));
+ let key_a = CoreContext::scope(Arc::clone(&alice), async { key_for("t1") }).await;
+ let key_b = CoreContext::scope(Arc::clone(&bob), async { key_for("t1") }).await;
+ assert_ne!(key_a, key_b);
+ assert_eq!(
+ CoreContext::scope(Arc::clone(&alice), async { unscope(&key_a) }).await,
+ "t1"
+ );
+ assert_eq!(
+ CoreContext::scope(Arc::clone(&alice), async { unscope(&key_b) }).await,
+ key_b,
+ "another tenant's key is not unscoped"
+ );
+ assert_eq!(thread_id_of_key(&key_b), Some("t1"));
+ // The desktop keeps the bare id.
+ assert_eq!(key_in(&crate::core::runtime::Tenant::default(), "t1"), "t1");
+}