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
chore: files changed tests/storage_flows_e2e.rs,tests/support/cron_policy_failure.rs
Steven Enamakele3335a0e563a
diff --git a/tests/storage_flows_e2e.rs b/tests/storage_flows_e2e.rsindex 9c70668785..61b2295a86 100644--- a/tests/storage_flows_e2e.rs+++ b/tests/storage_flows_e2e.rs@@ -85,7 +85,19 @@ async fn a_configured_backend_holds_cron_flows_and_flow_state(case: Case) {// A job's scheduling policy lives on the backend too.let policy_config = config.clone();tokio::task::spawn_blocking(move || {- use openhuman_core::cron::policy::{self, JobPolicy};+ use openhuman_core::cron::{CronJobPatch, JobPolicy};+ let set_policy = |config: &_, id: &str, policy: JobPolicy| {+ cron::update_job(+ config,+ id,+ CronJobPatch {+ policy: Some(policy),+ ..CronJobPatch::default()+ },+ )+ .unwrap()+ .policy+ };let job = cron::add_shell_job(&policy_config,Some("policy".to_string()),@@ -97,15 +109,13 @@ async fn a_configured_backend_holds_cron_flows_and_flow_state(case: Case) {retries: Some(0),single_flight: true,};- policy::set_policy(&policy_config, &job.id, wanted).unwrap();- assert_eq!(policy::get_policy(&policy_config, &job.id).unwrap(), wanted);+ assert_eq!(set_policy(&policy_config, &job.id, wanted), wanted);assert_eq!(cron::get_job(&policy_config, &job.id).unwrap().policy,wanted);- policy::clear_policy(&policy_config, &job.id).unwrap();assert_eq!(- policy::get_policy(&policy_config, &job.id).unwrap(),+ set_policy(&policy_config, &job.id, JobPolicy::default()),JobPolicy::default());})diff --git a/tests/support/cron_policy_failure.rs b/tests/support/cron_policy_failure.rsindex 2353ce77d9..c9dbf19d40 100644--- a/tests/support/cron_policy_failure.rs+++ b/tests/support/cron_policy_failure.rs@@ -2,7 +2,7 @@use super::*;use async_trait::async_trait;-use openhuman_core::cron::policy::{self, JobPolicy};+use openhuman_core::cron::{CronJobPatch, JobPolicy};use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};use std::sync::Mutex;use tinystoragedrivers_core::{@@ -12,6 +12,32 @@ use tinystoragedrivers_core::{use tinytools::Tool;type StoreResult<T> = Result<T, StorageError>;++/// A job's policy is a field of its job document: these read and write it+/// through the job, failing closed when the job cannot be read.+mod policy {+ use super::*;++ pub fn get_policy(config: &Config, job_id: &str) -> anyhow::Result<JobPolicy> {+ Ok(cron::get_job(config, job_id)?.policy)+ }++ pub fn set_policy(config: &Config, job_id: &str, policy: JobPolicy) -> anyhow::Result<()> {+ cron::update_job(+ config,+ job_id,+ CronJobPatch {+ policy: Some(policy),+ ..CronJobPatch::default()+ },+ )+ .map(|_| ())+ }++ pub fn clear_policy(config: &Config, job_id: &str) -> anyhow::Result<()> {+ set_policy(config, job_id, JobPolicy::default())+ }+}/// A job's policy is a field of its job document.const JOBS: &str = "cron_jobs";const BACKEND_DETAIL: &str = "mongodb://policy-user:secret@backend/private-payload";@@ -327,20 +353,15 @@ pub(super) async fn policy_reads_refuse_execution_without_consuming_a_slot(case:let after =CoreContext::scope(Arc::clone(&alpha), async { next_run_of(&config, &job.id) }).await;let scheduled_calls = calls.load(Ordering::SeqCst);- let mut agent_job = job.clone();- agent_job.job_type = cron::JobType::Agent;- agent_job.prompt = Some("complete the fixture".into());- let (direct, agent, manual, queued, tool) = CoreContext::scope(Arc::clone(&alpha), async {+ let (manual, queued, tool) = CoreContext::scope(Arc::clone(&alpha), async {assert!(policy::get_policy(&config, &job.id).is_err());- let direct = cron::scheduler::execute_job_now(&config, &job, "policy-direct").await;- let agent = cron::scheduler::execute_job_now(&config, &agent_job, "policy-agent").await;let manual = cron::ops::run_job_now(&config, &job.id).await;let queued = cron::ops::cron_run(&config, &job.id).await;let tool = cron::tools::CronRunTool::new(Arc::new(config.clone())).execute(json!({"job_id": job.id})).await.unwrap();- (direct, agent, manual, queued, tool)+ (manual, queued, tool)}).await;assert_eq!(@@ -356,10 +377,6 @@ pub(super) async fn policy_reads_refuse_execution_without_consuming_a_slot(case:after, before,"policy read failure consumed the due occurrence");- assert!(- !direct.0,- "direct execution must refuse an unreadable policy"- );assert!(manual.is_err(),"Run now must refuse before delivery/persistence"@@ -374,13 +391,12 @@ pub(super) async fn policy_reads_refuse_execution_without_consuming_a_slot(case:0,"manual paths executed the job");- // `direct` and `agent` run a job they were handed, so what they report is- // the policy refusal itself. The manual paths first load the job, and the- // policy is a field of that same document now, so the injected fault- // reaches them at the lookup; they must still refuse (asserted above).+ // Every manual path loads the job, and the policy is a field of that same+ // document, so the injected fault reaches them at the lookup; none may leak+ // backend detail.for (name, shown) in [- ("direct", format!("{direct:?}")),- ("agent", format!("{agent:?}")),+ ("manual", format!("{manual:?}")),+ ("queued", format!("{queued:?}")),] {assert!(!shown.contains("secret"),@@ -415,51 +431,6 @@ pub(super) async fn policy_reads_refuse_execution_without_consuming_a_slot(case:1,"missing policy row must still run with defaults");- // Losing the backend after a failed attempt must stop further attempts.- let retry_calls = Arc::new(AtomicUsize::new(0));- let recorded = Arc::clone(&retry_calls);- let failed_backend = Arc::clone(&faults);- let _retry_handler = cron::system_job_handlers::register(- "policy-retry-fixture",- Arc::new(move |_| {- recorded.fetch_add(1, Ordering::SeqCst);- failed_backend.read.store(true, Ordering::SeqCst);- Box::pin(async { Err("retryable fixture failure".to_string()) })- }),- );- CoreContext::scope(Arc::clone(&alpha), async {- let job = cron::system_jobs::ensure_system_job(- &config,- "policy-retry-fixture",- Schedule::Every {- every_ms: 3_600_000,- },- )- .unwrap();- policy::set_policy(- &config,- &job.id,- JobPolicy {- retries: Some(2),- single_flight: false,- },- )- .unwrap();- let (success, output) =- cron::scheduler::execute_job_now(&config, &job, "retry-read-failure").await;- assert!(!success);- assert_eq!(- retry_calls.load(Ordering::SeqCst),- 1,- "unreadable policy admitted a retry"- );- assert!(- output.contains("policy"),- "the refusal must identify policy availability"- );- assert!(!output.contains("secret"));- })- .await;assert!(AgentContextRegistry::deregister("policy-alpha", &alpha));assert!(AgentContextRegistry::deregister("policy-beta", &beta));}@@ -510,10 +481,10 @@ pub(super) async fn malformed_policy_rows_refuse_execution(case: Case) {policy::get_policy(&config, &job.id).is_err(),"a malformed existing row became a usable policy");- let (success, output) =- cron::scheduler::execute_job_now(&config, &job, "malformed-policy-run").await;- assert!(!success);- assert!(!output.contains("private-payload"));+ let refused = cron::ops::run_job_now(&config, &job.id)+ .await+ .expect_err("a malformed policy must refuse Run now");+ assert!(!refused.contains("private-payload"));assert_eq!(calls.load(Ordering::SeqCst), 0);}for (doc, wanted) in [