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.
This commit is contained in:
jubnl
2026-08-10 22:16:22 +02:00
parent f43aed762d
commit 08dac57577
9 changed files with 136 additions and 40 deletions
@@ -0,0 +1,43 @@
/**
* 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);
});
});
@@ -6,11 +6,11 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
const h = vi.hoisted(() => ({ tasks: [] as Array<{ expr: string; fn: () => void; stopped: boolean; stop(): void }> }));
vi.mock('node-cron', () => ({
default: {
validate: (expr: string) => typeof expr === 'string' && expr.trim() !== '' && expr !== 'not-a-cron',
schedule: (expr: string, fn: () => void) => {
const t = { expr, fn, stopped: false, stop() { this.stopped = true; } };
vi.mock('cron', () => ({
validateCronExpression: (expr: string) => ({ valid: typeof expr === 'string' && expr.trim() !== '' && expr !== 'not-a-cron' }),
CronJob: {
from: ({ cronTime, onTick }: { cronTime: string; onTick: () => void }) => {
const t = { expr: cronTime, fn: onTick, stopped: false, stop() { this.stopped = true; } };
h.tasks.push(t);
return t;
},