import { beforeEach, describe, expect, it, vi } from 'vitest' const listComments = vi.fn() const addComment = vi.fn() vi.mock('../../src/youtrack/api', () => ({ listComments, addComment })) const auth = { baseUrl: 'https://yt.example', token: 't' } describe('youtrack 状态评论', () => { beforeEach(() => { listComments.mockReset() addComment.mockReset() }) it('读到旧标记格式写的状态,跳过客户后来的回复', async () => { const { readStateComment } = await import('../../src/youtrack/stateComment.js') listComments.mockResolvedValue([ { id: '1', text: '\n{"column":"todo"}' }, { id: '2', text: '\n{"column":"in-progress","branch":"feat/x"}' }, { id: '3', text: '客户后续补充:还是不行' }, ]) expect(await readStateComment(auth, 'LXF-1')).toEqual({ column: 'in-progress', branch: 'feat/x' }) }) it('合并后用隐藏格式写回', async () => { const { mergeStateComment } = await import('../../src/youtrack/stateComment.js') const { serializeStateComment } = await import('../../src/issues/stateComment.js') const comments = [{ id: '1', text: '{"column":"todo"}' }] listComments.mockImplementation(async () => [...comments]) addComment.mockImplementation(async (_auth: unknown, _id: string, text: string) => { comments.push({ id: String(comments.length + 1), text }) }) await mergeStateComment(auth, 'LXF-1', { branch: 'feat/y' }) expect(addComment).toHaveBeenCalledOnce() expect(addComment).toHaveBeenCalledWith(auth, 'LXF-1', serializeStateComment({ column: 'todo', branch: 'feat/y' })) }) })