Hub 2.7.0: emergency updates as soon as possible; events on now need a second yes
asap (emergency only, reason + 2FA) queues the update now; the church is told it's happening now. A church whose Events heartbeat reports an event on now (stats.live, Events 3.2.0) refuses an emergency update with LIVE_EVENT until confirmLive. Both update forms offer "As soon as possible" and ask again for a live event. Contracts 1.10.0 vendored. 4 new tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -682,3 +682,51 @@ describe('the jobs list only asks for statuses the database knows (2.6.1)', () =
|
||||
expect(await jobs.listWhere({ status: 'failed,expired' })).toEqual({ AND: [{ status: { in: ['failed', 'expired'] } }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe('emergency updates as soon as possible, and events on now (2.7.0)', () => {
|
||||
async function liveChurch(shortName, live = null, heardMinutesAgo = 5) {
|
||||
let server = await db.server.findFirst({ where: { name: 'church-1' } });
|
||||
if (!server) {
|
||||
server = (await joinServer()).server;
|
||||
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
|
||||
}
|
||||
const n = (await db.deployment.count()) * 2;
|
||||
const install = await db.install.create({ data: { id: `inst-${shortName}`, customerId: 'cust-1', product: 'events', name: shortName, url: `https://events.${shortName}.co.za`, secret: 'x', version: '2.3.0', lastHeartbeatAt: new Date(NOW.getTime() - heardMinutesAgo * 60e3), stats: live ? { live } : {}, adminContact: { name: 'Admin', email: `admin@${shortName}.test` } } });
|
||||
return db.deployment.create({ data: { id: `dep-${shortName}`, serverId: server.id, customerId: 'cust-1', installId: install.id, product: 'events', shortName, domain: `events.${shortName}.co.za`, webPort: 23000 + n, apiPort: 23001 + n, status: 'live' } });
|
||||
}
|
||||
const urgent = (ids, extra = {}) => jobs.scheduleUpdate({ deploymentIds: ids, version: '2.4.0', emergency: true, reason: 'Broken release', totp: totpNow(), ...extra }, admin, NOW);
|
||||
|
||||
test('as soon as possible: queued now for the agent\'s next poll, with the church told it\'s happening now', async () => {
|
||||
const d = await liveChurch('quick');
|
||||
const { jobs: [job] } = await urgent([d.id], { asap: true });
|
||||
expect(job).toMatchObject({ status: 'queued', emergency: true });
|
||||
expect(new Date(job.notBefore).getTime()).toBe(NOW.getTime());
|
||||
expect(mockMails.find(m => m.to === 'admin@quick.test')?.subject).toBe('Urgent: Cross Events is being updated now');
|
||||
const notice = await db.notice.findUnique({ where: { id: job.noticeId } });
|
||||
expect(notice.message).toContain('is being updated now');
|
||||
});
|
||||
|
||||
test('still an emergency only, with a reason and two-factor; at a time it\'s still 15 minutes', async () => {
|
||||
const d = await liveChurch('rules');
|
||||
await expect(jobs.scheduleUpdate({ deploymentIds: [d.id], version: '2.4.0', asap: true }, admin, NOW)).rejects.toMatchObject({ message: expect.stringContaining('Only an emergency') });
|
||||
await expect(urgent([d.id], { asap: true, reason: '' })).rejects.toMatchObject({ message: expect.stringContaining('reason') });
|
||||
await expect(urgent([d.id], { asap: true, totp: '000000' })).rejects.toMatchObject({ code: 'BAD_TOTP' });
|
||||
await expect(urgent([d.id], { at: new Date(NOW.getTime() + 5 * 60e3) })).rejects.toMatchObject({ code: 'TOO_SOON' });
|
||||
});
|
||||
|
||||
test('a church with an event on now is named, and the update waits for a second yes', async () => {
|
||||
const busy = await liveChurch('busy', { eventsNow: 1, checkInsLastHour: 37 });
|
||||
const calm = await liveChurch('calm', { eventsNow: 0, checkInsLastHour: 0 });
|
||||
await expect(urgent([busy.id, calm.id], { asap: true })).rejects.toMatchObject({ code: 'LIVE_EVENT', message: expect.stringContaining('busy (1 event(s) on now, 37 check-in(s) in the last hour)') });
|
||||
expect(await db.job.count()).toBe(0);
|
||||
const out = await urgent([busy.id, calm.id], { asap: true, confirmLive: true });
|
||||
expect(out.jobs).toHaveLength(2);
|
||||
expect(out.warnings.join(' ')).toContain('Updated while an event was on: busy');
|
||||
});
|
||||
|
||||
test('an old heartbeat, or one without live stats, doesn\'t hold an update back', async () => {
|
||||
const stale = await liveChurch('stale', { eventsNow: 3, checkInsLastHour: 0 }, 90);
|
||||
const older = await liveChurch('older');
|
||||
expect((await urgent([stale.id, older.id], { asap: true })).jobs).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user