51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
|
|
import { createActivityTracker } from "../../src/routes/chatActivityTracker.js";
|
|
|
|
describe("createActivityTracker", () => {
|
|
it("groups actions and closes running children with their activity", () => {
|
|
const events: Array<{ event: string; data: Record<string, unknown> }> = [];
|
|
const tracker = createActivityTracker({
|
|
clientSessionId: "client-session-1",
|
|
write: (event, data) => events.push({ event, data }),
|
|
});
|
|
|
|
tracker.start("activity-1", "准备分析数据", "需要先获取分析输入。");
|
|
tracker.upsertAction(
|
|
{
|
|
id: "tool-1",
|
|
tool: "tjwater_cli",
|
|
state: {
|
|
status: "running",
|
|
input: { command: "data list" },
|
|
},
|
|
} as never,
|
|
{ command: "data list" },
|
|
);
|
|
tracker.finalize("cancelled");
|
|
|
|
expect(tracker.getCurrentContext()).toEqual({
|
|
id: "activity-1",
|
|
title: "准备分析数据",
|
|
reason: "需要先获取分析输入。",
|
|
});
|
|
expect(events.at(-1)).toMatchObject({
|
|
event: "activity_update",
|
|
data: {
|
|
session_id: "client-session-1",
|
|
activity: {
|
|
id: "activity-1",
|
|
status: "cancelled",
|
|
actions: [
|
|
expect.objectContaining({
|
|
id: "tool-1",
|
|
status: "completed",
|
|
target: "data list",
|
|
}),
|
|
],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
});
|