feat(db,schemas): add migration 004, runtime throttle profile, and v1.1 Zod schemas

This commit is contained in:
tyuXX 2026-11-27 22:15:50 +00:00
parent d7c3e11d7e
commit afc2d6358a
30 changed files with 792 additions and 118 deletions

View file

@ -141,6 +141,8 @@ describe('Phase 4: Workflows, Snippets, Fleet Broadcast & Cross-Server Transfers
return { status: res.status, data };
};
vi.useFakeTimers({ toFake: ['Date'] });
vi.setSystemTime(Date.now() - 35_000);
const bootInfo = await api('/api/auth/bootstrap');
const secretBase32 = String(bootInfo.data.secretBase32);
const totp = new OTPAuth.TOTP({
@ -161,7 +163,11 @@ describe('Phase 4: Workflows, Snippets, Fleet Broadcast & Cross-Server Transfers
initialSafeMode: false,
},
});
vi.useRealTimers();
csrfToken = String(boot.data.csrfToken);
expect(
(await api('/api/auth/step-up', { method: 'POST', body: { code: totp.generate() } })).status,
).toBe(200);
await api('/api/vault/init', { method: 'POST', body: {} });
const keyRes = await api('/api/vault/generate-ed25519', {
@ -751,20 +757,36 @@ describe('Phase 4: Workflows, Snippets, Fleet Broadcast & Cross-Server Transfers
expect(dCancelled.run.status).toBe('cancelled');
expect(dCancelled.run.cancelledBy).toBe('admin');
// --- 5. Cron Workflow Scheduling ---
await api('/api/workflows', {
// --- 5. Cron Workflow Scheduling (5-field enforced; 6-field rejected) ---
const badCronRes = await api('/api/workflows', {
method: 'POST',
body: {
id: 'wf-cron-bad',
name: '6-Field Spam Cron',
enabled: true,
trigger: { type: 'cron', expression: '* * * * * *', timezone: 'UTC' },
overlapPolicy: 'skip',
display: { mode: 'log' },
inputs: [],
steps: [{ id: 'tick', type: 'exec', target: { serverId: 'srv-b' }, command: 'echo NOPE' }],
},
});
expect(badCronRes.status).toBe(400);
const okCronRes = await api('/api/workflows', {
method: 'POST',
body: {
id: 'wf-cron-sec',
name: 'Every Second Cron',
name: 'Every Minute Cron',
enabled: true,
trigger: { type: 'cron', expression: '* * * * * *', timezone: 'UTC' },
trigger: { type: 'cron', expression: '* * * * *', timezone: 'UTC' },
overlapPolicy: 'skip',
display: { mode: 'log' },
inputs: [],
steps: [{ id: 'tick', type: 'exec', target: { serverId: 'srv-b' }, command: 'echo CRON_TICK' }],
},
});
expect(okCronRes.status).toBe(201);
const listSummary = await api('/api/workflows');
const cronSummary = (
@ -776,6 +798,7 @@ describe('Phase 4: Workflows, Snippets, Fleet Broadcast & Cross-Server Transfers
expect(typeof cronSummary?.nextRunAt).toBe('number');
expect(cronSummary!.nextRunAt!).toBeGreaterThan(Date.now() - 2000);
expect(await server.workflowEngine.triggerScheduledCron('wf-cron-sec')).toBe(true);
const cronRun = await waitFor(
() => {
const runs = server.workflowEngine.listRuns('wf-cron-sec');