Hub 2.0 step 3: releases per product, with requirements
- Release.product and requires; unique (product, version); latest version per product (latest_version stays Cross Events' latest) - Release sources per product (Releases page): repository, tag prefix, notes file. Defaults: every product from crosscode-platform plus Cross Events' v1.2.3 tags from hope-events. A product's releases are only removed when all its sources were read and found tags - "— requires accounts 1.2.0" in a notes heading: Request update answers 409 REQUIREMENT_NOT_MET until the church's install of that product is new enough; install page and Releases page show it; v2 replies carry requires - @crosscode/contracts 1.1.0 vendored (optional requires on releases) - Alerts, dashboard and install lists compare against each product's latest Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,7 @@ const mockL_EVENTS = '2d0b5e4c-7f6a-4b8c-9d9e-3f4a5b6c7d8e';
|
||||
const mockL_WEBSITE = '3e1c6f5d-8a7b-4c9d-8eaf-4a5b6c7d8e9f';
|
||||
const mockL_OTHER = '4f2d7a6e-9b8c-4dae-9fb0-5b6c7d8e9fa0';
|
||||
const mockDb = (() => {
|
||||
const t = { licences: [], installs: [], events: [], heartbeats: [] };
|
||||
const t = { licences: [], installs: [], events: [], heartbeats: [], releases: [] };
|
||||
const id = p => `${p}_${crypto.randomUUID()}`;
|
||||
const customers = { [mockC1]: { id: mockC1, name: 'Hope Family Church' }, [mockC2]: { id: mockC2, name: 'Grace Church' } };
|
||||
const withLicence = l => l && { ...l, install: t.installs.find(i => i.licenceId === l.id) || null, customer: customers[l.customerId] };
|
||||
@@ -26,8 +26,9 @@ const mockDb = (() => {
|
||||
create: jest.fn(async ({ data }) => { const row = { id: crypto.randomUUID(), registeredAt: new Date(Date.now() + t.installs.length), releasedAt: null, ...data }; t.installs.push(row); return row; }),
|
||||
update: jest.fn(async ({ where, data }) => Object.assign(t.installs.find(i => i.id === where.id), Object.fromEntries(Object.entries(data).filter(([, v]) => v !== undefined)))),
|
||||
findMany: jest.fn(async ({ where, select }) => t.installs
|
||||
.filter(i => i.customerId === where.customerId && i.id !== where.id.not && i.releasedAt === null && i.publicKey != null)
|
||||
.filter(i => t.licences.find(l => l.id === i.licenceId)?.status !== 'revoked')
|
||||
.filter(i => i.customerId === where.customerId && i.id !== where.id.not && i.releasedAt === null)
|
||||
.filter(i => !where.publicKey || i.publicKey != null)
|
||||
.filter(i => !where.licence || t.licences.find(l => l.id === i.licenceId)?.status !== 'revoked')
|
||||
.sort((a, b) => a.registeredAt - b.registeredAt)
|
||||
.map(i => Object.fromEntries(Object.keys(select).map(k => [k, i[k]])))),
|
||||
},
|
||||
@@ -38,6 +39,7 @@ const mockDb = (() => {
|
||||
findMany: jest.fn(async () => []),
|
||||
},
|
||||
heartbeat: { create: jest.fn(async ({ data }) => { t.heartbeats.push(data); return data; }) },
|
||||
release: { findMany: jest.fn(async ({ where } = {}) => t.releases.filter(r => !where?.product || r.product === where.product)) },
|
||||
customer: { findUnique: jest.fn(async ({ where }) => customers[where.id]) },
|
||||
$transaction: jest.fn(async ops => Promise.all(ops)),
|
||||
};
|
||||
@@ -45,10 +47,7 @@ const mockDb = (() => {
|
||||
jest.mock('../src/config/db', () => mockDb);
|
||||
// Every test registers: the hourly register limit would cut in part-way through the file.
|
||||
jest.mock('express-rate-limit', () => () => (req, res, next) => next());
|
||||
jest.mock('../src/utils/settings', () => ({ getSettings: jest.fn(async () => ({ latest_version: '2.4.0' })) }));
|
||||
jest.mock('../src/utils/releases', () => ({
|
||||
releasesForInstall: jest.fn(async () => [{ version: '2.4.0', releasedAt: '2026-11-20T08:00:00.000Z', urgent: false, notes: '- Event feed' }]),
|
||||
}));
|
||||
jest.mock('../src/utils/settings', () => ({ getSettings: jest.fn(async () => ({})), setSettings: jest.fn(async () => ({})) }));
|
||||
jest.mock('../src/utils/notices', () => ({ noticesForInstall: jest.fn(async () => []) }));
|
||||
|
||||
process.env.HUB_ENCRYPTION_KEY = 'test-encryption-key-that-is-long-enough-123';
|
||||
@@ -80,6 +79,12 @@ afterAll(() => new Promise(resolve => server.close(resolve)));
|
||||
beforeEach(() => {
|
||||
const { t } = mockDb;
|
||||
t.installs.length = 0; t.events.length = 0; t.heartbeats.length = 0;
|
||||
t.releases.splice(0, t.releases.length,
|
||||
{ product: 'events', version: '2.4.0', releasedAt: new Date('2026-11-20T08:00:00Z'), urgent: false, notes: '- Event feed', requires: [] },
|
||||
{ product: 'events', version: '3.0.0', releasedAt: new Date('2026-12-01T08:00:00Z'), urgent: false, notes: '- Sign in with your church account', requires: [{ product: 'accounts', version: '1.2.0' }] },
|
||||
{ product: 'website', version: '1.0.0', releasedAt: new Date('2026-11-25T08:00:00Z'), urgent: false, notes: '- First release', requires: [] },
|
||||
{ product: 'website', version: '1.1.0', releasedAt: new Date('2026-12-05T08:00:00Z'), urgent: false, notes: '- Sermon series', requires: [] },
|
||||
);
|
||||
t.licences.splice(0, t.licences.length,
|
||||
{ id: mockL_EVENTS, customerId: mockC1, product: 'events', key: KEYS.events, status: 'active', plan: 'Grow', expiresAt: null, graceDays: 14, aiMonthlyCapCents: 0 },
|
||||
{ id: mockL_WEBSITE, customerId: mockC1, product: 'website', key: KEYS.website, status: 'active', plan: 'Website', expiresAt: null, graceDays: 14, aiMonthlyCapCents: 0 },
|
||||
@@ -191,11 +196,22 @@ describe('heartbeat', () => {
|
||||
expect(json.linkedProducts.map(l => [l.product, l.installId])).toEqual([['website', website.installId]]);
|
||||
});
|
||||
|
||||
test('releases are Cross Events\' only until releases per product', async () => {
|
||||
test('each product is told its own releases', async () => {
|
||||
const { json: website } = await register(websiteRegistration());
|
||||
expect(website).toMatchObject({ latestVersion: null, releases: [] });
|
||||
expect(website.latestVersion).toBe('1.1.0');
|
||||
expect(website.releases.map(r => r.version)).toEqual(['1.1.0']);
|
||||
const { json: events } = await register(eventsRegistration());
|
||||
expect(events.latestVersion).toBe('2.4.0');
|
||||
expect(events.latestVersion).toBe('3.0.0');
|
||||
expect(events.releases.map(r => r.version)).toEqual(['3.0.0', '2.4.0']);
|
||||
});
|
||||
|
||||
test('v2 replies carry requirements; v1 replies are as before', async () => {
|
||||
const { json: v2 } = await register(eventsRegistration());
|
||||
expect(v2.releases[0].requires).toEqual([{ product: 'accounts', version: '1.2.0' }]);
|
||||
expect(v2.releases[1]).not.toHaveProperty('requires');
|
||||
const r = eventsRegistration();
|
||||
const { json: v1 } = await register({ protocolVersion: 1, licenceKey: r.licenceKey, install: { name: r.install.name, url: r.install.url, version: '2.1.1' } });
|
||||
expect(v1.releases.every(x => !('requires' in x))).toBe(true);
|
||||
});
|
||||
|
||||
test('a heartbeat for another product is refused', async () => {
|
||||
@@ -238,11 +254,38 @@ describe('update requests (v2)', () => {
|
||||
expect((await res.json()).code).toBe('INVALID_REQUEST');
|
||||
});
|
||||
|
||||
test('a v2 request is recorded', async () => {
|
||||
test('an update that needs Accounts first is refused until Accounts is new enough', async () => {
|
||||
const { json: reg } = await register(eventsRegistration());
|
||||
const res = await signed('/installs/update-request', reg, { protocolVersion: 2, version: '2.3.0' });
|
||||
const json = await res.json();
|
||||
let res = await signed('/installs/update-request', reg, { protocolVersion: 2, version: '2.3.0' });
|
||||
let json = await res.json();
|
||||
expect(res.status).toBe(409);
|
||||
expect(json).toMatchObject({ code: 'REQUIREMENT_NOT_MET', requirements: [{ product: 'accounts', version: '1.2.0', current: null }] });
|
||||
expect(json.message).toContain('Accounts 1.2.0 or later must be installed first');
|
||||
|
||||
// The church's Accounts install, on 1.1.0: still refused, and the message says what it runs.
|
||||
mockDb.t.installs.push({ id: crypto.randomUUID(), customerId: mockC1, product: 'accounts', version: '1.1.0', releasedAt: null, registeredAt: new Date() });
|
||||
json = await (await signed('/installs/update-request', reg, { protocolVersion: 2, version: '2.3.0' })).json();
|
||||
expect(json.message).toContain('Accounts must be updated to 1.2.0 first (it runs 1.1.0)');
|
||||
|
||||
// On 1.2.0: the request goes through, and fits the contract.
|
||||
mockDb.t.installs.find(i => i.product === 'accounts').version = '1.2.0';
|
||||
res = await signed('/installs/update-request', reg, { protocolVersion: 2, version: '2.3.0' });
|
||||
json = await res.json();
|
||||
expect(res.status).toBe(201);
|
||||
expect(json.version).toBe('3.0.0');
|
||||
expect(hub.updateRequestResponseSchema.safeParse(json).error?.issues ?? []).toEqual([]);
|
||||
});
|
||||
|
||||
test('another church\'s Accounts doesn\'t count', async () => {
|
||||
mockDb.t.installs.push({ id: crypto.randomUUID(), customerId: mockC2, product: 'accounts', version: '9.0.0', releasedAt: null, registeredAt: new Date() });
|
||||
const { json: reg } = await register(eventsRegistration());
|
||||
const res = await signed('/installs/update-request', reg, { protocolVersion: 2, version: '2.3.0' });
|
||||
expect(res.status).toBe(409);
|
||||
});
|
||||
|
||||
test('a product with no requirements updates as before', async () => {
|
||||
const { json: reg } = await register(websiteRegistration());
|
||||
const res = await signed('/installs/update-request', reg, { protocolVersion: 2, version: '1.0.0' });
|
||||
expect(res.status).toBe(201);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user