fix(sidebar): make destructive table operation cancellation reliable

This commit is contained in:
Melody Ruch authored and GitHub committed 2026-08-20 22:23:37 +08:00
1 parent 7ce992b8f8
commit b4015a4393
20 files changed
+481 -140

No files matched your search

@@ -1594,6 +1594,10 @@ function openSidebarContextMenu(event: MouseEvent, node: TreeNode, openContextMe
}
function openSidebarDangerDialog(request: SidebarDangerDialogRequest) {
if (sidebarDangerRunningExecutionId.value) {
toast(t("contextMenu.dangerOperationAlreadyRunning"), 4000);
return;
}
sidebarDangerDialogRequest.value = request;
sidebarDangerDialogConfirming.value = false;
// Defense in depth: sidebarDangerDialogCancelling is a singleton shared
@@ -70,7 +70,6 @@ import { useDatabaseOptions } from "@/composables/useDatabaseOptions";
import type { ColumnInfo, DatabaseType, TreeNode, TreeNodeType } from "@/types/database";
import * as api from "@/lib/backend/api";
import { queryTimeoutSecsForConnection } from "@/lib/sql/queryTimeout";
import { uuid } from "@/lib/common/utils";
import { resolveDefaultDatabase } from "@/lib/database/defaultDatabase";
import { connectionUsesVisibleSchemaFilter } from "@/lib/database/visibleDatabases";
import { canTreeNodePin, canTreeNodeShowExpander } from "@/lib/sidebar/sidebarTreeItemLayout";
@@ -2524,13 +2523,25 @@ function openRenameObjectDialog() {
async function executeTreeNodeSqlWithProductionGuard(
node: Pick<TreeNode, "connectionId" | "database" | "schema">,
sql: string,
options: { database?: string; schema?: string; executeAsScript?: boolean; executionId?: string; isCancelledBeforeDispatch?: () => boolean; markDispatched?: () => void } = {},
options: {
database?: string;
schema?: string;
executeAsScript?: boolean;
executionId?: string;
isCancelledBeforeDispatch?: () => boolean;
markDispatched?: () => void;
} = {},
) {
if (!node.connectionId) return undefined;
const database = options.database ?? node.database ?? "";
const config = connectionStore.getConfig(node.connectionId);
// Always resolve the connection's configured timeout the same way the
// main editor does — independent of whether this call also wires up
// Cancel-button UI. Gating this behind an opt-in flag previously left
// every non-danger-dialog caller falling back to the backend's hardcoded
// 30s default instead of the user's configured (or unlimited) timeout.
const timeoutSecs = queryTimeoutSecsForConnection(config, settingsStore.editorSettings.globalQueryTimeoutSecs);
const executionId = options.executionId ?? uuid();
const executionId = options.executionId;
return executeWithProductionSqlGuard({
connection: config,
database,
@@ -0,0 +1,10 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
const connectionTreeSource = readFileSync(new URL("../ConnectionTree.vue", import.meta.url), "utf8");
describe("ConnectionTree danger dialog guard", () => {
it("refuses to open a new danger dialog while a previous danger operation is still running", () => {
expect(connectionTreeSource).toMatch(/function openSidebarDangerDialog\(request: SidebarDangerDialogRequest\) \{\s*if \(sidebarDangerRunningExecutionId\.value\) \{\s*toast\(t\("contextMenu\.dangerOperationAlreadyRunning"\), \d+\);\s*return;\s*\}/);
});
});
@@ -0,0 +1,11 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
const source = readFileSync(new URL("../SidebarTreeRuntimeHost.vue", import.meta.url), "utf8");
describe("executeTreeNodeSqlWithProductionGuard executionId", () => {
it("only registers a backend execution id for callers that opt in, instead of generating one for every caller", () => {
expect(source).toContain("const executionId = options.executionId;");
expect(source).not.toMatch(/executionId\s*=\s*options\.executionId\s*\?\?\s*uuid\(\)/);
});
});
@@ -0,0 +1,14 @@
import { describe, expect, it } from "vitest";
import { resetSidebarTreeDialogState, sidebarDangerRunningCancel, sidebarDangerRunningExecutionId } from "../sidebarTreeDialogState";
describe("resetSidebarTreeDialogState", () => {
it("clears the danger-running singleton", () => {
sidebarDangerRunningExecutionId.value = "exec-1";
sidebarDangerRunningCancel.value = () => {};
resetSidebarTreeDialogState();
expect(sidebarDangerRunningExecutionId.value).toBe("");
expect(sidebarDangerRunningCancel.value).toBeNull();
});
});
@@ -241,6 +241,8 @@ export function resetSidebarTreeDialogState() {
sidebarTreeDialogOwner.value = null;
sidebarDangerTarget.value = null;
sidebarFormTarget.value = null;
sidebarDangerRunningExecutionId.value = "";
sidebarDangerRunningCancel.value = null;
connectionDeleteTargetSnapshot.value = [];
connectionGroupDeleteTargetSnapshot.value = [];
deleteConnectionsWithGroup.value = false;