fix(updates): auto-continue client upgrade on update-all

This commit is contained in:
zipg authored and GitHub committed 2026-09-23 14:43:14 +08:00
1 parent 6471e37e5f
commit da95bd435f
10 files changed
+200 -61

No files matched your search

+20 -11
View File
@@ -33,6 +33,7 @@ import type { PluginUpdateBlock } from "@/composables/useComponentUpdates";
import { COMPONENT_UPDATES_CHANGED_EVENT, notifyComponentPluginsUpdated, notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents"; import { COMPONENT_UPDATES_CHANGED_EVENT, notifyComponentPluginsUpdated, notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents";
import { driverStoreUpdateBadgeCount, showMcpUpdateBadge, showToolbarUpdateAction } from "@/lib/updates/updateBadges"; import { driverStoreUpdateBadgeCount, showMcpUpdateBadge, showToolbarUpdateAction } from "@/lib/updates/updateBadges";
import { import {
continuePreparedAppUpdate,
hasPendingComponentUpdatesAfterAppRestart, hasPendingComponentUpdatesAfterAppRestart,
markPendingComponentUpdatesAfterAppUpdate, markPendingComponentUpdatesAfterAppUpdate,
resolveUpdateAllAction, resolveUpdateAllAction,
@@ -40,6 +41,7 @@ import {
runPendingComponentUpdatePlan, runPendingComponentUpdatePlan,
shouldCloseUpdateCenterAfterComponentUpdate, shouldCloseUpdateCenterAfterComponentUpdate,
takePendingComponentUpdatesAfterAppRestart, takePendingComponentUpdatesAfterAppRestart,
updateBlockerLabels,
type PendingComponentUpdatePlan, type PendingComponentUpdatePlan,
} from "@/lib/updates/componentUpdateOrchestration"; } from "@/lib/updates/componentUpdateOrchestration";
import { isUpdatePreviewMockEnabled } from "@/lib/updates/updatePreviewMock"; import { isUpdatePreviewMockEnabled } from "@/lib/updates/updatePreviewMock";
@@ -1289,7 +1291,9 @@ function reportComponentUpdateResult(result: Awaited<ReturnType<typeof component
if (result.failed.length === 0) syncToolbarComponentUpdateState(); if (result.failed.length === 0) syncToolbarComponentUpdateState();
if (result.plugins > 0) notifyComponentPluginsUpdated(); if (result.plugins > 0) notifyComponentPluginsUpdated();
if (updatedComponents.length) toast(t("updates.componentsAutoUpdated", { components: updatedComponents.join(t("updates.componentListSeparator")) })); if (updatedComponents.length) toast(t("updates.componentsAutoUpdated", { components: updatedComponents.join(t("updates.componentListSeparator")) }));
if (result.skippedDrivers > 0) toast(t("updates.componentsAutoUpdateSkipped"), 6000); if (result.blockedDrivers.length) {
toast(t("driverStore.driverUpdateBlocked", { labels: updateBlockerLabels(result.blockedDrivers).join(", ") }), 8000);
} else if (result.skippedDrivers > 0) toast(t("updates.componentsAutoUpdateSkipped"), 6000);
const otherFailureCount = result.failed.length - result.blockedPlugins.length; const otherFailureCount = result.failed.length - result.blockedPlugins.length;
const failureMessages = [result.blockedPlugins.map(pluginUpdateBlockMessage).join("\n"), otherFailureCount > 0 ? t("updates.componentsAutoUpdateFailed", { count: otherFailureCount }) : ""].filter(Boolean); const failureMessages = [result.blockedPlugins.map(pluginUpdateBlockMessage).join("\n"), otherFailureCount > 0 ? t("updates.componentsAutoUpdateFailed", { count: otherFailureCount }) : ""].filter(Boolean);
if (failureMessages.length) toast(failureMessages.join("\n"), 8000); if (failureMessages.length) toast(failureMessages.join("\n"), 8000);
@@ -1342,6 +1346,19 @@ function availableComponentUpdateCategories(): ComponentUpdateCategory[] {
return categories; return categories;
} }
function continueAppUpdateWithComponents(categories: ComponentUpdateCategory[]) {
return continuePreparedAppUpdate({
hasComponentUpdates: categories.length > 0,
restartOnly: updateReady.value,
rememberComponentUpdates: () => rememberComponentUpdatesForRestartedApp({ kind: "manual", categories }),
installComponents: async () => {
reportComponentUpdateResult(await componentUpdates.installCategories(categories));
},
installDownloadedUpdate,
restartApp,
});
}
async function updateAllAvailable() { async function updateAllAvailable() {
if (updatingAllUpdates.value) return; if (updatingAllUpdates.value) return;
updatingAllUpdates.value = true; updatingAllUpdates.value = true;
@@ -1359,17 +1376,9 @@ async function updateAllAvailable() {
reportComponentUpdateResult(await componentUpdates.installCategories(categories)); reportComponentUpdateResult(await componentUpdates.installCategories(categories));
return; return;
} }
if (action === "defer-components") { if (action === "install-app") return continueAppUpdateWithComponents(categories);
const remembered = await rememberComponentUpdatesForRestartedApp({ kind: "manual", categories });
if (remembered) {
toast(t("settings.updateRestartHint"), 6000);
return;
}
reportComponentUpdateResult(await componentUpdates.installCategories(categories));
return;
}
if (action === "download-app") await downloadUpdateInBackground(); if (action === "download-app") await downloadUpdateInBackground();
if (updateDownloaded.value || updateReady.value) await rememberComponentUpdatesForRestartedApp({ kind: "manual", categories }); if (updateDownloaded.value || updateReady.value) await continueAppUpdateWithComponents(categories);
} finally { } finally {
updatingAllUpdates.value = false; updatingAllUpdates.value = false;
} }
@@ -41,6 +41,7 @@ import { runAgentOfflineExportAction } from "@/lib/driverStore/agentOfflineExpor
import { DRIVER_CATEGORIES, getCategoryForAgentDriver, assertAgentDriverCategoriesComplete } from "@/lib/connection/driver-category-definitions"; import { DRIVER_CATEGORIES, getCategoryForAgentDriver, assertAgentDriverCategoriesComplete } from "@/lib/connection/driver-category-definitions";
import { hasAnyUpdatableDriverMatching, countInstalledDrivers, countAvailableDrivers, partitionDriversByInstallStatus, upgradeAllDriverTypes, upgradeAllMatchesFullUpdateSet, type DriverInstallStatusFilter } from "@/lib/connection/driverListFilter"; import { hasAnyUpdatableDriverMatching, countInstalledDrivers, countAvailableDrivers, partitionDriversByInstallStatus, upgradeAllDriverTypes, upgradeAllMatchesFullUpdateSet, type DriverInstallStatusFilter } from "@/lib/connection/driverListFilter";
import { notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents"; import { notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents";
import { updateBlockerLabels } from "@/lib/updates/componentUpdateOrchestration";
const { t } = useI18n(); const { t } = useI18n();
const { toast } = useToast(); const { toast } = useToast();
@@ -53,6 +54,10 @@ function backendError(e: unknown): string {
return translateBackendError(t, message); return translateBackendError(t, message);
} }
function driverUpdateBlockedMessage(blockers: Awaited<ReturnType<typeof api.checkAgentUpdateBlockers>>): string {
return updateBlockerLabels(blockers).join(", ");
}
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
updateNotificationsEnabled?: boolean; updateNotificationsEnabled?: boolean;
@@ -504,7 +509,7 @@ async function runDriverInstall(dbType: string) {
} }
const blockers = await api.checkAgentUpdateBlockers([dbType]); const blockers = await api.checkAgentUpdateBlockers([dbType]);
if (blockers.length > 0) { if (blockers.length > 0) {
toast(t("driverStore.driverUpdateBlocked", { labels: blockers.map((blocker) => blocker.label).join(", ") })); toast(t("driverStore.driverUpdateBlocked", { labels: driverUpdateBlockedMessage(blockers) }));
return; return;
} }
const operationId = uuid(); const operationId = uuid();
@@ -548,7 +553,7 @@ async function upgradeAll() {
if (updatableDbTypes.length === 0) return; if (updatableDbTypes.length === 0) return;
const blockers = await api.checkAgentUpdateBlockers(updatableDbTypes); const blockers = await api.checkAgentUpdateBlockers(updatableDbTypes);
if (blockers.length > 0) { if (blockers.length > 0) {
toast(t("driverStore.driverUpdateBlocked", { labels: blockers.map((blocker) => blocker.label).join(", ") })); toast(t("driverStore.driverUpdateBlocked", { labels: driverUpdateBlockedMessage(blockers) }));
return; return;
} }
// Do not expose Cancel until the backend operation has registered its token. // Do not expose Cancel until the backend operation has registered its token.
@@ -623,7 +628,7 @@ async function uninstallDriver(dbType: string) {
} }
const blockers = await api.checkAgentUpdateBlockers([dbType]); const blockers = await api.checkAgentUpdateBlockers([dbType]);
if (blockers.length > 0) { if (blockers.length > 0) {
toast(t("driverStore.driverUpdateBlocked", { labels: blockers.map((blocker) => blocker.label).join(", ") })); toast(t("driverStore.driverUpdateBlocked", { labels: driverUpdateBlockedMessage(blockers) }));
return; return;
} }
await api.uninstallAgent(dbType); await api.uninstallAgent(dbType);
@@ -791,7 +796,7 @@ async function importDriverFile(driver: AgentDriverInfo) {
} }
const blockers = await api.checkAgentUpdateBlockers([dbType]); const blockers = await api.checkAgentUpdateBlockers([dbType]);
if (blockers.length > 0) { if (blockers.length > 0) {
toast(t("driverStore.driverUpdateBlocked", { labels: blockers.map((blocker) => blocker.label).join(", ") })); toast(t("driverStore.driverUpdateBlocked", { labels: driverUpdateBlockedMessage(blockers) }));
return; return;
} }
const label = driverLabel(dbType); const label = driverLabel(dbType);
@@ -131,7 +131,7 @@ describe("useComponentUpdates", () => {
expect(mocks.installJdbcPlugin).toHaveBeenCalledOnce(); expect(mocks.installJdbcPlugin).toHaveBeenCalledOnce();
expect(mocks.installMcpServer).toHaveBeenCalledOnce(); expect(mocks.installMcpServer).toHaveBeenCalledOnce();
expect(mocks.installMarketplacePlugin).toHaveBeenCalledWith({ repositoryId: "official", pluginId: "example", version: "1.1.0" }); expect(mocks.installMarketplacePlugin).toHaveBeenCalledWith({ repositoryId: "official", pluginId: "example", version: "1.1.0" });
expect(result).toEqual({ drivers: 1, jdbc: true, mcp: true, plugins: 1, skippedDrivers: 0, failed: [], blockedPlugins: [] }); expect(result).toEqual({ drivers: 1, jdbc: true, mcp: true, plugins: 1, skippedDrivers: 0, blockedDrivers: [], failed: [], blockedPlugins: [] });
}); });
it("shares one update operation between automatic and manual callers", async () => { it("shares one update operation between automatic and manual callers", async () => {
@@ -172,7 +172,7 @@ describe("useComponentUpdates", () => {
expect(mocks.installJdbcPlugin).not.toHaveBeenCalled(); expect(mocks.installJdbcPlugin).not.toHaveBeenCalled();
expect(mocks.installMcpServer).not.toHaveBeenCalled(); expect(mocks.installMcpServer).not.toHaveBeenCalled();
expect(mocks.installMarketplacePlugin).not.toHaveBeenCalled(); expect(mocks.installMarketplacePlugin).not.toHaveBeenCalled();
expect(result).toEqual({ drivers: 0, jdbc: false, mcp: false, plugins: 0, skippedDrivers: 0, failed: [], blockedPlugins: [] }); expect(result).toEqual({ drivers: 0, jdbc: false, mcp: false, plugins: 0, skippedDrivers: 0, blockedDrivers: [], failed: [], blockedPlugins: [] });
}); });
it("installs every manually selected category when no DBX update exists and automatic updates are disabled", async () => { it("installs every manually selected category when no DBX update exists and automatic updates are disabled", async () => {
@@ -190,7 +190,7 @@ describe("useComponentUpdates", () => {
expect(mocks.installJdbcPlugin).toHaveBeenCalledOnce(); expect(mocks.installJdbcPlugin).toHaveBeenCalledOnce();
expect(mocks.installMcpServer).toHaveBeenCalledOnce(); expect(mocks.installMcpServer).toHaveBeenCalledOnce();
expect(mocks.installMarketplacePlugin).toHaveBeenCalledOnce(); expect(mocks.installMarketplacePlugin).toHaveBeenCalledOnce();
expect(result).toEqual({ drivers: 1, jdbc: true, mcp: true, plugins: 1, skippedDrivers: 0, failed: [], blockedPlugins: [] }); expect(result).toEqual({ drivers: 1, jdbc: true, mcp: true, plugins: 1, skippedDrivers: 0, blockedDrivers: [], failed: [], blockedPlugins: [] });
}); });
it("resumes a persisted manual update-all plan after restart while automatic updates are disabled", async () => { it("resumes a persisted manual update-all plan after restart while automatic updates are disabled", async () => {
@@ -213,7 +213,7 @@ describe("useComponentUpdates", () => {
expect(mocks.installJdbcPlugin).toHaveBeenCalledOnce(); expect(mocks.installJdbcPlugin).toHaveBeenCalledOnce();
expect(mocks.installMcpServer).toHaveBeenCalledOnce(); expect(mocks.installMcpServer).toHaveBeenCalledOnce();
expect(mocks.installMarketplacePlugin).toHaveBeenCalledOnce(); expect(mocks.installMarketplacePlugin).toHaveBeenCalledOnce();
expect(result).toEqual({ drivers: 1, jdbc: true, mcp: true, plugins: 1, skippedDrivers: 0, failed: [], blockedPlugins: [] }); expect(result).toEqual({ drivers: 1, jdbc: true, mcp: true, plugins: 1, skippedDrivers: 0, blockedDrivers: [], failed: [], blockedPlugins: [] });
}); });
it("keeps the toolbar update action hidden while a persisted restart plan is still installing", async () => { it("keeps the toolbar update action hidden while a persisted restart plan is still installing", async () => {
@@ -247,7 +247,7 @@ describe("useComponentUpdates", () => {
}); });
it("skips blocked agent updates while allowing other component updates", async () => { it("skips blocked agent updates while allowing other component updates", async () => {
mocks.checkAgentUpdateBlockers.mockResolvedValue([{ db_type: "mysql", label: "MySQL" }]); mocks.checkAgentUpdateBlockers.mockResolvedValue([{ db_type: "mysql", label: "MySQL", connections: ["生产 MySQL", "报表 MySQL"] }]);
const updates = useComponentUpdates({ isDesktop: true }); const updates = useComponentUpdates({ isDesktop: true });
const result = await updates.autoUpdateEnabledComponents(); const result = await updates.autoUpdateEnabledComponents();
@@ -257,6 +257,7 @@ describe("useComponentUpdates", () => {
expect(mocks.installMcpServer).toHaveBeenCalledOnce(); expect(mocks.installMcpServer).toHaveBeenCalledOnce();
expect(mocks.installMarketplacePlugin).toHaveBeenCalledOnce(); expect(mocks.installMarketplacePlugin).toHaveBeenCalledOnce();
expect(result.skippedDrivers).toBe(1); expect(result.skippedDrivers).toBe(1);
expect(result.blockedDrivers).toEqual([{ db_type: "mysql", label: "MySQL", connections: ["生产 MySQL", "报表 MySQL"] }]);
}); });
it("does not install from stale state when update detection fails", async () => { it("does not install from stale state when update detection fails", async () => {
@@ -302,7 +303,7 @@ describe("useComponentUpdates", () => {
const result = await updates.installCategory("jdbc"); const result = await updates.installCategory("jdbc");
expect(mocks.installJdbcPlugin).toHaveBeenCalledOnce(); expect(mocks.installJdbcPlugin).toHaveBeenCalledOnce();
expect(result).toEqual({ drivers: 0, jdbc: true, mcp: false, plugins: 0, skippedDrivers: 0, failed: [], blockedPlugins: [] }); expect(result).toEqual({ drivers: 0, jdbc: true, mcp: false, plugins: 0, skippedDrivers: 0, blockedDrivers: [], failed: [], blockedPlugins: [] });
}); });
it("reports the blocking connections when a K8S plugin update cannot start", async () => { it("reports the blocking connections when a K8S plugin update cannot start", async () => {
@@ -6,7 +6,7 @@ import { mcpUpdateAvailability } from "@/lib/mcp/mcpUpdateStatus";
import { useSettingsStore } from "@/stores/settingsStore"; import { useSettingsStore } from "@/stores/settingsStore";
import { isUpdatePreviewMockEnabled, previewDriverUpdates, previewJdbcUpdate, previewMcpUpdate, previewPluginUpdates } from "@/lib/updates/updatePreviewMock"; import { isUpdatePreviewMockEnabled, previewDriverUpdates, previewJdbcUpdate, previewMcpUpdate, previewPluginUpdates } from "@/lib/updates/updatePreviewMock";
import type { ComponentUpdateCategory } from "@/lib/updates/componentUpdateOrchestration"; import type { ComponentUpdateCategory } from "@/lib/updates/componentUpdateOrchestration";
import type { AgentDriverInfo, McpServerStatus } from "@/lib/backend/tauri"; import type { AgentDriverInfo, AgentUpdateBlocker, McpServerStatus } from "@/lib/backend/tauri";
import type { JdbcPluginStatus } from "@/types/database"; import type { JdbcPluginStatus } from "@/types/database";
export type { ComponentUpdateCategory } from "@/lib/updates/componentUpdateOrchestration"; export type { ComponentUpdateCategory } from "@/lib/updates/componentUpdateOrchestration";
@@ -19,6 +19,7 @@ export interface ComponentUpdateResult {
mcp: boolean; mcp: boolean;
plugins: number; plugins: number;
skippedDrivers: number; skippedDrivers: number;
blockedDrivers: AgentUpdateBlocker[];
failed: string[]; failed: string[];
blockedPlugins: PluginUpdateBlock[]; blockedPlugins: PluginUpdateBlock[];
} }
@@ -28,7 +29,7 @@ interface ComponentUpdateRefreshOptions {
} }
function emptyResult(): ComponentUpdateResult { function emptyResult(): ComponentUpdateResult {
return { drivers: 0, jdbc: false, mcp: false, plugins: 0, skippedDrivers: 0, failed: [], blockedPlugins: [] }; return { drivers: 0, jdbc: false, mcp: false, plugins: 0, skippedDrivers: 0, blockedDrivers: [], failed: [], blockedPlugins: [] };
} }
function pluginUpdateBlock(pluginName: string, message: string): PluginUpdateBlock | null { function pluginUpdateBlock(pluginName: string, message: string): PluginUpdateBlock | null {
@@ -139,6 +140,7 @@ export function useComponentUpdates(options: { isDesktop: boolean }) {
const blockers = await api.checkAgentUpdateBlockers(updatable); const blockers = await api.checkAgentUpdateBlockers(updatable);
if (blockers.length) { if (blockers.length) {
result.skippedDrivers = blockers.length; result.skippedDrivers = blockers.length;
result.blockedDrivers = blockers;
return; return;
} }
const upgraded = await api.upgradeAllAgents(); const upgraded = await api.upgradeAllAgents();
+1
View File
@@ -204,6 +204,7 @@ export interface UpgradeAllAgentDriversResult {
export interface AgentUpdateBlocker { export interface AgentUpdateBlocker {
db_type: string; db_type: string;
label: string; label: string;
connections: string[];
} }
export type AgentOfflineArtifactKind = "jar" | "native"; export type AgentOfflineArtifactKind = "jar" | "native";
@@ -3,6 +3,7 @@
import { beforeEach, describe, expect, it, vi } from "vitest"; import { beforeEach, describe, expect, it, vi } from "vitest";
import { import {
clearPendingComponentUpdatesAfterAppUpdate, clearPendingComponentUpdatesAfterAppUpdate,
continuePreparedAppUpdate,
hasPendingComponentUpdatesAfterAppRestart, hasPendingComponentUpdatesAfterAppRestart,
markPendingComponentUpdatesAfterAppUpdate, markPendingComponentUpdatesAfterAppUpdate,
resolveUpdateAllAction, resolveUpdateAllAction,
@@ -10,6 +11,7 @@ import {
runPendingComponentUpdatePlan, runPendingComponentUpdatePlan,
shouldCloseUpdateCenterAfterComponentUpdate, shouldCloseUpdateCenterAfterComponentUpdate,
takePendingComponentUpdatesAfterAppRestart, takePendingComponentUpdatesAfterAppRestart,
updateBlockerLabels,
} from "@/lib/updates/componentUpdateOrchestration"; } from "@/lib/updates/componentUpdateOrchestration";
describe("component update orchestration", () => { describe("component update orchestration", () => {
@@ -17,6 +19,16 @@ describe("component update orchestration", () => {
localStorage.clear(); localStorage.clear();
}); });
it("lists blocked connection names and falls back to the driver label", () => {
expect(
updateBlockerLabels([
{ label: "MySQL", connections: ["生产 MySQL", "报表 MySQL"] },
{ label: "Oracle", connections: [] },
{ label: "DuckDB", connections: ["生产 MySQL"] },
]),
).toEqual(["生产 MySQL", "报表 MySQL", "Oracle"]);
});
it("keeps pending component updates across a failed or ordinary startup", () => { it("keeps pending component updates across a failed or ordinary startup", () => {
expect(markPendingComponentUpdatesAfterAppUpdate("0.6.16", "0.6.17")).toBe(true); expect(markPendingComponentUpdatesAfterAppUpdate("0.6.16", "0.6.17")).toBe(true);
@@ -162,19 +174,74 @@ describe("component update orchestration", () => {
expect(takePendingComponentUpdatesAfterAppRestart("0.6.17")?.plan).toEqual({ kind: "auto" }); expect(takePendingComponentUpdatesAfterAppRestart("0.6.17")?.plan).toEqual({ kind: "auto" });
}); });
it("downloads DBX before deferring component updates", () => { it("downloads DBX before installing it with component updates", () => {
expect(resolveUpdateAllAction({ hasAppUpdate: true, appUpdateCanInstall: true, appUpdatePrepared: false, hasComponentUpdates: true })).toBe("download-app"); expect(resolveUpdateAllAction({ hasAppUpdate: true, appUpdateCanInstall: true, appUpdatePrepared: false, hasComponentUpdates: true })).toBe("download-app");
expect(resolveUpdateAllAction({ hasAppUpdate: true, appUpdateCanInstall: true, appUpdatePrepared: true, hasComponentUpdates: true })).toBe("defer-components"); expect(resolveUpdateAllAction({ hasAppUpdate: true, appUpdateCanInstall: true, appUpdatePrepared: true, hasComponentUpdates: true })).toBe("install-app");
}); });
it("persists the selected component categories when the DBX package is already prepared", () => { it("persists the selected component categories when the DBX package is already prepared", () => {
const action = resolveUpdateAllAction({ hasAppUpdate: true, appUpdateCanInstall: true, appUpdatePrepared: true, hasComponentUpdates: true }); const action = resolveUpdateAllAction({ hasAppUpdate: true, appUpdateCanInstall: true, appUpdatePrepared: true, hasComponentUpdates: true });
expect(action).toBe("defer-components"); expect(action).toBe("install-app");
expect(markPendingComponentUpdatesAfterAppUpdate("0.6.16", "0.6.17", { kind: "manual", categories: ["drivers", "mcp"] })).toBe(true); expect(markPendingComponentUpdatesAfterAppUpdate("0.6.16", "0.6.17", { kind: "manual", categories: ["drivers", "mcp"] })).toBe(true);
expect(takePendingComponentUpdatesAfterAppRestart("0.6.17")?.plan).toEqual({ kind: "manual", categories: ["drivers", "mcp"] }); expect(takePendingComponentUpdatesAfterAppRestart("0.6.17")?.plan).toEqual({ kind: "manual", categories: ["drivers", "mcp"] });
}); });
it("continues from update all into the prepared app install", async () => {
const rememberComponentUpdates = vi.fn(async () => true);
const installComponents = vi.fn(async () => {});
const installDownloadedUpdate = vi.fn(async () => {});
const restartApp = vi.fn(async () => {});
await continuePreparedAppUpdate({
hasComponentUpdates: true,
restartOnly: false,
rememberComponentUpdates,
installComponents,
installDownloadedUpdate,
restartApp,
});
expect(rememberComponentUpdates).toHaveBeenCalledOnce();
expect(installDownloadedUpdate).toHaveBeenCalledOnce();
expect(restartApp).not.toHaveBeenCalled();
expect(installComponents).not.toHaveBeenCalled();
});
it("continues from update all into restart when the app update is already staged", async () => {
const restartApp = vi.fn(async () => {});
await continuePreparedAppUpdate({
hasComponentUpdates: true,
restartOnly: true,
rememberComponentUpdates: async () => true,
installComponents: async () => {},
installDownloadedUpdate: async () => {},
restartApp,
});
expect(restartApp).toHaveBeenCalledOnce();
});
it("falls back to component updates without restarting when the restart plan cannot be persisted", async () => {
const installComponents = vi.fn(async () => {});
const installDownloadedUpdate = vi.fn(async () => {});
const restartApp = vi.fn(async () => {});
await continuePreparedAppUpdate({
hasComponentUpdates: true,
restartOnly: false,
rememberComponentUpdates: async () => false,
installComponents,
installDownloadedUpdate,
restartApp,
});
expect(installComponents).toHaveBeenCalledOnce();
expect(installDownloadedUpdate).not.toHaveBeenCalled();
expect(restartApp).not.toHaveBeenCalled();
});
it("updates components immediately when no DBX update exists or the package cannot be installed", () => { it("updates components immediately when no DBX update exists or the package cannot be installed", () => {
expect(resolveUpdateAllAction({ hasAppUpdate: false, appUpdateCanInstall: true, appUpdatePrepared: false, hasComponentUpdates: true })).toBe("update-components"); expect(resolveUpdateAllAction({ hasAppUpdate: false, appUpdateCanInstall: true, appUpdatePrepared: false, hasComponentUpdates: true })).toBe("update-components");
expect(resolveUpdateAllAction({ hasAppUpdate: true, appUpdateCanInstall: false, appUpdatePrepared: false, hasComponentUpdates: true })).toBe("update-components"); expect(resolveUpdateAllAction({ hasAppUpdate: true, appUpdateCanInstall: false, appUpdatePrepared: false, hasComponentUpdates: true })).toBe("update-components");
@@ -14,7 +14,11 @@ export interface PendingComponentUpdates {
plan: PendingComponentUpdatePlan; plan: PendingComponentUpdatePlan;
} }
export type UpdateAllAction = "none" | "download-app" | "defer-components" | "update-components"; export type UpdateAllAction = "none" | "download-app" | "install-app" | "update-components";
export function updateBlockerLabels(blockers: Array<{ label: string; connections?: string[] }>): string[] {
return [...new Set(blockers.flatMap((blocker) => (blocker.connections?.length ? blocker.connections : [blocker.label])))];
}
function normalizeVersion(version: string): string { function normalizeVersion(version: string): string {
return version.trim().replace(/^[vV]/, ""); return version.trim().replace(/^[vV]/, "");
@@ -112,7 +116,16 @@ export function takePendingComponentUpdatesAfterAppRestart(currentVersion: strin
export function resolveUpdateAllAction(options: { hasAppUpdate: boolean; appUpdateCanInstall: boolean; appUpdatePrepared: boolean; hasComponentUpdates: boolean }): UpdateAllAction { export function resolveUpdateAllAction(options: { hasAppUpdate: boolean; appUpdateCanInstall: boolean; appUpdatePrepared: boolean; hasComponentUpdates: boolean }): UpdateAllAction {
if (!options.hasAppUpdate || !options.appUpdateCanInstall) return options.hasComponentUpdates ? "update-components" : "none"; if (!options.hasAppUpdate || !options.appUpdateCanInstall) return options.hasComponentUpdates ? "update-components" : "none";
return options.appUpdatePrepared ? "defer-components" : "download-app"; return options.appUpdatePrepared ? "install-app" : "download-app";
}
export async function continuePreparedAppUpdate(options: { hasComponentUpdates: boolean; restartOnly: boolean; rememberComponentUpdates: () => Promise<boolean>; installComponents: () => Promise<void>; installDownloadedUpdate: () => Promise<void>; restartApp: () => Promise<void> }): Promise<void> {
if (options.hasComponentUpdates && !(await options.rememberComponentUpdates())) {
await options.installComponents();
return;
}
if (options.restartOnly) await options.restartApp();
else await options.installDownloadedUpdate();
} }
export function shouldCloseUpdateCenterAfterComponentUpdate(options: { failedCount: number; skippedDriverCount: number; hasAppUpdate: boolean; remainingComponentUpdateCount: number }): boolean { export function shouldCloseUpdateCenterAfterComponentUpdate(options: { failedCount: number; skippedDriverCount: number; hasAppUpdate: boolean; remainingComponentUpdateCount: number }): boolean {
+40 -15
View File
@@ -4904,15 +4904,17 @@ impl AppState {
Ok(closed) Ok(closed)
} }
pub async fn active_agent_connection_driver_keys(&self) -> HashSet<String> { pub async fn active_agent_connection_driver_connections(&self) -> HashMap<String, Vec<String>> {
let configs = self.configs.read().await; let configs = self.configs.read().await;
let connections = self.connection_pools_snapshot().await; let connections = self.connection_pools_snapshot().await;
let mut keys = HashSet::new(); let mut connections_by_key: HashMap<String, Vec<String>> = HashMap::new();
for (pool_key, pool) in connections.iter() { for (pool_key, pool) in connections.iter() {
#[cfg(feature = "duckdb-sidecar")] #[cfg(feature = "duckdb-sidecar")]
if matches!(pool, PoolKind::DuckDbWorker(_)) { if matches!(pool, PoolKind::DuckDbWorker(_)) {
keys.insert("duckdb".to_string()); if let Some(config) = config_for_pool_key(pool_key, &configs) {
connections_by_key.entry("duckdb".to_string()).or_default().push(config.name.clone());
}
continue; continue;
} }
if !matches!(pool, PoolKind::Agent(_)) { if !matches!(pool, PoolKind::Agent(_)) {
@@ -4925,25 +4927,33 @@ impl AppState {
&config.db_type, &config.db_type,
config.driver_profile.as_deref(), config.driver_profile.as_deref(),
) { ) {
keys.insert(agent_key.to_string()); connections_by_key.entry(agent_key.to_string()).or_default().push(config.name.clone());
} }
} }
keys for names in connections_by_key.values_mut() {
names.sort();
names.dedup();
}
connections_by_key
} }
pub async fn prepare_agent_driver_updates(&self, driver_keys: &[String]) -> HashSet<String> { pub async fn active_agent_connection_driver_keys(&self) -> HashSet<String> {
self.active_agent_connection_driver_connections().await.into_keys().collect()
}
pub async fn prepare_agent_driver_updates(&self, driver_keys: &[String]) -> HashMap<String, Vec<String>> {
let candidates = driver_keys.iter().cloned().collect::<HashSet<_>>(); let candidates = driver_keys.iter().cloned().collect::<HashSet<_>>();
if candidates.is_empty() { if candidates.is_empty() {
return HashSet::new(); return HashMap::new();
} }
let blockers = self let blockers = self
.active_agent_connection_driver_keys() .active_agent_connection_driver_connections()
.await .await
.into_iter() .into_iter()
.filter(|key| candidates.contains(key)) .filter(|(key, _)| candidates.contains(key))
.collect::<HashSet<_>>(); .collect::<HashMap<_, _>>();
if !blockers.is_empty() { if !blockers.is_empty() {
return blockers; return blockers;
} }
@@ -4953,7 +4963,11 @@ impl AppState {
} }
// A connection may have started while idle runtimes were stopping. // A connection may have started while idle runtimes were stopping.
self.active_agent_connection_driver_keys().await.into_iter().filter(|key| candidates.contains(key)).collect() self.active_agent_connection_driver_connections()
.await
.into_iter()
.filter(|(key, _)| candidates.contains(key))
.collect()
} }
pub async fn connection_identifier_quote( pub async fn connection_identifier_quote(
@@ -7842,8 +7856,13 @@ mod tests {
let (state, dir) = test_app_state().await; let (state, dir) = test_app_state().await;
let mut config = mysql_config(None); let mut config = mysql_config(None);
config.id = "dameng-conn".to_string(); config.id = "dameng-conn".to_string();
config.name = "达梦生产".to_string();
config.db_type = DatabaseType::Dameng; config.db_type = DatabaseType::Dameng;
let mut replica_config = config.clone();
replica_config.id = "dameng-replica".to_string();
replica_config.name = "达梦报表".to_string();
state.configs.write().await.insert(config.id.clone(), config); state.configs.write().await.insert(config.id.clone(), config);
state.configs.write().await.insert(replica_config.id.clone(), replica_config);
state state
.agent_manager .agent_manager
.daemons .daemons
@@ -7851,14 +7870,19 @@ mod tests {
.await .await
.insert("oracle".to_string(), crate::db::agent_driver::AgentDriverClient::test_stub()); .insert("oracle".to_string(), crate::db::agent_driver::AgentDriverClient::test_stub());
state.connections.write().await.insert("dameng-conn".to_string(), agent_pool_stub()); state.connections.write().await.insert("dameng-conn".to_string(), agent_pool_stub());
state.connections.write().await.insert("dameng-replica".to_string(), agent_pool_stub());
assert_eq!( assert_eq!(
state.active_agent_connection_driver_keys().await, state.active_agent_connection_driver_connections().await,
std::collections::HashSet::from(["dameng".to_string()]) std::collections::HashMap::from([(
"dameng".to_string(),
vec!["达梦报表".to_string(), "达梦生产".to_string()]
)])
); );
state.connections.write().await.remove("dameng-conn"); state.connections.write().await.remove("dameng-conn");
assert!(state.active_agent_connection_driver_keys().await.is_empty()); state.connections.write().await.remove("dameng-replica");
assert!(state.active_agent_connection_driver_connections().await.is_empty());
let _ = std::fs::remove_dir_all(dir); let _ = std::fs::remove_dir_all(dir);
} }
@@ -7886,6 +7910,7 @@ mod tests {
let (state, dir) = test_app_state().await; let (state, dir) = test_app_state().await;
let mut config = mysql_config(None); let mut config = mysql_config(None);
config.id = "dameng-conn".to_string(); config.id = "dameng-conn".to_string();
config.name = "达梦生产".to_string();
config.db_type = DatabaseType::Dameng; config.db_type = DatabaseType::Dameng;
state.configs.write().await.insert(config.id.clone(), config); state.configs.write().await.insert(config.id.clone(), config);
state.connections.write().await.insert("dameng-conn".to_string(), agent_pool_stub()); state.connections.write().await.insert("dameng-conn".to_string(), agent_pool_stub());
@@ -7898,7 +7923,7 @@ mod tests {
let blockers = state.prepare_agent_driver_updates(&["dameng".to_string()]).await; let blockers = state.prepare_agent_driver_updates(&["dameng".to_string()]).await;
assert_eq!(blockers, std::collections::HashSet::from(["dameng".to_string()])); assert_eq!(blockers, std::collections::HashMap::from([("dameng".to_string(), vec!["达梦生产".to_string()])]));
assert_eq!(state.agent_manager.active_daemon_keys().await, vec!["dameng".to_string()]); assert_eq!(state.agent_manager.active_daemon_keys().await, vec!["dameng".to_string()]);
let _ = std::fs::remove_dir_all(dir); let _ = std::fs::remove_dir_all(dir);
+20 -10
View File
@@ -53,6 +53,7 @@ pub struct AgentUpdateBlockersRequest {
pub struct AgentUpdateBlocker { pub struct AgentUpdateBlocker {
pub db_type: String, pub db_type: String,
pub label: String, pub label: String,
pub connections: Vec<String>,
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@@ -407,32 +408,37 @@ async fn ensure_no_agent_update_blockers(
state: &dbx_core::connection::AppState, state: &dbx_core::connection::AppState,
db_types: &[String], db_types: &[String],
) -> Result<(), String> { ) -> Result<(), String> {
let blockers = update_blockers_from_keys(state.prepare_agent_driver_updates(db_types).await, db_types); let blockers = update_blockers_from_connections(state.prepare_agent_driver_updates(db_types).await, db_types);
if blockers.is_empty() { if blockers.is_empty() {
return Ok(()); return Ok(());
} }
let labels = blockers.into_iter().map(|blocker| blocker.label).collect::<Vec<_>>().join(", "); let labels = blockers
.into_iter()
.flat_map(|blocker| if blocker.connections.is_empty() { vec![blocker.label] } else { blocker.connections })
.collect::<Vec<_>>()
.join(", ");
Err(format!("Close these database connections before updating drivers: {labels}")) Err(format!("Close these database connections before updating drivers: {labels}"))
} }
async fn agent_update_blockers(state: &dbx_core::connection::AppState, db_types: &[String]) -> Vec<AgentUpdateBlocker> { async fn agent_update_blockers(state: &dbx_core::connection::AppState, db_types: &[String]) -> Vec<AgentUpdateBlocker> {
update_blockers_from_keys(state.active_agent_connection_driver_keys().await, db_types) update_blockers_from_connections(state.active_agent_connection_driver_connections().await, db_types)
} }
fn update_blockers_from_keys( fn update_blockers_from_connections(
active_keys: std::collections::HashSet<String>, active_connections: std::collections::HashMap<String, Vec<String>>,
db_types: &[String], db_types: &[String],
) -> Vec<AgentUpdateBlocker> { ) -> Vec<AgentUpdateBlocker> {
let candidate_keys: std::collections::HashSet<&str> = db_types.iter().map(String::as_str).collect(); let candidate_keys: std::collections::HashSet<&str> = db_types.iter().map(String::as_str).collect();
if candidate_keys.is_empty() { if candidate_keys.is_empty() {
return Vec::new(); return Vec::new();
} }
let mut blockers = active_keys let mut blockers = active_connections
.into_iter() .into_iter()
.filter(|key| candidate_keys.contains(key.as_str())) .filter(|(key, _)| candidate_keys.contains(key.as_str()))
.map(|db_type| AgentUpdateBlocker { .map(|(db_type, connections)| AgentUpdateBlocker {
label: dbx_core::agent_catalog::label_for_key(&db_type).unwrap_or(&db_type).to_string(), label: dbx_core::agent_catalog::label_for_key(&db_type).unwrap_or(&db_type).to_string(),
db_type, db_type,
connections,
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
blockers.sort_by(|left, right| left.label.cmp(&right.label)); blockers.sort_by(|left, right| left.label.cmp(&right.label));
@@ -472,12 +478,16 @@ mod tests {
#[test] #[test]
fn update_blockers_include_active_duckdb_connections() { fn update_blockers_include_active_duckdb_connections() {
let active_keys = ["duckdb".to_string(), "oracle".to_string()].into_iter().collect(); let active_connections = std::collections::HashMap::from([
let blockers = update_blockers_from_keys(active_keys, &["duckdb".to_string()]); ("duckdb".to_string(), vec!["本地分析".to_string()]),
("oracle".to_string(), vec!["生产 Oracle".to_string()]),
]);
let blockers = update_blockers_from_connections(active_connections, &["duckdb".to_string()]);
assert_eq!(blockers.len(), 1); assert_eq!(blockers.len(), 1);
assert_eq!(blockers[0].db_type, "duckdb"); assert_eq!(blockers[0].db_type, "duckdb");
assert_eq!(blockers[0].label, "DuckDB"); assert_eq!(blockers[0].label, "DuckDB");
assert_eq!(blockers[0].connections, vec!["本地分析"]);
} }
#[test] #[test]
+14 -8
View File
@@ -24,6 +24,7 @@ use dbx_core::DownloadSource;
pub struct AgentUpdateBlocker { pub struct AgentUpdateBlocker {
pub db_type: String, pub db_type: String,
pub label: String, pub label: String,
pub connections: Vec<String>,
} }
#[tauri::command] #[tauri::command]
@@ -314,11 +315,15 @@ fn emit_agent_progress(app: &tauri::AppHandle, operation_id: &str, event: AgentP
} }
async fn ensure_no_agent_update_blockers(state: &AppState, db_types: &[String]) -> Result<(), String> { async fn ensure_no_agent_update_blockers(state: &AppState, db_types: &[String]) -> Result<(), String> {
let blockers = update_blockers_from_keys(state.prepare_agent_driver_updates(db_types).await, db_types); let blockers = update_blockers_from_connections(state.prepare_agent_driver_updates(db_types).await, db_types);
if blockers.is_empty() { if blockers.is_empty() {
return Ok(()); return Ok(());
} }
let labels = blockers.into_iter().map(|blocker| blocker.label).collect::<Vec<_>>().join(", "); let labels = blockers
.into_iter()
.flat_map(|blocker| if blocker.connections.is_empty() { vec![blocker.label] } else { blocker.connections })
.collect::<Vec<_>>()
.join(", ");
Err(format!("Close these database connections before updating drivers: {labels}")) Err(format!("Close these database connections before updating drivers: {labels}"))
} }
@@ -336,23 +341,24 @@ async fn ensure_no_offline_import_blockers(state: &AppState, plan: &OfflineImpor
} }
async fn agent_update_blockers(state: &AppState, db_types: &[String]) -> Vec<AgentUpdateBlocker> { async fn agent_update_blockers(state: &AppState, db_types: &[String]) -> Vec<AgentUpdateBlocker> {
update_blockers_from_keys(state.active_agent_connection_driver_keys().await, db_types) update_blockers_from_connections(state.active_agent_connection_driver_connections().await, db_types)
} }
fn update_blockers_from_keys( fn update_blockers_from_connections(
active_keys: std::collections::HashSet<String>, active_connections: std::collections::HashMap<String, Vec<String>>,
db_types: &[String], db_types: &[String],
) -> Vec<AgentUpdateBlocker> { ) -> Vec<AgentUpdateBlocker> {
let candidate_keys: std::collections::HashSet<&str> = db_types.iter().map(String::as_str).collect(); let candidate_keys: std::collections::HashSet<&str> = db_types.iter().map(String::as_str).collect();
if candidate_keys.is_empty() { if candidate_keys.is_empty() {
return Vec::new(); return Vec::new();
} }
let mut blockers = active_keys let mut blockers = active_connections
.into_iter() .into_iter()
.filter(|key| candidate_keys.contains(key.as_str())) .filter(|(key, _)| candidate_keys.contains(key.as_str()))
.map(|db_type| AgentUpdateBlocker { .map(|(db_type, connections)| AgentUpdateBlocker {
label: dbx_core::agent_catalog::label_for_key(&db_type).unwrap_or(&db_type).to_string(), label: dbx_core::agent_catalog::label_for_key(&db_type).unwrap_or(&db_type).to_string(),
db_type, db_type,
connections,
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
blockers.sort_by(|left, right| left.label.cmp(&right.label)); blockers.sort_by(|left, right| left.label.cmp(&right.label));