60 lines
2.9 KiB
TypeScript
60 lines
2.9 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("keeps accepted reply snapshots with both text and rich history", () => {
|
|
const reply = { type: "data-interaction_reply" as const, data: { interaction_id: "accepted-question" } };
|
|
for (const rich of [false, true]) {
|
|
const parts: UIMessage["parts"] = [{ type: "text", text: "核查范围: 北侧管网" }, reply,
|
|
...(rich ? [{ type: "data-final_answer" as const, data: { content: "核查范围: 北侧管网" } }] : [])];
|
|
const messages = [{ id: "reply", role: "user", parts: [...parts, { type: "data-progress", data: { title: "执行记录" } }] }] as unknown as UIMessage[];
|
|
expect(toCollaborationMessages(messages)).toEqual([{ id: "reply", role: "user", parts }]);
|
|
}
|
|
});
|
|
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" }),
|
|
]);
|
|
});
|
|
});
|