51 lines
2.2 KiB
TypeScript
51 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import type { UIMessage } from "ai";
|
|
|
|
import {
|
|
buildFailedTaskExecutionPlan,
|
|
toCollaborationMessages,
|
|
} from "../../src/routes/chatStreamRoute.js";
|
|
|
|
describe("task collaboration history", () => {
|
|
it("persists only user and assistant text instead of execution trajectory", () => {
|
|
const messages = [
|
|
{ id: "user-1", role: "user", parts: [{ type: "text", text: "为什么这样判断?" }] },
|
|
{
|
|
id: "assistant-1",
|
|
role: "assistant",
|
|
parts: [
|
|
{ type: "data-progress", data: { title: "查询 SCADA" } },
|
|
{ type: "text", text: "因为上游数据正常,而投诉集中在同一小区。" },
|
|
{ type: "data-tool_call", data: { tool: "query_operational_task_data" } },
|
|
],
|
|
},
|
|
] as unknown as UIMessage[];
|
|
|
|
expect(toCollaborationMessages(messages)).toEqual([
|
|
{ id: "user-1", role: "user", parts: [{ type: "text", text: "为什么这样判断?" }] },
|
|
{ id: "assistant-1", role: "assistant", parts: [{ type: "text", text: "因为上游数据正常,而投诉集中在同一小区。" }] },
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe("failed task execution plan", () => {
|
|
it("turns active work into an explicit failed task artifact", () => {
|
|
const plan = buildFailedTaskExecutionPlan([{
|
|
title: "调查",
|
|
reason: "开始",
|
|
nodes: [
|
|
{ id: "READ", title: "读取", status: "completed", owner: "agent", detail: "完成", evidence: ["evidence-1"], action_refs: [] },
|
|
{ id: "ANALYZE", title: "分析", status: "running", owner: "agent", detail: "分析中", evidence: [], action_refs: [] },
|
|
{ id: "SAMPLE", title: "采样", status: "waiting", owner: "human", detail: "等待现场", evidence: [], action_refs: [] },
|
|
],
|
|
edges: [{ from: "READ", to: "ANALYZE", label: "数据已读取" }],
|
|
}]);
|
|
|
|
expect(plan.nodes).toEqual([
|
|
{ id: "READ", title: "读取", status: "completed", owner: "agent", detail: "完成", evidence: ["evidence-1"], action_refs: [] },
|
|
expect.objectContaining({ id: "ANALYZE", status: "failed" }),
|
|
expect.objectContaining({ id: "SAMPLE", status: "cancelled" }),
|
|
]);
|
|
});
|
|
});
|