refactor(scheduler): drive scheduled-action metadata from a shared registry (#1428)

Scheduled-operation action metadata was duplicated across the backend route
validator, the DatabaseService action union, the desktop action picker, the
Timeline lanes, and the mobile labels/tones. Adding or renaming one action meant
editing all of them.

Introduce one registry per package as the single source within that package:

- backend/src/services/scheduledActionRegistry.ts owns the action list and
  target-type validation; routes/scheduledTasks.ts and DatabaseService import
  from it (BackendScheduledAction type, VALID_ACTIONS, validateActionTarget).
- frontend/src/lib/scheduledActions.ts owns the UI metadata (labels, short
  labels, categories, tones, target/node/stack/service flags, helper text) and
  drives the create-flow picker, the All Tasks label, the Timeline lanes, and
  the mobile schedule view.

Timeline lanes now group by semantic category (Lifecycle, Updates, Security,
Maintenance, Backups) sourced from the registry. The update-fleet UI alias is
made explicit via a backendAction field. Backend validation stays authoritative;
parity tests on each side keep the action sets in lockstep.
This commit is contained in:
Anso
2026-06-24 20:09:13 -04:00
committed by GitHub
parent 330f9f1acd
commit 0af7ad1df2
11 changed files with 551 additions and 123 deletions
@@ -0,0 +1,77 @@
/**
* Locks the backend scheduled-action registry: the action list stays in sync
* with what the route layer validates, and validateActionTarget reproduces the
* exact per-action error messages that are part of the API contract.
*/
import { describe, it, expect } from 'vitest';
import {
VALID_ACTIONS,
BACKEND_SCHEDULED_ACTIONS,
INVALID_ACTION_MESSAGE,
validateActionTarget,
type BackendScheduledAction,
type TargetType,
} from '../services/scheduledActionRegistry';
const EXPECTED_ACTIONS: BackendScheduledAction[] = [
'restart', 'snapshot', 'prune', 'update', 'scan',
'auto_backup', 'auto_stop', 'auto_down', 'auto_start',
];
const ALL_TARGET_TYPES: TargetType[] = ['stack', 'fleet', 'system'];
describe('scheduledActionRegistry', () => {
it('exposes exactly the known backend actions, in order', () => {
expect([...VALID_ACTIONS]).toEqual(EXPECTED_ACTIONS);
});
it('every valid action has a registry entry and vice versa', () => {
const entryIds = BACKEND_SCHEDULED_ACTIONS.map(a => a.id);
expect([...entryIds].sort()).toEqual([...VALID_ACTIONS].sort());
});
it('derives the invalid-action message from the action list', () => {
expect(INVALID_ACTION_MESSAGE).toBe(
'Invalid action. Must be restart, snapshot, prune, update, scan, auto_backup, auto_stop, auto_down, or auto_start.',
);
});
describe('validateActionTarget', () => {
const validPairs: Record<BackendScheduledAction, TargetType[]> = {
restart: ['stack'],
snapshot: ['fleet'],
prune: ['system'],
update: ['stack', 'fleet'],
scan: ['system'],
auto_backup: ['stack'],
auto_stop: ['stack'],
auto_down: ['stack'],
auto_start: ['stack'],
};
const mismatchMessage: Record<BackendScheduledAction, string> = {
restart: 'Restart action requires target_type "stack".',
snapshot: 'Snapshot action requires target_type "fleet".',
prune: 'Prune action requires target_type "system".',
update: 'Update action requires target_type "stack" or "fleet".',
scan: 'Scan action requires target_type "system".',
auto_backup: 'auto_backup action requires target_type "stack".',
auto_stop: 'auto_stop action requires target_type "stack".',
auto_down: 'auto_down action requires target_type "stack".',
auto_start: 'auto_start action requires target_type "stack".',
};
for (const action of EXPECTED_ACTIONS) {
it(`accepts valid and rejects invalid target types for ${action}`, () => {
for (const targetType of ALL_TARGET_TYPES) {
const result = validateActionTarget(action, targetType);
if (validPairs[action].includes(targetType)) {
expect(result).toBeNull();
} else {
expect(result).toBe(mismatchMessage[action]);
}
}
});
}
});
});