Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): keep automation change-back state accurate
Xubin Ren17a66dcecf04
diff --git a/webui/src/components/settings/system/AutomationChatBinding.tsx b/webui/src/components/settings/system/AutomationChatBinding.tsxindex 72d52fc95..d16d02469 100644--- a/webui/src/components/settings/system/AutomationChatBinding.tsx+++ b/webui/src/components/settings/system/AutomationChatBinding.tsx@@ -56,7 +56,10 @@ export function AutomationChatBinding({ job, token, chatNames, onSave, childrenconst controller = new AbortController();setLoadError(false);void fetchAutomationChats(token, job.id, controller.signal).then(value => {- if (!controller.signal.aborted) setData(value);+ if (!controller.signal.aborted) {+ setData(value);+ setSaved(previous => previous?.target.id === value.current?.id ? previous : null);+ }}).catch(() => { if (!controller.signal.aborted) setLoadError(true); });return () => controller.abort();}, [token, job.id, job.chat_binding_revision, reload]);@@ -91,7 +94,7 @@ export function AutomationChatBinding({ job, token, chatNames, onSave, childrendisabled={pickerDisabled} onValueChange={id => {const target = data?.chats.find(chat => chat.id === id);if (!target || target.unavailable || id === current?.id) return;- setError(""); setSaved(null);+ setError("");setDraft(previous => previous ? { ...previous, target } : {target, previous: current ?? fallback,revision: job.chat_binding_revision!, message: job.payload.message,diff --git a/webui/src/tests/automation-chat-binding.test.tsx b/webui/src/tests/automation-chat-binding.test.tsxindex cb3ed66b0..48fb9fca1 100644--- a/webui/src/tests/automation-chat-binding.test.tsx+++ b/webui/src/tests/automation-chat-binding.test.tsx@@ -90,6 +90,43 @@ it("uses Chinese for the task menu and the change/cancel path", async () => {expect(save).not.toHaveBeenCalled();});+it("keeps change-back available when another proposed change is cancelled", async () => {+ const user = userEvent.setup();+ const save = vi.fn().mockResolvedValue(undefined);+ const { rerender } = render(<AutomationDetailDialog {...props} job={job} onChangeChat={save} />);+ await choose();+ vi.mocked(fetchAutomationChats).mockResolvedValue({ ...choices, current: target, revision: "rev-2" });+ await user.click(screen.getByRole("button", { name: "Confirm change" }));+ rerender(<AutomationDetailDialog {...props} job={{ ...job, chat_binding_revision: "rev-2" }} onChangeChat={save} />);+ const changeBack = await screen.findByRole("button", { name: "Change back to “My planning”" });+ await waitFor(() => expect(changeBack).toBeEnabled());+ fireEvent.keyDown(screen.getByRole("combobox", { name: "Run and reply in" }), { key: "ArrowDown" });+ await user.click(await screen.findByRole("option", { name: /My planning/ }));+ await user.click(screen.getByRole("button", { name: "Cancel" }));+ expect(screen.getByRole("combobox", { name: "Run and reply in" })).toHaveTextContent("Product team");+ expect(screen.getByRole("button", { name: "Change back to “My planning”" })).toBeEnabled();+ expect(save).toHaveBeenCalledTimes(1);+});++it("removes an obsolete save confirmation after another client changes the chat", async () => {+ const user = userEvent.setup();+ const save = vi.fn().mockResolvedValue(undefined);+ const { rerender } = render(<AutomationDetailDialog {...props} job={job} onChangeChat={save} />);+ await choose();+ vi.mocked(fetchAutomationChats).mockResolvedValue({ ...choices, current: target, revision: "rev-2" });+ await user.click(screen.getByRole("button", { name: "Confirm change" }));+ rerender(<AutomationDetailDialog {...props} job={{ ...job, chat_binding_revision: "rev-2" }} onChangeChat={save} />);+ expect(await screen.findByRole("status")).toHaveTextContent("Product team");++ vi.mocked(fetchAutomationChats).mockResolvedValue({ ...choices, revision: "rev-3" });+ rerender(<AutomationDetailDialog {...props} job={{ ...job, chat_binding_revision: "rev-3" }} onChangeChat={save} />);+ await waitFor(() => expect(screen.getByRole("combobox", { name: "Run and reply in" })).toBeEnabled());+ expect(screen.getByRole("combobox", { name: "Run and reply in" })).toHaveTextContent("My planning");+ expect(screen.queryByRole("status")).not.toBeInTheDocument();+ expect(screen.queryByRole("button", { name: /Change back/ })).not.toBeInTheDocument();+ expect(save).toHaveBeenCalledTimes(1);+});+it("cancels a chat change without saving the edited instructions", async () => {const user = userEvent.setup();const save = vi.fn();