Files
TREK/server/tests/unit/plugins/plugin-jobs.cron-compat.test.ts
T
Maurice 724c88c201 style: format server and shared with prettier
A mechanical prettier --write over server/src, server/tests, server/scripts
and shared/src with the workspaces' .prettierrc; nothing but layout and
import order changes, and every file keeps the same set of imports. shared
is formatted throughout and its format baseline is empty. The server
baseline keeps the 35 files that Prettier would grow past their lint:size
limit (they need a split first, which is not a formatting change), and the
generated entity files stay as their generator writes them.
2026-10-10 21:23:37 +02:00

44 lines
1.4 KiB
TypeScript

/**
* 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);
});
});