import { describe, expect, it } from 'vitest' import { cleanCommentSummary, systemCommentText } from '../../src/gitea/issueComment' describe('cleanCommentSummary', () => { it('保留普通单行纯文本', () => { expect(cleanCommentSummary('好的我来看下')).toBe('好的我来看下') }) it('空文本返回空字符串', () => { expect(cleanCommentSummary('')).toBe('') }) it('去除 Markdown 引用(> 开头的行)', () => { const raw = `> 上一条评论的内容 > 引用多行 好的收到,马上修改` expect(cleanCommentSummary(raw)).toBe('好的收到,马上修改') }) it('当全部内容都是引用时,回退提取去掉 > 后的文字', () => { const raw = `> 收到回复` expect(cleanCommentSummary(raw)).toBe('收到回复') }) it('去除围栏代码块,保留正文', () => { const raw = `问题定位如下: \`\`\`ts const x = 1 console.log(x) \`\`\` 请检查修复。` expect(cleanCommentSummary(raw)).toBe('问题定位如下: 请检查修复。') }) it('清洗行内代码为纯文本', () => { expect(cleanCommentSummary('请检查 `coordinator.ts` 中的参数配置')).toBe('请检查 coordinator.ts 中的参数配置') }) it('清洗 Markdown 链接与图片', () => { const raw = '![效果图](https://img.example.com/pic.png) 请参考 [规范文档](https://example.com/doc) 进行修改' expect(cleanCommentSummary(raw)).toBe('请参考 规范文档 进行修改') }) it('去除 Markdown 表格线与表格符号', () => { const raw = `审查结论如下: | 模块 | 结果 | | --- | --- | | 登录 | 通过 | | 支付 | 待测 |` expect(cleanCommentSummary(raw)).toBe('审查结论如下: 模块 结果 登录 通过 支付 待测') }) it('去除粗体、斜体、删除线、标题符号', () => { const raw = '### **重要通知**:*今天* ~~不~~ 发布' expect(cleanCommentSummary(raw)).toBe('重要通知:今天 不 发布') }) it('去除任务列表标记与列表符号', () => { const raw = `- [x] 第一步\n- [ ] 第二步` expect(cleanCommentSummary(raw)).toBe('第一步 第二步') }) it('去除 HTML 注释', () => { const raw = '这是一条评论' expect(cleanCommentSummary(raw)).toBe('这是一条评论') }) it('单行截断:不超过 60 字符不截断,超过 60 字符截断并追加 ...', () => { const exact60 = 'a'.repeat(60) expect(cleanCommentSummary(exact60)).toBe(exact60) const over60 = 'b'.repeat(70) expect(cleanCommentSummary(over60)).toBe(`${'b'.repeat(60)}...`) }) }) describe('systemCommentText', () => { it('识别 review 评论', () => { expect(systemCommentText('评审意见')).toBe('评审意见') expect(systemCommentText('')).toBe('提交了审查') }) it('普通文本不是系统评论', () => { expect(systemCommentText('这是一条普通的讨论')).toBeUndefined() }) })