π OpenHands: AI-Driven Development
feat: allow editing automations on cloud backends (#17191)
Hiep Ledc39ea89e3c1
diff --git a/__tests__/components/features/home/build-pinned-automation-menu-items.test.ts b/__tests__/components/features/home/build-pinned-automation-menu-items.test.tsindex 2b11d9bcdb..442f8af6cb 100644--- a/__tests__/components/features/home/build-pinned-automation-menu-items.test.ts+++ b/__tests__/components/features/home/build-pinned-automation-menu-items.test.ts@@ -34,7 +34,6 @@ describe("buildHomeAutomationMenuItems", () => {automation: makeAutomation(),t: (key) => key,canManage: true,- canEdit: true,isRunPending: false,isCancelPending: false,canCancel: false,@@ -70,7 +69,6 @@ describe("buildHomeAutomationMenuItems", () => {automation: makeAutomation(),t: (key) => key,canManage: true,- canEdit: false,isRunPending: false,isCancelPending: false,canCancel: true,@@ -96,7 +94,6 @@ describe("buildHomeAutomationMenuItems", () => {automation: makeAutomation(),t: (key) => key,canManage: false,- canEdit: true,isRunPending: false,isCancelPending: false,canCancel: false,diff --git a/__tests__/components/features/home/featured-automations-section.test.tsx b/__tests__/components/features/home/featured-automations-section.test.tsxindex 93b55fec6e..7ddd0fe7e2 100644--- a/__tests__/components/features/home/featured-automations-section.test.tsx+++ b/__tests__/components/features/home/featured-automations-section.test.tsx@@ -1,4 +1,4 @@-import { beforeEach, describe, expect, it, vi } from "vitest";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import React from "react";import { render, screen, waitFor, within } from "@testing-library/react";import userEvent from "@testing-library/user-event";@@ -7,6 +7,14 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import AutomationService from "#/api/automation-service/automation-service.api";import AgentServerConversationService from "#/api/conversation-service/agent-server-conversation-service.api";import type { AppConversation } from "#/api/conversation-service/agent-server-conversation-service.types";+import ProfilesService from "#/api/profiles-service/profiles-service.api";+import {+ __resetActiveStoreForTests,+ setActiveSelection,+ setRegisteredBackends,+} from "#/api/backend-registry/active-store";+import type { Backend } from "#/api/backend-registry/types";+import { ActiveBackendProvider } from "#/contexts/active-backend-context";import { PinnedAutomationsDashboard } from "#/components/features/home/featured-automations/pinned-automations-dashboard";import { RunningAutomationsList } from "#/components/features/home/featured-automations/running-automations-list";import { NavigationProvider } from "#/context/navigation-context";@@ -41,6 +49,12 @@ vi.mock("#/api/automation-service/automation-service.api", () => ({},}));+vi.mock("#/api/profiles-service/profiles-service.api", () => ({+ default: {+ listProfiles: vi.fn(),+ },+}));+vi.mock("#/utils/custom-toast-handlers", () => ({displaySuccessToast: vi.fn(),displayErrorToast: vi.fn(),@@ -164,6 +178,10 @@ beforeEach(() => {vi.mocked(AgentServerConversationService.batchGetAppConversations,).mockResolvedValue([]);+ vi.mocked(ProfilesService.listProfiles).mockResolvedValue({+ profiles: [],+ active_profile: null,+ });});describe("home automations composer layout", () => {@@ -540,3 +558,41 @@ describe("home automations composer layout", () => {});});});++describe("home automations on a cloud backend", () => {+ const cloudBackend: Backend = {+ id: "cloud-1",+ name: "Production",+ host: "https://app.all-hands.dev",+ apiKey: "bearer-key",+ kind: "cloud",+ };++ afterEach(() => {+ __resetActiveStoreForTests();+ });++ it("opens the Edit modal in place from a row menu instead of leaving the home surface", async () => {+ // Arrange β make a cloud backend active before mounting.+ setRegisteredBackends([cloudBackend]);+ setActiveSelection({ backendId: cloudBackend.id });+ const user = userEvent.setup();+ renderHomeAutomations(+ <ActiveBackendProvider>+ <RunningAutomationsList />+ </ActiveBackendProvider>,+ );+ await screen.findByTestId("running-automations-list");++ // Act β pick Edit from the row menu.+ await user.click(screen.getByTestId("running-automation-menu-auto-1"));+ await user.click(screen.getByTestId("running-automation-edit-auto-1"));++ // Assert β the editor opens pre-filled for this row rather than+ // bouncing the user to the detail page.+ const nameInput = (await screen.findByTestId(+ "edit-automation-name",+ )) as HTMLInputElement;+ expect(nameInput.value).toBe("Daily digest");+ });+});diff --git a/__tests__/routes/automation-detail.test.tsx b/__tests__/routes/automation-detail.test.tsxindex 0adf6db235..6941dd1484 100644--- a/__tests__/routes/automation-detail.test.tsx+++ b/__tests__/routes/automation-detail.test.tsx@@ -9,6 +9,7 @@ import { HttpError } from "@openhands/typescript-client";import { I18nKey } from "#/i18n/declaration";import AutomationService from "#/api/automation-service/automation-service.api";+import ProfilesService from "#/api/profiles-service/profiles-service.api";import {__resetActiveStoreForTests,setActiveSelection,@@ -31,6 +32,12 @@ vi.mock("#/api/automation-service/automation-service.api", () => ({},}));+vi.mock("#/api/profiles-service/profiles-service.api", () => ({+ default: {+ listProfiles: vi.fn(),+ },+}));+// Mock permission hooks so cloud-backend tests don't need a real /me endpoint.vi.mock("#/hooks/use-automation-permissions", () => ({useAutomationPermissions: () => ({@@ -111,6 +118,11 @@ beforeEach(() => {vi.mocked(AutomationService.getAutomation).mockResolvedValue(automation);vi.mocked(AutomationService.getAutomationRuns).mockReset();vi.mocked(AutomationService.getAutomationRuns).mockResolvedValue(emptyRuns);+ vi.mocked(ProfilesService.listProfiles).mockReset();+ vi.mocked(ProfilesService.listProfiles).mockResolvedValue({+ profiles: [],+ active_profile: null,+ });setRegisteredBackends([localBackend, cloudBackend]);setActiveSelection({ backendId: localBackend.id });});@@ -120,7 +132,7 @@ afterEach(() => {__resetActiveStoreForTests();});-describe("AutomationDetail β Edit is local-only", () => {+describe("AutomationDetail β Edit in the kebab menu", () => {it("shows Edit in the kebab menu when the active backend is local", async () => {// Arrange β default beforeEach selects the local backend.const user = userEvent.setup();@@ -139,7 +151,7 @@ describe("AutomationDetail β Edit is local-only", () => {).toBeInTheDocument();});- it("hides Edit in the kebab menu when the active backend is cloud", async () => {+ it("opens the Edit modal pre-filled from the kebab menu when the active backend is cloud", async () => {// Arrange β switch to the cloud backend BEFORE rendering so the// detail page mounts under cloud (the backend-change guard would// otherwise stop the fetch).@@ -150,17 +162,19 @@ describe("AutomationDetail β Edit is local-only", () => {expect(AutomationService.getAutomation).toHaveBeenCalledTimes(1);});- // Act+ // Act β open the kebab menu and pick Edit.await user.click(screen.getByLabelText(I18nKey.AUTOMATIONS$ACTIONS_MENU));+ await user.click(+ screen.getByRole("button", { name: I18nKey.AUTOMATIONS$EDIT }),+ );- // Assert β Edit must not appear on cloud; Delete still does, proving- // we opened the menu and didn't merely fail to render.- expect(- screen.queryByRole("button", { name: I18nKey.AUTOMATIONS$EDIT }),- ).not.toBeInTheDocument();- expect(- screen.getByRole("button", { name: I18nKey.AUTOMATIONS$DELETE }),- ).toBeInTheDocument();+ // Assert β the Edit modal mounts on cloud, pre-filled for this+ // automation; the permission model (mocked to canManage above) decides,+ // not the backend kind.+ const nameInput = (await screen.findByTestId(+ "edit-automation-name",+ )) as HTMLInputElement;+ expect(nameInput.value).toBe(automation.name);});});diff --git a/__tests__/routes/automations-list.test.tsx b/__tests__/routes/automations-list.test.tsxindex 63975621b8..521be86c85 100644--- a/__tests__/routes/automations-list.test.tsx+++ b/__tests__/routes/automations-list.test.tsx@@ -9,6 +9,7 @@ import { HttpError } from "@openhands/typescript-client";import { I18nKey } from "#/i18n/declaration";import AutomationService from "#/api/automation-service/automation-service.api";+import ProfilesService from "#/api/profiles-service/profiles-service.api";import {__resetActiveStoreForTests,setActiveSelection,@@ -35,6 +36,12 @@ vi.mock("#/api/automation-service/automation-service.api", () => ({},}));+vi.mock("#/api/profiles-service/profiles-service.api", () => ({+ default: {+ listProfiles: vi.fn(),+ },+}));+vi.mock("#/utils/custom-toast-handlers", () => ({displaySuccessToast: vi.fn(),displayErrorToast: vi.fn(),@@ -109,6 +116,11 @@ beforeEach(() => {vi.mocked(AutomationService.getAutomations).mockResolvedValue(listResponse);vi.mocked(AutomationService.updateAutomation).mockReset();vi.mocked(AutomationService.dispatchAutomation).mockReset();+ vi.mocked(ProfilesService.listProfiles).mockReset();+ vi.mocked(ProfilesService.listProfiles).mockResolvedValue({+ profiles: [],+ active_profile: null,+ });setRegisteredBackends([localBackend, cloudBackend]);setActiveSelection({ backendId: localBackend.id });});@@ -118,7 +130,7 @@ afterEach(() => {__resetActiveStoreForTests();});-describe("AutomationsList β Edit from the row kebab is local-only", () => {+describe("AutomationsList β Edit from the row kebab", () => {it("opens the Edit modal pre-filled with the row's values when the active backend is local", async () => {// Arrange β local backend is active (default beforeEach); render the list// and wait for the row to appear.@@ -145,7 +157,7 @@ describe("AutomationsList β Edit from the row kebab is local-only", () => {expect(nameInput.value).toBe(automation.name);});- it("hides Edit in the row kebab when the active backend is cloud", async () => {+ it("opens the Edit modal pre-filled from the row kebab when the active backend is cloud", async () => {// Arrange β switch to the cloud backend before mounting so the page sees// it as the active backend on first render.setActiveSelection({ backendId: cloudBackend.id });@@ -156,18 +168,34 @@ describe("AutomationsList β Edit from the row kebab is local-only", () => {});await screen.findByText(automation.name);- // Act β open the row kebab. The aria-label resolves to the I18n key- // in tests because `t` is mocked to return the key itself.+ // Act β open the row kebab and pick Edit. The aria-label resolves to+ // the I18n key in tests because `t` is mocked to return the key itself.await user.click(screen.getByLabelText(I18nKey.AUTOMATIONS$ACTIONS_MENU));+ await user.click(+ screen.getByRole("button", { name: I18nKey.AUTOMATIONS$EDIT }),+ );++ // Assert β the same Edit modal mounts on cloud, wired to this row; the+ // permission model (mocked to canManage above) decides, not the backend.+ const nameInput = (await screen.findByTestId(+ "edit-automation-name",+ )) as HTMLInputElement;+ expect(nameInput.value).toBe(automation.name);+ });+});++describe("AutomationsList β Git Sync entry point", () => {+ it("hides the Git Sync button when the active backend is cloud", async () => {+ // Arrange β Git Sync is a local-only operator feature that used to share+ // Edit's backend gate; it must not follow Edit onto cloud.+ setActiveSelection({ backendId: cloudBackend.id });+ renderList();+ await screen.findByText(automation.name);- // Assert β Edit must not appear on cloud; Delete still does, proving the- // menu actually opened and we didn't merely fail to render it.+ // Assertexpect(- screen.queryByRole("button", { name: I18nKey.AUTOMATIONS$EDIT }),+ screen.queryByTestId("automations-git-sync"),).not.toBeInTheDocument();- expect(- screen.getByRole("button", { name: I18nKey.AUTOMATIONS$DELETE }),- ).toBeInTheDocument();});});diff --git a/src/components/features/automations/detail/detail-header.tsx b/src/components/features/automations/detail/detail-header.tsxindex 6145e876a6..fc4267f3f1 100644--- a/src/components/features/automations/detail/detail-header.tsx+++ b/src/components/features/automations/detail/detail-header.tsx@@ -13,10 +13,7 @@ import { ActiveStatusBadge } from "./active-status-badge";interface DetailHeaderProps {automation: Automation;onToggle: () => void;- /**- * When provided, the kebab menu shows an Edit entry. Omitted for cloud- * backends where the Edit feature is not supported in MVP.- */+ /** When provided (and the user can manage), the kebab menu shows an Edit entry. */onEdit?: () => void;onDelete: () => void;onExport: () => void;diff --git a/src/components/features/home/featured-automations/build-home-automation-menu-items.tsx b/src/components/features/home/featured-automations/build-home-automation-menu-items.tsxindex e9ec0b4e88..b6530d0473 100644--- a/src/components/features/home/featured-automations/build-home-automation-menu-items.tsx+++ b/src/components/features/home/featured-automations/build-home-automation-menu-items.tsx@@ -22,7 +22,6 @@ interface BuildHomeAutomationMenuItemsOptions {automation: Automation;t: (key: I18nKey) => string;canManage: boolean;- canEdit: boolean;isRunPending: boolean;isCancelPending: boolean;canCancel: boolean;@@ -45,7 +44,6 @@ export function buildHomeAutomationMenuItems({automation,t,canManage,- canEdit,isRunPending,isCancelPending,canCancel,@@ -94,7 +92,7 @@ export function buildHomeAutomationMenuItems({testId: `${testIdPrefix}-view-${automation.id}`,});- if (canManage && canEdit && onEdit) {+ if (canManage && onEdit) {items.push({kind: "item",key: "edit",diff --git a/src/components/features/home/featured-automations/build-pinned-automation-menu-items.tsx b/src/components/features/home/featured-automations/build-pinned-automation-menu-items.tsxindex 2253ea63e3..8e8097b4b1 100644--- a/src/components/features/home/featured-automations/build-pinned-automation-menu-items.tsx+++ b/src/components/features/home/featured-automations/build-pinned-automation-menu-items.tsx@@ -11,7 +11,6 @@ interface BuildPinnedAutomationMenuItemsOptions {automation: Automation;t: (key: I18nKey) => string;canManage: boolean;- canEdit: boolean;isRunPending: boolean;isCancelPending: boolean;canCancel: boolean;diff --git a/src/components/features/home/featured-automations/pinned-automation-card.tsx b/src/components/features/home/featured-automations/pinned-automation-card.tsxindex fc6f14a06c..032dd5e717 100644--- a/src/components/features/home/featured-automations/pinned-automation-card.tsx+++ b/src/components/features/home/featured-automations/pinned-automation-card.tsx@@ -109,14 +109,13 @@ export function PinnedAutomationCard({automation,t,canManage: actions.canManage,- canEdit: actions.canEdit,isRunPending: actions.isRunPending,isCancelPending: actions.isCancelPending,canCancel: actions.canCancel,onRunNow: actions.runNow,onCancelRun: actions.cancelRun,onView: actions.viewDetails,- onEdit: actions.canEdit ? actions.openEdit : undefined,+ onEdit: actions.openEdit,onTurnOff: actions.requestTurnOff,onUnpin: () => onUnpin(automation.id),});diff --git a/src/components/features/home/featured-automations/running-automations-list.tsx b/src/components/features/home/featured-automations/running-automations-list.tsxindex 5059ae94f9..0634d0c762 100644--- a/src/components/features/home/featured-automations/running-automations-list.tsx+++ b/src/components/features/home/featured-automations/running-automations-list.tsx@@ -79,7 +79,6 @@ function RunningAutomationRow({automation,t,canManage: actions.canManage,- canEdit: actions.canEdit,isRunPending: actions.isRunPending,isCancelPending: actions.isCancelPending,canCancel: actions.canCancel,@@ -89,7 +88,7 @@ function RunningAutomationRow({onRunNow: actions.runNow,onCancelRun: actions.cancelRun,onView: actions.viewDetails,- onEdit: actions.canEdit ? actions.openEdit : undefined,+ onEdit: actions.openEdit,onTurnOff: actions.requestTurnOff,onTogglePin: () => togglePin(item.id),});diff --git a/src/hooks/use-home-automation-actions.ts b/src/hooks/use-home-automation-actions.tsindex 93a362c8fd..f83ba1ba31 100644--- a/src/hooks/use-home-automation-actions.ts+++ b/src/hooks/use-home-automation-actions.ts@@ -1,6 +1,5 @@import { useCallback, useState } from "react";import { useTranslation } from "react-i18next";-import { useActiveBackend } from "#/contexts/active-backend-context";import { useNavigation } from "#/context/navigation-context";import {useCancelAutomationRun,@@ -35,7 +34,7 @@ export function isInFlightAutomationRun(/*** Shared home-surface actions for pinned cards and activity rows:- * run now, view, edit (local), turn off (with confirm), cancel in-flight.+ * run now, view, edit, turn off (with confirm), cancel in-flight.*/export function useHomeAutomationActions(automation: Automation,@@ -43,13 +42,11 @@ export function useHomeAutomationActions() {const { t } = useTranslation("openhands");const { navigate } = useNavigation();- const active = useActiveBackend();const { canManage: hasManagePermission } = useAutomationPermissions();const isOwner = useIsAutomationOwner(automation);// Write actions on a specific automation are allowed when the user has// manage permission OR is the automation's creator (creator escape hatch).const canManage = hasManagePermission || isOwner;- const canEdit = active.backend.kind === "local";const isDemo = isHomeAutomationsDemoEnabled();const dispatchMutation = useDispatchAutomation();@@ -88,12 +85,8 @@ export function useHomeAutomationActions(}, [automation.id, navigate]);const openEdit = useCallback(() => {- if (!canEdit) {- viewDetails();- return;- }setEditOpen(true);- }, [canEdit, viewDetails]);+ }, []);const requestTurnOff = useCallback(() => {setTurnOffConfirmOpen(true);@@ -141,7 +134,6 @@ export function useHomeAutomationActions(return {canManage,- canEdit,isRunPending,isCancelPending,canCancel,diff --git a/src/routes/automation-detail.tsx b/src/routes/automation-detail.tsxindex 832ca01b7a..076bc0a8cf 100644--- a/src/routes/automation-detail.tsx+++ b/src/routes/automation-detail.tsx@@ -217,9 +217,6 @@ export default function AutomationDetail() {trackAutomationExported({ backendKind: active.backend.kind });};- // Edit is a local-backend-only feature in MVP β cloud automations- // are managed elsewhere and we don't yet surface them here.- const canEdit = active.backend.kind === "local";// Write actions on a specific automation: manage OR creator (escape hatch).const canManage = hasManagePermission || isOwner;// Non-creators may turn an automation off but not back on.@@ -233,7 +230,7 @@ export default function AutomationDetail() {<DetailHeaderautomation={automation}onToggle={handleToggle}- onEdit={canEdit ? () => setShowEditModal(true) : undefined}+ onEdit={() => setShowEditModal(true)}onDelete={() => setShowDeleteModal(true)}onExport={handleExport}onDownloadTarball={() =>@@ -263,7 +260,7 @@ export default function AutomationDetail() {onConfirm={handleDelete}onCancel={() => setShowDeleteModal(false)}/>- {canEdit && (+ {showEditModal && (<EditAutomationModalautomation={automation}isOpen={showEditModal}diff --git a/src/routes/automations-list.tsx b/src/routes/automations-list.tsxindex 19c006eac1..6f1eab87d4 100644--- a/src/routes/automations-list.tsx+++ b/src/routes/automations-list.tsx@@ -119,9 +119,8 @@ export default function AutomationsList() {const active = useActiveBackend();const { navigate } = useNavigation();- // Edit is a local-backend-only feature in MVP β cloud automations- // are managed elsewhere and we don't yet surface them here.- const canEdit = active.backend.kind === "local";+ // Git Sync is only available on local backends.+ const isLocalBackend = active.backend.kind === "local";// Creating an automation requires manage_automations (no owner escape hatch// β it's a new record, not a mutation of an existing one).const { canManage } = useAutomationPermissions();@@ -377,7 +376,7 @@ export default function AutomationsList() {</p></div><div className="flex shrink-0 flex-wrap justify-end gap-2">- {canEdit && (+ {isLocalBackend && (<BrandButtontype="button"variant="secondary"@@ -468,7 +467,7 @@ export default function AutomationsList() {}onDelete={handleDeleteRequest}onExport={handleExport}- onEdit={canEdit ? handleEditRequest : undefined}+ onEdit={handleEditRequest}insights={groupInsights}/><AutomationGroup@@ -485,7 +484,7 @@ export default function AutomationsList() {}onDelete={handleDeleteRequest}onExport={handleExport}- onEdit={canEdit ? handleEditRequest : undefined}+ onEdit={handleEditRequest}insights={groupInsights}/>@@ -517,7 +516,7 @@ export default function AutomationsList() {onCancel={() => setDeleteTarget(null)}/>- {/* Edit modal β local backends only */}+ {/* Edit modal */}{editTarget && (<EditAutomationModalautomation={editTarget}