Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

1.4 KB
Raw Blame
/**
 * Grammar-compat pin for the plugin job scheduler's node-cron → cron migration.
 *
 * A validation *tightening* would silently disable a published plugin's job
 * (an invalid cron is skipped, never scheduled — deliberately, so a bad
 * schedule can't take the host down). This runs the REAL `cron` validator
 * (unmocked) over the manifest shapes plugins realistically declare and pins
 * that everything node-cron accepted still schedules, and garbage still
 * doesn't.
 */
import { validateCronExpression } from 'cron';
import { describe, it, expect } from 'vitest';

const ACCEPTED = [
  '0 0 * * *', // nightly
  '*/5 * * * *', // step minutes
  '0 9 * * MON', // day-of-week name
  '0 9 * * sun', // lowercase name
  '0 9 * * 7', // 7-as-Sunday
  '0 0 1 JAN *', // month name
  '30 */2 * * 0-5', // range + step combined
  '1-5 * * * *', // minute range
  '*/30 * * * * *', // 6-field with seconds first
  '0 0 29 2 *', // leap-day
];

const REJECTED = [
  'not-a-cron',
  '',
  '* * *', // too few fields
  '61 * * * *', // minute out of range
  '0 24 * * *', // hour out of range
];

describe('plugin job cron grammar (real validator)', () => {
  it.each(ACCEPTED)('PJOB-COMPAT accepts %j', (expr) => {
    expect(validateCronExpression(expr).valid).toBe(true);
  });

  it.each(REJECTED)('PJOB-COMPAT rejects %j', (expr) => {
    expect(validateCronExpression(expr).valid).toBe(false);
  });
});