Skip to content

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

test(cron): cover per-agent job stores and dormant jobs (#7032)

oxoxDeva3f3c50a43b3
diff --git a/crates/openhuman-core/src/cron/store_tests.rs b/crates/openhuman-core/src/cron/store_tests.rs
index 4e241a19e5..a06ef38848 100644
--- a/crates/openhuman-core/src/cron/store_tests.rs
+++ b/crates/openhuman-core/src/cron/store_tests.rs
@@ -48,3 +48,77 @@ fn run_history_cap_follows_cron_max_run_history() {
}
assert_eq!(list_runs(&config, &job.id, 10).unwrap().len(), 2);
}
+
+fn agent_context(
+ config: &Config,
+ agent: &str,
+) -> std::sync::Arc<crate::core::runtime::CoreContext> {
+ use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};
+ CoreContext::for_test_with_config(DomainSet::full(), config.clone()).derive_with(
+ ContextOverlay::new(
+ config.clone(),
+ DomainSet::full(),
+ crate::tools::toolpacks::ToolGroups::none(),
+ )
+ .session_agent(agent),
+ )
+}
+
+#[tokio::test]
+async fn an_agents_jobs_live_in_its_own_database() {
+ use crate::core::runtime::CoreContext;
+ let tmp = TempDir::new().unwrap();
+ let config = test_config(&tmp);
+
+ let job = CoreContext::scope(agent_context(&config, "alpha"), async {
+ add_job(&config, "*/5 * * * *", "echo alpha").unwrap()
+ })
+ .await;
+
+ assert!(tmp
+ .path()
+ .join("workspace/agents/alpha/cron/jobs.db")
+ .is_file());
+ let alpha_ids = CoreContext::scope(agent_context(&config, "alpha"), async {
+ list_jobs(&config)
+ .unwrap()
+ .into_iter()
+ .map(|job| job.id)
+ .collect::<Vec<_>>()
+ })
+ .await;
+ assert_eq!(alpha_ids, [job.id.clone()]);
+ let beta_jobs = CoreContext::scope(agent_context(&config, "beta"), async {
+ list_jobs(&config).unwrap()
+ })
+ .await;
+ assert!(beta_jobs.is_empty());
+ assert!(
+ list_jobs(&config).unwrap().is_empty(),
+ "the workspace store stays empty"
+ );
+}
+
+#[tokio::test]
+async fn a_job_whose_agent_is_not_live_stays_dormant() {
+ use crate::core::runtime::CoreContext;
+ let tmp = TempDir::new().unwrap();
+ let config = test_config(&tmp);
+ let ctx = agent_context(&config, "dormant-agent");
+ let job = CoreContext::scope(std::sync::Arc::clone(&ctx), async {
+ add_job(&config, "* * * * *", "echo dormant").unwrap()
+ })
+ .await;
+ drop(ctx);
+
+ crate::cron::scheduler::tick_live_agents().await;
+
+ let after = CoreContext::scope(agent_context(&config, "dormant-agent"), async {
+ get_job(&config, &job.id).unwrap()
+ })
+ .await;
+ assert!(
+ after.last_run.is_none(),
+ "nothing ran the dormant agent's job"
+ );
+}