diff --git a/apps/sim/lib/workflows/code/apply/schedules.test.ts b/apps/sim/lib/workflows/code/apply/schedules.test.ts index b5f03b05a7d..0cd3f7ddb76 100644 --- a/apps/sim/lib/workflows/code/apply/schedules.test.ts +++ b/apps/sim/lib/workflows/code/apply/schedules.test.ts @@ -43,6 +43,33 @@ describe('findInvalidSchedules', () => { expect(refusal?.blockKey).toBe('nightly') }) + it.each([ + ['an interval over 1440', { scheduleType: 'minutes', minutesInterval: '5000' }], + ['a time without HH:MM', { scheduleType: 'daily', dailyTime: '9am' }], + [ + 'a day of the month over 31', + { scheduleType: 'monthly', monthlyDay: '40', monthlyTime: '09:00' }, + ], + ])( + 'names the bad value in %s instead of calling it missing or pointing to cron', + (_label, values) => { + const [refusal] = refusals(schedule('nightly', values)) + expect(refusal?.message).not.toMatch(/required/) + expect(refusal?.hint ?? '').not.toMatch(/cron/i) + } + ) + + it('keeps the cron and timezone hint for a timezone deploy cannot schedule in', () => { + const [refusal] = refusals( + schedule('nightly', { + scheduleType: 'daily', + dailyTime: '09:00', + timezone: 'Mars/Olympus_Mons', + }) + ) + expect(refusal?.hint).toMatch(/timezone/) + }) + it.each([ [ 'a valid cron in a timezone', diff --git a/apps/sim/lib/workflows/code/apply/schedules.ts b/apps/sim/lib/workflows/code/apply/schedules.ts index eae4baa543f..b996f2ee793 100644 --- a/apps/sim/lib/workflows/code/apply/schedules.ts +++ b/apps/sim/lib/workflows/code/apply/schedules.ts @@ -1,6 +1,10 @@ import type { Diagnostic } from '@sim/workflow-code' import type { GraphDiff, SourceGraph } from '@/lib/workflows/code/apply/graph-diff' -import { findScheduleBlocks, validateScheduleBlock } from '@/lib/workflows/schedules/validation' +import { + findScheduleBlocks, + hasValidScheduleConfig, + validateScheduleBlock, +} from '@/lib/workflows/schedules/validation' export type InvalidScheduleDiagnostic = Diagnostic<'E_APPLY_INVALID_SCHEDULE'> @@ -9,7 +13,9 @@ export type InvalidScheduleDiagnostic = Diagnostic<'E_APPLY_INVALID_SCHEDULE'> * deploy runs (`validateScheduleBlock`), so a dry run fails where deploy would instead of passing * and leaving deploy to refuse. A schedule whose type is still missing a field is a draft not * filled in yet; deploy refuses it, but the required-field gates own that, so it is not refused - * here. `keyOf` names a block's source key by id, to locate each refusal. + * here. Only a refusal whose timing fields pass gets the cron and timezone hint, since an + * out-of-range field's message already names its range. `keyOf` names a block's source key by + * id, to locate each refusal. */ export function findInvalidSchedules( target: SourceGraph, @@ -29,7 +35,11 @@ export function findInvalidSchedules( message: `Schedule "${block.name}" cannot run: ${result.error ?? 'its timing is invalid'}.`, blockId: block.id, ...(blockKey !== undefined ? { blockKey } : {}), - hint: 'Write a five-field cron expression (minute hour day-of-month month day-of-week) and an IANA timezone such as America/New_York; deploy refuses this schedule as written.', + ...(hasValidScheduleConfig(result.scheduleType, block) + ? { + hint: 'Write a five-field cron expression (minute hour day-of-month month day-of-week) and an IANA timezone such as America/New_York; deploy refuses this schedule as written.', + } + : {}), }) } return refusals diff --git a/apps/sim/lib/workflows/schedules/deploy.test.ts b/apps/sim/lib/workflows/schedules/deploy.test.ts index 451f1f89ab2..67bfcd0641c 100644 --- a/apps/sim/lib/workflows/schedules/deploy.test.ts +++ b/apps/sim/lib/workflows/schedules/deploy.test.ts @@ -155,7 +155,9 @@ describe('Schedule Deploy Utilities', () => { const result = validateScheduleBlock(block) expect(result.isValid).toBe(false) - expect(result.error).toBe('Minutes interval is required for minute-based schedules') + expect(result.error).toBe( + 'Minutes interval must be between 1 and 1440 for minute-based schedules' + ) }) }) @@ -193,7 +195,9 @@ describe('Schedule Deploy Utilities', () => { const result = validateScheduleBlock(block) expect(result.isValid).toBe(false) - expect(result.error).toBe('Day and time are required for monthly schedules') + expect(result.error).toBe( + 'Day must be between 1 and 31 and time must be HH:MM for monthly schedules' + ) }) }) diff --git a/apps/sim/lib/workflows/schedules/validation.ts b/apps/sim/lib/workflows/schedules/validation.ts index 40a853c374f..9a942537183 100644 --- a/apps/sim/lib/workflows/schedules/validation.ts +++ b/apps/sim/lib/workflows/schedules/validation.ts @@ -41,7 +41,10 @@ function isValidTimeValue(value: string | null | undefined): boolean { * Check if a schedule type has valid configuration * Uses raw block values to avoid false positives from default parsing */ -function hasValidScheduleConfig(scheduleType: string | undefined, block: BlockState): boolean { +export function hasValidScheduleConfig( + scheduleType: string | undefined, + block: BlockState +): boolean { switch (scheduleType) { case 'minutes': { const rawValue = getSubBlockValue(block, 'minutesInterval') @@ -113,6 +116,27 @@ function getMissingConfigError(scheduleType: string): string { } } +/** + * Get human-readable error message for schedule configuration that is filled in but cannot + * schedule (an out-of-range number or a time that is not HH:MM) + */ +function getInvalidConfigError(scheduleType: string): string { + switch (scheduleType) { + case 'minutes': + return 'Minutes interval must be between 1 and 1440 for minute-based schedules' + case 'hourly': + return 'Minute value must be between 0 and 59 for hourly schedules' + case 'daily': + return 'Time must be HH:MM for daily schedules' + case 'weekly': + return 'Time must be HH:MM for weekly schedules' + case 'monthly': + return 'Day must be between 1 and 31 and time must be HH:MM for monthly schedules' + default: + return getMissingConfigError(scheduleType) + } +} + /** * Find schedule blocks in a workflow's blocks * Only returns enabled schedule blocks (disabled blocks are skipped) @@ -150,7 +174,7 @@ export function validateScheduleBlock(block: BlockState): ScheduleValidationResu }) return { isValid: false, - error: getMissingConfigError(scheduleType), + error: missing ? getMissingConfigError(scheduleType) : getInvalidConfigError(scheduleType), reason: missing ? 'missing' : 'invalid', scheduleType, }