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/cron/tools/collapsed_tests.rs

Steven Enamakel6afcb70f675a
diff --git a/crates/openhuman-core/src/cron/tools/collapsed_tests.rs b/crates/openhuman-core/src/cron/tools/collapsed_tests.rs
index 3c3df4d566..922fb285b3 100644
--- a/crates/openhuman-core/src/cron/tools/collapsed_tests.rs
+++ b/crates/openhuman-core/src/cron/tools/collapsed_tests.rs
@@ -1,4 +1,8 @@
use super::*;
+use crate::agent::tinyagents::host::OpenHumanRunContext;
+use crate::agent::turn_origin::AgentTurnOrigin;
+use crate::core::runtime::{ComponentSet, CoreContext, DomainSet};
+use tinyagents_harness::{context::RunConfig, ids::CallId, tool::ToolExecutionContext};
fn tool() -> CronTool {
CronTool::new(
@@ -7,6 +11,11 @@ fn tool() -> CronTool {
)
}
+fn execution_context(run: OpenHumanRunContext) -> ToolExecutionContext {
+ let run = run.into_tinyagents(RunConfig::new("cron-collapsed-context"));
+ ToolExecutionContext::from_run_context(&run, CallId::new("cron-collapsed-call"))
+}
+
#[test]
fn the_schema_advertises_every_action() {
let schema = tool().parameters_schema();
@@ -90,3 +99,107 @@ fn every_member_is_hidden_so_the_collapse_actually_saves_something() {
);
}
}
+
+#[tokio::test]
+async fn run_uses_the_explicit_core_context_and_preserves_markdown_options() {
+ let tmp = tempfile::TempDir::new().unwrap();
+ let workspace = tmp.path().join("workspace");
+ tokio::fs::create_dir_all(&workspace).await.unwrap();
+ let config = Arc::new(Config {
+ workspace_dir: workspace.clone(),
+ action_dir: workspace,
+ config_path: tmp.path().join("config.toml"),
+ ..Config::default()
+ });
+ let job = crate::cron::add_flow_schedule_job(
+ &config,
+ "cron-collapsed-context-flow",
+ tinyflows_bus::schedule::types::Schedule::Every { every_ms: 300_000 },
+ )
+ .unwrap();
+
+ let mut components = ComponentSet::all();
+ components.flows = false;
+ let explicit = CoreContext::for_test_with_components(components);
+ let ambient = CoreContext::for_test(DomainSet::full(), None);
+ let context = execution_context(OpenHumanRunContext::new().with_core(Some(explicit)));
+ let cron = CronTool::new(config, Arc::new(SecurityPolicy::default()));
+
+ let result = CoreContext::scope(ambient, async {
+ cron.execute_with_context(
+ serde_json::json!({"action": "run", "job_id": job.id}),
+ ToolCallOptions { prefer_markdown: true, ..Default::default() },
+ Some(&context),
+ )
+ .await
+ .unwrap()
+ })
+ .await;
+
+ assert!(result.is_error, "the explicit context disables flows: {}", result.output());
+ assert!(result.output().contains("COMPONENT_DISABLED:flows"), "{}", result.output());
+ assert!(result.markdown_formatted.as_deref().is_some_and(|md| md.contains("status")));
+}
+
+#[tokio::test]
+async fn add_uses_the_explicit_channel_origin_without_ambient_turn_state() {
+ let tmp = tempfile::TempDir::new().unwrap();
+ let workspace = tmp.path().join("workspace");
+ tokio::fs::create_dir_all(&workspace).await.unwrap();
+ let mut cfg = Config {
+ workspace_dir: workspace.clone(),
+ action_dir: workspace,
+ config_path: tmp.path().join("config.toml"),
+ ..Config::default()
+ };
+ cfg.cron.agent_jobs_only = true;
+ let config = Arc::new(cfg);
+ let origin = AgentTurnOrigin::ExternalChannel {
+ sender_name: None,
+ channel: "telegram".into(),
+ sender: Some("alice".into()),
+ reply_target: "42".into(),
+ message_id: "message-1".into(),
+ history_key: Some("telegram-alice-42".into()),
+ };
+ let context = execution_context(OpenHumanRunContext {
+ origin: Some(origin),
+ ..OpenHumanRunContext::new()
+ });
+ let cron = CronTool::new(config.clone(), Arc::new(SecurityPolicy::default()));
+
+ let result = cron
+ .execute_with_context(
+ serde_json::json!({
+ "action": "add",
+ "schedule": {"kind": "every", "every_ms": 300000},
+ "job_type": "agent",
+ "prompt": "send a reminder"
+ }),
+ ToolCallOptions::default(),
+ Some(&context),
+ )
+ .await
+ .unwrap();
+
+ assert!(!result.is_error, "{}", result.output());
+ let jobs = crate::cron::list_jobs(&config).unwrap();
+ assert_eq!(jobs.len(), 1);
+ assert_eq!(jobs[0].origin, Some(crate::cron::types::JobOrigin::Channel {
+ channel: "telegram".into(),
+ reply_target: "42".into(),
+ history_key: "telegram-alice-42".into(),
+ sender: Some("alice".into()),
+ thread_id: None,
+ }));
+ assert_eq!(jobs[0].delivery.mode, "origin");
+}
+
+#[test]
+fn description_says_conversation_jobs_reply_automatically_and_documents_overrides() {
+ let description = tool().description();
+ assert!(description.contains("automatically"));
+ assert!(description.contains("proactive"));
+ assert!(description.contains("none"));
+ assert!(!description.contains("copy a reply target"));
+}