|
|
@@ -0,0 +1,65 @@
|
|
|
+import { expect, test } from "bun:test"
|
|
|
+import { buildProjectInbox } from "./inbox"
|
|
|
+
|
|
|
+const chat = (id: string, projectID: string, messages: Record<string, unknown>[]) => ({
|
|
|
+ id,
|
|
|
+ projectID,
|
|
|
+ agentID: "research67",
|
|
|
+ name: "科研助手",
|
|
|
+ title: `会话 ${id}`,
|
|
|
+ threadID: `thread-${id}`,
|
|
|
+ draft: "",
|
|
|
+ files: [],
|
|
|
+ messages,
|
|
|
+})
|
|
|
+
|
|
|
+test("builds approvals, failures and unread completions for the current project", () => {
|
|
|
+ const items = buildProjectInbox({
|
|
|
+ projectID: "p1",
|
|
|
+ seen: new Set<string>(),
|
|
|
+ chats: [
|
|
|
+ chat("a", "p1", [
|
|
|
+ { id: "m1", role: "assistant", runID: "run-a", status: "waiting_human", text: "请确认" },
|
|
|
+ { id: "m2", role: "assistant", runID: "run-b", status: "failed", text: "", error: "失败" },
|
|
|
+ { id: "m3", role: "assistant", runID: "run-c", status: "completed", text: "完成报告" },
|
|
|
+ ]),
|
|
|
+ chat("b", "p2", [
|
|
|
+ { id: "m4", role: "assistant", runID: "run-d", status: "waiting_human", text: "其他项目" },
|
|
|
+ ]),
|
|
|
+ ],
|
|
|
+ tasks: [],
|
|
|
+ })
|
|
|
+ expect(items.map((item) => item.kind)).toEqual(["approval", "failed", "unread"])
|
|
|
+ expect(items.every((item) => item.projectID === "p1")).toBe(true)
|
|
|
+})
|
|
|
+
|
|
|
+test("task rows only join through current project threads and dedupe runs", () => {
|
|
|
+ const items = buildProjectInbox({
|
|
|
+ projectID: "p1",
|
|
|
+ seen: new Set<string>(),
|
|
|
+ chats: [chat("a", "p1", [{ id: "m1", role: "assistant", runID: "run-a", status: "waiting_human", text: "" }])],
|
|
|
+ tasks: [
|
|
|
+ { run_id: "run-a", thread_id: "thread-a", status: "waiting_human", input: "重复" },
|
|
|
+ { run_id: "run-b", thread_id: "thread-b", status: "failed", input: "外部任务" },
|
|
|
+ { run_id: "run-c", thread_id: "thread-a", status: "completed", input: "任务完成" },
|
|
|
+ ],
|
|
|
+ })
|
|
|
+ expect(items.filter((item) => item.runID === "run-a")).toHaveLength(1)
|
|
|
+ expect(items.some((item) => item.runID === "run-b")).toBe(false)
|
|
|
+ expect(items.some((item) => item.runID === "run-c" && item.kind === "unread")).toBe(true)
|
|
|
+})
|
|
|
+
|
|
|
+test("seen only hides completed unread items", () => {
|
|
|
+ const items = buildProjectInbox({
|
|
|
+ projectID: "p1",
|
|
|
+ seen: new Set(["unread:run-b"]),
|
|
|
+ chats: [
|
|
|
+ chat("a", "p1", [
|
|
|
+ { id: "m1", role: "assistant", runID: "run-a", status: "waiting_human", text: "" },
|
|
|
+ { id: "m2", role: "assistant", runID: "run-b", status: "completed", text: "完成" },
|
|
|
+ ]),
|
|
|
+ ],
|
|
|
+ tasks: [],
|
|
|
+ })
|
|
|
+ expect(items.map((item) => item.kind)).toEqual(["approval"])
|
|
|
+})
|