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(cron): add channel session testing utilities
Steven Enamakel6a0fbeb3a87e
diff --git a/crates/openhuman-core/src/cron/origin_tests.rs b/crates/openhuman-core/src/cron/origin_tests.rsindex 969fc5fd49..091be5d3bf 100644--- a/crates/openhuman-core/src/cron/origin_tests.rs+++ b/crates/openhuman-core/src/cron/origin_tests.rs@@ -1,9 +1,32 @@use super::*;use crate::agent::turn_origin::{with_origin, TrustedAutomationSource};use serde_json::json;-use tinyflows_bus::schedule::types::Schedule;+use tinyflows_bus::schedule::types::{+ ChannelConversationIdentity, ChannelSessionIdentity, Schedule,+};-fn channel_turn(history_key: Option<&str>) -> AgentTurnOrigin {+fn test_channel_session() -> ChannelSessionIdentity {+ ChannelSessionIdentity {+ tenant_key: "profile:alice".into(),+ agent_id: "orchestrator".into(),+ session_key: "main:telegram:bot-a:group:room-42".into(),+ provider: "telegram".into(),+ account_id: Some("telegram:bot-a".into()),+ conversation: ChannelConversationIdentity {+ kind: "group".into(),+ id: "room-42".into(),+ scope_id: Some("guild-1".into()),+ parent_id: Some("parent-1".into()),+ thread_id: Some("thread-1".into()),+ topic_id: Some("topic-1".into()),+ },+ }+}++fn channel_turn_with_session(+ history_key: Option<&str>,+ channel_session: Option<ChannelSessionIdentity>,+) -> AgentTurnOrigin {AgentTurnOrigin::ExternalChannel {sender_name: None,channel: "telegram".into(),@@ -11,10 +34,14 @@ fn channel_turn(history_key: Option<&str>) -> AgentTurnOrigin {reply_target: "42".into(),message_id: "m1".into(),history_key: history_key.map(str::to_string),- channel_session: None,+ channel_session,}}+fn channel_turn(history_key: Option<&str>) -> AgentTurnOrigin {+ channel_turn_with_session(history_key, Some(test_channel_session()))+}+fn web_turn(thread_id: &str) -> AgentTurnOrigin {AgentTurnOrigin::WebChat {thread_id: thread_id.into(),@@ -45,7 +72,7 @@ fn channel_turn_maps_to_channel_origin_with_history_key() {history_key: "telegram_alice_42".into(),sender: Some("alice".into()),thread_id: None,- channel_session: None,+ channel_session: Some(Box::new(test_channel_session())),}));}@@ -56,6 +83,17 @@ fn channel_labelled_turn_without_history_key_has_no_origin() {assert_eq!(job_origin_from_turn(&channel_turn(None)), None);}+#[test]+fn legacy_channel_history_key_cannot_authorize_a_durable_job_origin() {+ assert_eq!(+ job_origin_from_turn(&channel_turn_with_session(+ Some("legacy-history-key"),+ None,+ )),+ None+ );+}+#[test]fn other_origins_have_no_job_origin() {for origin in [@@ -118,7 +156,7 @@ fn channel_origin_job_runs_as_external_channel_turn() {history_key: "k".into(),sender: Some("alice".into()),thread_id: None,- channel_session: None,+ channel_session: Some(Box::new(test_channel_session())),}));match turn_origin_for_job_run(&job, "run-1") {AgentTurnOrigin::ExternalChannel {@@ -128,12 +166,14 @@ fn channel_origin_job_runs_as_external_channel_turn() {reply_target,message_id,history_key,+ channel_session,} => {assert_eq!(channel, "telegram");assert_eq!(sender.as_deref(), Some("alice"));assert_eq!(reply_target, "42");assert_eq!(message_id, format!("cron:{}:run-1", job.id));assert_eq!(history_key.as_deref(), Some("k"));+ assert_eq!(channel_session, Some(test_channel_session()));}other => panic!("expected ExternalChannel, got {other:?}"),}