Files
TREK/server/tests/unit/plugins/plugin-jobs.cron-compat.test.ts
jubnl 08dac57577 refactor(server): migrate plugin jobs off node-cron
The plugin host's job scheduler now uses the cron package (the one
@nestjs/schedule wraps), so node-cron and @types/node-cron leave the
dependency tree entirely. Verified against both real libraries that the
accepted cron grammar is identical — no plugin's declared schedule tightens —
and pinned that with an unmocked compat test.
2026-08-10 22:16:22 +02:00

44 lines
1.5 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 { describe, it, expect } from 'vitest';
import { validateCronExpression } from 'cron';
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);
});
});