Skip to content

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

test(cron): cover agent-only run checks for memory system jobs

Steven Enamakel88496c15d18b
diff --git a/crates/openhuman-core/src/cron/limits_tests.rs b/crates/openhuman-core/src/cron/limits_tests.rs
index 3a27eacdb2..6d36bedf30 100644
--- a/crates/openhuman-core/src/cron/limits_tests.rs
+++ b/crates/openhuman-core/src/cron/limits_tests.rs
@@ -245,6 +245,30 @@ fn stored_rows_that_break_the_limits_are_refused_at_run() {
limits::check_run(&config, &ok).unwrap();
}
+#[test]
+fn only_reserved_memory_system_jobs_pass_the_agent_only_run_check() {
+ let tmp = TempDir::new().unwrap();
+ let mut config = limited(&tmp);
+ config.cron.agent_jobs_only = false;
+ crate::cron::system_jobs::ensure_memory_jobs(&config).unwrap();
+ let memory = crate::cron::list_jobs(&config)
+ .unwrap()
+ .into_iter()
+ .find(|job| {
+ crate::cron::system_jobs::system_job_name(job)
+ == Some(crate::memory::lifecycle::jobs::BACKGROUND_JOB)
+ })
+ .unwrap();
+
+ config.cron.agent_jobs_only = true;
+ limits::check_run(&config, &memory)
+ .expect("the memory owner may run its internally seeded system job");
+
+ let mut other_system = memory;
+ other_system.command = "system:untrusted_flow".into();
+ assert!(limits::check_run(&config, &other_system).is_err());
+}
+
#[tokio::test]
async fn run_now_refuses_a_stored_job_that_breaks_the_limits() {
let tmp = TempDir::new().unwrap();
diff --git a/crates/openhuman-core/src/cron/system_jobs_tests.rs b/crates/openhuman-core/src/cron/system_jobs_tests.rs
index 3d969f6919..73c5b4e74d 100644
--- a/crates/openhuman-core/src/cron/system_jobs_tests.rs
+++ b/crates/openhuman-core/src/cron/system_jobs_tests.rs
@@ -128,3 +128,22 @@ fn ensure_memory_jobs_seeds_both_jobs_and_retires_the_context_refresh() {
assert_eq!(system_rows(&config, BACKGROUND_JOB)[0].id, background[0].id);
assert_eq!(system_rows(&config, SOURCES_SYNC_JOB)[0].id, sync[0].id);
}
+
+#[test]
+fn memory_jobs_seed_under_agent_only_without_authorizing_generic_flows() {
+ let tmp = TempDir::new().unwrap();
+ let mut config = test_config(&tmp);
+ config.cron.agent_jobs_only = true;
+
+ ensure_memory_jobs(&config).expect("trusted memory jobs should seed in an enforced scope");
+ let background = system_rows(&config, BACKGROUND_JOB);
+ let sync = system_rows(&config, SOURCES_SYNC_JOB);
+ assert_eq!(background.len(), 1);
+ assert_eq!(sync.len(), 1);
+ for job in background.iter().chain(sync.iter()) {
+ crate::cron::limits::check_run(&config, job).unwrap();
+ }
+
+ assert!(add_flow_schedule_job(&config, "system:memory_background", every(30)).is_err());
+ assert!(ensure_system_job(&config, "untrusted_flow", every(30)).is_err());
+}