40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
import type { UIMessage } from 'ai'
|
|
import {
|
|
hasCompletedPascalAgentResponse,
|
|
parsePendingPascalAgentRun,
|
|
} from './pascal-agent-recovery'
|
|
|
|
describe('Pascal agent conversation recovery', () => {
|
|
test('parses valid pending runs and rejects incomplete values', () => {
|
|
const pending = {
|
|
conversationId: crypto.randomUUID(),
|
|
startedAt: Date.now(),
|
|
userMessageId: crypto.randomUUID(),
|
|
}
|
|
expect(parsePendingPascalAgentRun(JSON.stringify(pending))).toEqual(pending)
|
|
expect(parsePendingPascalAgentRun('{"conversationId":"missing-fields"}')).toBeNull()
|
|
expect(parsePendingPascalAgentRun('invalid')).toBeNull()
|
|
})
|
|
|
|
test('detects a completed assistant response after the submitted message', () => {
|
|
const userMessageId = crypto.randomUUID()
|
|
const messages: UIMessage[] = [
|
|
{ id: userMessageId, role: 'user', parts: [{ type: 'text', text: '调整布局' }] },
|
|
{
|
|
id: crypto.randomUUID(),
|
|
role: 'assistant',
|
|
parts: [
|
|
{
|
|
type: 'data-pascal-tool-activity',
|
|
data: { state: 'output-available', toolName: 'apply_patch' },
|
|
},
|
|
],
|
|
},
|
|
]
|
|
|
|
expect(hasCompletedPascalAgentResponse(messages, userMessageId)).toBe(true)
|
|
expect(hasCompletedPascalAgentResponse(messages, crypto.randomUUID())).toBe(false)
|
|
})
|
|
})
|