A release needs what every earlier release of its product needed (the highest version per product), so "requires accounts 1.7.0" is written once in WHATS-NEW.md. Fixes New install -> Website 1.0.1 sending a Website-only install job: its heading didn't repeat 1.0.0's requirement, so Accounts wasn't installed first and the agent refused the job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
3.6 KiB
JavaScript
94 lines
3.6 KiB
JavaScript
// Releases from git: reading the repo address and WHATS-NEW.md.
|
|
jest.mock('../src/config/db', () => ({}));
|
|
|
|
const { parseRepoUrl, parseNotes, inheritRequirements } = require('../src/utils/releaseSync');
|
|
|
|
test('the repository address becomes the Gitea API', () => {
|
|
expect(parseRepoUrl('https://c-git.crosscode.co.za/joshua/hope-events')).toEqual({ api: 'https://c-git.crosscode.co.za/api/v1/repos/joshua/hope-events', owner: 'joshua', repo: 'hope-events' });
|
|
expect(parseRepoUrl('https://c-git.crosscode.co.za/joshua/hope-events.git/').api).toBe('https://c-git.crosscode.co.za/api/v1/repos/joshua/hope-events');
|
|
expect(parseRepoUrl('https://c-git.crosscode.co.za/joshua')).toBeNull();
|
|
expect(parseRepoUrl('ftp://x/y/z')).toBeNull();
|
|
expect(parseRepoUrl('')).toBeNull();
|
|
});
|
|
|
|
describe('WHATS-NEW.md', () => {
|
|
const md = `# What's new in Cross Events
|
|
|
|
Intro text that isn't a release.
|
|
|
|
<!--
|
|
## 9.9.9
|
|
Hidden instructions are not a release.
|
|
-->
|
|
|
|
## 1.46.2 — urgent
|
|
|
|
- **See what's new** before you update, on the
|
|
Licence page.
|
|
- Uses \`code\` and [a link](https://example.com).
|
|
|
|
## [1.46.1] - 2026-10-28
|
|
|
|
Behind-the-scenes maintenance.
|
|
Nothing changes for you.
|
|
|
|
## v1.46.0 (security fix)
|
|
|
|
### Volunteers
|
|
- Rosters
|
|
- Swaps
|
|
`;
|
|
const notes = parseNotes(md);
|
|
|
|
test('one section per version; comments and the title are skipped', () => {
|
|
expect(Object.keys(notes).sort()).toEqual(['1.46.0', '1.46.1', '1.46.2']);
|
|
});
|
|
|
|
test('"urgent" or "security" in the heading marks it urgent', () => {
|
|
expect(notes['1.46.2'].urgent).toBe(true);
|
|
expect(notes['1.46.1'].urgent).toBe(false);
|
|
expect(notes['1.46.0'].urgent).toBe(true);
|
|
});
|
|
|
|
test('markup is removed, wrapped lines joined, list items kept', () => {
|
|
expect(notes['1.46.2'].notes).toBe("- See what's new before you update, on the Licence page.\n- Uses code and a link.");
|
|
expect(notes['1.46.1'].notes).toBe('Behind-the-scenes maintenance. Nothing changes for you.');
|
|
expect(notes['1.46.0'].notes).toBe('Volunteers\n- Rosters\n- Swaps');
|
|
});
|
|
|
|
test('no file means no notes', () => {
|
|
expect(parseNotes('')).toEqual({});
|
|
expect(parseNotes(null)).toEqual({});
|
|
});
|
|
});
|
|
|
|
describe('requirements carry forward (Hub 2.23.0)', () => {
|
|
const tagged = (entries) => new Map(entries.map(([v, requires]) => [v, { requires }]));
|
|
|
|
test('a later release needs what an earlier one needed, without repeating it', () => {
|
|
const out = inheritRequirements(tagged([
|
|
['1.0.1', []],
|
|
['1.0.0', [{ product: 'accounts', version: '1.7.0' }]],
|
|
['1.1.0', []],
|
|
]));
|
|
expect(out.get('1.0.0')).toEqual([{ product: 'accounts', version: '1.7.0' }]);
|
|
expect(out.get('1.0.1')).toEqual([{ product: 'accounts', version: '1.7.0' }]);
|
|
expect(out.get('1.1.0')).toEqual([{ product: 'accounts', version: '1.7.0' }]);
|
|
});
|
|
|
|
test('releases before the first requirement need nothing; a later heading raises it, never lowers it', () => {
|
|
const out = inheritRequirements(tagged([
|
|
['2.9.0', []],
|
|
['3.0.0', [{ product: 'accounts', version: '1.1.0' }]],
|
|
['3.1.0', [{ product: 'accounts', version: '1.2.0' }]],
|
|
['3.2.0', [{ product: 'accounts', version: '1.0.0' }, { product: 'website', version: '1.0.0' }]],
|
|
['3.10.0', []],
|
|
]));
|
|
expect(out.get('2.9.0')).toEqual([]);
|
|
expect(out.get('3.0.0')).toEqual([{ product: 'accounts', version: '1.1.0' }]);
|
|
expect(out.get('3.2.0')).toEqual([{ product: 'accounts', version: '1.2.0' }, { product: 'website', version: '1.0.0' }]);
|
|
// 3.10.0 sorts after 3.2.0 as a version, not as text.
|
|
expect(out.get('3.10.0')).toEqual([{ product: 'accounts', version: '1.2.0' }, { product: 'website', version: '1.0.0' }]);
|
|
});
|
|
});
|