Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix: align broken tests with recent API and shared lib changes

Generfb31034f51ae
diff --git a/src/email-worker/src/imap-poller-do.test.ts b/src/email-worker/src/imap-poller-do.test.ts
index 7cb86953c..8a4a29f83 100644
--- a/src/email-worker/src/imap-poller-do.test.ts
+++ b/src/email-worker/src/imap-poller-do.test.ts
@@ -59,7 +59,8 @@ const mockGetEmailAccount = vi.fn()
const mockUpdateEmailAccount = vi.fn()
const mockIsWhitelisted = vi.fn().mockResolvedValue(true)
-vi.mock("@alook/shared", () => {
+vi.mock("@alook/shared", async () => {
+ const real = await vi.importActual<typeof import("@alook/shared")>("@alook/shared")
const noopLogger = {
debug: () => {},
info: () => {},
@@ -70,6 +71,8 @@ vi.mock("@alook/shared", () => {
return {
createDb: () => ({}),
createLogger: () => noopLogger,
+ parseIcs: real.parseIcs,
+ extractAttachmentMeta: real.extractAttachmentMeta,
DEV_WEB_URL: "http://localhost:3000",
queries: {
emailAccount: {
diff --git a/src/email-worker/src/index.test.ts b/src/email-worker/src/index.test.ts
index e4c3f084b..6b3753378 100644
--- a/src/email-worker/src/index.test.ts
+++ b/src/email-worker/src/index.test.ts
@@ -50,6 +50,8 @@ vi.mock("@alook/shared", async () => {
}
return {
buildMimeMessage: real.buildMimeMessage,
+ extractAttachmentMeta: real.extractAttachmentMeta,
+ filterDownloadableAttachments: real.filterDownloadableAttachments,
createDb: (d1: unknown) => mockCreateDb(d1),
createLogger: () => noopLogger,
parseEmailHandle: (address: string) => {
diff --git a/src/web/src/app/api/agents/pins/route.test.ts b/src/web/src/app/api/agents/pins/route.test.ts
index d21364363..85054cfdc 100644
--- a/src/web/src/app/api/agents/pins/route.test.ts
+++ b/src/web/src/app/api/agents/pins/route.test.ts
@@ -8,6 +8,8 @@ vi.mock("@/lib/db", () => ({ getDb: vi.fn(() => ({})) }));
const mockListPins = vi.fn();
+const mockListSidebarOrder = vi.fn();
+
vi.mock("@alook/shared", async () => {
const actual = await vi.importActual("@alook/shared");
return {
@@ -16,6 +18,9 @@ vi.mock("@alook/shared", async () => {
agentPin: {
listPins: (...args: unknown[]) => mockListPins(...args),
},
+ agentSidebarOrder: {
+ listOrder: (...args: unknown[]) => mockListSidebarOrder(...args),
+ },
},
};
});
@@ -39,11 +44,16 @@ import { GET } from "./route";
beforeEach(() => vi.clearAllMocks());
+beforeEach(() => {
+ vi.clearAllMocks();
+ mockListSidebarOrder.mockResolvedValue([]);
+});
+
describe("GET /api/agents/pins", () => {
it("returns list of pins with mapped fields", async () => {
mockListPins.mockResolvedValue([
- { id: "pin1", agentId: "a1", createdAt: "2025-01-01T00:00:00Z" },
- { id: "pin2", agentId: "a2", createdAt: "2025-01-02T00:00:00Z" },
+ { id: "pin1", agentId: "a1", createdAt: "2025-01-01T00:00:00Z", position: 0 },
+ { id: "pin2", agentId: "a2", createdAt: "2025-01-02T00:00:00Z", position: 1 },
]);
const req = new NextRequest("http://localhost/api/agents/pins");
@@ -51,10 +61,11 @@ describe("GET /api/agents/pins", () => {
const body = await res.json();
expect(res.status).toBe(200);
- expect(body).toEqual([
- { id: "pin1", agent_id: "a1", created_at: "2025-01-01T00:00:00Z" },
- { id: "pin2", agent_id: "a2", created_at: "2025-01-02T00:00:00Z" },
+ expect(body.pins).toEqual([
+ { id: "pin1", agent_id: "a1", created_at: "2025-01-01T00:00:00Z", position: 0 },
+ { id: "pin2", agent_id: "a2", created_at: "2025-01-02T00:00:00Z", position: 1 },
]);
+ expect(body.sidebar_order).toEqual([]);
expect(mockListPins).toHaveBeenCalledWith({}, "w1", "u1");
});
@@ -66,6 +77,7 @@ describe("GET /api/agents/pins", () => {
const body = await res.json();
expect(res.status).toBe(200);
- expect(body).toEqual([]);
+ expect(body.pins).toEqual([]);
+ expect(body.sidebar_order).toEqual([]);
});
});
diff --git a/src/web/src/app/api/calendar/[id]/route.ts b/src/web/src/app/api/calendar/[id]/route.ts
index daa7627d2..e0a544f66 100644
--- a/src/web/src/app/api/calendar/[id]/route.ts
+++ b/src/web/src/app/api/calendar/[id]/route.ts
@@ -4,6 +4,7 @@ import {
UpdateCalendarEventRequestSchema,
DeleteCalendarEventRequestSchema,
computeNextScheduledAt,
+ isEmptyHtml,
} from "@alook/shared";
import { getDb } from "@/lib/db";
import { withAuth } from "@/lib/middleware/auth";
@@ -72,8 +73,8 @@ export const PATCH = withAuth(async (req, ctx) => {
if (body.title !== undefined) patch.title = body.title;
if (body.description !== undefined) {
- patch.description =
- body.description?.trim() || null;
+ const rawDesc = body.description?.trim() || null;
+ patch.description = rawDesc && isEmptyHtml(rawDesc) ? null : rawDesc;
}
if (body.agent_id !== undefined) patch.agentId = body.agent_id;
if (body.scheduled_at !== undefined) {
diff --git a/src/web/src/app/api/calendar/route.ts b/src/web/src/app/api/calendar/route.ts
index 9ea80ca47..6989e5e1d 100644
--- a/src/web/src/app/api/calendar/route.ts
+++ b/src/web/src/app/api/calendar/route.ts
@@ -4,6 +4,7 @@ import {
queries,
CreateCalendarEventRequestSchema,
expandOccurrences,
+ isEmptyHtml,
} from "@alook/shared";
import { getDb } from "@/lib/db";
import { withAuth } from "@/lib/middleware/auth";
@@ -123,7 +124,8 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
}
}
- const description = body.description?.trim() || null;
+ const rawDesc = body.description?.trim() || null;
+ const description = rawDesc && isEmptyHtml(rawDesc) ? null : rawDesc;
const created = await queries.calendarEvent.createCalendarEvent(db, {
agentId: body.agent_id,
diff --git a/src/web/src/app/api/email/notify/route.test.ts b/src/web/src/app/api/email/notify/route.test.ts
index 10f2323d3..0c8fd250e 100644
--- a/src/web/src/app/api/email/notify/route.test.ts
+++ b/src/web/src/app/api/email/notify/route.test.ts
@@ -72,6 +72,10 @@ vi.mock("@/lib/broadcast", () => ({
broadcastToUser: vi.fn().mockResolvedValue(undefined),
}));
+vi.mock("@/lib/api/responses", () => ({
+ taskToResponse: (t: unknown) => t,
+}));
+
import { POST } from "./route";
function makeNotifyReq(body: Record<string, unknown>) {
diff --git a/src/web/src/test/e2e/agent-pin.test.ts b/src/web/src/test/e2e/agent-pin.test.ts
index 28cb50993..4403d327c 100644
--- a/src/web/src/test/e2e/agent-pin.test.ts
+++ b/src/web/src/test/e2e/agent-pin.test.ts
@@ -19,8 +19,8 @@ describe("agent pin", () => {
seed.machineToken,
)
expect(res.status).toBe(200)
- const data = await res.json() as Array<Record<string, unknown>>
- expect(data).toEqual([])
+ const data = await res.json() as { pins: Array<Record<string, unknown>>; sidebar_order: Array<Record<string, unknown>> }
+ expect(data.pins).toEqual([])
})
it("POST /api/agents/:id/pin pins an agent", async () => {
@@ -51,9 +51,9 @@ describe("agent pin", () => {
seed.machineToken,
)
expect(res.status).toBe(200)
- const data = await res.json() as Array<Record<string, unknown>>
- expect(data).toHaveLength(1)
- expect(data[0].agent_id).toBe(seed.agentId)
+ const data = await res.json() as { pins: Array<Record<string, unknown>>; sidebar_order: Array<Record<string, unknown>> }
+ expect(data.pins).toHaveLength(1)
+ expect(data.pins[0].agent_id).toBe(seed.agentId)
})
it("DELETE /api/agents/:id/pin unpins the agent", async () => {
@@ -71,8 +71,8 @@ describe("agent pin", () => {
seed.machineToken,
)
expect(res.status).toBe(200)
- const data = await res.json() as Array<Record<string, unknown>>
- expect(data).toEqual([])
+ const data = await res.json() as { pins: Array<Record<string, unknown>>; sidebar_order: Array<Record<string, unknown>> }
+ expect(data.pins).toEqual([])
})
it("DELETE /api/agents/:id/pin is idempotent (unpin again)", async () => {