Hub 2.19.0: the server agent's releases; Update agent picks one
- AgentRelease (migration 20261123150000_agent_release): the agent's releases, apart from the products' so licences and billing are untouched. - Release sources can be for the Server agent; the defaults include it (monorepo agent@ tags, apps/agent/WHATS-NEW.md). Same sync rules as products. A saved list without it gets an "Add the agent's source" button on the Releases page. - GET /api/admin/agent-releases; server summaries carry agentLatest; update-agent jobs go to a known agent release, the latest when none is asked for (agentTag). - Update agent is a ReleaseSelect with the chosen version's notes; the Servers list and a server's page say when a newer agent is out; the Releases page shows agent releases (Server agent filter, Everything newest first by date). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,20 @@
|
||||
// stub; the database is in memory.
|
||||
|
||||
const mockReleases = [];
|
||||
const mockAgentReleases = [];
|
||||
const mockSettings = { values: {} };
|
||||
const mockDb = {
|
||||
// Hub 2.19.0: the server agent's releases.
|
||||
agentRelease: {
|
||||
findMany: jest.fn(async ({ select } = {}) => (select ? mockAgentReleases.map(r => Object.fromEntries(Object.keys(select).map(k => [k, r[k]]))) : mockAgentReleases)),
|
||||
create: jest.fn(async ({ data }) => { const row = { id: `a${mockAgentReleases.length + 1}_${data.version}`, ...data }; mockAgentReleases.push(row); return row; }),
|
||||
update: jest.fn(async ({ where, data }) => Object.assign(mockAgentReleases.find(r => r.id === where.id), data)),
|
||||
deleteMany: jest.fn(async ({ where }) => {
|
||||
const ids = new Set(where.id.in);
|
||||
for (let i = mockAgentReleases.length - 1; i >= 0; i--) if (ids.has(mockAgentReleases[i].id)) mockAgentReleases.splice(i, 1);
|
||||
return { count: ids.size };
|
||||
}),
|
||||
},
|
||||
release: {
|
||||
findMany: jest.fn(async ({ where, select } = {}) => {
|
||||
const rows = mockReleases.filter(r => !where?.product || r.product === where.product);
|
||||
@@ -27,7 +39,7 @@ jest.mock('../src/utils/settings', () => ({
|
||||
}));
|
||||
|
||||
const { parseNotes, parseRequirements, tagPattern, defaultSources, cleanSources, releaseSources, syncReleases, PLATFORM_REPO } = require('../src/utils/releaseSync');
|
||||
const { unmetRequirements, latestByProduct } = require('../src/utils/releases');
|
||||
const { unmetRequirements, latestByProduct, agentTag, latestAgentVersion } = require('../src/utils/releases');
|
||||
|
||||
const LEGACY = 'https://c-git.crosscode.co.za/joshua/hope-events';
|
||||
const api = repo => `https://c-git.crosscode.co.za/api/v1/repos/joshua/${repo}`;
|
||||
@@ -49,15 +61,17 @@ global.fetch = jest.fn(async url => {
|
||||
|
||||
beforeEach(() => {
|
||||
mockReleases.length = 0;
|
||||
mockAgentReleases.length = 0;
|
||||
mockSettings.values = { release_repo_url: LEGACY, release_notes_path: 'WHATS-NEW.md' };
|
||||
gitea = {
|
||||
'hope-events': { tags: ['v2.0.0', 'v2.1.0', 'v2.1.1', 'not-a-version'], files: { 'WHATS-NEW.md': '## 2.1.1\n- Feedback in the background\n## 2.1.0\n- Feedback page' } },
|
||||
'crosscode-platform': {
|
||||
tags: ['contracts@1.0.0', 'contracts@1.1.0', 'events@2.2.0', 'events@3.0.0', 'accounts@1.2.0', 'website@1.0.0'],
|
||||
tags: ['contracts@1.0.0', 'contracts@1.1.0', 'events@2.2.0', 'events@3.0.0', 'accounts@1.2.0', 'website@1.0.0', 'agent@1.4.0', 'agent@1.5.0'],
|
||||
files: {
|
||||
'apps/events/WHATS-NEW.md': '## 3.0.0 — requires accounts 1.2.0\n- Sign in with your church account\n## 2.2.0\n- Moved into the monorepo',
|
||||
'apps/accounts/WHATS-NEW.md': '## 1.2.0\n- Authenticator app',
|
||||
'apps/website/WHATS-NEW.md': '## 1.0.0 — requires events 2.4.0\n- First release',
|
||||
'apps/agent/WHATS-NEW.md': '## 1.5.0 — urgent\n- One product of a church at a time\n## 1.4.0\n- frp config from the Hub',
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -66,13 +80,14 @@ beforeEach(() => {
|
||||
const versions = product => mockReleases.filter(r => r.product === product).map(r => r.version).sort();
|
||||
|
||||
describe('sources', () => {
|
||||
test('the defaults: every product from the monorepo, plus Cross Events from the repo set before 2.0', () => {
|
||||
test('the defaults: every product from the monorepo, plus Cross Events from the repo set before 2.0, and the agent', () => {
|
||||
expect(defaultSources(mockSettings.values)).toEqual([
|
||||
{ product: 'events', repo: PLATFORM_REPO, tagPrefix: 'events@', notesPath: 'apps/events/WHATS-NEW.md' },
|
||||
{ product: 'events', repo: LEGACY, tagPrefix: 'v', notesPath: 'WHATS-NEW.md' },
|
||||
{ product: 'accounts', repo: PLATFORM_REPO, tagPrefix: 'accounts@', notesPath: 'apps/accounts/WHATS-NEW.md' },
|
||||
{ product: 'website', repo: PLATFORM_REPO, tagPrefix: 'website@', notesPath: 'apps/website/WHATS-NEW.md' },
|
||||
{ product: 'app', repo: PLATFORM_REPO, tagPrefix: 'app@', notesPath: 'apps/app/WHATS-NEW.md' },
|
||||
{ product: 'agent', repo: PLATFORM_REPO, tagPrefix: 'agent@', notesPath: 'apps/agent/WHATS-NEW.md' },
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -81,6 +96,10 @@ describe('sources', () => {
|
||||
expect(releaseSources({ release_sources: JSON.stringify(saved) })).toEqual(saved);
|
||||
});
|
||||
|
||||
test('a source can be for the server agent', () => {
|
||||
expect(cleanSources([{ product: 'agent', repo: PLATFORM_REPO, tagPrefix: 'agent@', notesPath: 'apps/agent/WHATS-NEW.md' }])[0].product).toBe('agent');
|
||||
});
|
||||
|
||||
test('bad sources are refused with what is wrong', () => {
|
||||
expect(() => cleanSources([{ product: 'shop', repo: LEGACY }])).toThrow(/product/);
|
||||
expect(() => cleanSources([{ product: 'events', repo: 'not a url' }])).toThrow(/repository/);
|
||||
@@ -180,6 +199,49 @@ describe('sync', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('the server agent (2.19.0)', () => {
|
||||
const agentVersions = () => mockAgentReleases.map(r => r.version).sort();
|
||||
|
||||
test('its tags go to the agent releases, with notes, not to any product', async () => {
|
||||
await syncReleases();
|
||||
expect(agentVersions()).toEqual(['1.4.0', '1.5.0']);
|
||||
expect(mockReleases.some(r => r.version === '1.5.0' || r.version === '1.4.0')).toBe(false);
|
||||
const r = mockAgentReleases.find(x => x.version === '1.5.0');
|
||||
expect(r).toMatchObject({ notes: '- One product of a church at a time', urgent: true });
|
||||
expect(r).not.toHaveProperty('product');
|
||||
expect(r).not.toHaveProperty('requires');
|
||||
});
|
||||
|
||||
test('a removed tag removes its release; an unreachable source keeps them', async () => {
|
||||
await syncReleases();
|
||||
gitea['crosscode-platform'].tags = gitea['crosscode-platform'].tags.filter(t => t !== 'agent@1.4.0');
|
||||
await syncReleases();
|
||||
expect(agentVersions()).toEqual(['1.5.0']);
|
||||
gitea['crosscode-platform'] = 'down';
|
||||
await syncReleases();
|
||||
expect(agentVersions()).toEqual(['1.5.0']);
|
||||
});
|
||||
|
||||
test('a saved list without the agent leaves its releases alone', async () => {
|
||||
await syncReleases();
|
||||
mockSettings.values.release_sources = JSON.stringify([{ product: 'events', repo: LEGACY, tagPrefix: 'v', notesPath: 'WHATS-NEW.md' }]);
|
||||
await syncReleases();
|
||||
expect(agentVersions()).toEqual(['1.4.0', '1.5.0']);
|
||||
});
|
||||
|
||||
test('the latest, and the tag an update-agent job gets', async () => {
|
||||
await expect(agentTag('')).rejects.toMatchObject({ code: 'NO_RELEASE' });
|
||||
expect(await agentTag('agent@1.3.0')).toBe('agent@1.3.0'); // no agent releases yet: taken as asked
|
||||
await syncReleases();
|
||||
expect(await latestAgentVersion()).toBe('1.5.0');
|
||||
expect(await agentTag('')).toBe('agent@1.5.0');
|
||||
expect(await agentTag('1.4.0')).toBe('agent@1.4.0');
|
||||
expect(await agentTag('agent@1.4.0')).toBe('agent@1.4.0');
|
||||
await expect(agentTag('1.3.0')).rejects.toMatchObject({ code: 'NO_RELEASE' });
|
||||
await expect(agentTag('latest')).rejects.toMatchObject({ code: 'BAD_REQUEST' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('unmet requirements', () => {
|
||||
const releases = [
|
||||
{ version: '2.4.0', requires: [] },
|
||||
|
||||
Reference in New Issue
Block a user