Hub 2.6.0: paged lists, job status filters, one-product updates, installs found on servers
- Jobs: Succeeded/Cancelled filters, product, type and church search, paged on the server; audit log and alerts paged on the server with search; every other list paged. - Updates: one product at a time with its own releases; an Events update pins the church's Accounts (or updates it when the release needs it, or installs it first); fixes the requirement check comparing an object. - A status job adds installs found on a server and ties them to their registration; unlinked registered sites trigger one (daily); heartbeats tie install records too; the install page shows its registration. 13 new tests (209). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -289,6 +289,61 @@ describe('scheduled updates (§8)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('updates never mix products, and say what happens to Accounts (2.6.0)', () => {
|
||||
const at = () => new Date(NOW.getTime() + 5 * H);
|
||||
async function church(shortName, { accounts = null } = {}) {
|
||||
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 ev = await db.deployment.create({ data: { id: `ev-${shortName}`, serverId: server.id, customerId: 'cust-1', product: 'events', shortName, domain: `events.${shortName}.co.za`, webPort: 21000 + n, apiPort: 21001 + n, status: 'live', version: '2.4.0' } });
|
||||
let acc = null;
|
||||
if (accounts) acc = await db.deployment.create({ data: { id: `acc-${shortName}`, serverId: server.id, customerId: 'cust-1', product: 'accounts', shortName, domain: `accounts.${shortName}.co.za`, webPort: 21100 + n, apiPort: 21101 + n, status: 'live', version: accounts } });
|
||||
return { server, ev, acc };
|
||||
}
|
||||
beforeEach(async () => {
|
||||
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 } });
|
||||
});
|
||||
|
||||
test('Events and Accounts installs in one update are refused, and so is the wrong product\'s release', async () => {
|
||||
const { ev, acc } = await church('mix', { accounts: '1.1.0' });
|
||||
await expect(jobs.scheduleUpdate({ deploymentIds: [ev.id, acc.id], at: at() }, admin, NOW)).rejects.toMatchObject({ message: expect.stringContaining('one product') });
|
||||
await expect(jobs.scheduleUpdate({ deploymentIds: [ev.id], product: 'accounts', at: at() }, admin, NOW)).rejects.toMatchObject({ code: 'WRONG_PRODUCT' });
|
||||
await expect(jobs.scheduleUpdate({ deploymentIds: [ev.id], version: 'accounts@1.1.0', at: at() }, admin, NOW)).rejects.toMatchObject({ code: 'WRONG_PRODUCT' });
|
||||
await expect(jobs.scheduleUpdate({ deploymentIds: [acc.id], version: '3.0.0', at: at() }, admin, NOW)).rejects.toMatchObject({ code: 'NO_RELEASE' });
|
||||
});
|
||||
|
||||
test('an Events update keeps Accounts on the version it runs when nothing needs more', async () => {
|
||||
const { ev } = await church('keep', { accounts: '1.0.0' });
|
||||
const { jobs: [job], warnings } = await jobs.scheduleUpdate({ deploymentIds: [ev.id], version: '2.4.0', at: at() }, admin, NOW);
|
||||
expect(job.args).toEqual({ church: 'keep', products: ['events'], versions: ['accounts@1.0.0', 'events@2.4.0'] });
|
||||
expect(warnings.join(' ')).not.toContain('Accounts is updated');
|
||||
});
|
||||
|
||||
test('Events 3.0 updates an older Accounts in the same deploy, and says so', async () => {
|
||||
const { ev } = await church('older', { accounts: '1.0.0' });
|
||||
const { jobs: [job], warnings } = await jobs.scheduleUpdate({ deploymentIds: [ev.id], version: '3.0.0', at: at() }, admin, NOW);
|
||||
expect(job.args.versions).toEqual(['accounts@1.1.0', 'events@3.0.0']);
|
||||
expect(warnings.join(' ')).toContain('Accounts is updated from 1.0.0 to 1.1.0');
|
||||
});
|
||||
|
||||
test('a church without Accounts gets it installed first, then the update, in one batch', async () => {
|
||||
const { ev } = await church('none');
|
||||
const { jobs: made, batchId, warnings } = await jobs.scheduleUpdate({ deploymentIds: [ev.id], version: '3.0.0', at: at() }, admin, NOW);
|
||||
expect(batchId).toMatch(/^batch_/);
|
||||
expect(made.map(j => [j.type, j.status])).toEqual([['add-product', 'queued'], ['deploy', 'scheduled']]);
|
||||
expect(made[0].args).toMatchObject({ church: 'none', product: 'accounts', version: 'accounts@1.1.0', domain: 'accounts.none.co.za' });
|
||||
expect(made[1].args.versions).toEqual(['events@3.0.0']);
|
||||
expect(warnings.join(' ')).toContain('installed first at accounts.none.co.za');
|
||||
expect(await db.deployment.findFirst({ where: { shortName: 'none', product: 'accounts' } })).toMatchObject({ status: 'installing' });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('ports and alerts', () => {
|
||||
test('ports are unique, and a released one is reused only after 30 days', async () => {
|
||||
const { server } = await joinServer();
|
||||
@@ -556,3 +611,63 @@ describe('demo sites (2.4.0)', () => {
|
||||
expect(await db.job.findMany({})).toEqual([]);
|
||||
});
|
||||
});
|
||||
describe('sites added on a server are found and tied to their registration (2.6.0)', () => {
|
||||
const statusResult = (domain = 'accounts.found.co.za') => ({ churches: [{ church: 'found', address: 'found.co.za', products: [
|
||||
{ product: 'events', ref: 'events@2.4.1', domain: 'events.found.co.za', ports: '21201 21200' },
|
||||
{ product: 'accounts', ref: 'accounts@1.1.0', domain, ports: '21203 21202' },
|
||||
] }] });
|
||||
|
||||
test('a status report adds the Accounts the Hub didn\'t know, tied to its registered site, with its ports', async () => {
|
||||
const { server } = await joinServer();
|
||||
await db.deployment.create({ data: { id: 'ev-found', serverId: server.id, customerId: 'cust-1', product: 'events', shortName: 'found', domain: 'events.found.co.za', webPort: 21200, apiPort: 21201, status: 'live' } });
|
||||
const licence = await db.licence.create({ data: { id: 'lic-acc', customerId: 'cust-1', product: 'accounts', key: 'CCA-TEST', status: 'active' } });
|
||||
await db.install.create({ data: { id: 'inst-acc', customerId: 'cust-1', licenceId: licence.id, product: 'accounts', name: 'Found Accounts', url: 'https://accounts.found.co.za', secret: 'x', version: '1.1.0' } });
|
||||
const job = await jobs.runNow({ serverId: server.id, type: 'status', args: {} }, admin, NOW);
|
||||
await jobs.receiveReport(server, signedReport(job, 'succeeded', { result: statusResult() }), NOW);
|
||||
const acc = await db.deployment.findFirst({ where: { shortName: 'found', product: 'accounts' } });
|
||||
expect(acc).toMatchObject({ serverId: server.id, customerId: 'cust-1', installId: 'inst-acc', licenceId: 'lic-acc', domain: 'accounts.found.co.za', webPort: 21202, apiPort: 21203, version: '1.1.0', status: 'live' });
|
||||
expect((await db.port.findMany({ where: { deploymentId: acc.id } })).map(p => p.port).sort()).toEqual([21202, 21203]);
|
||||
expect((await db.job.findUnique({ where: { id: job.id } })).message).toContain('Added: found (Accounts');
|
||||
// A second report changes nothing.
|
||||
const again = await jobs.runNow({ serverId: server.id, type: 'status', args: {} }, admin, NOW);
|
||||
await jobs.receiveReport(server, signedReport(again, 'succeeded', { result: statusResult() }), NOW);
|
||||
expect(await db.deployment.count({ where: { shortName: 'found', product: 'accounts' } })).toBe(1);
|
||||
});
|
||||
|
||||
test('a registered site with no install record asks its customer\'s server what\'s on it, once a day', async () => {
|
||||
const { server } = await joinServer();
|
||||
await db.deployment.create({ data: { id: 'ev-ask', serverId: server.id, customerId: 'cust-1', product: 'events', shortName: 'ask', domain: 'events.ask.co.za', webPort: 21300, apiPort: 21301, status: 'live' } });
|
||||
const install = await db.install.create({ data: { id: 'inst-ask', customerId: 'cust-1', product: 'accounts', name: 'Ask Accounts', url: 'https://accounts.ask.co.za', secret: 'x', version: '1.1.0', releasedAt: null } });
|
||||
const job = await jobs.lookForUnlinked(install, NOW);
|
||||
expect(job).toMatchObject({ type: 'status', serverId: server.id, status: 'queued' });
|
||||
expect(await jobs.lookForUnlinked(install, new Date(NOW.getTime() + 3600e3))).toBeNull();
|
||||
});
|
||||
|
||||
test('a site the Hub installed, tied already, asks nothing', async () => {
|
||||
const { server } = await joinServer();
|
||||
const install = await db.install.create({ data: { id: 'inst-own', customerId: 'cust-1', product: 'events', name: 'Own', url: 'https://events.own.co.za', secret: 'x', releasedAt: null } });
|
||||
await db.deployment.create({ data: { id: 'ev-own', serverId: server.id, customerId: 'cust-1', installId: install.id, product: 'events', shortName: 'own', domain: 'events.own.co.za', webPort: 21400, apiPort: 21401, status: 'live' } });
|
||||
expect(await jobs.lookForUnlinked(install, NOW)).toBeNull();
|
||||
});
|
||||
});
|
||||
describe('the jobs list: every status, product, search and pages (2.6.0)', () => {
|
||||
const { pageOf, paged } = require('../src/utils/paging');
|
||||
const list = async (q) => paged(db.job, { where: await jobs.listWhere(q), orderBy: [{ notBefore: 'desc' }], include: { deployment: true } }, pageOf(q));
|
||||
|
||||
test('succeeded and cancelled can be listed, by product and church, a page at a time', async () => {
|
||||
const { server } = await joinServer();
|
||||
await db.deployment.create({ data: { id: 'd-ev', serverId: server.id, customerId: 'cust-1', product: 'events', shortName: 'hope', domain: 'events.hope.co.za', webPort: 22000, apiPort: 22001, status: 'live' } });
|
||||
await db.deployment.create({ data: { id: 'd-acc', serverId: server.id, customerId: 'cust-1', product: 'accounts', shortName: 'hope', domain: 'accounts.hope.co.za', webPort: 22002, apiPort: 22003, status: 'live' } });
|
||||
for (let i = 0; i < 7; i++) {
|
||||
await db.job.create({ data: { id: `job_test${i}0000`, serverId: server.id, type: 'deploy', deploymentId: i % 2 ? 'd-acc' : 'd-ev', status: i < 5 ? 'succeeded' : 'cancelled', args: {}, notBefore: new Date(NOW.getTime() + i * 60e3), expiresAt: NOW } });
|
||||
}
|
||||
const ok = await list({ status: 'succeeded', pageSize: '2' });
|
||||
expect([ok.total, ok.pages, ok.rows.length]).toEqual([5, 3, 2]);
|
||||
expect((await list({ status: 'succeeded', pageSize: '2', page: '3' })).rows.map(j => j.id)).toEqual(['job_test00000']);
|
||||
expect((await list({ status: 'cancelled' })).total).toBe(2);
|
||||
expect((await list({ product: 'accounts' })).rows.every(j => j.deployment.product === 'accounts')).toBe(true);
|
||||
expect((await list({ q: 'ACCOUNTS.hope' })).total).toBe(3);
|
||||
await expect(jobs.listWhere({ status: 'nonsense' })).rejects.toThrow('Unknown job status.');
|
||||
expect(pageOf({ pageSize: '100000' }).pageSize).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user