Hub 2.5.0: a New install of Events 3.x installs the church's Accounts first

A release's "requires accounts" is met at install: Accounts then the
product in one batch (the product runs only after Accounts succeeded; a
failed Accounts fails the product's record and frees its ports). Accounts
domain from the form, or accounts.<rest of the domain>. An Accounts older
than required is refused. Contracts 1.8.0 vendored. 4 new tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 14:17:58 +02:00
co-authored by Claude Opus 5.5
parent 575c0cac68
commit 05d043e0a3
10 changed files with 172 additions and 24 deletions
+63
View File
@@ -397,6 +397,69 @@ describe('Accounts from the Hub (2.3.0)', () => {
});
});
describe('Cross Events 3.0 brings its Accounts (2.5.0)', () => {
const poll = (server) => jobs.poll(server, { agentApiVersion: 1, agentVersion: '1.1.0', mode: 'church', runningJobId: null }, NOW);
beforeEach(async () => {
await db.release.create({ data: { id: 'r3', product: 'events', version: '3.0.0', notes: '- Sign-in through Accounts', requires: [{ product: 'accounts', version: '1.1.0' }], releasedAt: NOW } });
await db.release.create({ data: { id: 'ra1', product: 'accounts', version: '1.0.0', notes: '- First release', releasedAt: NOW } });
await db.release.create({ data: { id: 'ra2', product: 'accounts', version: '1.1.0', notes: '- For Events 3.0', releasedAt: NOW } });
});
test('a new church gets Accounts installed first, then Events next to it once that succeeded', async () => {
const { server } = await joinServer();
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
const out = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'grace', domain: 'events.grace.co.za' }, admin, NOW);
expect(out.alsoInstalling).toEqual({ product: 'accounts', domain: 'accounts.grace.co.za', version: '1.1.0' });
const accounts = await db.deployment.findFirst({ where: { shortName: 'grace', product: 'accounts' } });
expect(accounts).toMatchObject({ status: 'installing', domain: 'accounts.grace.co.za' });
// Only Accounts runs now.
const [first] = (await poll(server)).jobs;
expect(first).toMatchObject({ type: 'install', args: { products: ['accounts'], versions: { accounts: 'accounts@1.1.0' } } });
expect(signing.openConfig(first.config, keys.x.privateKeyPem).install.accounts.HUB_LICENCE_KEY).toMatch(/^CCA-/);
expect((await poll(server)).jobs).toEqual([]);
await jobs.receiveReport(server, signedReport(first, 'succeeded', { result: { versions: { accounts: 'accounts@1.1.0' } } }), NOW);
// Then Events, added next to it.
const [second] = (await poll(server)).jobs;
expect(second).toMatchObject({ type: 'add-product', args: { church: 'grace', product: 'events', version: 'events@3.0.0', domain: 'events.grace.co.za' } });
expect(agent.agentJobSchema.safeParse(second).success).toBe(true);
});
test('when Accounts fails, Events never runs and its ports are freed', async () => {
const { server } = await joinServer();
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
const out = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'grace', domain: 'events.grace.co.za', accountsDomain: 'login.grace.co.za' }, admin, NOW);
expect(out.alsoInstalling.domain).toBe('login.grace.co.za');
const [first] = (await poll(server)).jobs;
await jobs.receiveReport(server, signedReport(first, 'failed'), NOW);
expect(await db.deployment.findUnique({ where: { id: out.deployment.id } })).toMatchObject({ status: 'failed' });
expect(await db.port.findMany({ where: { port: { in: [out.deployment.webPort, out.deployment.apiPort] } } })).toEqual([]);
expect((await poll(server)).jobs).toEqual([]);
});
test("a church whose Accounts is older than Events 3.0 needs is refused; a new enough one isn't installed again", async () => {
const { server } = await joinServer();
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
const a = await jobs.newInstall({ product: 'accounts', customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'accounts.hope.co.za', version: '1.0.0' }, admin, NOW);
await db.deployment.update({ where: { id: a.deployment.id }, data: { status: 'live', version: '1.0.0' } });
await db.job.updateMany({ where: { deploymentId: a.deployment.id }, data: { status: 'succeeded' } });
await expect(jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW)).rejects.toMatchObject({ code: 'REQUIREMENT_NOT_MET' });
await db.deployment.update({ where: { id: a.deployment.id }, data: { version: '1.1.0' } });
const out = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW);
expect(out.alsoInstalling).toBeUndefined();
const [job] = (await poll(server)).jobs;
expect(job).toMatchObject({ type: 'add-product', args: { product: 'events', version: 'events@3.0.0' } });
});
test('Events 2.x installs as before, without Accounts', async () => {
const { server } = await joinServer();
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
const out = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'old', domain: 'events.old.co.za', version: '2.4.0' }, admin, NOW);
expect(out.alsoInstalling).toBeUndefined();
expect(await db.deployment.findFirst({ where: { shortName: 'old', product: 'accounts' } })).toBeNull();
});
});
describe('settings for servers (found in the VM test)', () => {
test('install defaults, the port range and the central IP are saved', async () => {
const { setSettings } = require('../src/utils/settings');