import { afterEach, describe, expect, it, vi } from 'vitest' import { api } from '../src/api' import { auth } from '../src/auth' afterEach(() => vi.restoreAllMocks()) describe('versioned work request bodies', () => { it('preserves multiple selections and free input on the card action endpoint', async () => { const request = vi.spyOn(auth, 'fetch').mockResolvedValue(new Response(JSON.stringify({ card: { id: 'task' } }))) await api.cardAction('task', 'work.submit', { resultVersion: 3, selectedIds: ['summary', 'parameters'], freeText: '请说明依据' }) const [url, options] = request.mock.calls[0] expect(url).toBe('/api/cards/task/actions/work.submit') expect(JSON.parse(String(options?.body))).toEqual({ resultVersion: 3, selectedIds: ['summary', 'parameters'], freeText: '请说明依据' }) }) it('sends a result identity separately from the user message and discards client display metadata', async () => { const request = vi.spyOn(auth, 'fetch').mockResolvedValue(new Response(JSON.stringify({ message: { id: 'reply' } }))) const reference = { cardId: 'task', resultVersion: 3, title: '说明书整理', result: 'must-not-be-client-context' } await api.sendMessage('conversation', '比较这些重点', [], 'request-1', reference) expect(JSON.parse(String(request.mock.calls[0][1]?.body))).toEqual({ text: '比较这些重点', attachmentIds: [], requestId: 'request-1', taskRef: { cardId: 'task', resultVersion: 3 }, }) }) })