fix(updates): sync entry-point states after component updates
This commit is contained in:
7 files changed
+86
-7
No files matched your search
@@ -27,6 +27,7 @@ import { useTheme } from "@/composables/useTheme";
|
|||||||
import { canDownloadAndInstallUpdate, useAppUpdater } from "@/composables/useAppUpdater";
|
import { canDownloadAndInstallUpdate, useAppUpdater } from "@/composables/useAppUpdater";
|
||||||
import { useMcpUpdateBadge } from "@/composables/useMcpUpdateBadge";
|
import { useMcpUpdateBadge } from "@/composables/useMcpUpdateBadge";
|
||||||
import { useComponentUpdates, type ComponentUpdateCategory } from "@/composables/useComponentUpdates";
|
import { useComponentUpdates, type ComponentUpdateCategory } from "@/composables/useComponentUpdates";
|
||||||
|
import { notifyComponentPluginsUpdated } from "@/lib/updates/componentUpdateEvents";
|
||||||
import { driverStoreUpdateBadgeCount, showMcpUpdateBadge } from "@/lib/updates/updateBadges";
|
import { driverStoreUpdateBadgeCount, showMcpUpdateBadge } from "@/lib/updates/updateBadges";
|
||||||
import { markPendingComponentUpdatesAfterAppUpdate, resolveUpdateAllAction, runPendingComponentUpdatePlan, shouldCloseUpdateCenterAfterComponentUpdate, takePendingComponentUpdatesAfterAppRestart, type PendingComponentUpdatePlan } from "@/lib/updates/componentUpdateOrchestration";
|
import { markPendingComponentUpdatesAfterAppUpdate, resolveUpdateAllAction, runPendingComponentUpdatePlan, shouldCloseUpdateCenterAfterComponentUpdate, takePendingComponentUpdatesAfterAppRestart, type PendingComponentUpdatePlan } from "@/lib/updates/componentUpdateOrchestration";
|
||||||
import { isUpdatePreviewMockEnabled } from "@/lib/updates/updatePreviewMock";
|
import { isUpdatePreviewMockEnabled } from "@/lib/updates/updatePreviewMock";
|
||||||
@@ -314,7 +315,7 @@ const activeAiRunCount = computed(() => (isDesktop ? activeDesktopAiRuns().lengt
|
|||||||
/** Runs waiting for a write confirmation — the panel-entry badge shows these
|
/** Runs waiting for a write confirmation — the panel-entry badge shows these
|
||||||
* with a higher-priority indicator (parent PRD §4 line 71 / §9). */
|
* with a higher-priority indicator (parent PRD §4 line 71 / §9). */
|
||||||
const awaitingAiRunCount = computed(() => (isDesktop ? activeDesktopAiRuns().filter((run) => run.status === "awaiting_write_confirmation").length : 0));
|
const awaitingAiRunCount = computed(() => (isDesktop ? activeDesktopAiRuns().filter((run) => run.status === "awaiting_write_confirmation").length : 0));
|
||||||
const { mcpUpdateAvailable, refreshMcpUpdateStatus, handleMcpStatusChanged } = useMcpUpdateBadge({
|
const { mcpUpdateAvailable, refreshMcpUpdateStatus, handleMcpStatusChanged, applyMcpStatus } = useMcpUpdateBadge({
|
||||||
isDesktop,
|
isDesktop,
|
||||||
// Update availability remains visible when every auto-update switch is off;
|
// Update availability remains visible when every auto-update switch is off;
|
||||||
// the switches control installation, not whether the user can be reminded.
|
// the switches control installation, not whether the user can be reminded.
|
||||||
@@ -1206,7 +1207,8 @@ async function checkAllUpdates() {
|
|||||||
manualCheckingAllUpdates.value = true;
|
manualCheckingAllUpdates.value = true;
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
try {
|
try {
|
||||||
await Promise.allSettled([checkUpdates({ silent: true }), componentUpdates.refresh()]);
|
const [, componentRefresh] = await Promise.allSettled([checkUpdates({ silent: true }), componentUpdates.refresh()]);
|
||||||
|
if (componentRefresh.status === "fulfilled" && componentRefresh.value) syncToolbarComponentUpdateState();
|
||||||
const remaining = 500 - (Date.now() - startedAt);
|
const remaining = 500 - (Date.now() - startedAt);
|
||||||
if (remaining > 0) await new Promise((resolve) => setTimeout(resolve, remaining));
|
if (remaining > 0) await new Promise((resolve) => setTimeout(resolve, remaining));
|
||||||
} finally {
|
} finally {
|
||||||
@@ -1221,13 +1223,19 @@ function openDriverStoreFromUpdate(target?: DriverStoreTab) {
|
|||||||
|
|
||||||
function handleToolbarUpdateClick() {
|
function handleToolbarUpdateClick() {
|
||||||
showUpdateDialog.value = true;
|
showUpdateDialog.value = true;
|
||||||
if (!toolbarHasUpdateAvailable.value && !checkingAllUpdates.value) void checkAllUpdates();
|
if (!checkingAllUpdates.value) void checkAllUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncToolbarComponentUpdateState() {
|
||||||
|
agentDriverUpdateCount.value = componentUpdates.driverUpdateCount.value;
|
||||||
|
applyMcpStatus(componentUpdates.mcpUpdateAvailable.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function reportComponentUpdateResult(result: Awaited<ReturnType<typeof componentUpdates.installCategory>>) {
|
function reportComponentUpdateResult(result: Awaited<ReturnType<typeof componentUpdates.installCategory>>) {
|
||||||
const updatedComponents = [result.drivers > 0 ? t("settings.updateDrivers") : "", result.jdbc ? t("settings.updateJdbc") : "", result.mcp ? t("settings.updateMcp") : "", result.plugins > 0 ? t("settings.updatePlugins") : ""].filter(Boolean);
|
const updatedComponents = [result.drivers > 0 ? t("settings.updateDrivers") : "", result.jdbc ? t("settings.updateJdbc") : "", result.mcp ? t("settings.updateMcp") : "", result.plugins > 0 ? t("settings.updatePlugins") : ""].filter(Boolean);
|
||||||
// Only a clean refresh is authoritative; a failed registry check must not clear the toolbar count.
|
// Only a clean refresh is authoritative; a failed registry check must not clear stale toolbar state.
|
||||||
if (result.failed.length === 0) agentDriverUpdateCount.value = componentUpdates.driverUpdateCount.value;
|
if (result.failed.length === 0) syncToolbarComponentUpdateState();
|
||||||
|
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.skippedDrivers > 0) toast(t("updates.componentsAutoUpdateSkipped"), 6000);
|
||||||
if (result.failed.length) toast(t("updates.componentsAutoUpdateFailed", { count: result.failed.length }), 6000);
|
if (result.failed.length) toast(t("updates.componentsAutoUpdateFailed", { count: result.failed.length }), 6000);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { physicalDropPositionInsideRect } from "@/lib/ai/aiAttachments";
|
|||||||
import { createFrontendPluginRegistry, pluginConnectionProviderIcon } from "@/lib/plugins/frontendPlugin";
|
import { createFrontendPluginRegistry, pluginConnectionProviderIcon } from "@/lib/plugins/frontendPlugin";
|
||||||
import { beaconPluginInstall, buildMarketplacePluginListings, filterMarketplacePluginListings, listingRepositoryCanVerify, marketplaceHomepageUrl, type MarketplacePluginListing } from "@/lib/plugins/pluginMarketplace";
|
import { beaconPluginInstall, buildMarketplacePluginListings, filterMarketplacePluginListings, listingRepositoryCanVerify, marketplaceHomepageUrl, type MarketplacePluginListing } from "@/lib/plugins/pluginMarketplace";
|
||||||
import { isBatchSelectableListing, runBatch } from "@/lib/plugins/pluginBatch";
|
import { isBatchSelectableListing, runBatch } from "@/lib/plugins/pluginBatch";
|
||||||
|
import { COMPONENT_PLUGINS_UPDATED_EVENT } from "@/lib/updates/componentUpdateEvents";
|
||||||
import { formatBytes } from "@/lib/database/serverMetrics";
|
import { formatBytes } from "@/lib/database/serverMetrics";
|
||||||
import type { PluginCenterFocus } from "@/lib/plugins/pluginCenterNavigation";
|
import type { PluginCenterFocus } from "@/lib/plugins/pluginCenterNavigation";
|
||||||
import { useConnectionStore } from "@/stores/connectionStore";
|
import { useConnectionStore } from "@/stores/connectionStore";
|
||||||
@@ -245,6 +246,19 @@ async function refreshAfterBatch() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function refreshAfterExternalPluginUpdate() {
|
||||||
|
clearPluginIconCache();
|
||||||
|
try {
|
||||||
|
installedPlugins.value = await api.listPlugins();
|
||||||
|
} catch (cause) {
|
||||||
|
error.value = cause instanceof Error ? cause.message : String(cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleComponentPluginsUpdated() {
|
||||||
|
void refreshAfterExternalPluginUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
function toggleBatchMode() {
|
function toggleBatchMode() {
|
||||||
if (batchRunning.value) return;
|
if (batchRunning.value) return;
|
||||||
batchMode.value = !batchMode.value;
|
batchMode.value = !batchMode.value;
|
||||||
@@ -737,10 +751,12 @@ watch(allowUnsigned, (value) => {
|
|||||||
});
|
});
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
void refresh();
|
void refresh();
|
||||||
|
window.addEventListener(COMPONENT_PLUGINS_UPDATED_EVENT, handleComponentPluginsUpdated);
|
||||||
if (isTauriRuntime()) document.addEventListener("dbx:tauri-file-drop", onTauriPluginDrop);
|
if (isTauriRuntime()) document.addEventListener("dbx:tauri-file-drop", onTauriPluginDrop);
|
||||||
});
|
});
|
||||||
watch(marketplaceViewMode, (mode) => safeLocalStorageSet(MARKETPLACE_VIEW_MODE_STORAGE_KEY, mode));
|
watch(marketplaceViewMode, (mode) => safeLocalStorageSet(MARKETPLACE_VIEW_MODE_STORAGE_KEY, mode));
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
|
window.removeEventListener(COMPONENT_PLUGINS_UPDATED_EVENT, handleComponentPluginsUpdated);
|
||||||
if (isTauriRuntime()) document.removeEventListener("dbx:tauri-file-drop", onTauriPluginDrop);
|
if (isTauriRuntime()) document.removeEventListener("dbx:tauri-file-drop", onTauriPluginDrop);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
+14
@@ -5,6 +5,7 @@ import { readFileSync } from "node:fs";
|
|||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import type { InstalledPlugin, PluginRepositoryCatalogResult } from "@/types/database";
|
import type { InstalledPlugin, PluginRepositoryCatalogResult } from "@/types/database";
|
||||||
import type { MarketplacePluginListing } from "@/lib/plugins/pluginMarketplace";
|
import type { MarketplacePluginListing } from "@/lib/plugins/pluginMarketplace";
|
||||||
|
import { COMPONENT_PLUGINS_UPDATED_EVENT } from "@/lib/updates/componentUpdateEvents";
|
||||||
|
|
||||||
const mocks = vi.hoisted(() => ({
|
const mocks = vi.hoisted(() => ({
|
||||||
listPlugins: vi.fn(),
|
listPlugins: vi.fn(),
|
||||||
@@ -299,6 +300,19 @@ describe("PluginContributionsPanel installed plugin pin controls", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("PluginContributionsPanel external component updates", () => {
|
||||||
|
it("refreshes installed plugins when the update center updates plugins", async () => {
|
||||||
|
expect(state.marketplaceListings.every((listing) => listing.status === "update")).toBe(true);
|
||||||
|
mocks.listPlugins.mockResolvedValueOnce([installed("a", "3.0.0"), installed("b", "3.0.0"), installed("c", "3.0.0")]);
|
||||||
|
|
||||||
|
window.dispatchEvent(new Event(COMPONENT_PLUGINS_UPDATED_EVENT));
|
||||||
|
await flushUi();
|
||||||
|
|
||||||
|
expect(mocks.listPlugins).toHaveBeenCalledOnce();
|
||||||
|
expect(state.marketplaceListings.every((listing) => listing.status === "installed")).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const batches = ["install", "uninstall"] as const;
|
const batches = ["install", "uninstall"] as const;
|
||||||
type Batch = (typeof batches)[number];
|
type Batch = (typeof batches)[number];
|
||||||
const singles = ["marketplace", "uninstall", "rollback", "package", "url"] as const;
|
const singles = ["marketplace", "uninstall", "rollback", "package", "url"] as const;
|
||||||
|
|||||||
@@ -87,14 +87,17 @@ describe("useComponentUpdates", () => {
|
|||||||
expect(updates.totalUpdateCount.value).toBe(4);
|
expect(updates.totalUpdateCount.value).toBe(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("clears the driver count after a successful update and refresh", async () => {
|
it("clears driver and MCP update state after a successful update and refresh", async () => {
|
||||||
mocks.listInstalledAgents.mockResolvedValueOnce([{ db_type: "mysql", update_available: true }]).mockResolvedValueOnce([{ db_type: "mysql", update_available: false }]);
|
mocks.listInstalledAgents.mockResolvedValueOnce([{ db_type: "mysql", update_available: true }]).mockResolvedValueOnce([{ db_type: "mysql", update_available: false }]);
|
||||||
|
mocks.checkMcpServerStatus.mockResolvedValueOnce(mcpStatus).mockResolvedValueOnce({ ...mcpStatus, latest_version: "1.0.0", update_available: false });
|
||||||
const updates = useComponentUpdates({ isDesktop: true });
|
const updates = useComponentUpdates({ isDesktop: true });
|
||||||
|
|
||||||
await updates.installCategories(["drivers"]);
|
await updates.installCategories(["drivers", "mcp"]);
|
||||||
|
|
||||||
expect(mocks.upgradeAllAgents).toHaveBeenCalledOnce();
|
expect(mocks.upgradeAllAgents).toHaveBeenCalledOnce();
|
||||||
|
expect(mocks.installMcpServer).toHaveBeenCalledOnce();
|
||||||
expect(updates.driverUpdateCount.value).toBe(0);
|
expect(updates.driverUpdateCount.value).toBe(0);
|
||||||
|
expect(updates.mcpUpdateAvailable.value).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("installs every enabled component category after an app update", async () => {
|
it("installs every enabled component category after an app update", async () => {
|
||||||
|
|||||||
@@ -26,6 +26,23 @@ describe("plugin center integration", () => {
|
|||||||
expect(driverStoreSource).not.toContain("PluginContributionsPanel");
|
expect(driverStoreSource).not.toContain("PluginContributionsPanel");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("refreshes toolbar update state after manual and component update checks", () => {
|
||||||
|
expect(appSource).toContain('if (componentRefresh.status === "fulfilled" && componentRefresh.value) syncToolbarComponentUpdateState()');
|
||||||
|
expect(appSource).toContain("if (result.failed.length === 0) syncToolbarComponentUpdateState()");
|
||||||
|
expect(appSource).toContain("function syncToolbarComponentUpdateState()");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("refreshes all update sources in the background whenever the update center opens", () => {
|
||||||
|
expect(appSource).toContain("function handleToolbarUpdateClick() {\n showUpdateDialog.value = true;\n if (!checkingAllUpdates.value) void checkAllUpdates();\n}");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("refreshes the plugin center after component-level plugin updates", () => {
|
||||||
|
expect(appSource).toContain("notifyComponentPluginsUpdated()");
|
||||||
|
expect(pluginCenterSource).toContain("COMPONENT_PLUGINS_UPDATED_EVENT");
|
||||||
|
expect(pluginCenterSource).toContain("window.addEventListener(COMPONENT_PLUGINS_UPDATED_EVENT, handleComponentPluginsUpdated)");
|
||||||
|
expect(pluginCenterSource).toContain("installedPlugins.value = await api.listPlugins()");
|
||||||
|
});
|
||||||
|
|
||||||
it("formats structured backend errors for local and URL package installs", () => {
|
it("formats structured backend errors for local and URL package installs", () => {
|
||||||
const localInstall = pluginCenterSource.slice(pluginCenterSource.indexOf("async function installPlugin("), pluginCenterSource.indexOf("function isHttpPackageUrl("));
|
const localInstall = pluginCenterSource.slice(pluginCenterSource.indexOf("async function installPlugin("), pluginCenterSource.indexOf("function isHttpPackageUrl("));
|
||||||
const urlInstall = pluginCenterSource.slice(pluginCenterSource.indexOf("async function installPluginFromUrl("), pluginCenterSource.indexOf("const urlProgressPercent"));
|
const urlInstall = pluginCenterSource.slice(pluginCenterSource.indexOf("async function installPluginFromUrl("), pluginCenterSource.indexOf("const urlProgressPercent"));
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// @vitest-environment happy-dom
|
||||||
|
|
||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
import { COMPONENT_PLUGINS_UPDATED_EVENT, notifyComponentPluginsUpdated } from "@/lib/updates/componentUpdateEvents";
|
||||||
|
|
||||||
|
describe("component update events", () => {
|
||||||
|
it("notifies plugin surfaces after component-level plugin updates", () => {
|
||||||
|
const listener = vi.fn();
|
||||||
|
window.addEventListener(COMPONENT_PLUGINS_UPDATED_EVENT, listener);
|
||||||
|
|
||||||
|
notifyComponentPluginsUpdated();
|
||||||
|
|
||||||
|
expect(listener).toHaveBeenCalledOnce();
|
||||||
|
window.removeEventListener(COMPONENT_PLUGINS_UPDATED_EVENT, listener);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export const COMPONENT_PLUGINS_UPDATED_EVENT = "dbx:component-plugins-updated";
|
||||||
|
|
||||||
|
export function notifyComponentPluginsUpdated(): void {
|
||||||
|
window.dispatchEvent(new Event(COMPONENT_PLUGINS_UPDATED_EVENT));
|
||||||
|
}
|
||||||
Reference in new issue
Block a user