Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(autopilots): keep fields saved elsewhere when the edit dialog saves (#11499)
pseudoyub72a3f9fc3d9
diff --git a/packages/views/autopilots/components/autopilot-dialog.project.test.tsx b/packages/views/autopilots/components/autopilot-dialog.project.test.tsxindex 0f6085e6db..0d0168d418 100644--- a/packages/views/autopilots/components/autopilot-dialog.project.test.tsx+++ b/packages/views/autopilots/components/autopilot-dialog.project.test.tsx@@ -88,7 +88,14 @@ vi.mock("../../editor", () => ({/>);},- ContentEditor: ({ placeholder }: any) => <textarea aria-label="runbook" placeholder={placeholder} />,+ ContentEditor: ({ defaultValue, placeholder, onUpdate }: any) => (+ <textarea+ aria-label="runbook"+ defaultValue={defaultValue}+ placeholder={placeholder}+ onChange={(e) => onUpdate?.(e.target.value)}+ />+ ),}));vi.mock("../../common/actor-avatar", () => ({@@ -96,7 +103,11 @@ vi.mock("../../common/actor-avatar", () => ({}));vi.mock("./subscriber-multi-select", () => ({- SubscriberMultiSelect: () => <div data-testid="subscriber-multi-select" />,+ SubscriberMultiSelect: ({ onChange }: { onChange: (ids: string[]) => void }) => (+ <button type="button" onClick={() => onChange([])}>+ clear subscribers+ </button>+ ),}));// Stand-in picker: renders the dialog's own trigger (so the selected project@@ -123,13 +134,17 @@ vi.mock("./pickers/timezone-picker", () => ({TimezonePicker: ({ value }: { value: string }) => <div data-testid="timezone-picker">{value}</div>,}));-import { AutopilotDialog } from "./autopilot-dialog";+import { AutopilotDialog, type AutopilotInitial } from "./autopilot-dialog";const AUTOPILOT_ID = "ap-1";-function renderEditDialog(mode: AutopilotExecutionMode, projectId: string | null) {+function renderEditDialog(+ mode: AutopilotExecutionMode,+ projectId: string | null,+ saved: Partial<AutopilotInitial> = {},+) {const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });- return renderWithI18n(+ const dialog = (overrides: Partial<AutopilotInitial>) => (<QueryClientProvider client={qc}><AutopilotDialogmode="edit"@@ -144,13 +159,17 @@ function renderEditDialog(mode: AutopilotExecutionMode, projectId: string | nullassignee_id: "agent-1",execution_mode: mode,subscriber_user_ids: [],+ ...overrides,}}triggers={[]}collaborators={[]}canManageAccess={false}/>- </QueryClientProvider>,+ </QueryClientProvider>);+ const view = renderWithI18n(dialog(saved));+ // Another session saved the autopilot while this dialog was open.+ return { changeElsewhere: (next: Partial<AutopilotInitial>) => view.rerender(dialog(next)) };}function renderCreateDialog() {@@ -204,10 +223,9 @@ describe("AutopilotDialog project section", () => {await user.click(saveButton());await waitFor(() => expect(mockUpdateAutopilot).toHaveBeenCalledTimes(1));- expect(mockUpdateAutopilot.mock.calls[0]?.[0]).toMatchObject({+ expect(mockUpdateAutopilot.mock.calls[0]?.[0]).toEqual({id: AUTOPILOT_ID,- execution_mode: "run_only",- project_id: "proj-1",+ title: "Push fleet repo to GitHub v2",});});@@ -218,7 +236,49 @@ describe("AutopilotDialog project section", () => {await user.click(saveButton());await waitFor(() => expect(mockUpdateAutopilot).toHaveBeenCalledTimes(1));- expect(mockUpdateAutopilot.mock.calls[0]?.[0]).toMatchObject({ project_id: "proj-1" });+ expect(mockUpdateAutopilot.mock.calls[0]?.[0]).toEqual({ id: AUTOPILOT_ID });+ });++ it("keeps fields saved elsewhere while the dialog was open", async () => {+ const user = userEvent.setup();+ const { changeElsewhere } = renderEditDialog("create_issue", null);++ await user.type(screen.getByLabelText("title"), " v2");+ changeElsewhere({+ description: "New runbook",+ project_id: "proj-1",+ assignee_type: "squad",+ assignee_id: "squad-1",+ execution_mode: "run_only",+ subscriber_user_ids: ["user-2"],+ });+ await user.click(saveButton());++ await waitFor(() => expect(mockUpdateAutopilot).toHaveBeenCalledTimes(1));+ expect(mockUpdateAutopilot.mock.calls[0]?.[0]).toEqual({+ id: AUTOPILOT_ID,+ title: "Push fleet repo to GitHub v2",+ });+ });++ it("sends every field the user changed", async () => {+ const user = userEvent.setup();+ renderEditDialog("create_issue", null, { subscriber_user_ids: ["user-1"] });++ await user.type(screen.getByLabelText("runbook"), "Steps");+ await user.click(screen.getByRole("button", { name: "pick Fleet" }));+ await user.click(screen.getByRole("button", { name: "clear subscribers" }));+ await user.click(screen.getByRole("button", { name: /Run only/ }));+ await user.click(saveButton());++ await waitFor(() => expect(mockUpdateAutopilot).toHaveBeenCalledTimes(1));+ expect(mockUpdateAutopilot.mock.calls[0]?.[0]).toEqual({+ id: AUTOPILOT_ID,+ description: "Steps",+ project_id: "proj-1",+ execution_mode: "run_only",+ subscribers: [],+ });});it("binds a project chosen while creating a run_only autopilot", async () => {diff --git a/packages/views/autopilots/components/autopilot-dialog.tsx b/packages/views/autopilots/components/autopilot-dialog.tsxindex 846e5d1cf4..7092a18a4e 100644--- a/packages/views/autopilots/components/autopilot-dialog.tsx+++ b/packages/views/autopilots/components/autopilot-dialog.tsx@@ -54,6 +54,7 @@ import type {AutopilotCollaborator,AutopilotExecutionMode,AutopilotTrigger,+ UpdateAutopilotRequest,} from "@multica/core/types";import { TitleEditor, ContentEditor, type TitleEditorRef } from "../../editor";import { ActorAvatar } from "../../common/actor-avatar";@@ -133,6 +134,10 @@ export function AutopilotDialog(props: AutopilotDialogProps) {? props.initial ?? {}: props.initial;+ // What this form opened with. `initial` follows the server, so a save compares+ // against this to leave fields the user never touched to whoever changed them.+ const openedRef = useRef(initial);+const [title, setTitle] = useState(initial.title ?? "");const [description, setDescription] = useState(initial.description ?? "");const [projectId, setProjectId] = useState<string | null>(initial.project_id ?? null);@@ -355,19 +360,23 @@ export function AutopilotDialog(props: AutopilotDialogProps) {toast.error(formatSchedulePartialFailureToast(t, "create", triggerErrMessage));}} else {- await updateAutopilot.mutateAsync({- id: props.autopilotId,- title: title.trim(),- description: description.trim() || null,- project_id: projectId,- assignee_type: assigneeType,- assignee_id: assigneeId,- execution_mode: executionMode,- subscribers: subscriberUserIds.map((user_id) => ({+ const opened = openedRef.current;+ const changes: UpdateAutopilotRequest = {};+ if (title !== opened.title) changes.title = title.trim();+ if (description !== opened.description) changes.description = description.trim() || null;+ if (projectId !== opened.project_id) changes.project_id = projectId;+ if (assigneeType !== opened.assignee_type || assigneeId !== opened.assignee_id) {+ changes.assignee_type = assigneeType;+ changes.assignee_id = assigneeId;+ }+ if (executionMode !== opened.execution_mode) changes.execution_mode = executionMode;+ if (subscriberUserIds.join() !== (opened.subscriber_user_ids ?? []).join()) {+ changes.subscribers = subscriberUserIds.map((user_id) => ({user_type: "member" as const,user_id,- })),- });+ }));+ }+ await updateAutopilot.mutateAsync({ id: props.autopilotId, ...changes });let triggerOk = true;let triggerErrMessage: string | null = null;// Skip the schedule sync when the autopilot's first trigger is a