|
@@ -1,5 +1,5 @@
|
|
|
import { expect, test } from "bun:test"
|
|
import { expect, test } from "bun:test"
|
|
|
-import { buildProjectInbox } from "./inbox"
|
|
|
|
|
|
|
+import { buildInbox } from "./inbox"
|
|
|
|
|
|
|
|
type TestMessage = {
|
|
type TestMessage = {
|
|
|
id: string
|
|
id: string
|
|
@@ -12,6 +12,11 @@ type TestMessage = {
|
|
|
started?: number
|
|
started?: number
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const projects = [
|
|
|
|
|
+ { id: "p1", name: "光学" },
|
|
|
|
|
+ { id: "p2", name: "数据分析" },
|
|
|
|
|
+]
|
|
|
|
|
+
|
|
|
const chat = (id: string, projectID: string, messages: TestMessage[]) => ({
|
|
const chat = (id: string, projectID: string, messages: TestMessage[]) => ({
|
|
|
id,
|
|
id,
|
|
|
projectID,
|
|
projectID,
|
|
@@ -24,10 +29,10 @@ const chat = (id: string, projectID: string, messages: TestMessage[]) => ({
|
|
|
messages,
|
|
messages,
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-test("builds approvals, failures and unread completions for the current project", () => {
|
|
|
|
|
- const items = buildProjectInbox({
|
|
|
|
|
- projectID: "p1",
|
|
|
|
|
- seen: new Set<string>(),
|
|
|
|
|
|
|
+test("builds approvals, failures and unread completions across projects", () => {
|
|
|
|
|
+ const items = buildInbox({
|
|
|
|
|
+ projects,
|
|
|
|
|
+ seen: new Map(),
|
|
|
chats: [
|
|
chats: [
|
|
|
chat("a", "p1", [
|
|
chat("a", "p1", [
|
|
|
{ id: "m1", role: "assistant", runID: "run-a", status: "waiting_human", text: "请确认" },
|
|
{ id: "m1", role: "assistant", runID: "run-a", status: "waiting_human", text: "请确认" },
|
|
@@ -37,17 +42,23 @@ test("builds approvals, failures and unread completions for the current project"
|
|
|
chat("b", "p2", [
|
|
chat("b", "p2", [
|
|
|
{ id: "m4", role: "assistant", runID: "run-d", status: "waiting_human", text: "其他项目" },
|
|
{ id: "m4", role: "assistant", runID: "run-d", status: "waiting_human", text: "其他项目" },
|
|
|
]),
|
|
]),
|
|
|
|
|
+ chat("c", "p3", [{ id: "m5", role: "assistant", runID: "run-e", status: "failed", text: "" }]),
|
|
|
],
|
|
],
|
|
|
tasks: [],
|
|
tasks: [],
|
|
|
})
|
|
})
|
|
|
- expect(items.map((item) => item.kind)).toEqual(["approval", "failed", "unread"])
|
|
|
|
|
- expect(items.every((item) => item.projectID === "p1")).toBe(true)
|
|
|
|
|
|
|
+ expect(items.map((item) => [item.projectID, item.projectName, item.kind])).toEqual([
|
|
|
|
|
+ ["p1", "光学", "approval"],
|
|
|
|
|
+ ["p2", "数据分析", "approval"],
|
|
|
|
|
+ ["p1", "光学", "failed"],
|
|
|
|
|
+ ["p1", "光学", "unread"],
|
|
|
|
|
+ ])
|
|
|
|
|
+ expect(items.some((item) => item.projectID === "p3")).toBe(false)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-test("task rows only join through current project threads and dedupe runs", () => {
|
|
|
|
|
- const items = buildProjectInbox({
|
|
|
|
|
- projectID: "p1",
|
|
|
|
|
- seen: new Set<string>(),
|
|
|
|
|
|
|
+test("task rows join through project threads and dedupe runs", () => {
|
|
|
|
|
+ const items = buildInbox({
|
|
|
|
|
+ projects,
|
|
|
|
|
+ seen: new Map(),
|
|
|
chats: [chat("a", "p1", [{ id: "m1", role: "assistant", runID: "run-a", status: "waiting_human", text: "" }])],
|
|
chats: [chat("a", "p1", [{ id: "m1", role: "assistant", runID: "run-a", status: "waiting_human", text: "" }])],
|
|
|
tasks: [
|
|
tasks: [
|
|
|
{ run_id: "run-a", thread_id: "thread-a", status: "waiting_human", input: "重复" },
|
|
{ run_id: "run-a", thread_id: "thread-a", status: "waiting_human", input: "重复" },
|
|
@@ -57,28 +68,33 @@ test("task rows only join through current project threads and dedupe runs", () =
|
|
|
})
|
|
})
|
|
|
expect(items.filter((item) => item.runID === "run-a")).toHaveLength(1)
|
|
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-b")).toBe(false)
|
|
|
- expect(items.some((item) => item.runID === "run-c" && item.kind === "unread")).toBe(true)
|
|
|
|
|
|
|
+ expect(items.find((item) => item.runID === "run-c")).toMatchObject({
|
|
|
|
|
+ kind: "unread",
|
|
|
|
|
+ projectID: "p1",
|
|
|
|
|
+ projectName: "光学",
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-test("seen only hides completed unread items", () => {
|
|
|
|
|
- const items = buildProjectInbox({
|
|
|
|
|
- projectID: "p1",
|
|
|
|
|
- seen: new Set(["unread:run-b"]),
|
|
|
|
|
|
|
+test("seen state is evaluated per project", () => {
|
|
|
|
|
+ const items = buildInbox({
|
|
|
|
|
+ projects,
|
|
|
|
|
+ seen: new Map([
|
|
|
|
|
+ ["p1", new Set(["unread:run-a"])],
|
|
|
|
|
+ ["p2", new Set()],
|
|
|
|
|
+ ]),
|
|
|
chats: [
|
|
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: "完成" },
|
|
|
|
|
- ]),
|
|
|
|
|
|
|
+ chat("a", "p1", [{ id: "m1", role: "assistant", runID: "run-a", status: "completed", text: "A" }]),
|
|
|
|
|
+ chat("b", "p2", [{ id: "m2", role: "assistant", runID: "run-b", status: "completed", text: "B" }]),
|
|
|
],
|
|
],
|
|
|
tasks: [],
|
|
tasks: [],
|
|
|
})
|
|
})
|
|
|
- expect(items.map((item) => item.kind)).toEqual(["approval"])
|
|
|
|
|
|
|
+ expect(items.map((item) => item.projectID)).toEqual(["p2"])
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
test("archived chats contribute no inbox items, including task-index rows", () => {
|
|
test("archived chats contribute no inbox items, including task-index rows", () => {
|
|
|
- const items = buildProjectInbox({
|
|
|
|
|
- projectID: "p1",
|
|
|
|
|
- seen: new Set<string>(),
|
|
|
|
|
|
|
+ const items = buildInbox({
|
|
|
|
|
+ projects,
|
|
|
|
|
+ seen: new Map(),
|
|
|
chats: [
|
|
chats: [
|
|
|
{
|
|
{
|
|
|
...chat("a", "p1", [
|
|
...chat("a", "p1", [
|