import type { RunActivityRow } from "@rakazo/contracts"; import { describe, expect, it } from "vitest"; import { projectThreads } from "./project-threads.js"; function run( runId: string, threadId: string, status: RunActivityRow["status"], spaceId = "space-1", botId = "bot-1", ): RunActivityRow { return { runId, botId, botName: "Researcher", groupId: null, groupName: null, threadId, spaceId, status, trigger: "delegation", notificationsEnabled: true, promptSnippet: "", updatedAt: "2026-10-10T00:00:00.000Z", }; } describe("projectThreads", () => { it("sorts a project's threads into needs you, running and done, once each", () => { const threads = projectThreads( { active: [ run("r1", "t-research", "running"), run("r2", "t-design", "queued"), run("r3", "t-design", "waiting_input"), run("r4", "t-other-space", "running", "space-2"), run("r5", "t-chief", "running", "space-1", "chief"), ], recent: [ run("r6", "t-research", "completed"), run("r7", "t-write", "failed"), // A specialist that worked inside the coordinator's conversation. run("r8", "t-chief", "completed", "space-1", "gardener"), ], }, { spaceId: "space-1", coordinator: { threadId: "t-chief", botId: "chief" } }, ); expect(threads.needsYou.map((item) => item.runId)).toEqual(["r3"]); expect(threads.running.map((item) => item.runId)).toEqual(["r1"]); expect(threads.done.map((item) => item.runId)).toEqual(["r7", "r8"]); }); });