AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend/library): align Scheduled filter with fleet summary (#13235)
Ubbe8fab7fe85ab6
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/__tests__/filter.test.tsx b/autogpt_platform/frontend/src/app/(platform)/library/__tests__/filter.test.tsxnew file mode 100644index 0000000000..ea522caf1c--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/library/__tests__/filter.test.tsx@@ -0,0 +1,165 @@+import { describe, expect, test, vi } from "vitest";+import { LibraryAgentSort } from "@/app/api/__generated__/models/libraryAgentSort";+import { render, screen, waitFor } from "@/tests/integrations/test-utils";+import { server } from "@/mocks/mock-server";+import {+ getGetV2ListLibraryAgentsMockHandler,+ getGetV2ListLibraryAgentsResponseMock,+ getGetV2ListFavoriteLibraryAgentsMockHandler,+ getGetV2ListFavoriteLibraryAgentsResponseMock,+} from "@/app/api/__generated__/endpoints/library/library.msw";+import {+ getGetV2ListLibraryFoldersMockHandler,+ getGetV2ListLibraryFoldersResponseMock,+} from "@/app/api/__generated__/endpoints/folders/folders.msw";+import { getGetV1ListAllExecutionsMockHandler } from "@/app/api/__generated__/endpoints/graphs/graphs.msw";+import { Flag } from "@/services/feature-flags/use-get-flag";+import { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";+import { LibraryAgentList } from "../components/LibraryAgentList/LibraryAgentList";+import { FavoriteAnimationProvider } from "../context/FavoriteAnimationContext";++vi.mock("@/services/feature-flags/use-get-flag", async () => {+ const actual = await vi.importActual<+ typeof import("@/services/feature-flags/use-get-flag")+ >("@/services/feature-flags/use-get-flag");+ return {+ ...actual,+ useGetFlag: (flag: Flag) => flag === "agent-briefing",+ };+});++function makeAgent(overrides: Partial<LibraryAgent>): LibraryAgent {+ const base = getGetV2ListLibraryAgentsResponseMock().agents[0];+ return {+ ...base,+ has_external_trigger: false,+ is_scheduled: false,+ recommended_schedule_cron: null,+ next_scheduled_run: null,+ ...overrides,+ };+}++function setupHandlers(agents: LibraryAgent[]) {+ server.use(+ getGetV2ListLibraryAgentsMockHandler({+ ...getGetV2ListLibraryAgentsResponseMock(),+ agents,+ pagination: {+ total_items: agents.length,+ total_pages: 1,+ current_page: 1,+ page_size: 20,+ },+ }),+ getGetV2ListFavoriteLibraryAgentsMockHandler({+ ...getGetV2ListFavoriteLibraryAgentsResponseMock(),+ agents: [],+ pagination: {+ total_items: 0,+ total_pages: 1,+ current_page: 1,+ page_size: 10,+ },+ }),+ getGetV2ListLibraryFoldersMockHandler(+ getGetV2ListLibraryFoldersResponseMock({+ folders: [],+ pagination: {+ total_items: 0,+ total_pages: 1,+ current_page: 1,+ page_size: 20,+ },+ }),+ ),+ getGetV1ListAllExecutionsMockHandler([]),+ );+}++function renderList(statusFilter: "all" | "scheduled" | "idle") {+ return render(+ <FavoriteAnimationProvider onAnimationComplete={() => undefined}>+ <LibraryAgentList+ searchTerm=""+ librarySort={LibraryAgentSort.createdAt}+ setLibrarySort={() => undefined}+ selectedFolderId={null}+ onFolderSelect={() => undefined}+ tabs={[]}+ activeTab="all"+ onTabChange={() => undefined}+ statusFilter={statusFilter}+ onStatusFilterChange={() => undefined}+ />+ </FavoriteAnimationProvider>,+ );+}++describe("LibraryAgentList — Scheduled status filter", () => {+ test("includes agents with is_scheduled=true even when recommended_schedule_cron is null", async () => {+ setupHandlers([+ makeAgent({+ id: "a-actually-scheduled",+ graph_id: "g-actually-scheduled",+ name: "Actually Scheduled Agent",+ is_scheduled: true,+ recommended_schedule_cron: null,+ }),+ makeAgent({+ id: "a-idle",+ graph_id: "g-idle",+ name: "Idle Agent",+ }),+ ]);++ renderList("scheduled");++ expect(await screen.findByText("Actually Scheduled Agent")).toBeDefined();+ await waitFor(() => {+ expect(screen.queryByText("Idle Agent")).toBeNull();+ });+ });++ test("excludes idle agents (no schedule, no recommendation) from the scheduled filter", async () => {+ setupHandlers([+ makeAgent({+ id: "a-idle",+ graph_id: "g-idle",+ name: "Idle Agent",+ }),+ ]);++ renderList("scheduled");++ // List should render (no loading spinner stuck) — wait briefly for the+ // empty filtered state to settle.+ await waitFor(() => {+ expect(screen.queryByText("Idle Agent")).toBeNull();+ });+ });++ test("excludes agents with is_scheduled=true from the idle filter", async () => {+ setupHandlers([+ makeAgent({+ id: "a-actually-scheduled",+ graph_id: "g-actually-scheduled",+ name: "Actually Scheduled Agent",+ is_scheduled: true,+ recommended_schedule_cron: null,+ }),+ makeAgent({+ id: "a-idle",+ graph_id: "g-idle",+ name: "Idle Agent",+ }),+ ]);++ renderList("idle");++ expect(await screen.findByText("Idle Agent")).toBeDefined();+ await waitFor(() => {+ expect(screen.queryByText("Actually Scheduled Agent")).toBeNull();+ });+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryAgentList/useLibraryAgentList.ts b/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryAgentList/useLibraryAgentList.tsindex d228c35a20..448c8a16e5 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryAgentList/useLibraryAgentList.ts+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/LibraryAgentList/useLibraryAgentList.ts@@ -25,6 +25,7 @@ import { useEffect, useMemo, useRef, useState } from "react";import type { AgentStatusFilter } from "../../types";import { useGetV1ListAllExecutions } from "@/app/api/__generated__/endpoints/graphs/graphs";import { AgentExecutionStatus } from "@/app/api/__generated__/models/agentExecutionStatus";+import { isAgentScheduled } from "../../hooks/executionHelpers";const FILTER_EXHAUST_THRESHOLD = 3;@@ -327,6 +328,7 @@ function filterAgentsByStatus<T extends {graph_id: string;has_external_trigger: boolean;+ is_scheduled?: boolean;recommended_schedule_cron?: string | null;},>(@@ -340,6 +342,7 @@ function filterAgentsByStatus<return agents.filter((agent) => {const isRunning = activeGraphIds.has(agent.graph_id);const hasError = errorGraphIds.has(agent.graph_id);+ const isScheduled = isAgentScheduled(agent);if (statusFilter === "running") return isRunning;if (statusFilter === "attention") return hasError && !isRunning;@@ -349,17 +352,11 @@ function filterAgentsByStatus<return !isRunning && !hasError && agent.has_external_trigger;if (statusFilter === "scheduled")return (- !isRunning &&- !hasError &&- !agent.has_external_trigger &&- !!agent.recommended_schedule_cron+ !isRunning && !hasError && !agent.has_external_trigger && isScheduled);if (statusFilter === "idle")return (- !isRunning &&- !hasError &&- !agent.has_external_trigger &&- !agent.recommended_schedule_cron+ !isRunning && !hasError && !agent.has_external_trigger && !isScheduled);if (statusFilter === "healthy") return !hasError;return true;diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/SitrepItem/useSitrepItems.ts b/autogpt_platform/frontend/src/app/(platform)/library/components/SitrepItem/useSitrepItems.tsindex 02c33b48eb..4dd0928dd7 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/components/SitrepItem/useSitrepItems.ts+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/SitrepItem/useSitrepItems.ts@@ -9,6 +9,7 @@ import { useMemo } from "react";import type { SitrepItemData, SitrepPriority } from "../../types";import {isActive,+ isAgentScheduled,isFailed,toEndTime,endedAfter,@@ -158,7 +159,7 @@ function buildSitrepFromConfig(};}- if (agent.is_scheduled || agent.recommended_schedule_cron) {+ if (isAgentScheduled(agent)) {if (!isNextRunWithin(agent.next_scheduled_run, scheduledWithinMs)) {return null;}diff --git a/autogpt_platform/frontend/src/app/(platform)/library/hooks/executionHelpers.test.ts b/autogpt_platform/frontend/src/app/(platform)/library/hooks/executionHelpers.test.tsnew file mode 100644index 0000000000..44644c1369--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/library/hooks/executionHelpers.test.ts@@ -0,0 +1,50 @@+import { describe, expect, it } from "vitest";+import { isAgentScheduled } from "./executionHelpers";++describe("isAgentScheduled", () => {+ it("returns true when is_scheduled is set", () => {+ expect(+ isAgentScheduled({ is_scheduled: true, recommended_schedule_cron: null }),+ ).toBe(true);+ });++ it("returns true when recommended_schedule_cron is a non-empty string", () => {+ expect(+ isAgentScheduled({+ is_scheduled: false,+ recommended_schedule_cron: "0 9 * * *",+ }),+ ).toBe(true);+ });++ it("returns true when both flags are set", () => {+ expect(+ isAgentScheduled({+ is_scheduled: true,+ recommended_schedule_cron: "0 9 * * *",+ }),+ ).toBe(true);+ });++ it("returns false when neither flag is set", () => {+ expect(+ isAgentScheduled({+ is_scheduled: false,+ recommended_schedule_cron: null,+ }),+ ).toBe(false);+ });++ it("returns false when both fields are undefined", () => {+ expect(isAgentScheduled({})).toBe(false);+ });++ it("returns false when recommended_schedule_cron is an empty string", () => {+ expect(+ isAgentScheduled({+ is_scheduled: false,+ recommended_schedule_cron: "",+ }),+ ).toBe(false);+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/library/hooks/executionHelpers.ts b/autogpt_platform/frontend/src/app/(platform)/library/hooks/executionHelpers.tsindex cd2505c7ce..35940548b8 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/hooks/executionHelpers.ts+++ b/autogpt_platform/frontend/src/app/(platform)/library/hooks/executionHelpers.ts@@ -3,6 +3,15 @@ import type { GraphExecutionMeta } from "@/app/api/__generated__/models/graphExeexport const SEVENTY_TWO_HOURS_MS = 72 * 60 * 60 * 1000;+// Shared scheduled-predicate used by fleet summary, sitrep, status-map, and the+// list filter so the four call sites stay in lockstep.+export function isAgentScheduled(agent: {+ is_scheduled?: boolean;+ recommended_schedule_cron?: string | null;+}): boolean {+ return !!agent.is_scheduled || !!agent.recommended_schedule_cron;+}+export function isActive(status: string): boolean {return (status === AgentExecutionStatus.RUNNING ||diff --git a/autogpt_platform/frontend/src/app/(platform)/library/hooks/useAgentStatus.ts b/autogpt_platform/frontend/src/app/(platform)/library/hooks/useAgentStatus.tsindex 2b3246454e..3f54bced18 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/hooks/useAgentStatus.ts+++ b/autogpt_platform/frontend/src/app/(platform)/library/hooks/useAgentStatus.ts@@ -14,6 +14,7 @@ import type {} from "../types";import {isActive,+ isAgentScheduled,isFailed,toEndTime,SEVENTY_TWO_HOURS_MS,@@ -64,7 +65,7 @@ function computeAgentStatus("Execution failed";} else if (agent.has_external_trigger) {status = "listening";- } else if (agent.is_scheduled || agent.recommended_schedule_cron) {+ } else if (isAgentScheduled(agent)) {status = "scheduled";} else {status = "idle";@@ -196,7 +197,7 @@ export function useFleetSummary(agents: LibraryAgent[]): FleetSummary {counts.error += 1;} else if (agent.has_external_trigger) {counts.listening += 1;- } else if (agent.is_scheduled || agent.recommended_schedule_cron) {+ } else if (isAgentScheduled(agent)) {counts.scheduled += 1;} else {counts.idle += 1;diff --git a/autogpt_platform/frontend/src/app/(platform)/library/hooks/useLibraryFleetSummary.ts b/autogpt_platform/frontend/src/app/(platform)/library/hooks/useLibraryFleetSummary.tsindex ad87d76aca..9d340743fe 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/hooks/useLibraryFleetSummary.ts+++ b/autogpt_platform/frontend/src/app/(platform)/library/hooks/useLibraryFleetSummary.ts@@ -13,7 +13,12 @@ import { useExecutionEvents } from "@/hooks/useExecutionEvents";import { useQueryClient } from "@tanstack/react-query";import { useCallback, useMemo } from "react";import type { FleetSummary } from "../types";-import { isActive, isFailed, SEVENTY_TWO_HOURS_MS } from "./executionHelpers";+import {+ isActive,+ isAgentScheduled,+ isFailed,+ SEVENTY_TWO_HOURS_MS,+} from "./executionHelpers";function isRecentFailure(status: string,@@ -111,7 +116,7 @@ export function useLibraryFleetSummary(summary.error += 1;} else if (agent.has_external_trigger) {summary.listening += 1;- } else if (agent.is_scheduled || agent.recommended_schedule_cron) {+ } else if (isAgentScheduled(agent)) {summary.scheduled += 1;} else {summary.idle += 1;