chore: 项目环境升级为 JDK25,Spring 4.1,项目重构为多模块
This commit is contained in:
32
web-ui/packages/agent/src/eventUtils.test.ts
Normal file
32
web-ui/packages/agent/src/eventUtils.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { AgentEvent } from './api'
|
||||
import { appendUniqueEvents, parseToolResult } from './eventUtils'
|
||||
|
||||
const event = (id: number): AgentEvent => ({
|
||||
id,
|
||||
projectId: 'project',
|
||||
runId: 'run',
|
||||
type: 'TEXT_MESSAGE_CONTENT',
|
||||
payload: { delta: String(id) },
|
||||
createdAt: '2026-08-24T00:00:00Z'
|
||||
})
|
||||
|
||||
describe('appendUniqueEvents', () => {
|
||||
it('保留顺序并忽略重放事件', () => {
|
||||
expect(appendUniqueEvents([event(1), event(2)], [event(2), event(3)]).map(item => item.id))
|
||||
.toEqual([1, 2, 3])
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
describe('parseToolResult', () => {
|
||||
it('优先使用结构化结果并识别旧的脚本错误', () => {
|
||||
expect(parseToolResult(JSON.stringify(JSON.stringify({ success: false, exitCode: 1, output: '错误' })), 'execute').failed).toBe(true)
|
||||
expect(parseToolResult({ success: true, exitCode: 0, output: '示例 TypeError:' }, 'execute').failed).toBe(false)
|
||||
expect(parseToolResult(JSON.stringify('Exit code: 0\n\nTypeError: children is not iterable'), 'execute').failed).toBe(true)
|
||||
expect(parseToolResult(JSON.stringify('Exit code: 0\n\nSyntaxError: Unexpected token'), 'execute').failed).toBe(true)
|
||||
expect(parseToolResult('TypeError: 文档中的示例', 'read_file').failed).toBe(false)
|
||||
expect(parseToolResult('{"success":false,"error":"文件中的业务数据"}', 'read_file').failed).toBe(false)
|
||||
expect(parseToolResult('document_view_result={"images":[],"errors":["无法渲染"]}', 'document_view').failed).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user