feat(agent): 完善分析编排与结果传输
This commit is contained in:
@@ -3,15 +3,40 @@ import { describe, expect, it } from "bun:test";
|
||||
import {
|
||||
appendBackendToolArtifact,
|
||||
cancelBackendTodos,
|
||||
completeBackendActivities,
|
||||
completeBackendTodos,
|
||||
upsertBackendQuestion,
|
||||
} from "../../src/routes/chatUiState.js";
|
||||
|
||||
describe("completeBackendActivities", () => {
|
||||
it("closes running child actions when the stream terminates", () => {
|
||||
const activities = completeBackendActivities([
|
||||
{
|
||||
id: "activity-1",
|
||||
status: "running",
|
||||
startedAt: Date.now() - 100,
|
||||
actions: [
|
||||
{
|
||||
id: "action-1",
|
||||
status: "running",
|
||||
startedAt: Date.now() - 50,
|
||||
},
|
||||
],
|
||||
},
|
||||
], "error") as Array<Record<string, unknown>>;
|
||||
|
||||
expect(activities[0]).toMatchObject({
|
||||
status: "error",
|
||||
actions: [expect.objectContaining({ status: "error" })],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("appendBackendToolArtifact", () => {
|
||||
it("persists show_chart tool calls as chart artifacts", () => {
|
||||
const artifacts = appendBackendToolArtifact([], {
|
||||
session_id: "session-1",
|
||||
tool: "show_chart",
|
||||
reason: "测试折线图渲染",
|
||||
params: {
|
||||
title: "压力曲线",
|
||||
chart_type: "line",
|
||||
@@ -25,7 +50,6 @@ describe("appendBackendToolArtifact", () => {
|
||||
tool: "show_chart",
|
||||
kind: "chart",
|
||||
title: "压力曲线",
|
||||
description: "测试折线图渲染",
|
||||
params: {
|
||||
chart_type: "line",
|
||||
x_data: ["00:00", "01:00"],
|
||||
@@ -160,3 +184,29 @@ describe("cancelBackendTodos", () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("completeBackendTodos", () => {
|
||||
it("marks pending and in-progress todos as completed after a successful run", () => {
|
||||
const completed = completeBackendTodos([
|
||||
{
|
||||
sessionId: "session-1",
|
||||
todos: [
|
||||
{ id: "todo-1", content: "分析水位", status: "in_progress" },
|
||||
{ id: "todo-2", content: "生成建议", status: "pending" },
|
||||
{ id: "todo-3", content: "完成报告", status: "completed" },
|
||||
],
|
||||
createdAt: 123,
|
||||
},
|
||||
]);
|
||||
|
||||
expect(completed).toEqual([
|
||||
expect.objectContaining({
|
||||
todos: [
|
||||
expect.objectContaining({ id: "todo-1", status: "completed" }),
|
||||
expect.objectContaining({ id: "todo-2", status: "completed" }),
|
||||
expect.objectContaining({ id: "todo-3", status: "completed" }),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user