Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix(web): update test mocks for workspace-level query functions
Gener308a27071f18
diff --git a/src/web/src/app/api/daemon/tasks/poll/route.test.ts b/src/web/src/app/api/daemon/tasks/poll/route.test.tsindex d5edaf7da..744f7a119 100644--- a/src/web/src/app/api/daemon/tasks/poll/route.test.ts+++ b/src/web/src/app/api/daemon/tasks/poll/route.test.ts@@ -7,6 +7,7 @@ const mockGetMachineByDaemon = vi.fn();const mockClearPendingUpdateVersion = vi.fn();const mockClearPendingRescan = vi.fn();const mockGetAgentsByIds = vi.fn();+const mockGetAllAgentsForWorkspace = vi.fn();const mockGetMemberByUserAndWorkspace = vi.fn();const mockGetConversation = vi.fn();const mockGetUser = vi.fn();@@ -19,7 +20,9 @@ const mockExpireStaleFileRequests = vi.fn();const mockListScheduledMeetings = vi.fn();const mockClaimMeetingSessions = vi.fn();const mockGetEmailAccountsByAgents = vi.fn();+const mockGetAllEmailAccountsForWorkspace = vi.fn();const mockGetColleaguesForAgents = vi.fn();+const mockGetAllColleaguesForWorkspace = vi.fn();vi.mock("@opennextjs/cloudflare", () => ({getCloudflareContext: vi.fn(() => ({ env: { DB: {} } })),@@ -47,6 +50,7 @@ vi.mock("@alook/shared", async () => {},agent: {getAgentsByIds: (...args: unknown[]) => mockGetAgentsByIds(...args),+ getAllAgentsForWorkspace: (...args: unknown[]) => mockGetAllAgentsForWorkspace(...args),},member: {getMemberByUserAndWorkspace: (...args: unknown[]) => mockGetMemberByUserAndWorkspace(...args),@@ -59,6 +63,7 @@ vi.mock("@alook/shared", async () => {},emailAccount: {getEmailAccountsByAgents: (...args: unknown[]) => mockGetEmailAccountsByAgents(...args),+ getAllEmailAccountsForWorkspace: (...args: unknown[]) => mockGetAllEmailAccountsForWorkspace(...args),},workspaceFileRequest: {getPendingByWorkspace: (...args: unknown[]) => mockGetPendingFileRequests(...args),@@ -71,6 +76,7 @@ vi.mock("@alook/shared", async () => {},agentLink: {getColleaguesForAgents: (...args: unknown[]) => mockGetColleaguesForAgents(...args),+ getAllColleaguesForWorkspace: (...args: unknown[]) => mockGetAllColleaguesForWorkspace(...args),},},};@@ -138,9 +144,12 @@ describe("POST /api/daemon/tasks/poll", () => {mockGetPendingFileRequests.mockResolvedValue([]);mockExpireStaleFileRequests.mockResolvedValue(undefined);mockListScheduledMeetings.mockResolvedValue([]);- mockGetAgentsByIds.mockResolvedValue([]);+ mockGetAllAgentsForWorkspace.mockResolvedValue([]);+ mockGetAllAgentsForWorkspace.mockResolvedValue([]);mockGetEmailAccountsByAgents.mockResolvedValue([]);+ mockGetAllEmailAccountsForWorkspace.mockResolvedValue([]);mockGetColleaguesForAgents.mockResolvedValue([]);+ mockGetAllColleaguesForWorkspace.mockResolvedValue([]);});it("returns evicted: true and skips heartbeat when daemon has no runtimes", async () => {@@ -198,7 +207,7 @@ describe("POST /api/daemon/tasks/poll", () => {mockClaimTasksForRuntimes.mockResolvedValue([{ id: "t1", agentId: "a1", runtimeId: "r1", workspaceId: "w1", prompt: "do it", status: "dispatched" },]);- mockGetAgentsByIds.mockResolvedValue([{+ mockGetAllAgentsForWorkspace.mockResolvedValue([{id: "a1",instructions: "be helpful",name: "Bot",@@ -397,7 +406,7 @@ describe("POST /api/daemon/tasks/poll", () => {mockClaimTasksForRuntimes.mockResolvedValue([{ id: "t1", agentId: "a1", runtimeId: "r1", workspaceId: "w1", prompt: "hi", status: "dispatched" },]);- mockGetAgentsByIds.mockResolvedValue([{+ mockGetAllAgentsForWorkspace.mockResolvedValue([{id: "a1",ownerId: "owner1",instructions: "you are a planner",@@ -424,7 +433,7 @@ describe("POST /api/daemon/tasks/poll", () => {mockClaimTasksForRuntimes.mockResolvedValue([{ id: "t1", agentId: "a1", runtimeId: "r1", workspaceId: "w1", prompt: "hi", status: "dispatched" },]);- mockGetAgentsByIds.mockResolvedValue([{+ mockGetAllAgentsForWorkspace.mockResolvedValue([{id: "a1",ownerId: "owner1",instructions: "you are a planner",@@ -449,7 +458,7 @@ describe("POST /api/daemon/tasks/poll", () => {mockClaimTasksForRuntimes.mockResolvedValue([{ id: "t1", agentId: "a1", runtimeId: "r1", workspaceId: "w1", prompt: "hi", status: "dispatched" },]);- mockGetAgentsByIds.mockResolvedValue([{+ mockGetAllAgentsForWorkspace.mockResolvedValue([{id: "a1",ownerId: null,instructions: "just agent",@@ -473,7 +482,7 @@ describe("POST /api/daemon/tasks/poll", () => {{ id: "t1", agentId: "a1", runtimeId: "r1", workspaceId: "w1", prompt: "hi", status: "dispatched" },{ id: "t2", agentId: "a2", runtimeId: "r1", workspaceId: "w1", prompt: "yo", status: "dispatched" },]);- mockGetAgentsByIds.mockResolvedValue([+ mockGetAllAgentsForWorkspace.mockResolvedValue([{ id: "a1", ownerId: "owner1", instructions: "inst1", name: "Bot1", runtimeConfig: {} },{ id: "a2", ownerId: "owner1", instructions: "inst2", name: "Bot2", runtimeConfig: {} },]);@@ -495,7 +504,7 @@ describe("POST /api/daemon/tasks/poll", () => {mockClaimTasksForRuntimes.mockResolvedValue([{ id: "t1", agentId: "a1", runtimeId: "r1", workspaceId: "w1", prompt: "hi", status: "dispatched" },]);- mockGetAgentsByIds.mockResolvedValue([{+ mockGetAllAgentsForWorkspace.mockResolvedValue([{id: "a1",ownerId: "owner1",instructions: "",@@ -520,7 +529,7 @@ describe("POST /api/daemon/tasks/poll", () => {mockClaimTasksForRuntimes.mockResolvedValue([{ id: "t1", agentId: "a1", runtimeId: "r1", workspaceId: "w1", conversationId: "c1", prompt: "hi", status: "dispatched", type: "user_dm_message" },]);- mockGetAgentsByIds.mockResolvedValue([{ id: "a1", ownerId: "u1", instructions: "", name: "Bot", runtimeConfig: {} }]);+ mockGetAllAgentsForWorkspace.mockResolvedValue([{ id: "a1", ownerId: "u1", instructions: "", name: "Bot", runtimeConfig: {} }]);mockGetConversation.mockResolvedValue({ userId: "u1" });mockGetUser.mockResolvedValue({ name: "Gus", email: "[email protected]" });@@ -538,7 +547,7 @@ describe("POST /api/daemon/tasks/poll", () => {mockClaimTasksForRuntimes.mockResolvedValue([{ id: "t1", agentId: "a1", runtimeId: "r1", workspaceId: "w1", conversationId: "c1", prompt: "hi", status: "dispatched", type: "user_dm_message" },]);- mockGetAgentsByIds.mockResolvedValue([{ id: "a1", ownerId: "owner1", instructions: "", name: "Bot", runtimeConfig: {} }]);+ mockGetAllAgentsForWorkspace.mockResolvedValue([{ id: "a1", ownerId: "owner1", instructions: "", name: "Bot", runtimeConfig: {} }]);mockGetConversation.mockResolvedValue({ userId: "u2" });mockGetUser.mockResolvedValue({ name: "Alice", email: "[email protected]" });@@ -556,7 +565,7 @@ describe("POST /api/daemon/tasks/poll", () => {mockClaimTasksForRuntimes.mockResolvedValue([{ id: "t1", agentId: "a1", runtimeId: "r1", workspaceId: "w1", conversationId: "c1", prompt: "standup", status: "dispatched", type: "calendar_event" },]);- mockGetAgentsByIds.mockResolvedValue([{ id: "a1", ownerId: "u1", instructions: "", name: "Bot", runtimeConfig: {} }]);+ mockGetAllAgentsForWorkspace.mockResolvedValue([{ id: "a1", ownerId: "u1", instructions: "", name: "Bot", runtimeConfig: {} }]);const res = await POST(postReq({ daemon_id: "d1" }));const body = await res.json();@@ -572,7 +581,7 @@ describe("POST /api/daemon/tasks/poll", () => {mockClaimTasksForRuntimes.mockResolvedValue([{ id: "t1", agentId: "a1", runtimeId: "r1", workspaceId: "w1", conversationId: "c1", prompt: "new email", status: "dispatched", type: "email_notification" },]);- mockGetAgentsByIds.mockResolvedValue([{ id: "a1", ownerId: "u1", instructions: "", name: "Bot", runtimeConfig: {} }]);+ mockGetAllAgentsForWorkspace.mockResolvedValue([{ id: "a1", ownerId: "u1", instructions: "", name: "Bot", runtimeConfig: {} }]);const res = await POST(postReq({ daemon_id: "d1" }));const body = await res.json();@@ -588,7 +597,7 @@ describe("POST /api/daemon/tasks/poll", () => {mockClaimTasksForRuntimes.mockResolvedValue([{ id: "t1", agentId: "a1", runtimeId: "r1", workspaceId: "w1", conversationId: "c1", prompt: "hi", status: "dispatched", type: "user_dm_message" },]);- mockGetAgentsByIds.mockResolvedValue([{ id: "a1", ownerId: "u1", instructions: "", name: "Bot", runtimeConfig: {} }]);+ mockGetAllAgentsForWorkspace.mockResolvedValue([{ id: "a1", ownerId: "u1", instructions: "", name: "Bot", runtimeConfig: {} }]);mockGetConversation.mockResolvedValue(null);const res = await POST(postReq({ daemon_id: "d1" }));@@ -605,7 +614,7 @@ describe("POST /api/daemon/tasks/poll", () => {mockClaimTasksForRuntimes.mockResolvedValue([{ id: "t1", agentId: "a1", runtimeId: "r1", workspaceId: "w1", conversationId: "c1", prompt: "hi", status: "dispatched", type: "user_dm_message" },]);- mockGetAgentsByIds.mockResolvedValue([{ id: "a1", ownerId: "u1", instructions: "", name: "Bot", runtimeConfig: {} }]);+ mockGetAllAgentsForWorkspace.mockResolvedValue([{ id: "a1", ownerId: "u1", instructions: "", name: "Bot", runtimeConfig: {} }]);mockGetConversation.mockResolvedValue({ userId: "u1" });mockGetUser.mockResolvedValue(null);@@ -624,7 +633,7 @@ describe("POST /api/daemon/tasks/poll", () => {{ id: "t1", agentId: "a1", runtimeId: "r1", workspaceId: "w1", conversationId: "c1", prompt: "hi", status: "dispatched", type: "user_dm_message" },{ id: "t2", agentId: "a1", runtimeId: "r1", workspaceId: "w1", conversationId: "c2", prompt: "yo", status: "dispatched", type: "user_dm_message" },]);- mockGetAgentsByIds.mockResolvedValue([{ id: "a1", ownerId: "owner1", instructions: "", name: "Bot", runtimeConfig: {} }]);+ mockGetAllAgentsForWorkspace.mockResolvedValue([{ id: "a1", ownerId: "owner1", instructions: "", name: "Bot", runtimeConfig: {} }]);mockGetConversation.mockResolvedValue({ userId: "u1" });mockGetUser.mockResolvedValue({ name: "Gus", email: "[email protected]" });diff --git a/src/web/src/app/api/email/send/route.test.ts b/src/web/src/app/api/email/send/route.test.tsindex 5fa532e06..2de67f511 100644--- a/src/web/src/app/api/email/send/route.test.ts+++ b/src/web/src/app/api/email/send/route.test.ts@@ -6,6 +6,7 @@ const mockGetAgentByHandle = vi.fn();const mockCreateEmail = vi.fn();const mockIsWhitelisted = vi.fn();const mockGetEmailAccountsByAgent = vi.fn();+const mockGetAllEmailAccountsForWorkspace = vi.fn();const mockGetEmailAccountScoped = vi.fn();const mockEmailWorkerFetch = vi.fn();const mockEmailBucketGet = vi.fn();@@ -48,6 +49,7 @@ vi.mock("@alook/shared", async () => {},emailAccount: {getEmailAccountsByAgent: (...args: unknown[]) => mockGetEmailAccountsByAgent(...args),+ getAllEmailAccountsForWorkspace: (...args: unknown[]) => mockGetAllEmailAccountsForWorkspace(...args),getEmailAccountScoped: (...args: unknown[]) => mockGetEmailAccountScoped(...args),},conversation: {@@ -95,7 +97,10 @@ function makeReq(body: Record<string, unknown>) {}describe("POST /api/email/send", () => {- beforeEach(() => vi.clearAllMocks());+ beforeEach(() => {+ vi.clearAllMocks();+ mockGetAllEmailAccountsForWorkspace.mockResolvedValue([]);+ });it("sends email via EMAIL_WORKER and returns the created record", async () => {mockGetAgent.mockResolvedValue({ id: "a1", emailHandle: "test-agent" });@@ -456,8 +461,8 @@ describe("POST /api/email/send", () => {it("skips local delivery when sender uses custom SMTP account", async () => {mockGetAgent.mockResolvedValue({ id: "a1", emailHandle: "sender-agent", workspaceId: "ws1" });- mockGetEmailAccountsByAgent.mockResolvedValue([- { id: "acct1", emailAddress: "[email protected]" },+ mockGetAllEmailAccountsForWorkspace.mockResolvedValue([+ { id: "acct1", agentId: "a1", emailAddress: "[email protected]" },]);mockEmailWorkerFetch.mockResolvedValue(Response.json({ ok: true, r2Key: "emails/x/raw" }));mockCreateEmail.mockResolvedValue({ id: "e1" });diff --git a/src/web/src/app/api/studios/route.test.ts b/src/web/src/app/api/studios/route.test.tsindex 43eebe034..ebe05c498 100644--- a/src/web/src/app/api/studios/route.test.ts+++ b/src/web/src/app/api/studios/route.test.ts@@ -29,6 +29,7 @@ vi.mock("@alook/shared", async () => {createAgent: (...args: unknown[]) => mockCreateAgent(...args),getAgentByHandle: (...args: unknown[]) => mockGetAgentByHandle(...args),listAgents: (...args: unknown[]) => mockListAgents(...args),+ getAllHandlesForWorkspace: vi.fn().mockResolvedValue([]),},runtime: {getAgentRuntimeForWorkspace: (...args: unknown[]) => mockGetAgentRuntimeForWorkspace(...args),