import type { ReleaseCommitGroup } from './messages' import { describe, expect, it } from 'vitest' import { filterCherryPickGroups, pickableShas, uniqueAuthors } from './cherryPickView' const groups: ReleaseCommitGroup[] = [ { title: '未关联 PR', authors: ['cruldra'], commits: [ { sha: 'a', subject: 'chore: lone', author: 'cruldra', date: '2026-09-01', body: '' }, ], }, { pr: 260, title: '连续包月', authors: ['chehongweo', 'cruldra'], commits: [ { sha: 'b', subject: 'fix: admin', author: 'chehongweo', date: '2026-08-31', body: '' }, { sha: 'c', subject: 'fix: membership', author: 'cruldra', date: '2026-08-30', body: '' }, ], }, ] describe('filterCherryPickGroups', () => { it('只勾选的作者才出现', () => { const out = filterCherryPickGroups(groups, '', new Set(['chehongweo'])) expect(out).toHaveLength(1) expect(out[0].pr).toBe(260) expect(out[0].commits.map(c => c.sha)).toEqual(['b']) }) }) describe('uniqueAuthors', () => { it('按出现顺序去重', () => { expect(uniqueAuthors(groups)).toEqual(['cruldra', 'chehongweo']) }) }) describe('pickableShas', () => { it('带不兼容迁移的提交不能勾;兼容的迁移照常', () => { const commits = [ { sha: 'a', subject: 'ok', author: 'x', date: '', body: '' }, { sha: 'b', subject: 'mig ok', author: 'x', date: '', body: '', migration: { files: ['alembic/versions/0002.py'] } }, { sha: 'c', subject: 'mig bad', author: 'x', date: '', body: '', migration: { files: ['alembic/versions/0003.py'], blocked: '上游迁移 0002 不在 release/x' } }, ] expect(pickableShas(commits)).toEqual(['a', 'b']) }) })