fix: preserve inherited workspace delete copy (#3864)
This commit is contained in:
@@ -4,6 +4,7 @@ import { useRef, type RefObject } from "react";
|
||||
import { useActiveWorkspaceRepositories } from "@/components/kanban-card-repositories";
|
||||
import { TaskArchiveConfirmation } from "@/components/task/task-archive-confirmation";
|
||||
import { TaskCreateDialog } from "@/components/task-create-dialog";
|
||||
import { cleanupSharesParentWorkspace } from "@/components/task/task-cleanup-summary";
|
||||
import { TaskDeleteConfirmDialog } from "@/components/task/task-delete-confirm-dialog";
|
||||
import { TaskDetachConfirmationSurface } from "@/components/task/task-detach-confirm-dialog";
|
||||
import { TaskExternalLinkDialog } from "@/components/task/task-external-link-dialog";
|
||||
@@ -122,6 +123,20 @@ function useLastResolvedBoardRow(
|
||||
return ref.current.boardRow;
|
||||
}
|
||||
|
||||
function buildConfirmationTarget(
|
||||
taskId: string,
|
||||
taskTitle: string,
|
||||
triggerRef: RefObject<HTMLElement | null>,
|
||||
) {
|
||||
return {
|
||||
taskId,
|
||||
taskTitle,
|
||||
anchorRef: triggerRef,
|
||||
focusReturnRef: triggerRef,
|
||||
restoreFocusOnConfirm: true,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Mounts every dialog a task actions menu entry can open. Hosted per surface
|
||||
* so a dialog outlives the menu that opened it.
|
||||
@@ -140,13 +155,7 @@ export function TaskActionsMenuDialogs({
|
||||
const editBoardRow = useLastResolvedBoardRow(taskId, boardRow);
|
||||
if (!taskId) return null;
|
||||
const linkDialogTask = buildLinkDialogTask(taskId, taskTitle, boardRow);
|
||||
const confirmationTarget = {
|
||||
taskId,
|
||||
taskTitle,
|
||||
anchorRef: menu.triggerRef,
|
||||
focusReturnRef: menu.triggerRef,
|
||||
restoreFocusOnConfirm: true,
|
||||
};
|
||||
const confirmationTarget = buildConfirmationTarget(taskId, taskTitle, menu.triggerRef);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -175,6 +184,7 @@ export function TaskActionsMenuDialogs({
|
||||
taskTitle={taskTitle}
|
||||
taskId={taskId}
|
||||
executorType={boardRow?.primaryExecutorType ?? subjectExecutorType}
|
||||
sharesParentWorkspace={cleanupSharesParentWorkspace(boardRow?.workspaceMode)}
|
||||
isDeleting={isDeleting}
|
||||
onConfirm={(opts) => menu.onConfirmDelete(opts)}
|
||||
focusReturnRef={menu.triggerRef}
|
||||
|
||||
@@ -25,6 +25,15 @@ describe("getCleanupSummary (single task)", () => {
|
||||
expect(notes.join(" ")).toMatch(/not affected/i);
|
||||
});
|
||||
|
||||
it("preserves the parent workspace for inherited-parent tasks", () => {
|
||||
expect(getCleanupSummary("worktree", { sharesParentWorkspace: true })).toEqual({
|
||||
effects: [AGENT_STOP_EFFECT],
|
||||
notes: [
|
||||
"This task shares its parent's workspace. The parent task's worktree, branch, and files are not touched.",
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("describes local_docker container removal", () => {
|
||||
const { effects, notes } = getCleanupSummary("local_docker");
|
||||
expect(effects[0]).toMatch(/Docker container/i);
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
// Executor types match models.ExecutorType in apps/backend/internal/task/models/models.go.
|
||||
import { t } from "@/lib/i18n";
|
||||
import type { WorkspaceMode } from "@/lib/kanban/map-task";
|
||||
|
||||
export type CleanupSummary = {
|
||||
effects: string[];
|
||||
notes: string[];
|
||||
};
|
||||
|
||||
export type CleanupSummaryOptions = {
|
||||
sharesParentWorkspace?: boolean;
|
||||
};
|
||||
|
||||
export function cleanupSharesParentWorkspace(
|
||||
workspaceMode: WorkspaceMode | null | undefined,
|
||||
): boolean | undefined {
|
||||
return workspaceMode == null ? undefined : workspaceMode === "inherit_parent";
|
||||
}
|
||||
|
||||
// mock_remote is test-only and intentionally falls through to the generic effect.
|
||||
type KnownExecutor =
|
||||
| "local"
|
||||
@@ -45,6 +56,7 @@ const SINGLE_COPIES: Record<KnownExecutor, CleanupCopy> = {
|
||||
};
|
||||
|
||||
const GENERIC_EFFECT_KEY = "task:cleanupAgentSessionsStopped";
|
||||
const INHERITED_PARENT_WORKSPACE_NOTE_KEY = "task:cleanupInheritedParentWorkspaceNote";
|
||||
|
||||
function normalize(executorType: string | null | undefined): KnownExecutor | null {
|
||||
if (!executorType) return null;
|
||||
@@ -65,7 +77,16 @@ function resolveCopy(copy: CleanupCopy, options?: { count: number }): CleanupSum
|
||||
}
|
||||
|
||||
/** Single-task variant. */
|
||||
export function getCleanupSummary(executorType: string | null | undefined): CleanupSummary {
|
||||
export function getCleanupSummary(
|
||||
executorType: string | null | undefined,
|
||||
options?: CleanupSummaryOptions,
|
||||
): CleanupSummary {
|
||||
if (options?.sharesParentWorkspace) {
|
||||
return {
|
||||
effects: [t(GENERIC_EFFECT_KEY)],
|
||||
notes: [t(INHERITED_PARENT_WORKSPACE_NOTE_KEY)],
|
||||
};
|
||||
}
|
||||
const known = normalize(executorType);
|
||||
return known
|
||||
? resolveCopy(SINGLE_COPIES[known])
|
||||
|
||||
@@ -14,7 +14,11 @@ vi.mock("@/lib/api", () => ({
|
||||
import { TaskDeleteConfirmDialog } from "./task-delete-confirm-dialog";
|
||||
import { expectCompactWarning } from "./task-confirm-dialog.test-helpers";
|
||||
|
||||
type SeedTask = { id: string; foregroundActivity?: "generating" | "background" | null };
|
||||
type SeedTask = {
|
||||
id: string;
|
||||
foregroundActivity?: "generating" | "background" | null;
|
||||
workspaceMode?: "inherit_parent" | "new_workspace" | "shared_group";
|
||||
};
|
||||
|
||||
// The dialog reads live foreground_activity from the store via useTaskInFlight,
|
||||
// so every render needs a StateProvider. `tasks` seeds the active kanban tasks
|
||||
@@ -33,6 +37,7 @@ function renderDialog(ui: ReactNode, tasks: SeedTask[] = []) {
|
||||
title: t.id,
|
||||
position: 0,
|
||||
foregroundActivity: t.foregroundActivity ?? undefined,
|
||||
workspaceMode: t.workspaceMode,
|
||||
})),
|
||||
},
|
||||
}}
|
||||
@@ -444,6 +449,72 @@ describe("TaskDeleteConfirmDialog executor cleanup copy", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("TaskDeleteConfirmDialog inherited-parent workspace copy", () => {
|
||||
it("describes inherited-parent workspace preservation from explicit context", () => {
|
||||
mockGetSubtaskCount.mockResolvedValue({ count: 0 });
|
||||
renderDialog(
|
||||
<TaskDeleteConfirmDialog
|
||||
open
|
||||
onOpenChange={() => {}}
|
||||
taskTitle="Child task"
|
||||
taskId={TASK_ID}
|
||||
executorType="worktree"
|
||||
sharesParentWorkspace
|
||||
onConfirm={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("task-cleanup-effects").querySelectorAll("li")).toHaveLength(1);
|
||||
expect(
|
||||
screen.getByText(
|
||||
/This task shares its parent's workspace\. The parent task's worktree, branch, and files are not touched\./i,
|
||||
),
|
||||
).toBeTruthy();
|
||||
expect(screen.queryByText(/worktree and its branch will be deleted/i)).toBeNull();
|
||||
});
|
||||
|
||||
it("resolves inherited-parent workspace preservation from the task store", () => {
|
||||
mockGetSubtaskCount.mockResolvedValue({ count: 0 });
|
||||
renderDialog(
|
||||
<TaskDeleteConfirmDialog
|
||||
open
|
||||
onOpenChange={() => {}}
|
||||
taskTitle="Child task"
|
||||
taskId={TASK_ID}
|
||||
executorType="worktree"
|
||||
onConfirm={() => {}}
|
||||
/>,
|
||||
[{ id: TASK_ID, workspaceMode: "inherit_parent" }],
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.getByText(
|
||||
/This task shares its parent's workspace\. The parent task's worktree, branch, and files are not touched\./i,
|
||||
),
|
||||
).toBeTruthy();
|
||||
expect(screen.queryByText(/worktree and its branch will be deleted/i)).toBeNull();
|
||||
});
|
||||
|
||||
it("prefers the live task-store mode over stale caller context", () => {
|
||||
mockGetSubtaskCount.mockResolvedValue({ count: 0 });
|
||||
renderDialog(
|
||||
<TaskDeleteConfirmDialog
|
||||
open
|
||||
onOpenChange={() => {}}
|
||||
taskTitle="Child task"
|
||||
taskId={TASK_ID}
|
||||
executorType="worktree"
|
||||
sharesParentWorkspace
|
||||
onConfirm={() => {}}
|
||||
/>,
|
||||
[{ id: TASK_ID, workspaceMode: "new_workspace" }],
|
||||
);
|
||||
|
||||
expect(screen.getByText(/worktree and its branch will be deleted/i)).toBeTruthy();
|
||||
expect(screen.queryByText(/shares its parent's workspace/i)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("TaskDeleteConfirmDialog still-working guard", () => {
|
||||
it("keeps the shared in-flight warning visually subordinate", () => {
|
||||
mockGetSubtaskCount.mockResolvedValue({ count: 0 });
|
||||
|
||||
@@ -23,6 +23,8 @@ import { useTaskInFlight } from "@/hooks/use-task-in-flight";
|
||||
import { getCleanupSummary, getBulkCleanupSummary } from "./task-cleanup-summary";
|
||||
import { TaskCleanupConsequences } from "./task-cleanup-consequences";
|
||||
import { StillWorkingWarning } from "./task-still-working-warning";
|
||||
import { useAppStore } from "@/components/state-provider";
|
||||
import { findTaskInSnapshots } from "@/lib/kanban/find-task";
|
||||
import {
|
||||
TASK_CONFIRM_ACTION_CLASS,
|
||||
TASK_CONFIRM_BODY_CLASS,
|
||||
@@ -34,6 +36,14 @@ import {
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { createFocusReturnHandler } from "@/lib/dialog-focus-return";
|
||||
|
||||
function useStoreSharesParentWorkspace(taskId: string | undefined, isBulkOperation?: boolean) {
|
||||
return useAppStore((state) => {
|
||||
if (isBulkOperation || !taskId) return undefined;
|
||||
const task = findTaskInSnapshots(taskId, state.kanbanMulti.snapshots, state.kanban.tasks);
|
||||
return task ? task.workspaceMode === "inherit_parent" : undefined;
|
||||
});
|
||||
}
|
||||
|
||||
type TaskDeleteConfirmDialogProps = {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
@@ -48,6 +58,8 @@ type TaskDeleteConfirmDialogProps = {
|
||||
executorType?: string | null;
|
||||
/** Executor types of the tasks being deleted (bulk). */
|
||||
executorTypes?: Array<string | null | undefined>;
|
||||
/** Whether the single task borrows its workspace from its parent. */
|
||||
sharesParentWorkspace?: boolean;
|
||||
onConfirm: (opts: { cascade: boolean; discardWorktreeChanges: boolean }) => void;
|
||||
confirmTestId?: string;
|
||||
/** Overrides default focus restoration when the original trigger may disappear. */
|
||||
@@ -284,6 +296,7 @@ export function TaskDeleteConfirmDialog({
|
||||
isInFlight,
|
||||
executorType,
|
||||
executorTypes,
|
||||
sharesParentWorkspace,
|
||||
onConfirm,
|
||||
confirmTestId,
|
||||
onCloseAutoFocus,
|
||||
@@ -297,9 +310,12 @@ export function TaskDeleteConfirmDialog({
|
||||
const description = isBulkOperation
|
||||
? t("task:deleteTasksConfirm", { count: safeCount })
|
||||
: t("task:deleteTaskConfirm", { taskTitle });
|
||||
const storeSharesParentWorkspace = useStoreSharesParentWorkspace(taskId, isBulkOperation);
|
||||
const cleanup = isBulkOperation
|
||||
? getBulkCleanupSummary(executorTypes ?? [])
|
||||
: getCleanupSummary(executorType);
|
||||
: getCleanupSummary(executorType, {
|
||||
sharesParentWorkspace: storeSharesParentWorkspace ?? sharesParentWorkspace,
|
||||
});
|
||||
|
||||
const {
|
||||
cascade,
|
||||
|
||||
@@ -19,6 +19,7 @@ import type { TaskPriority } from "@/lib/types/http";
|
||||
import { TaskManagementMenu, type TaskManagementMenuProps } from "./task-management-menu";
|
||||
import { TaskManagementDrawer, TaskManagementSheet } from "./task-management-drawer";
|
||||
import { TaskArchiveConfirmation } from "./task-archive-confirmation";
|
||||
import { cleanupSharesParentWorkspace } from "./task-cleanup-summary";
|
||||
import { TaskDeleteConfirmDialog } from "./task-delete-confirm-dialog";
|
||||
import { useSidebarLinkActions } from "./task-session-sidebar-link-actions";
|
||||
import { useSidebarTaskLinking } from "./task-session-sidebar-task-linking";
|
||||
@@ -215,6 +216,7 @@ function ManagementConfirmations({
|
||||
taskId={task.id}
|
||||
taskTitle={task.title}
|
||||
executorType={task.remoteExecutorType}
|
||||
sharesParentWorkspace={cleanupSharesParentWorkspace(task.workspaceMode)}
|
||||
isDeleting={mutations.disabled}
|
||||
onCloseAutoFocus={onCloseAutoFocus}
|
||||
confirmTestId="thread-delete-confirm"
|
||||
|
||||
Reference in New Issue
Block a user