Skip to content

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

test(web_chat): cover per-agent turn tables (#7032)

oxoxDevdce4c0f78e4a
diff --git a/crates/openhuman-core/src/web_chat/ops/state.rs b/crates/openhuman-core/src/web_chat/ops/state.rs
index 417021499a..28b1674f9c 100644
--- a/crates/openhuman-core/src/web_chat/ops/state.rs
+++ b/crates/openhuman-core/src/web_chat/ops/state.rs
@@ -143,3 +143,6 @@ pub fn cancel_should_target(requested: Option<&str>, in_flight: &str) -> bool {
}
}
+#[cfg(test)]
+#[path = "state_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/web_chat/ops/state_tests.rs b/crates/openhuman-core/src/web_chat/ops/state_tests.rs
new file mode 100644
index 0000000000..84e1c03223
--- /dev/null
+++ b/crates/openhuman-core/src/web_chat/ops/state_tests.rs
@@ -0,0 +1,37 @@
+use super::*;
+use crate::core::runtime::{context::CoreContext, ContextOverlay, DomainSet};
+use crate::tools::toolpacks::ToolGroups;
+
+fn agent(parent: &Arc<CoreContext>, id: &str) -> Arc<CoreContext> {
+ parent.derive_with(
+ ContextOverlay::new(
+ crate::config::Config::default(),
+ DomainSet::kernel(),
+ ToolGroups::none(),
+ )
+ .session_agent(id),
+ )
+}
+
+#[tokio::test]
+async fn each_agent_context_owns_its_turn_tables() {
+ let root = CoreContext::for_test(DomainSet::full(), None);
+ let alpha = agent(&root, "alpha");
+ let beta = agent(&root, "beta");
+
+ let (alpha_sessions, alpha_in_flight, alpha_parallel) =
+ CoreContext::scope(Arc::clone(&alpha), async {
+ (thread_sessions(), in_flight(), parallel_in_flight())
+ })
+ .await;
+ let (beta_sessions, beta_in_flight, beta_parallel) = CoreContext::scope(beta, async {
+ (thread_sessions(), in_flight(), parallel_in_flight())
+ })
+ .await;
+ let alpha_again = CoreContext::scope(alpha, async { in_flight() }).await;
+
+ assert!(!Arc::ptr_eq(&alpha_sessions, &beta_sessions));
+ assert!(!Arc::ptr_eq(&alpha_in_flight, &beta_in_flight));
+ assert!(!Arc::ptr_eq(&alpha_parallel, &beta_parallel));
+ assert!(Arc::ptr_eq(&alpha_in_flight, &alpha_again));
+}