π OpenHands: AI-Driven Development
fix(automations): keep the setup handoff on its own conversation (#18385)
Engel Nyst34386d08d311
diff --git a/__tests__/components/features/conversation/conversation-main.test.tsx b/__tests__/components/features/conversation/conversation-main.test.tsxindex a2cd4fe263..d0dcddc9e5 100644--- a/__tests__/components/features/conversation/conversation-main.test.tsx+++ b/__tests__/components/features/conversation/conversation-main.test.tsx@@ -7,12 +7,12 @@ import {type NavigationContextValue,} from "#/context/navigation-context";import { requestAutomationSetupAgent } from "#/components/features/automations/setup/automation-setup-agent-request";+import { markAutomationSetupHandoff } from "#/api/automation-setup-handoff-store";// Mutable mock state for controlling breakpointlet mockIsMobile = false;let mockIsRightPanelShown = false;let mockLeftWidth = 50;-let mockHasAutomationSetupHandoff = false;let mockActiveConversationTags: Record<string, string> | null = null;const mockNavigate = vi.fn();@@ -21,6 +21,9 @@ const mockSetIsRightPanelShown = vi.fn();// Track ChatInterface unmount via vi.fn()const chatInterfaceUnmount = vi.fn();+// Every conversation id the setup panel is rendered for. The real panel tags+// that conversation as an automation setup on mount.+const automationSetupPanelRender = vi.fn();vi.mock("react-i18next", () => ({useTranslation: () => ({ t: (key: string) => key }),@@ -49,10 +52,6 @@ vi.mock("#/stores/conversation-store", () => ({}),}));-vi.mock("#/api/automation-setup-handoff-store", () => ({- consumeAutomationSetupHandoff: () => mockHasAutomationSetupHandoff,-}));-vi.mock("#/hooks/query/use-active-conversation", () => ({useActiveConversation: () => ({data: { title: "Daily Morning Haiku", tags: mockActiveConversationTags },@@ -149,30 +148,36 @@ vi.mock(}: {conversationId?: string | null;toolbarPortal?: HTMLElement | null;- }) => (- <>- {toolbarPortal- ? createPortal(- <button type="button" data-testid="automation-setup-create" />,- toolbarPortal,- )- : null}- <div- data-testid="automation-setup-panel"- data-conversation-id={conversationId ?? ""}- />- </>- ),+ }) => {+ automationSetupPanelRender(conversationId);+ return (+ <>+ {toolbarPortal+ ? createPortal(+ <button+ type="button"+ data-testid="automation-setup-create"+ />,+ toolbarPortal,+ )+ : null}+ <div+ data-testid="automation-setup-panel"+ data-conversation-id={conversationId ?? ""}+ />+ </>+ );+ },};},);import { ConversationMain } from "#/components/features/conversation/conversation-main/conversation-main";-function conversationMainTree() {+function conversationMainTree(conversationId = "conv-1") {const navigation: NavigationContextValue = {- currentPath: "/conversations/conv-1",- conversationId: "conv-1",+ currentPath: `/conversations/${conversationId}`,+ conversationId,isNavigating: false,navigate: mockNavigate,};@@ -195,9 +200,10 @@ describe("ConversationMain - Layout Transition Stability", () => {mockIsMobile = false;mockIsRightPanelShown = false;mockLeftWidth = 50;- mockHasAutomationSetupHandoff = false;mockActiveConversationTags = null;+ window.sessionStorage.clear();chatInterfaceUnmount.mockClear();+ automationSetupPanelRender.mockClear();mockNavigate.mockClear();mockSetHasRightPanelToggled.mockClear();mockSetIsRightPanelShown.mockClear();@@ -215,6 +221,25 @@ describe("ConversationMain - Layout Transition Stability", () => {expect(mockSetIsRightPanelShown).toHaveBeenCalledWith(true);});+ it("keeps a setup handoff on its own conversation when navigating to another", () => {+ markAutomationSetupHandoff("conv-1");+ const { rerender } = render(conversationMainTree("conv-1"));+ expect(screen.getByTestId("automation-setup-panel")).toHaveAttribute(+ "data-conversation-id",+ "conv-1",+ );++ rerender(conversationMainTree("conv-2"));++ expect(automationSetupPanelRender).not.toHaveBeenCalledWith("conv-2");+ expect(+ screen.queryByTestId("automation-setup-panel"),+ ).not.toBeInTheDocument();+ expect(+ screen.queryByTestId("automation-setup-topbar"),+ ).not.toBeInTheDocument();+ });+it.each([["desktop", false],["mobile", true],@@ -261,7 +286,7 @@ describe("ConversationMain - Layout Transition Stability", () => {it("uses a single automation setup top bar", () => {mockIsRightPanelShown = true;- mockHasAutomationSetupHandoff = true;+ markAutomationSetupHandoff("conv-1");renderConversationMain();@@ -296,7 +321,7 @@ describe("ConversationMain - Layout Transition Stability", () => {const user = userEvent.setup();mockIsMobile = true;mockIsRightPanelShown = true;- mockHasAutomationSetupHandoff = true;+ markAutomationSetupHandoff("conv-1");renderConversationMain();@@ -379,7 +404,7 @@ describe("ConversationMain - Layout Transition Stability", () => {it("expands the automation form to full width when hiding the agent", async () => {const user = userEvent.setup();mockIsRightPanelShown = true;- mockHasAutomationSetupHandoff = true;+ markAutomationSetupHandoff("conv-1");renderConversationMain();@@ -412,7 +437,7 @@ describe("ConversationMain - Layout Transition Stability", () => {async (trigger) => {const user = userEvent.setup();mockIsRightPanelShown = true;- mockHasAutomationSetupHandoff = true;+ markAutomationSetupHandoff("conv-1");renderConversationMain();await user.click(screen.getByTestId("automation-setup-agent-toggle"));diff --git a/src/components/features/conversation/conversation-main/conversation-main.tsx b/src/components/features/conversation/conversation-main/conversation-main.tsxindex ae4601a8c0..1720384e99 100644--- a/src/components/features/conversation/conversation-main/conversation-main.tsx+++ b/src/components/features/conversation/conversation-main/conversation-main.tsx@@ -1,4 +1,4 @@-import { useEffect, useState } from "react";+import { useEffect, useMemo, useState } from "react";import { FileText, MessageSquare } from "lucide-react";import { useTranslation } from "react-i18next";import { cn } from "#/utils/utils";@@ -84,8 +84,14 @@ export function ConversationMain() {const isSidebarRailHidden = useBreakpoint(SIDEBAR_RAIL_COLLAPSE_MAX_WIDTH);const { isRightPanelShown, setHasRightPanelToggled, setIsRightPanelShown } =useConversationStore();- const [isAutomationSetupModeHandoff, setIsAutomationSetupModeHandoff] =- useState(() => consumeAutomationSetupHandoff(conversationId));+ // Derived per conversation during render: holding it in state reset by an+ // effect let the first render after a conversation switch reuse the previous+ // conversation's handoff, mounting the setup panel (which tags the+ // conversation as an automation setup) on the wrong conversation.+ const isAutomationSetupModeHandoff = useMemo(+ () => consumeAutomationSetupHandoff(conversationId),+ [conversationId],+ );const [automationToolbarElement, setAutomationToolbarElement] =useState<HTMLDivElement | null>(null);const [isAutomationAgentHidden, setIsAutomationAgentHidden] = useState(false);@@ -114,12 +120,6 @@ export function ConversationMain() {storageKey: "desktop-layout-panel-width",});- useEffect(() => {- setIsAutomationSetupModeHandoff(- consumeAutomationSetupHandoff(conversationId),- );- }, [conversationId]);-useEffect(() => {if (!automationSetupDraft) return;setHasRightPanelToggled(true);