From 89f4fba2a96eb79497702bedf76c70faae6043d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B6=85=E6=B8=A1=E6=B3=95=E5=B8=AB?= Date: Thu, 30 Apr 2026 05:55:07 +0000 Subject: [PATCH] fix(cron): skip validation for disabled cronjobs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit validate_cronjobs() now skips jobs with enabled=false, aligning startup validation with runtime scheduling semantics. Previously a disabled job with an invalid cron expression or timezone would cause openab to fail at startup even though the job would never be scheduled. Discovered during four-monk review of PR #638. Co-authored-by: 擺渡法師 --- src/cron.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/cron.rs b/src/cron.rs index cd0eae3b..ce5245ec 100644 --- a/src/cron.rs +++ b/src/cron.rs @@ -41,6 +41,7 @@ const VALID_PLATFORMS: &[&str] = &["discord", "slack"]; /// Validate all cronjob configs (fail-fast on bad cron expressions or timezones). pub fn validate_cronjobs(cronjobs: &[CronJobConfig], configured_platforms: &[&str]) -> anyhow::Result<()> { for (i, job) in cronjobs.iter().enumerate() { + if !job.enabled { continue; } parse_cron_expr(&job.schedule).map_err(|e| { anyhow::anyhow!("cronjobs[{i}]: invalid cron expression {:?}: {e}", job.schedule) })?; @@ -611,6 +612,26 @@ platform = "slack" assert!(err.to_string().contains("not configured")); } + #[test] + fn validate_cronjobs_disabled_with_invalid_cron_passes() { + let jobs = vec![CronJobConfig { + enabled: false, schedule: "bad".into(), channel: "123".into(), + message: "hi".into(), platform: "discord".into(), sender_name: "test".into(), + thread_id: None, timezone: "UTC".into(), + }]; + assert!(validate_cronjobs(&jobs, &["discord"]).is_ok()); + } + + #[test] + fn validate_cronjobs_enabled_with_invalid_cron_still_fails() { + let jobs = vec![CronJobConfig { + enabled: true, schedule: "bad".into(), channel: "123".into(), + message: "hi".into(), platform: "discord".into(), sender_name: "test".into(), + thread_id: None, timezone: "UTC".into(), + }]; + assert!(validate_cronjobs(&jobs, &["discord"]).is_err()); + } + // --- file_mtime tests --- #[test]