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: exclude completed one-off events from calendar listings (#251)
Generb6710bc29c50
diff --git a/src/shared/src/db/queries/calendar-event.ts b/src/shared/src/db/queries/calendar-event.tsindex fff018fce..e284c374d 100644--- a/src/shared/src/db/queries/calendar-event.ts+++ b/src/shared/src/db/queries/calendar-event.ts@@ -79,6 +79,17 @@ export async function listCalendarEvents() {const conditions = [eq(calendarEvent.workspaceId, workspaceId)];if (opts.agentId) conditions.push(eq(calendarEvent.agentId, opts.agentId));++ // Exclude completed one-off events: non-recurring events where+ // lastTriggeredAt is set and >= scheduledAt are "done".+ conditions.push(+ or(+ isNotNull(calendarEvent.repeatInterval),+ isNull(calendarEvent.lastTriggeredAt),+ lt(calendarEvent.lastTriggeredAt, calendarEvent.scheduledAt)+ )!+ );+if (opts.from && opts.to) {// Non-recurring rows are bounded strictly by [from, to] on scheduled_at.// Recurring rows may have scheduled_at before `from` (next fire isdiff --git a/src/shared/test/queries/calendar-event.test.ts b/src/shared/test/queries/calendar-event.test.tsindex d670d291a..b906399e4 100644--- a/src/shared/test/queries/calendar-event.test.ts+++ b/src/shared/test/queries/calendar-event.test.ts@@ -1,4 +1,4 @@-import { describe, it, expect } from "vitest";+import { describe, it, expect, vi } from "vitest";import * as calendarQueries from "../../src/db/queries/calendar-event";describe("calendar-event query module exports", () => {@@ -257,6 +257,39 @@ describe("getOccurrencesPerDay", () => {});});+describe("listCalendarEvents — completed one-off exclusion", () => {+ function createMockDb(rows: any[]) {+ const chain: any = {};+ chain.select = vi.fn(() => chain);+ chain.from = vi.fn(() => chain);+ chain.where = vi.fn(() => chain);+ chain.orderBy = vi.fn(() => Promise.resolve(rows));+ return chain;+ }++ it("calls where() with conditions that would exclude completed one-off events", async () => {+ const db = createMockDb([]);+ await calendarQueries.listCalendarEvents(db, "ws_1");+ expect(db.where).toHaveBeenCalledOnce();+ });++ it("returns all rows from the database (filter logic is in SQL)", async () => {+ const rows = [+ { id: "ce_1", repeatInterval: null, lastTriggeredAt: null },+ { id: "ce_2", repeatInterval: "1day", lastTriggeredAt: "2026-01-01T10:00:00.000Z" },+ ];+ const db = createMockDb(rows);+ const result = await calendarQueries.listCalendarEvents(db, "ws_1");+ expect(result).toEqual(rows);+ });++ it("passes agentId filter when provided", async () => {+ const db = createMockDb([]);+ await calendarQueries.listCalendarEvents(db, "ws_1", { agentId: "ag_1" });+ expect(db.where).toHaveBeenCalledOnce();+ });+});+describe("expandOccurrences", () => {it("returns one entry per occurrence within [from, to] for a daily event", () => {const out = calendarQueries.expandOccurrences(