Files
superwork/vscode/webview-ui/src/lib/cherryPickView.test.ts
T
cruldra 028195ab2b ✨ feat(vscode): 摘修复识别 alembic 迁移,接不上发布分支链的高亮禁用不可摘
按 writing-alembic-migrations 的规矩判断:迁移的前任必须已在发布分支上,
且发布分支上该前任不能已有别的后继;根迁移接不上已有链、删迁移会断链也不可摘。
列表里带迁移的提交打「迁移」角标,不可摘的高亮警告色、禁用勾选并写明原因;
确认接口再校验一遍,绕过前端也摘不进去。

Claude-Session: https://claude.ai/code/session_01QWxLb6X8Vd2G5vHnp6R7qm
2026-09-08 11:44:24 +08:00

49 lines
1.7 KiB
TypeScript

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'])
})
})