Hub 2.24.0: update everything at a church to latest
A customer's Sites card has "Update everything to latest": every product that's behind, in one batch (Accounts first, one at a time, stopping at the first failure), scheduled or as an emergency, planned whole or not at all. Later products keep Accounts at the version the batch updates it to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1236,3 +1236,77 @@ describe('frps allow_ports and port labels (Hub 2.20.0)', () => {
|
||||
expect((await db.serverAlert.findFirst({ where: { serverId: central.id, type: 'allow_ports' } })).resolvedAt).toEqual(NOW);
|
||||
});
|
||||
});
|
||||
|
||||
describe('a whole church to latest in one go (2.24.0)', () => {
|
||||
const at = () => new Date(NOW.getTime() + 5 * H);
|
||||
async function church() {
|
||||
const { server } = await joinServer();
|
||||
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
|
||||
await db.release.create({ data: { id: 'r30', product: 'events', version: '3.0.0', notes: '- Accounts', requires: [{ product: 'accounts', version: '1.1.0' }], releasedAt: NOW } });
|
||||
await db.release.create({ data: { id: 'ra10', product: 'accounts', version: '1.0.0', releasedAt: NOW } });
|
||||
await db.release.create({ data: { id: 'ra11', product: 'accounts', version: '1.1.0', releasedAt: NOW } });
|
||||
await db.release.create({ data: { id: 'rw10', product: 'website', version: '1.0.0', releasedAt: NOW } });
|
||||
const dep = (id, product, version, port) => db.deployment.create({ data: { id, serverId: server.id, customerId: 'cust-1', product, shortName: 'hope', domain: `${product}.hope.co.za`, webPort: port, apiPort: port + 1, status: 'live', version } });
|
||||
const ev = await dep('ev-hope', 'events', '2.4.0', 22000);
|
||||
const acc = await dep('acc-hope', 'accounts', '1.0.0', 22010);
|
||||
const web = await dep('web-hope', 'website', '1.0.0', 22020);
|
||||
return { server, ev, acc, web };
|
||||
}
|
||||
|
||||
test('the plan lists every product in update order, Accounts first, and says which are behind', async () => {
|
||||
await church();
|
||||
const plan = await jobs.churchUpdatePlan('cust-1');
|
||||
expect(plan.map(p => [p.product, p.current, p.latest, p.ready])).toEqual([
|
||||
['accounts', '1.0.0', '1.1.0', true], ['events', '2.4.0', '3.0.0', true], ['website', '1.0.0', '1.0.0', false],
|
||||
]);
|
||||
expect(plan[2].why).toBe('On the latest release.');
|
||||
});
|
||||
|
||||
test('one batch: Accounts first, then Events, which keeps the new Accounts; up to date products are left alone', async () => {
|
||||
const { server } = await church();
|
||||
const out = await jobs.scheduleChurchUpdate('cust-1', { at: at() }, admin, NOW);
|
||||
expect(out.batchId).toMatch(/^batch_/);
|
||||
expect(out.jobs.map(j => [j.deploymentId, j.status, j.batchOrder, j.batchId])).toEqual([
|
||||
['acc-hope', 'queued', 0, out.batchId], ['ev-hope', 'scheduled', 1, out.batchId],
|
||||
]);
|
||||
expect(out.jobs[0].args.versions).toEqual(['accounts@1.1.0']);
|
||||
// Not accounts@1.0.0: that would undo the update just before it.
|
||||
expect(out.jobs[1].args.versions).toEqual(['accounts@1.1.0', 'events@3.0.0']);
|
||||
expect(out.updates).toEqual([
|
||||
{ product: 'accounts', domain: 'accounts.hope.co.za', from: '1.0.0', to: '1.1.0' },
|
||||
{ product: 'events', domain: 'events.hope.co.za', from: '2.4.0', to: '3.0.0' },
|
||||
]);
|
||||
// The batch runs on: Accounts succeeds, so Events is queued.
|
||||
const poll = when => jobs.poll(server, { agentApiVersion: 1, agentVersion: '1.0.0', mode: 'church', runningJobId: null }, when);
|
||||
const first = (await poll(at())).jobs[0];
|
||||
expect(first.id).toBe(out.jobs[0].id);
|
||||
await jobs.receiveReport(server, signedReport(first, 'succeeded'), at());
|
||||
expect((await db.job.findUnique({ where: { id: out.jobs[1].id } })).status).toBe('queued');
|
||||
// Everything is planned now: a second click is refused.
|
||||
await expect(jobs.scheduleChurchUpdate('cust-1', { at: at() }, admin, NOW)).rejects.toMatchObject({ code: 'NOT_READY' });
|
||||
});
|
||||
|
||||
test('planned whole or not at all, and refused when there is nothing to update', async () => {
|
||||
const { ev } = await church();
|
||||
await jobs.scheduleUpdate({ deploymentIds: [ev.id], version: '2.4.0', at: at() }, admin, NOW).catch(() => null);
|
||||
const { jobs: [planned] } = await jobs.scheduleUpdate({ deploymentIds: ['acc-hope'], version: '1.1.0', at: at() }, admin, NOW);
|
||||
const before = await db.job.count();
|
||||
await expect(jobs.scheduleChurchUpdate('cust-1', { at: at() }, admin, NOW)).rejects.toMatchObject({ code: 'NOT_READY', message: expect.stringContaining('Accounts (accounts.hope.co.za): An update is planned') });
|
||||
expect(await db.job.count()).toBe(before);
|
||||
expect(planned.status).toBe('queued');
|
||||
|
||||
await db.deployment.update({ where: { id: 'ev-hope' }, data: { version: '3.0.0' } });
|
||||
await db.deployment.update({ where: { id: 'acc-hope' }, data: { version: '1.1.0' } });
|
||||
await db.job.update({ where: { id: planned.id }, data: { status: 'cancelled' } });
|
||||
await expect(jobs.scheduleChurchUpdate('cust-1', { at: at() }, admin, NOW)).rejects.toMatchObject({ code: 'UP_TO_DATE' });
|
||||
});
|
||||
|
||||
test('an emergency runs as soon as possible, with a reason and one two-factor code', async () => {
|
||||
await church();
|
||||
await expect(jobs.scheduleChurchUpdate('cust-1', { emergency: true, asap: true, reason: 'Security fix', totp: '000000' }, admin, NOW)).rejects.toMatchObject({ code: 'BAD_TOTP' });
|
||||
await expect(jobs.scheduleChurchUpdate('cust-1', { emergency: true, asap: true, totp: totpNow() }, admin, NOW)).rejects.toMatchObject({ message: expect.stringContaining('reason') });
|
||||
const out = await jobs.scheduleChurchUpdate('cust-1', { emergency: true, asap: true, reason: 'Security fix', totp: totpNow() }, admin, NOW);
|
||||
expect(out.jobs.map(j => [j.emergency, j.reason, j.status])).toEqual([[true, 'Security fix', 'queued'], [true, 'Security fix', 'scheduled']]);
|
||||
expect(out.jobs[0].notBefore).toEqual(NOW);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user