π OpenHands: AI-Driven Development
fix: disable Run Now when the automation is turned off (#800)
Hiep Led2a021e5d364
diff --git a/__tests__/routes/automation-detail.test.tsx b/__tests__/routes/automation-detail.test.tsxindex 37d6b5d78c..a05128c50b 100644--- a/__tests__/routes/automation-detail.test.tsx+++ b/__tests__/routes/automation-detail.test.tsx@@ -197,4 +197,22 @@ describe("AutomationDetail β backend-change guard", () => {});expect(AutomationService.dispatchAutomation).toHaveBeenCalledTimes(1);});++ it("does not dispatch when Run now is clicked on a disabled automation", async () => {+ // Arrange β the detail page loads a turned-off automation.+ vi.mocked(AutomationService.getAutomation).mockResolvedValue({+ ...automation,+ enabled: false,+ });+ const user = userEvent.setup();+ renderDetail();+ const runNow = await screen.findByRole("button", { name: "Run now" });++ // Act β userEvent honors the disabled attribute and suppresses the click.+ await user.click(runNow);++ // Assert β the off-state gate prevents the dispatch API from firing.+ expect(runNow).toBeDisabled();+ expect(AutomationService.dispatchAutomation).not.toHaveBeenCalled();+ });});diff --git a/__tests__/routes/automations-list.test.tsx b/__tests__/routes/automations-list.test.tsxindex 009c500d28..d1dd6214a1 100644--- a/__tests__/routes/automations-list.test.tsx+++ b/__tests__/routes/automations-list.test.tsx@@ -246,6 +246,53 @@ describe("AutomationsList β Run now toasts", () => {expect(displayErrorToast).not.toHaveBeenCalled();});+ it("does not dispatch when Run now is clicked on a disabled automation (grid view)", async () => {+ // Arrange β single automation that is turned off.+ const disabledAutomation: Automation = { ...automation, enabled: false };+ vi.mocked(AutomationService.getAutomations).mockResolvedValue({+ automations: [disabledAutomation],+ total: 1,+ });+ const user = userEvent.setup();+ renderList();+ const button = await screen.findByTestId(+ `automation-run-now-${disabledAutomation.id}`,+ );++ // Act β userEvent honors the disabled attribute, so the click is suppressed.+ await user.click(button);++ // Assert β the off-state gate prevents the dispatch API from firing.+ expect(button).toBeDisabled();+ expect(AutomationService.dispatchAutomation).not.toHaveBeenCalled();+ });++ it("does not dispatch when Run now is clicked on a disabled automation (list view)", async () => {+ // Arrange β pre-seed the stored view mode so the page mounts in list view,+ // then return a single disabled automation.+ window.localStorage.setItem("openhands-automations-view", "list");+ const disabledAutomation: Automation = { ...automation, enabled: false };+ vi.mocked(AutomationService.getAutomations).mockResolvedValue({+ automations: [disabledAutomation],+ total: 1,+ });+ const user = userEvent.setup();+ renderList();+ await screen.findByTestId(+ `automation-list-row-${disabledAutomation.id}`,+ );+ const button = screen.getByTestId(+ `automation-run-now-${disabledAutomation.id}`,+ );++ // Act+ await user.click(button);++ // Assert+ expect(button).toBeDisabled();+ expect(AutomationService.dispatchAutomation).not.toHaveBeenCalled();+ });+it("shows an error toast when the dispatch API rejects", async () => {// Arrange β service rejects with a plain Error so the fallback branch fires.vi.mocked(AutomationService.dispatchAutomation).mockRejectedValue(diff --git a/src/components/features/automations/automation-card.tsx b/src/components/features/automations/automation-card.tsxindex 32dc80acd5..ba58e24e89 100644--- a/src/components/features/automations/automation-card.tsx+++ b/src/components/features/automations/automation-card.tsx@@ -97,7 +97,7 @@ export function AutomationCard({type="button"data-testid={`automation-run-now-${automation.id}`}aria-busy={isRunPending}- disabled={isRunPending}+ disabled={isRunPending || !automation.enabled}onClick={(event) => {event.stopPropagation();onRunNow(automation.id);diff --git a/src/components/features/automations/automation-list-row.tsx b/src/components/features/automations/automation-list-row.tsxindex fcb14929df..352027a6c3 100644--- a/src/components/features/automations/automation-list-row.tsx+++ b/src/components/features/automations/automation-list-row.tsx@@ -108,7 +108,7 @@ export function AutomationListRow({data-testid={`automation-run-now-${automation.id}`}aria-label={t(I18nKey.AUTOMATIONS$RUN_NOW)}aria-busy={isRunPending}- disabled={isRunPending}+ disabled={isRunPending || !automation.enabled}onClick={(event) => {event.stopPropagation();onRunNow(automation.id);diff --git a/src/components/features/automations/build-automation-menu-items.tsx b/src/components/features/automations/build-automation-menu-items.tsxindex a9ffe0e3e4..2b8bb445d0 100644--- a/src/components/features/automations/build-automation-menu-items.tsx+++ b/src/components/features/automations/build-automation-menu-items.tsx@@ -37,7 +37,7 @@ export function buildAutomationMenuItems({label: t(I18nKey.AUTOMATIONS$RUN_NOW),icon: <PlayIcon className="size-4" />,onClick: () => onRunNow(automation.id),- disabled: isRunPending,+ disabled: isRunPending || !automation.enabled,},]: []),diff --git a/src/components/features/automations/detail/detail-header.tsx b/src/components/features/automations/detail/detail-header.tsxindex cf26228f1d..ae27bc7119 100644--- a/src/components/features/automations/detail/detail-header.tsx+++ b/src/components/features/automations/detail/detail-header.tsx@@ -80,7 +80,7 @@ export function DetailHeader({<buttontype="button"className="rounded-md border border-[var(--oh-border)] px-3 py-1.5 text-sm font-medium text-content transition-colors hover:bg-surface-raised disabled:cursor-not-allowed disabled:opacity-60"- disabled={isRunningNow}+ disabled={isRunningNow || !automation.enabled}onClick={onRunNow}>{isRunningNow ? "Startingβ¦" : "Run now"}