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
test(cron): align frequency tests with async host verdict
Steven Enamakel684c4440c75e
diff --git a/crates/openhuman-core/src/cron/scheduler_frequency_tests.rs b/crates/openhuman-core/src/cron/scheduler_frequency_tests.rsindex f01e0bbbf1..393811c604 100644--- a/crates/openhuman-core/src/cron/scheduler_frequency_tests.rs+++ b/crates/openhuman-core/src/cron/scheduler_frequency_tests.rs@@ -94,12 +94,11 @@ async fn cron_agent_job_short_loopback_send_error_stays_retryable() {// ── agent-job frequency check (#6158) ───────────────────────────//-// The `Schedule::Cron` arm used to compare the next run after now with the-// next run after now plus one second — the same instant unless a run fell-// inside that second — so *every* cron-scheduled agent job warned, whatever-// its expression, and the three `// should not panic` tests could not tell.-// The verdict is now returned with its evidence and measured over-// consecutive runs, so each case below asserts it.+// The cadence maths (`RunsCloserThan`: the tightest pair of consecutive runs,+// the exact-five-minutes boundary, irregular expressions) is the module's and+// is tested there. What the host owns, and pins here, is the verdict it draws+// from the module's answer: which jobs it asks about, and that a module that+// cannot read a schedule is not evidence of anything.fn agent_job_on(schedule: Schedule) -> CronJob {let mut job = test_job("echo hi");@@ -116,86 +115,64 @@ fn cron_agent_job(expr: &str) -> CronJob {})}-#[test]-fn non_agent_and_one_shot_jobs_are_never_high_frequency() {- // `test_job` runs every minute — but it is a shell job.+#[tokio::test]+async fn non_agent_and_one_shot_jobs_are_never_high_frequency() {+ let config = Config::default();+ // `test_job` runs every minute, but it is a shell job.let mut shell = test_job("echo hi");shell.job_type = JobType::Shell;- assert!(agent_job_too_frequent(&shell).is_none());- warn_if_high_frequency_agent_job(&shell);+ assert!(agent_job_too_frequent(&config, &shell).await.is_none());+ warn_if_high_frequency_agent_job(&config, &shell).await;let once = agent_job_on(Schedule::At { at: Utc::now() });- assert!(agent_job_too_frequent(&once).is_none());- warn_if_high_frequency_agent_job(&once);+ assert!(agent_job_too_frequent(&config, &once).await.is_none());+ warn_if_high_frequency_agent_job(&config, &once).await;}-#[test]-fn every_ms_below_five_minutes_is_high_frequency() {+#[tokio::test]+async fn every_ms_below_five_minutes_is_high_frequency() {+ let config = Config::default();let job = agent_job_on(Schedule::Every { every_ms: 60_000 });assert_eq!(- agent_job_too_frequent(&job),+ agent_job_too_frequent(&config, &job).await,Some(TooFrequent::FixedInterval(ChronoDuration::minutes(1))));- warn_if_high_frequency_agent_job(&job); // logs the evidence, must not panic+ warn_if_high_frequency_agent_job(&config, &job).await; // logs the evidence, must not panic}/// The regression: every ordinary schedule was reported as too frequent.-#[test]-fn an_ordinary_cron_agent_job_is_not_high_frequency() {- for expr in [- "*/10 * * * *",- "0 * * * *",- "0 9 * * *",- "*/6 * * * *",- "0 9 * * 1-5",- ] {+#[tokio::test]+async fn an_ordinary_cron_agent_job_is_not_high_frequency() {+ let config = Config::default();+ for expr in ["*/10 * * * *", "0 9 * * *", "0 9 * * 1-5"] {assert!(- agent_job_too_frequent(&cron_agent_job(expr)).is_none(),+ agent_job_too_frequent(&config, &cron_agent_job(expr))+ .await+ .is_none(),"{expr} runs at most every 6 minutes and must not warn");}}-#[test]-fn a_cron_agent_job_under_five_minutes_is_still_caught() {- for expr in [- "*/3 * * * *",- "*/1 * * * *",- "*/4 * * * *",- "*/30 * * * * *",- ] {- let hit = agent_job_too_frequent(&cron_agent_job(expr))+#[tokio::test]+async fn a_cron_agent_job_under_five_minutes_is_still_caught() {+ let config = Config::default();+ for expr in ["*/3 * * * *", "1,2,30 * * * *"] {+ let hit = agent_job_too_frequent(&config, &cron_agent_job(expr))+ .await.unwrap_or_else(|| panic!("{expr} runs oftener than every 5 minutes and must warn"));assert!(hit.gap() < MIN_AGENT_JOB_INTERVAL, "{expr}: {hit}");}}-/// An irregular expression is judged by its tightest pair, whatever minute-/// the check happens to run at (CodeRabbit / Codex on #6159).-#[test]-fn an_irregular_cron_agent_job_is_judged_by_its_shortest_gap() {- for expr in ["1,2,30 * * * *", "0,1 * * * *", "0,3 9 * * *"] {- let hit = agent_job_too_frequent(&cron_agent_job(expr))- .unwrap_or_else(|| panic!("{expr} has two runs inside five minutes and must warn"));- assert!(hit.gap() <= ChronoDuration::minutes(3), "{expr}: {hit}");- }-}--/// Exactly five minutes is the boundary the message names, and it is not-/// over it. `*/5` is also the expression the codebase's own tests reach for,-/// so warning on it would train an operator to ignore the warning.-#[test]-fn a_cron_agent_job_at_exactly_five_minutes_is_not_high_frequency() {- assert!(agent_job_too_frequent(&cron_agent_job("*/5 * * * *")).is_none());- let every_five = agent_job_on(Schedule::Every {- every_ms: 5 * 60 * 1000,- });- assert!(agent_job_too_frequent(&every_five).is_none());-}--/// A schedule the arm cannot read is not evidence of anything, least of all-/// of running too often.-#[test]-fn an_unparseable_cron_expression_is_not_high_frequency() {- assert!(agent_job_too_frequent(&cron_agent_job("not a cron expression")).is_none());+/// A schedule the module cannot read is not evidence of anything, least of+/// all of running too often.+#[tokio::test]+async fn an_unparseable_cron_expression_is_not_high_frequency() {+ let config = Config::default();+ assert!(+ agent_job_too_frequent(&config, &cron_agent_job("not a cron expression"))+ .await+ .is_none()+ );}