High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: the dashboard deletes a profile on one unconfirmed click and swallows the failure, so a destructive action looks identical to a no-op (PIN-252)
Luigi Agosti6fd4c8bbc883
diff --git a/dashboard/src/pages/ProfilesPage.test.tsx b/dashboard/src/pages/ProfilesPage.test.tsxindex fe27372a..5d2843cd 100644--- a/dashboard/src/pages/ProfilesPage.test.tsx+++ b/dashboard/src/pages/ProfilesPage.test.tsx@@ -3,6 +3,7 @@ import userEvent from "@testing-library/user-event";import { beforeEach, describe, expect, it, vi } from "vitest";import { MemoryRouter } from "react-router-dom";import ProfilesPage from "./ProfilesPage";+import * as api from "../services/api";import { useAppStore } from "../stores/useAppStore";import type { Instance, Profile } from "../generated/types";@@ -310,3 +311,108 @@ describe("ProfilesPage classification groups", () => {}});});++// One unconfirmed click used to destroy a profile directory with no undo, and a failed+// delete died in console.error — so a 409 refusal from the in-use guard reached the user+// as nothing at all. These tests pin the confirmation, both failure paths, the visible+// success, and the running-profile withholding.+describe("ProfilesPage delete safety", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ useAppStore.setState({+ profiles,+ profilesLoading: false,+ instances,+ });+ });++ async function openDeleteConfirmation() {+ renderProfilesPage();+ await waitFor(() => {+ expect(+ screen.getByRole("button", { name: /Profile: beta/i }),+ ).toBeInTheDocument();+ });+ await clickSidebarProfile("alpha");+ const detailPanel = getDetailPanel()!;+ await userEvent.click(+ within(detailPanel).getByRole("button", { name: "Delete" }),+ );+ expect(screen.getByText(/Delete profile "alpha"\?/)).toBeInTheDocument();+ }++ it("dismissing the confirmation issues no request", async () => {+ await openDeleteConfirmation();++ await userEvent.click(screen.getByRole("button", { name: "Cancel" }));++ expect(api.deleteProfile).not.toHaveBeenCalled();+ expect(screen.queryByText(/Delete profile "alpha"\?/)).toBeNull();+ });++ it("confirming deletes and visibly confirms the success", async () => {+ vi.mocked(api.deleteProfile).mockResolvedValue(undefined);+ vi.mocked(api.fetchProfiles).mockResolvedValue([profiles[1]]);+ await openDeleteConfirmation();++ await userEvent.click(+ screen.getByRole("button", { name: "Delete profile" }),+ );++ expect(api.deleteProfile).toHaveBeenCalledWith("prof_alpha");+ await waitFor(() => {+ expect(screen.getByRole("status")).toHaveTextContent(+ 'Profile "alpha" deleted',+ );+ });+ });++ it("renders the server's 409 refusal instead of swallowing it", async () => {+ vi.mocked(api.deleteProfile).mockRejectedValue(+ new Error('profile "alpha" is in use by inst_x; delete with force=true'),+ );+ await openDeleteConfirmation();++ await userEvent.click(+ screen.getByRole("button", { name: "Delete profile" }),+ );++ await waitFor(() => {+ expect(screen.getByRole("alert")).toHaveTextContent(/in use by inst_x/);+ });+ expect(+ screen.getByRole("button", { name: /Profile: alpha/i }),+ ).toBeInTheDocument();+ });++ it("renders a 500 failure through the same path", async () => {+ vi.mocked(api.deleteProfile).mockRejectedValue(+ new Error("HTTP 500: something broke"),+ );+ await openDeleteConfirmation();++ await userEvent.click(+ screen.getByRole("button", { name: "Delete profile" }),+ );++ await waitFor(() => {+ expect(screen.getByRole("alert")).toHaveTextContent(/something broke/);+ });+ });++ it("does not offer Delete for a profile reporting running", async () => {+ renderProfilesPage();+ await waitFor(() => {+ expect(+ screen.getByRole("button", { name: /Profile: beta/i }),+ ).toBeInTheDocument();+ });++ const detailPanel = getDetailPanel()!;+ expect(+ within(detailPanel).queryByRole("button", { name: "Delete" }),+ ).toBeNull();+ // The withholding fails safe: alpha reports running false and keeps the+ // confirmed delete path, asserted by the dismissal test above.+ });+});diff --git a/dashboard/src/pages/ProfilesPage.tsx b/dashboard/src/pages/ProfilesPage.tsxindex ea2a16cc..a8502959 100644--- a/dashboard/src/pages/ProfilesPage.tsx+++ b/dashboard/src/pages/ProfilesPage.tsx@@ -93,6 +93,8 @@ export default function ProfilesPage() {loadProfiles,handleStop,handleDelete,+ deleteError,+ deleteNotice,handleSave,} = useProfilesController();const [showCreate, setShowCreate] = useState(false);@@ -190,6 +192,8 @@ export default function ProfilesPage() {}onSave={handleSave}onDelete={handleDelete}+ deleteError={deleteError}+ deleteNotice={deleteNotice}/></div></div>diff --git a/dashboard/src/pages/useProfilesController.ts b/dashboard/src/pages/useProfilesController.tsindex 64aa6347..465abb91 100644--- a/dashboard/src/pages/useProfilesController.ts+++ b/dashboard/src/pages/useProfilesController.ts@@ -35,6 +35,8 @@ export function useProfilesController() {const [selectedProfileKey, setSelectedProfileKey] = useState<string | null>(null,);+ const [deleteError, setDeleteError] = useState<string | null>(null);+ const [deleteNotice, setDeleteNotice] = useState<string | null>(null);const locationState = location.state as ProfilesLocationState | null;const routeSelectedProfileKey = locationState?.selectedProfileKey ?? null;@@ -140,14 +142,23 @@ export function useProfilesController() {}};+ // The outcome lives HERE, not in the toolbar: deletion moves the selection to+ // a surviving profile, which remounts the toolbar and would take any+ // component-local notice or error with it. A refusal the user cannot see —+ // the backend answers 409 for an in-use profile — is barely better than the+ // silent success it replaced, so console.error alone is not handling.const handleDelete = async () => {if (!selectedProfile?.id) return;+ setDeleteError(null);+ setDeleteNotice(null);+ const name = selectedProfile.name;try {await api.deleteProfile(selectedProfile.id);- setSelectedProfileKey(null);+ setDeleteNotice(`Profile "${name}" deleted`);+ setTimeout(() => setDeleteNotice(null), 4000);loadProfiles();} catch (e) {- console.error("Failed to delete profile", e);+ setDeleteError(e instanceof Error ? e.message : String(e));}};@@ -177,6 +188,8 @@ export function useProfilesController() {loadProfiles,handleStop,handleDelete,+ deleteError,+ deleteNotice,handleSave,};}diff --git a/dashboard/src/profiles/ProfileDetailsPanel.tsx b/dashboard/src/profiles/ProfileDetailsPanel.tsxindex 1b821dc3..6b567c65 100644--- a/dashboard/src/profiles/ProfileDetailsPanel.tsx+++ b/dashboard/src/profiles/ProfileDetailsPanel.tsx@@ -17,6 +17,8 @@ interface Props {onStop?: () => void;onSave?: (name: string, useWhen: string) => void;onDelete?: () => void;+ deleteError?: string | null;+ deleteNotice?: string | null;}type TabId = "profile" | "live" | "tabs" | "logs";@@ -28,6 +30,8 @@ export default function ProfileDetailsPanel({onStop,onSave,onDelete,+ deleteError,+ deleteNotice,}: Props) {const [activeTab, setActiveTab] = useState<TabId>("profile");const [tabs, setTabs] = useState<InstanceTab[]>([]);@@ -114,6 +118,8 @@ export default function ProfileDetailsPanel({onStop={onStop || (() => {})}onSave={handleSave}onDelete={onDelete || (() => {})}+ deleteError={deleteError}+ deleteNotice={deleteNotice}isSaveDisabled={!formValues.name.trim() || !hasChanges}/>}diff --git a/dashboard/src/profiles/ProfileToolbarButtons.tsx b/dashboard/src/profiles/ProfileToolbarButtons.tsxindex 4397e0b3..fc79c491 100644--- a/dashboard/src/profiles/ProfileToolbarButtons.tsx+++ b/dashboard/src/profiles/ProfileToolbarButtons.tsx@@ -1,5 +1,5 @@import { useState } from "react";-import { Button } from "../components/atoms";+import { Button, Modal } from "../components/atoms";import type { Profile, Instance } from "../generated/types";interface Props {@@ -9,6 +9,8 @@ interface Props {onStop: () => void;onSave: () => void;onDelete: () => void;+ deleteError?: string | null;+ deleteNotice?: string | null;isSaveDisabled: boolean;}@@ -19,10 +21,19 @@ export default function ProfileToolbarButtons({onStop,onSave,onDelete,+ deleteError,+ deleteNotice,isSaveDisabled,}: Props) {const [copyFeedback, setCopyFeedback] = useState("");+ const [confirmingDelete, setConfirmingDelete] = useState(false);const isRunning = instance?.status === "running";+ // Two sources ORed, not tried in order: the server's own running flag and the+ // instance join each know holders the other can miss, and this predicate only+ // hides a destructive control — a false "running" costs a hidden button, a+ // false "idle" costs the live profile. It fails SAFE: only a positive true+ // withholds Delete; an absent or false flag keeps the confirmed path.+ const deleteWithheld = profile.running === true || isRunning;const handleCopyId = async () => {if (!profile.id) return;@@ -36,16 +47,37 @@ export default function ProfileToolbarButtons({}};+ const confirmDelete = () => {+ setConfirmingDelete(false);+ onDelete();+ };+return (<div className="flex shrink-0 items-center gap-1.5">+ {deleteError && (+ <span role="alert" className="text-xs text-destructive">+ {deleteError}+ </span>+ )}+ {deleteNotice && (+ <span role="status" className="text-xs text-text-secondary">+ {deleteNotice}+ </span>+ )}{profile.id && (<Button size="sm" variant="secondary" onClick={handleCopyId}>{copyFeedback || "Copy ID"}</Button>)}- <Button size="sm" variant="secondary" onClick={onDelete}>- Delete- </Button>+ {!deleteWithheld && (+ <Button+ size="sm"+ variant="secondary"+ onClick={() => setConfirmingDelete(true)}+ >+ Delete+ </Button>+ )}<Buttonsize="sm"variant="primary"@@ -63,6 +95,29 @@ export default function ProfileToolbarButtons({Start</Button>)}+ <Modal+ open={confirmingDelete}+ onClose={() => setConfirmingDelete(false)}+ title="Delete profile"+ actions={+ <>+ <Button+ variant="secondary"+ onClick={() => setConfirmingDelete(false)}+ >+ Cancel+ </Button>+ <Button variant="danger" onClick={confirmDelete}>+ Delete profile+ </Button>+ </>+ }+ >+ <p>+ Delete profile "{profile.name}"? Every cookie, login and+ session stored in it is permanently lost. There is no undo.+ </p>+ </Modal></div>);}