Skip to content

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

test(agent-chat): cover chat origin resolution precedence

Steven Enamakel75c8d2895f04
diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat_tests.rs b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat_tests.rs
index 816bbfddab..7a61d43ce9 100644
--- a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat_tests.rs
+++ b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat_tests.rs
@@ -82,3 +82,35 @@ fn explicit_turn_temperature_overrides_the_definition_without_mutating_it() {
));
assert_eq!(definition_for_turn(&definition, None).temperature, 0.6);
}
+
+fn chat_origin(thread: &str) -> crate::agent::turn_origin::AgentTurnOrigin {
+ crate::agent::turn_origin::AgentTurnOrigin::WebChat {
+ thread_id: thread.into(),
+ client_id: "client".into(),
+ request_id: format!("req-{thread}").into(),
+ }
+}
+
+#[tokio::test]
+async fn agent_chat_origin_comes_from_the_turn_context_before_the_task_scope() {
+ use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};
+ let base = CoreContext::for_test(DomainSet::full(), None);
+ let own = DispatchCtx::new(std::sync::Arc::new(
+ base.derive_channel_turn(None, Some(chat_origin("own"))),
+ ));
+ let scoped = std::sync::Arc::new(base.derive_channel_turn(None, Some(chat_origin("scoped"))));
+ CoreContext::scope(scoped, async {
+ // The turn's own context wins over whatever the task scope carries.
+ assert_eq!(effective_agent_chat_origin(&own), chat_origin("own"));
+ // A context with no origin of its own falls back to the task scope.
+ let bare = DispatchCtx::new(CoreContext::for_test(DomainSet::full(), None));
+ assert_eq!(effective_agent_chat_origin(&bare), chat_origin("scoped"));
+ })
+ .await;
+ // Neither: the trusted direct-chat label.
+ let bare = DispatchCtx::new(CoreContext::for_test(DomainSet::full(), None));
+ assert_eq!(
+ effective_agent_chat_origin(&bare),
+ crate::agent::turn_origin::AgentTurnOrigin::DirectChat
+ );
+}