|
| 1 | +import { describe, it } from 'node:test'; |
| 2 | +import assert from 'node:assert'; |
| 3 | + |
| 4 | +import CherryPick from '../../lib/cherry_pick.js'; |
| 5 | + |
| 6 | +function stubCli() { |
| 7 | + return { |
| 8 | + warn() {}, |
| 9 | + ok() {}, |
| 10 | + log() {}, |
| 11 | + async prompt() { return 'CVE-2026-XXXXX'; } |
| 12 | + }; |
| 13 | +} |
| 14 | + |
| 15 | +describe('CherryPick: prototype wiring', () => { |
| 16 | + // `amend()` is borrowed from LandingSession and calls |
| 17 | + // `this.generateAmendedMessage()`, so it must be borrowed too. |
| 18 | + for (const method of [ |
| 19 | + 'downloadAndPatch', |
| 20 | + 'validateLint', |
| 21 | + 'getMessagePath', |
| 22 | + 'saveMessage', |
| 23 | + 'generateAmendedMessage' |
| 24 | + ]) { |
| 25 | + it(`borrows ${method} from LandingSession`, () => { |
| 26 | + assert.strictEqual(typeof CherryPick.prototype[method], 'function'); |
| 27 | + }); |
| 28 | + } |
| 29 | +}); |
| 30 | + |
| 31 | +describe('CherryPick: generateAmendedMessage', () => { |
| 32 | + it('adds the CVE-ID trailer from cveIds during a security cherry-pick', async() => { |
| 33 | + const cp = new CherryPick(896, process.cwd(), stubCli(), { |
| 34 | + owner: 'nodejs-private', |
| 35 | + repo: 'node-private', |
| 36 | + includeCVE: true, |
| 37 | + cveIds: ['CVE-2026-58044'] |
| 38 | + }); |
| 39 | + cp.metadata = 'PR-URL: https://github.com/nodejs-private/node-private/pull/896\n' + |
| 40 | + 'Reviewed-By: Robert Nagy <[email protected]>'; |
| 41 | + |
| 42 | + const original = 'sqlite: invalidate tag store iterators on statement reset\n\n' + |
| 43 | + 'PR-URL: https://github.com/nodejs/node/pull/123'; |
| 44 | + |
| 45 | + const amended = await cp.generateAmendedMessage(original); |
| 46 | + assert.match(amended, /CVE-ID: CVE-2026-58044/); |
| 47 | + }); |
| 48 | +}); |
0 commit comments