import { describe, expect, it } from 'vitest' import { isDraftPr, renderPrBody } from './pr-body.mjs' const repoUrl = 'https://github.com/payloadcms/payload' const runUrl = 'https://github.com/payloadcms/payload/actions/runs/1' const now = new Date('2026-09-10T00:00:00Z') const compareUrl = 'https://github.com/adaltas/node-csv/compare/csv-parse@5.6.0...csv-parse@7.0.2' const MAJOR_BANNER = 'Major version: no automated review. Read the release notes and check breaking changes before you merge.' const ZERO_WIDTH_SPACE = '​' const csvBump = { id: 'csv-parse-7', dependency: 'csv-parse', from: '5.6.0', fromVersion: '5.6.0', to: '7.0.2', isMajor: true, manifests: ['packages/plugin-import-export/package.json'], advisories: ['GHSA-8cw4-87c7-c6xx'], } const csvDetails = { notes: { entries: [ { version: '7.0.0', url: 'https://github.com/adaltas/node-csv/blob/csv-parse@7.0.0/packages/csv-parse/CHANGELOG.md', text: '# 7.0.0\n\nWARNING: published by mistake.', isMajor: true, }, ], links: { releases: null, changelog: 'https://github.com/adaltas/node-csv/blob/main/packages/csv-parse/CHANGELOG.md', compare: compareUrl, }, source: 'changelog', }, commits: { commits: [ { sha: 'eb4d148aaaaaaaa', message: 'fix(csv-parse): prototype replacement\n\nbody', url: 'https://github.com/adaltas/node-csv/commit/eb4d148aaaaaaaa', }, ], total: 12, compareUrl, repoMoved: false, releaseLinks: [], }, advisories: [ { ghsa: 'GHSA-8cw4-87c7-c6xx', summary: 'Prototype replacement still reachable via columns path', description: 'Impact text.', severity: 'moderate', }, ], packageMeta: { repo: { owner: 'adaltas', name: 'node-csv', directory: 'packages/csv-parse' }, publishedAt: '2026-06-13T00:00:00Z', }, downloads: 3685407, affects: { direct: [{ name: '@payloadcms/plugin-import-export', dir: 'plugin-import-export' }], via: [], }, } const noNotes = { ...csvDetails, notes: { entries: [], links: { releases: null, changelog: null, compare: null }, source: 'none' }, } function render({ pr = { id: 'csv-parse-7', kind: 'major', branch: 'b', bumpIds: [csvBump.id] }, bumps = [csvBump], details = { [csvBump.id]: csvDetails }, fixed = csvBump.advisories, partly = [], } = {}) { return renderPrBody({ pr, bumps, details, fixed, partly, scope: 'consumer-facing', severity: 'moderate', ref: 'main', repoUrl, runUrl, now, }) } function renderCsv({ details }) { return render({ details: { [csvBump.id]: details } }) } function renderGroup({ bumps, details }) { return render({ pr: { id: 'non-major', kind: 'group', branch: 'b', bumpIds: bumps.map((bump) => bump.id) }, bumps, details: Object.fromEntries(bumps.map((bump) => [bump.id, details])), fixed: [], }) } function withNoteText({ text }) { return { ...csvDetails.notes, entries: [{ ...csvDetails.notes.entries[0], text }] } } describe('major review banner', () => { it('should start a major body with the review banner, naming missing notes only when absent', () => { const withNotes = renderCsv({ details: csvDetails }).split('\n') const withoutNotes = renderCsv({ details: noNotes }).split('\n') expect(withNotes[0]).toBe(MAJOR_BANNER) expect(withNotes.slice(0, 3).join('\n')).not.toContain('No release notes found for') expect(withoutNotes[0]).toBe(MAJOR_BANNER) expect(withoutNotes[1]).toBe('No release notes found for 7.x.') }) it('should draft every major PR and no group PR', () => { expect(isDraftPr({ pr: { kind: 'major' } })).toBe(true) expect(isDraftPr({ pr: { kind: 'group' } })).toBe(false) }) }) describe('partly fixed advisories', () => { it('should render partly in the Fixes column and the lead line', () => { const partlyAdvisory = { ghsa: 'GHSA-w5hq-cccc-ffff', summary: 'other', description: '', severity: 'high', } const body = render({ details: { [csvBump.id]: { ...csvDetails, advisories: [...csvDetails.advisories, partlyAdvisory] }, }, partly: [partlyAdvisory.ghsa], }) expect(body).toContain('partly [w5hq](https://github.com/advisories/GHSA-w5hq-cccc-ffff)') expect(body).toContain( 'This PR fixes 1 advisory (consumer-facing, moderate+). 1 more is partly fixed.', ) }) }) describe('outside text', () => { it('should not let outside text break structure', () => { const evil = 'x -->