Skip to content

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

test(cron): seed a prior turn before asserting origin delivery

Steven Enamakelfed1d69efa0f
diff --git a/crates/openhuman-core/src/cron/scheduler/origin_delivery_channel_tests.rs b/crates/openhuman-core/src/cron/scheduler/origin_delivery_channel_tests.rs
index 89e053ac24..475f0be02d 100644
--- a/crates/openhuman-core/src/cron/scheduler/origin_delivery_channel_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler/origin_delivery_channel_tests.rs
@@ -54,6 +54,35 @@ fn account_of(objects: &std::collections::HashMap<String, tinybus::module::Modul
.clone()
}
+/// A prior live turn, written the way the session host does, so the cron
+/// append has a session to extend (a channel that never spoke has none).
+fn seed_session(ctx: &DispatchCtx, config: &Config, identity: &ChannelSessionIdentity) {
+ use tinyagents_session::transcript::{TranscriptMessage, TranscriptTurn};
+ let tenant = ctx.tenant().unwrap();
+ let locator = origin_channel_transcripts(ctx, config, identity, &identity.agent_id).unwrap();
+ let session = SessionRef::scoped(
+ &crate::core::runtime::tenant_key(&tenant, &identity.session_key),
+ &identity.agent_id,
+ );
+ let meta = super::tests::meta();
+ let next = vec![
+ TranscriptMessage::user("remind me"),
+ TranscriptMessage::assistant("Scheduled."),
+ ];
+ locator
+ .open_session(&session, meta.clone())
+ .unwrap()
+ .append_turn(TranscriptTurn {
+ prev: &[],
+ next: &next,
+ meta: &meta,
+ turn_usage: None,
+ request_id: None,
+ tools: None,
+ })
+ .unwrap();
+}
+
fn assistant_messages(
ctx: &DispatchCtx,
config: &Config,
@@ -89,6 +118,7 @@ async fn channel_origin_reply_reaches_the_provider_and_the_durable_session() {
let cfg = config(&tmp);
let ctx = ctx_for(&cfg);
let ident = identity(&ctx, &cfg, &account);
+ seed_session(&ctx, &cfg, &ident);
let j = job(Some(channel_origin(Some(ident.clone()))));
let status = deliver_to_origin(&ctx, &cfg, &j, "run-chan-1", "Drink water!").await;
@@ -100,7 +130,7 @@ async fn channel_origin_reply_reaches_the_provider_and_the_durable_session() {
.await
.iter()
.any(|p| p.ends_with("/sendMessage")));
- assert_eq!(assistant_messages(&ctx, &cfg, &ident), ["Drink water!"]);
+ assert_eq!(assistant_messages(&ctx, &cfg, &ident), ["Scheduled.", "Drink water!"]);
}
#[tokio::test]
@@ -180,6 +210,7 @@ async fn host_routed_channel_origin_reply_is_also_recorded_in_the_session_transc
let sink = Arc::new(Capture(Mutex::new(Vec::new())));
let previous = crate::cron::host_delivery::install(sink.clone());
+ seed_session(&ctx, &cfg, &ident);
let j = job(Some(channel_origin(Some(ident.clone()))));
let status = deliver_to_origin(&ctx, &cfg, &j, "run-host-1", "Host reply").await;
@@ -192,5 +223,5 @@ async fn host_routed_channel_origin_reply_is_also_recorded_in_the_session_transc
assert_eq!(replies.len(), 1);
assert_eq!(replies[0].text, "Host reply");
assert_eq!(replies[0].profile_id.as_deref(), Some("cron-origin-profile"));
- assert_eq!(assistant_messages(&ctx, &cfg, &ident), ["Host reply"]);
+ assert_eq!(assistant_messages(&ctx, &cfg, &ident), ["Scheduled.", "Host reply"]);
}
diff --git a/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs b/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs
index b8291b648b..71852bc9eb 100644
--- a/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs
@@ -277,7 +277,7 @@ async fn origin_mode_without_an_origin_is_an_error() {
.is_err());
}
-fn meta() -> TranscriptMeta {
+pub(super) fn meta() -> TranscriptMeta {
TranscriptMeta {
session_id: None,
parent_session_id: None,