25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(plugins): retire plugin batch failure banner on state change
Abeautifulsnow092a562ebff3
diff --git a/apps/desktop/src/components/plugins/PluginContributionsPanel.vue b/apps/desktop/src/components/plugins/PluginContributionsPanel.vueindex 5a469810b1..dd0b5975d4 100644--- a/apps/desktop/src/components/plugins/PluginContributionsPanel.vue+++ b/apps/desktop/src/components/plugins/PluginContributionsPanel.vue@@ -1,6 +1,6 @@<script setup lang="ts">import { computed, defineComponent, h, onBeforeUnmount, onMounted, ref, watch, TransitionGroup } from "vue";-import { ArrowUp, BadgeCheck, Check, ChevronRight, CircleAlert, Download, ExternalLink, FileUp, FolderTree, Globe, Info, LayoutGrid, Link2, List, Loader2, PackageCheck, Pencil, Pin, PinOff, Plus, RefreshCw, RotateCcw, Search, Settings2, ShieldCheck, Store, Trash2 } from "@lucide/vue";+import { ArrowUp, BadgeCheck, Check, ChevronRight, CircleAlert, Download, ExternalLink, FileUp, FolderTree, Globe, Info, LayoutGrid, Link2, List, Loader2, PackageCheck, Pencil, Pin, PinOff, Plus, RefreshCw, RotateCcw, Search, Settings2, ShieldCheck, Store, Trash2, X } from "@lucide/vue";import { Badge } from "@/components/ui/badge";import { isSensitivePluginPermission } from "@/lib/plugins/pluginPermissions";import { Button } from "@/components/ui/button";@@ -37,7 +37,7 @@ import {type MarketplacePluginSortMode,type PluginSourceChange,} from "@/lib/plugins/pluginMarketplace";-import { isBatchSelectableListing, runBatch } from "@/lib/plugins/pluginBatch";+import { isBatchSelectableListing, runBatch, type BatchOutcome } from "@/lib/plugins/pluginBatch";import { COMPONENT_PLUGINS_UPDATED_EVENT, notifyComponentPluginsUpdated, notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents";import { formatBytes } from "@/lib/database/serverMetrics";import type { PluginCenterFocus } from "@/lib/plugins/pluginCenterNavigation";@@ -97,7 +97,24 @@ const marketplaceInstallingKey = ref("");const marketplaceUnavailable = ref(false);const installedUpdateProgress = ref<{ current: number; total: number } | null>(null);const operating = ref(false);-const error = ref("");+// Page-level failure banner, split by lifetime. `batchFailures` is keyed by plugin: a later+// success retires exactly its own line instead of leaving a stale banner behind, and each line+// records what the failed attempt was trying to do (`kind`), because "no longer pending" means+// opposite things for an install (never retire a not-installed plugin) and an update.+type PluginBatchFailureKind = "install" | "update" | "uninstall";+interface PluginBatchFailure {+ pluginId: string;+ name: string;+ message: string;+ kind: PluginBatchFailureKind;+ // Marketplace repository the attempt came from; an update failure may only be reconciled while+ // that repository's catalog actually loaded (not applicable to uninstall).+ repositoryId?: string;+}+const batchFailures = ref<PluginBatchFailure[]>([]);+// Load / refresh failures only: their lifecycle is "the next successful state re-read clears them".+const loadError = ref("");+const errorBannerText = computed(() => [...batchFailures.value.map((failure) => `${failure.name}: ${failure.message}`), loadError.value].filter(Boolean).join("\n"));const selectedPluginId = ref("");const selectedContributionId = ref("");const selectedConnectionId = ref("");@@ -233,6 +250,70 @@ function markRecentlyCompleted(key: string) {}, 900);}+// --- Batch failure banner lifecycle -------------------------------------------------------------+// A batch failure is retired from two directions, and both are needed: precisely when this+// component sees the plugin change successfully, and by reconciliation when the state was changed+// elsewhere (the update center, another window) so no callback ever reaches this panel.++function retireBatchFailures(pluginIds: Iterable<string>): void {+ const retired = new Set(pluginIds);+ if (!retired.size) return;+ if (!batchFailures.value.some((failure) => retired.has(failure.pluginId))) return;+ batchFailures.value = batchFailures.value.filter((failure) => !retired.has(failure.pluginId));+}++function retireBatchFailure(pluginId: string): void {+ retireBatchFailures([pluginId]);+}++function dismissErrorBanner(): void {+ // Explicit escape hatch: the banner has no auto-expiry, and dismissing is purely cosmetic —+ // no plugin state is touched.+ batchFailures.value = [];+ loadError.value = "";+}++// An update failure may only be reconciled against a catalog check that is actually trustworthy.+// The panel already refuses to read an incomplete check as "up to date" (catalogChecked /+// catalogPartialFailure); the same rule applies here, otherwise "we could not check" would silently+// erase a failure the user still needs to act on.+function updateCheckTrustworthy(failure: PluginBatchFailure): boolean {+ if (marketplaceLoading.value) return false;+ if (marketplaceUnavailable.value) return false;+ if (!repositoriesEnabled.value) return false;+ // A repository that errored cannot prove its plugin is up to date. Only the failure's own+ // repository matters: another repository's error says nothing about this plugin's source.+ if (failure.repositoryId && catalogErrors.value.some((result) => result.repository.id === failure.repositoryId)) return false;+ return true;+}++function reconcileBatchFailures(): void {+ if (!batchFailures.value.length) return;+ const installedIds = new Set(installedPlugins.value.map((plugin) => plugin.manifest.id));+ batchFailures.value = batchFailures.value.filter((failure) => {+ // A failed uninstall stays until the plugin is actually gone.+ if (failure.kind === "uninstall") return installedIds.has(failure.pluginId);+ // A failed install stays while the plugin is not installed: absence from the pending-update+ // index is the normal state of a not-yet-installed plugin, not evidence the failure is stale.+ if (failure.kind === "install") return !installedIds.has(failure.pluginId);+ if (!updateCheckTrustworthy(failure)) return true;+ // Kept only while the fresh state still asks for the update: installed AND still not latest.+ return installedIds.has(failure.pluginId) && installedUpdateIndex.value.has(failure.pluginId);+ });+}++// Single choke point for assigning a freshly read installed list: every successful re-read clears a+// stale load failure and reconciles the per-plugin banner, so a new call site cannot forget either.+function applyInstalledPlugins(plugins: InstalledPlugin[]): void {+ installedPlugins.value = plugins;+ loadError.value = "";+ reconcileBatchFailures();+}++async function reloadInstalledPlugins(): Promise<void> {+ applyInstalledPlugins(await api.listPlugins());+}+function openExternal(url?: string) {const target = url?.trim();if (!target) return;@@ -248,16 +329,19 @@ function openExternal(url?: string) {async function refresh(preferredPluginId = props.focusTarget?.pluginId || selectedPluginId.value) {loading.value = true;- error.value = "";+ loadError.value = "";try {- [installedPlugins.value, trustedKeys.value, repositories.value] = await Promise.all([api.listPlugins(), api.listPluginTrustedKeys(), api.listPluginRepositories()]);+ const [plugins, keys, repositoryList] = await Promise.all([api.listPlugins(), api.listPluginTrustedKeys(), api.listPluginRepositories()]);+ trustedKeys.value = keys;+ repositories.value = repositoryList;+ applyInstalledPlugins(plugins);await refreshMarketplace();// Settings navigation is handled immediately by the watcher; replaying it// after loading would overwrite any subsequent navigation by the user.if (props.focusTarget && props.focusTarget.section !== "settings") applyFocusTarget(props.focusTarget);else selectFirstProvider(preferredPluginId);} catch (cause) {- error.value = cause instanceof Error ? cause.message : String(cause);+ loadError.value = cause instanceof Error ? cause.message : String(cause);} finally {loading.value = false;}@@ -265,9 +349,11 @@ async function refresh(preferredPluginId = props.focusTarget?.pluginId || selectasync function refreshMarketplace() {marketplaceLoading.value = true;+ let loaded = false;try {catalogResults.value = await api.fetchPluginMarketplaceCatalogs();marketplaceUnavailable.value = false;+ loaded = true;} catch (cause) {catalogResults.value = [];// Track total failure separately: catalogErrors is derived from catalogResults, which is@@ -277,6 +363,9 @@ async function refreshMarketplace() {} finally {marketplaceLoading.value = false;}+ // Only a catalog that actually loaded may re-check update failures — and only once the loading+ // flag is down, so the trust gate does not read this very fetch as still in flight.+ if (loaded) reconcileBatchFailures();}function applyFocusTarget(focus: PluginCenterFocus) {@@ -336,6 +425,9 @@ async function installMarketplaceListing(listing: MarketplacePluginListing, optimarketplaceInstallingKey.value = listing.key;try {const result = await installListing(listing, options.allowSourceChange === true);+ // Precise retirement: this plugin just changed successfully, so its own failure line (if any)+ // is stale. Other plugins' lines are untouched.+ retireBatchFailure(result.plugin.manifest.id);markRecentlyCompleted(listing.key);toast(t(listing.status === "update" ? "pluginPlatform.updateSuccess" : "pluginPlatform.installSuccess", { name: result.plugin.manifest.name, version: result.plugin.manifest.version }));// The COMPONENT_PLUGINS_UPDATED_EVENT handler does the panel-side refresh (icon cache +@@ -348,8 +440,8 @@ async function installMarketplaceListing(listing: MarketplacePluginListing, optitoast(translateBackendError(t, cause), 8000);// A failed install can still have mutated the store (a partially replaced version directory, for// instance), so re-read the installed list instead of leaving the card on state it may no longer- // describe.- installedPlugins.value = await api.listPlugins().catch(() => installedPlugins.value);+ // describe. The fallback keeps the previous list when the re-read itself fails.+ applyInstalledPlugins(await api.listPlugins().catch(() => installedPlugins.value));notifyComponentUpdatesChanged();} finally {marketplaceInstallingKey.value = "";@@ -360,18 +452,47 @@ function batchSummaryKey(outcome: { succeeded: unknown[]; failed: { name: stringreturn outcome.failed.length ? "pluginPlatform.batchSummaryWithFailures" : "pluginPlatform.batchSummary";}-function reportBatchSummary(outcome: { succeeded: unknown[]; failed: { name: string; error: string }[] }) {+/** What a failed batch item was trying to do, and where its update came from. */+interface BatchFailureDescriptor {+ pluginId: string;+ kind: PluginBatchFailureKind;+ repositoryId?: string;+}++function reportBatchSummary(outcome: BatchOutcome, descriptors: readonly BatchFailureDescriptor[]) {const failedNames = outcome.failed.map((failure) => failure.name).join("、");- error.value = outcome.failed.map((failure) => `${failure.name}: ${translateBackendError(t, failure.error)}`).join("\n");+ const descriptorById = new Map<string, BatchFailureDescriptor>();+ for (const descriptor of descriptors) descriptorById.set(descriptor.pluginId, descriptor);+ const reported: PluginBatchFailure[] = outcome.failed.map((failure) => {+ const descriptor = descriptorById.get(failure.id);+ return {+ pluginId: failure.id,+ name: failure.name,+ message: translateBackendError(t, failure.error),+ // Every failed item came from a batch target, so a descriptor is always present; a missing one+ // (a future call site) falls back to the conservative kind that is never retired by absence.+ kind: descriptor?.kind ?? "install",+ repositoryId: descriptor?.repositoryId,+ };+ });+ // One line per plugin: re-running a batch replaces that plugin's previous line instead of stacking.+ const reportedIds = new Set(reported.map((failure) => failure.pluginId));+ batchFailures.value = [...batchFailures.value.filter((failure) => !reportedIds.has(failure.pluginId)), ...reported];toast(t(batchSummaryKey(outcome), { success: outcome.succeeded.length, failed: outcome.failed.length, names: failedNames }), outcome.failed.length ? 8000 : 4000);}+function succeededIds(outcome: BatchOutcome): string[] {+ return outcome.results.filter((result) => result.ok).map((result) => result.id);+}+async function refreshAfterBatch() {try {- installedPlugins.value = await api.listPlugins();+ await reloadInstalledPlugins();window.dispatchEvent(new CustomEvent("dbx:plugins-changed"));} catch (cause) {- error.value = [error.value, t("pluginPlatform.batchRefreshFailed", { error: cause instanceof Error ? cause.message : String(cause) })].filter(Boolean).join("\n");+ // A refresh failure is its own lifetime (cleared by the next successful re-read), no longer+ // appended to the batch summary it would otherwise be indistinguishable from.+ loadError.value = t("pluginPlatform.batchRefreshFailed", { error: cause instanceof Error ? cause.message : String(cause) });}}@@ -387,7 +508,10 @@ async function runUpdateAllInstalled() {if (sourceChanged.length) toast(t("pluginPlatform.batchSourceChangeSkipped", { names: sourceChanged.map((entry) => entry.listing.name).join("、") }), 8000);if (!entries.length || mutationRunning.value) return;batchRunning.value = true;- error.value = "";+ // A new run retries the state read; its own outcome owns the banner from here (per-plugin+ // failures are retired individually, never wholesale).+ loadError.value = "";+ const descriptors: BatchFailureDescriptor[] = entries.map((entry) => ({ pluginId: entry.listing.plugin.id, kind: "update", repositoryId: entry.listing.repository.id }));installedUpdateProgress.value = { current: 0, total: entries.length };try {const outcome = await runBatch(@@ -396,6 +520,7 @@ async function runUpdateAllInstalled() {async (entry) => {await installListing(entry.listing);},+ (entry) => entry.listing.plugin.id,(current, total) => {installedUpdateProgress.value = { current, total };},@@ -405,7 +530,8 @@ async function runUpdateAllInstalled() {notifyComponentPluginsUpdated();notifyComponentUpdatesChanged();}- reportBatchSummary(outcome);+ reportBatchSummary(outcome, descriptors);+ retireBatchFailures(succeededIds(outcome));await refreshAfterBatch();} finally {batchRunning.value = false;@@ -416,9 +542,9 @@ async function runUpdateAllInstalled() {async function refreshAfterExternalPluginUpdate() {clearPluginIconCache();try {- installedPlugins.value = await api.listPlugins();+ await reloadInstalledPlugins();} catch (cause) {- error.value = cause instanceof Error ? cause.message : String(cause);+ loadError.value = cause instanceof Error ? cause.message : String(cause);}}@@ -482,7 +608,10 @@ async function runBatchInstallUpdate() {const sourceChangedListings = targets.filter((listing) => pluginSourceChange(listing));if (sourceChangedListings.length) return toast(t("pluginPlatform.batchSourceChangeSkipped", { names: sourceChangedListings.map((listing) => listing.name).join("、") }), 8000);batchRunning.value = true;- error.value = "";+ loadError.value = "";+ // `status` records which attempt this is: an install of a not-yet-installed plugin must stay+ // visible while it is absent, while a failed update retires once the plugin is up to date.+ const descriptors: BatchFailureDescriptor[] = targets.map((listing) => ({ pluginId: listing.plugin.id, kind: listing.status === "update" ? "update" : "install", repositoryId: listing.repository.id }));try {const outcome = await runBatch(targets,@@ -490,9 +619,11 @@ async function runBatchInstallUpdate() {async (listing) => {await installListing(listing);},+ (listing) => listing.plugin.id,);clearBatchSelection();- reportBatchSummary(outcome);+ reportBatchSummary(outcome, descriptors);+ retireBatchFailures(succeededIds(outcome));await refreshAfterBatch();notifyComponentUpdatesChanged();} finally {@@ -506,7 +637,8 @@ async function runBatchUninstall() {const names = targets.map((definition) => definition.plugin.manifest.name).join("、");if (!window.confirm(t("pluginPlatform.batchUninstallConfirm", { count: targets.length, names }))) return;batchRunning.value = true;- error.value = "";+ loadError.value = "";+ const descriptors: BatchFailureDescriptor[] = targets.map((definition) => ({ pluginId: definition.plugin.manifest.id, kind: "uninstall" }));try {const outcome = await runBatch(targets,@@ -514,9 +646,11 @@ async function runBatchUninstall() {async (definition) => {await api.uninstallPlugin(definition.plugin.manifest.id);},+ (definition) => definition.plugin.manifest.id,);clearBatchSelection();- reportBatchSummary(outcome);+ reportBatchSummary(outcome, descriptors);+ retireBatchFailures(succeededIds(outcome));await refreshAfterBatch();notifyComponentUpdatesChanged();} finally {@@ -722,7 +856,10 @@ async function finishInstall(result: PluginInstallResult) {toast(t("pluginPlatform.installSuccess", { name: result.plugin.manifest.name, version: result.plugin.manifest.version }));clearPluginIconCache();notifyComponentPluginsUpdated();- installedPlugins.value = await api.listPlugins();+ // Retire first: this plugin's install already succeeded, so its failure line is stale even if the+ // re-read below fails (the read only refreshes the panel, it cannot uninstall the plugin).+ retireBatchFailure(result.plugin.manifest.id);+ await reloadInstalledPlugins();notifyComponentUpdatesChanged();window.dispatchEvent(new CustomEvent("dbx:plugins-changed"));selectPlugin(result.plugin.manifest.id);@@ -870,7 +1007,9 @@ async function rollbackSelectedPlugin() {notifyPluginRuntimeReplaced(result.plugin.manifest.id);toast(t("pluginPlatform.rollbackSuccess", { version: result.plugin.manifest.version }));clearPluginIconCache();- installedPlugins.value = await api.listPlugins();+ // Retire before the re-read for the same reason as finishInstall: the rollback already happened.+ retireBatchFailure(result.plugin.manifest.id);+ await reloadInstalledPlugins();notifyComponentUpdatesChanged();window.dispatchEvent(new CustomEvent("dbx:plugins-changed"));selectPlugin(result.plugin.manifest.id);@@ -886,7 +1025,8 @@ async function uninstallSelectedPlugin() {if (mutationRunning.value || !definition || !window.confirm(t("pluginPlatform.uninstallConfirm", { name: definition.plugin.manifest.name }))) return;operating.value = true;try {- installedPlugins.value = await api.uninstallPlugin(definition.plugin.manifest.id);+ applyInstalledPlugins(await api.uninstallPlugin(definition.plugin.manifest.id));+ retireBatchFailure(definition.plugin.manifest.id);notifyComponentUpdatesChanged();window.dispatchEvent(new CustomEvent("dbx:plugins-changed"));clearPluginIconCache();@@ -956,7 +1096,14 @@ onBeforeUnmount(() => {<template><div ref="panelRootRef" class="plugin-center-view relative mx-auto flex h-full w-full max-w-6xl flex-col gap-4 overflow-hidden px-6 py-6" @dragenter="onWebDragEnter" @dragover="onWebDragOver" @dragleave="onWebDragLeave" @drop="onWebDrop"><input ref="webFileInput" type="file" accept=".dbxp" class="hidden" @change="handleWebPackage" />- <div v-if="error" class="shrink-0 whitespace-pre-wrap rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs text-destructive">{{ error }}</div>+ <div v-if="errorBannerText" class="flex shrink-0 items-start gap-2 rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs text-destructive">+ <div class="min-w-0 flex-1 whitespace-pre-wrap">{{ errorBannerText }}</div>+ <!-- The banner has no auto-expiry, so the user needs an explicit way out; dismissing only+ clears the notice, no plugin state is touched. -->+ <button type="button" data-plugin-error-dismiss class="shrink-0 rounded p-0.5 transition-colors hover:bg-destructive/10" :title="t('common.close')" :aria-label="t('common.close')" @click="dismissErrorBanner">+ <X class="size-3.5" />+ </button>+ </div><Tabs v-model="activeSection" class="min-h-0 flex-1 gap-3"><TabsList class="grid h-9 w-full grid-cols-3">diff --git a/apps/desktop/src/components/plugins/__tests__/PluginContributionsPanelBatch.spec.ts b/apps/desktop/src/components/plugins/__tests__/PluginContributionsPanelBatch.spec.tsindex 4b9d98c1a1..e4f9cfc8e5 100644--- a/apps/desktop/src/components/plugins/__tests__/PluginContributionsPanelBatch.spec.ts+++ b/apps/desktop/src/components/plugins/__tests__/PluginContributionsPanelBatch.spec.ts@@ -84,7 +84,12 @@ type PanelState = {repositoryCatalogUrl: string;trustedKeyId: string;trustedPublicKey: string;- error: string;+ // The page-level banner is split by lifetime: per-plugin batch failures (retired when that+ // plugin's state contradicts them), load/refresh failures (cleared by the next successful+ // re-read) and the aggregate text the banner renders.+ batchFailures: { pluginId: string; name: string; message: string; kind: string; repositoryId?: string }[];+ loadError: string;+ errorBannerText: string;toggleListingSelection: (listing: MarketplacePluginListing) => void;selectAllUpdatable: () => void;runBatchInstallUpdate: () => Promise<void>;@@ -389,7 +394,7 @@ describe("PluginContributionsPanel installed-tab updates", () => {mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("update denied"));await state.runUpdateAllInstalled();expect(mocks.installMarketplacePlugin).toHaveBeenCalledTimes(3);- expect(state.error).toBe("a: update denied");+ expect(state.errorBannerText).toBe("a: update denied");expect(state.installedUpdateProgress).toBeNull();expect(state.batchRunning).toBe(false);});@@ -576,7 +581,7 @@ describe("PluginContributionsPanel workbench refresh", () => {await running;}expect(mocks.refreshPluginWorkbenches.mock.calls).toEqual([["a"], ["c"]]);- expect(state.error).toContain("replacement denied");+ expect(state.errorBannerText).toContain("replacement denied");});it("leaves Tauri batch refresh to the native runtime events", async () => {@@ -719,7 +724,7 @@ describe("PluginContributionsPanel completed batch outcomes", () => {mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("Plugin update blocked by active connections: Production S3"));await state.runBatchInstallUpdate();expect(mocks.installMarketplacePlugin).toHaveBeenCalledTimes(3);- expect(state.error).toBe('a: pluginPlatform.updateBlockedByConnections:{"labels":"Production S3"}');+ expect(state.errorBannerText).toBe('a: pluginPlatform.updateBlockedByConnections:{"labels":"Production S3"}');await nextTick();expect(host.textContent).toContain("Production S3");});@@ -748,13 +753,18 @@ describe("PluginContributionsPanel completed batch outcomes", () => {expect(mutation).toHaveBeenCalledTimes(3);expect(mocks.toast).toHaveBeenCalledTimes(1);expect(mocks.toast).toHaveBeenLastCalledWith(summary, failures ? 8000 : 4000);- expect(state.error).toBe([...["a", "b", "c"].slice(0, failures).map((name) => `${name}: denied`), 'pluginPlatform.batchRefreshFailed:{"error":"refresh offline"}'].join("\n"));+ // Per-plugin lines first, then the refresh failure: a failed refresh no longer shares a string+ // with the batch summary, but the rendered text stays identical.+ expect(state.errorBannerText).toBe([...["a", "b", "c"].slice(0, failures).map((name) => `${name}: denied`), 'pluginPlatform.batchRefreshFailed:{"error":"refresh offline"}'].join("\n"));await nextTick();- expect(host.textContent).toContain(state.error);+ expect(host.textContent).toContain(state.errorBannerText);expect(state.batchRunning).toBe(false);state.selectedListingKeys = new Set(["first:a"]);await state.runBatchInstallUpdate();- expect(state.error).toBe("");+ // The retried plugin's own line is retired by its success and the refresh failure is cleared by+ // the successful re-read; failures of plugins this run never attempted ("b"/"c") are still valid.+ expect(state.loadError).toBe("");+ expect(state.batchFailures.map((failure) => failure.pluginId)).toEqual(["a", "b", "c"].slice(1, failures));});it.each(batches)("runs batch %s in order, continues after rejection and refreshes once", async (batch) => {@@ -772,7 +782,7 @@ describe("PluginContributionsPanel completed batch outcomes", () => {expect(mutation.mock.calls.map(([request]) => (batch === "install" ? request.pluginId : request))).toEqual(["a", "b", "c"]);expect(mocks.listPlugins).toHaveBeenCalledTimes(1);expect(mocks.toast).toHaveBeenLastCalledWith('pluginPlatform.batchSummaryWithFailures:{"success":2,"failed":1,"names":"b"}', 8000);- expect(state.error).toBe("b: denied");+ expect(state.errorBannerText).toBe("b: denied");expect(state.batchRunning).toBe(false);expect(state.selectedListingKeys.size).toBe(0);expect(state.selectedInstalledIds.size).toBe(0);@@ -817,6 +827,247 @@ describe("PluginContributionsPanel completed batch outcomes", () => {});});+// The failure banner is page-level and persistent, so the bug this covers is a stale line surviving+// the very success that fixed it. Each case drives one retirement path.+describe("PluginContributionsPanel stale failure banner", () => {+ function enableRepositories(): void {+ state.repositories = [{ id: "first", name: "first", kind: "custom", enabled: true, managed: false }];+ }++ it("retires exactly the plugin a later successful update fixes and keeps the other failures", async () => {+ state.selectAllUpdatable();+ mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("a down")).mockRejectedValueOnce(new Error("b down"));+ await state.runBatchInstallUpdate();+ expect(mocks.installMarketplacePlugin).toHaveBeenCalledTimes(3);+ expect(state.errorBannerText).toBe("a: a down\nb: b down");++ await state.updateInstalledPlugin("a");++ expect(state.errorBannerText).toBe("b: b down");+ expect(state.batchFailures.map((failure) => failure.pluginId)).toEqual(["b"]);+ });++ it("retires a failure once a fresh catalog check proves the plugin is up to date", async () => {+ enableRepositories();+ state.selectAllUpdatable();+ mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("a down"));+ await state.runBatchInstallUpdate();+ expect(state.errorBannerText).toBe("a: a down");++ // The plugin landed at the latest version (outside this panel's success callbacks), so a+ // catalog re-read is the only thing that can notice.+ state.installedPlugins = [installed("a", "3.0.0"), installed("b", "3.0.0"), installed("c", "3.0.0")];+ await state.refreshMarketplace();++ expect(state.installedUpdateCount).toBe(0);+ expect(state.errorBannerText).toBe("");+ expect(state.batchFailures).toEqual([]);+ });++ it("retires a failure when the plugin was updated outside this panel", async () => {+ enableRepositories();+ state.selectAllUpdatable();+ mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("a down"));+ await state.runBatchInstallUpdate();+ expect(state.errorBannerText).toBe("a: a down");++ mocks.listPlugins.mockResolvedValue([installed("a", "3.0.0")]);+ window.dispatchEvent(new Event(COMPONENT_PLUGINS_UPDATED_EVENT));+ await flushUi();++ expect(state.errorBannerText).toBe("");+ });++ it("does not retire an update failure while its own repository fails to load", async () => {+ enableRepositories();+ state.selectAllUpdatable();+ mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("a down"));+ await state.runBatchInstallUpdate();+ expect(state.errorBannerText).toBe("a: a down");++ // "a" drops out of the update index only because its repository's catalog failed: an incomplete+ // check must never read as "the failure is fixed".+ state.installedPlugins = [installed("a", "3.0.0")];+ mocks.fetchPluginMarketplaceCatalogs.mockResolvedValueOnce([{ ...catalog("first", []), catalog: undefined, error: "catalog offline" }]);+ await state.refreshMarketplace();++ expect(state.catalogPartialFailure).toBe(true);+ expect(state.installedUpdateCount).toBe(0);+ expect(state.errorBannerText).toBe("a: a down");+ });++ it("does not retire a failure while no repository is enabled or the catalog is unavailable", async () => {+ state.selectAllUpdatable();+ mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("a down"));+ await state.runBatchInstallUpdate();++ state.installedPlugins = [installed("a", "3.0.0")];+ await state.refreshMarketplace();+ // No enabled repository: the "not pending" verdict cannot be trusted.+ expect(state.errorBannerText).toBe("a: a down");++ enableRepositories();+ mocks.fetchPluginMarketplaceCatalogs.mockRejectedValueOnce(new Error("offline"));+ await state.refreshMarketplace();+ expect(state.marketplaceUnavailable).toBe(true);+ // A state re-read while the catalog is unavailable must not turn "we could not check" into+ // "the failure is fixed" (the update index is empty precisely because nothing loaded).+ window.dispatchEvent(new Event(COMPONENT_PLUGINS_UPDATED_EVENT));+ await flushUi();+ expect(state.errorBannerText).toBe("a: a down");+ });++ it("keeps an install failure while the plugin is still not installed", async () => {+ mocks.listPlugins.mockResolvedValue([installed("b")]);+ state.installedPlugins = [installed("b")];+ state.catalogResults = [catalog("first", ["a"])];+ state.selectedListingKeys = new Set(["first:a"]);+ await nextTick();+ expect(state.marketplaceListings.map((listing) => listing.status)).toEqual(["install"]);++ mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("download failed"));+ await state.runBatchInstallUpdate();+ expect(state.batchFailures).toEqual([{ pluginId: "a", name: "a", message: "download failed", kind: "install", repositoryId: "first" }]);+ expect(state.errorBannerText).toBe("a: download failed");++ // A never-installed plugin is absent from the update index by definition; a fresh catalog check+ // must not read that as "the install failure is stale".+ enableRepositories();+ await state.refreshMarketplace();+ expect(state.errorBannerText).toBe("a: download failed");+ });++ it("does not retire while the catalog check is still in flight", async () => {+ enableRepositories();+ state.selectAllUpdatable();+ mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("a down"));+ await state.runBatchInstallUpdate();+ expect(state.errorBannerText).toBe("a: a down");++ // A newer version was published (4.0.0) and "a" was updated to 3.0.0 elsewhere, so the catalog+ // re-read is what decides whether the failure is still actionable. Until it answers, the old+ // catalog in memory would read "3.0.0 is not pending" and wrongly retire the line.+ const pending = deferred<PluginRepositoryCatalogResult[]>();+ mocks.fetchPluginMarketplaceCatalogs.mockReturnValueOnce(pending.promise);+ const refreshing = state.refreshMarketplace();+ await nextTick();+ mocks.listPlugins.mockResolvedValue([installed("a", "3.0.0")]);+ window.dispatchEvent(new Event(COMPONENT_PLUGINS_UPDATED_EVENT));+ await flushUi();+ expect(state.errorBannerText).toBe("a: a down");++ pending.resolve([catalog("first", ["a", "b", "c"], "4.0.0")]);+ await refreshing;+ // Settled check: 4.0.0 is still pending, so the failure stays.+ expect(state.installedUpdateCount).toBe(1);+ expect(state.errorBannerText).toBe("a: a down");+ });++ it("clears the banner through the dismiss control without touching plugin state", async () => {+ state.selectAllUpdatable();+ mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("a down"));+ await state.runBatchInstallUpdate();+ const mutationsBefore = mutationCount();+ await nextTick();++ const dismiss = host.querySelector<HTMLButtonElement>("[data-plugin-error-dismiss]");+ expect(dismiss).toBeInstanceOf(HTMLButtonElement);+ expect(dismiss?.getAttribute("aria-label")).toContain("common.close");+ dismiss!.click();+ await nextTick();++ expect(state.errorBannerText).toBe("");+ expect(state.batchFailures).toEqual([]);+ expect(state.loadError).toBe("");+ expect(host.querySelector("[data-plugin-error-dismiss]")).toBeNull();+ expect(mutationCount()).toBe(mutationsBefore);+ });++ it("retires a plugin that succeeded in the same one-click update run and keeps its latest failure only once", async () => {+ state.selectAllUpdatable();+ mocks.installMarketplacePlugin.mockImplementation(async ({ pluginId }: { pluginId: string }) => {+ if (pluginId === "a") throw new Error("a down");+ if (pluginId === "b") throw new Error("b down");+ return { plugin: installed(pluginId, "3.0.0") };+ });+ await state.runBatchInstallUpdate();+ expect(state.batchFailures.map((failure) => failure.pluginId)).toEqual(["a", "b"]);++ // The retry leaves "b" failing with a newer message. The stub keeps the pre-update installed+ // list, so reconciliation can only *keep* both lines here: whatever disappears is the retried+ // plugin's own success, and "b" must be replaced by its newest message, not stacked twice.+ mocks.installMarketplacePlugin.mockImplementation(async ({ pluginId }: { pluginId: string }) => {+ if (pluginId === "b") throw new Error("b still down");+ return { plugin: installed(pluginId, "3.0.0") };+ });+ await state.runUpdateAllInstalled();++ expect(mocks.installMarketplacePlugin).toHaveBeenCalledTimes(6);+ expect(state.batchFailures.map((failure) => `${failure.pluginId}:${failure.message}`)).toEqual(["b:b still down"]);+ expect(state.errorBannerText).toBe("b: b still down");+ });++ it("retires an uninstall failure whose own retry succeeded in the batch", async () => {+ state.selectedInstalledIds = new Set(["a", "b"]);+ mocks.uninstallPlugin.mockRejectedValueOnce(new Error("a locked"));+ await state.runBatchUninstall();+ expect(state.batchFailures.map((failure) => failure.pluginId)).toEqual(["a"]);++ state.selectedInstalledIds = new Set(["a"]);+ await state.runBatchUninstall();++ // The installed stub still lists "a", so reconciliation keeps this line: only the successful+ // retry inside the batch may retire it.+ expect(state.batchFailures).toEqual([]);+ expect(state.errorBannerText).toBe("");+ });++ it("retires an uninstall failure once a fresh read proves the plugin is gone", async () => {+ state.selectedInstalledIds = new Set(["a"]);+ mocks.uninstallPlugin.mockRejectedValueOnce(new Error("a locked"));+ await state.runBatchUninstall();+ expect(state.batchFailures.map((failure) => failure.pluginId)).toEqual(["a"]);++ mocks.listPlugins.mockResolvedValue([installed("b"), installed("c")]);+ window.dispatchEvent(new Event(COMPONENT_PLUGINS_UPDATED_EVENT));+ await flushUi();++ expect(state.batchFailures).toEqual([]);+ expect(state.errorBannerText).toBe("");+ });++ it("clears a load failure after the next successful state re-read", async () => {+ mocks.listPlugins.mockRejectedValueOnce(new Error("list offline"));+ window.dispatchEvent(new Event(COMPONENT_PLUGINS_UPDATED_EVENT));+ await flushUi();+ expect(state.loadError).toBe("list offline");+ expect(state.errorBannerText).toBe("list offline");++ window.dispatchEvent(new Event(COMPONENT_PLUGINS_UPDATED_EVENT));+ await flushUi();++ expect(state.loadError).toBe("");+ expect(state.errorBannerText).toBe("");+ });++ it.each(["package", "rollback"] as const)("retires a plugin's failure as soon as its %s succeeded, even when the follow-up read fails", async (single) => {+ state.selectAllUpdatable();+ mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("a down"));+ await state.runBatchInstallUpdate();+ expect(state.batchFailures.map((failure) => failure.pluginId)).toEqual(["a"]);++ // The re-read cannot prove anything here, so only "the plugin itself changed successfully"+ // may retire the line — a refresh failure must not leave a stale failure behind.+ mocks.listPlugins.mockRejectedValue(new Error("list offline"));+ await startSingle(single === "package" ? "package" : "rollback");++ expect(state.batchFailures).toEqual([]);+ // The failed re-read keeps its own lifetime: the package path surfaces it as a load failure+ // (never as the plugin's failure), the rollback path reports it in a toast only.+ expect(state.errorBannerText).toBe(single === "package" ? "list offline" : "");+ });+});+describe("PluginContributionsPanel marketplace sort", () => {const OLDEST = "2025-01-01T00:00:00Z";const NEWEST = "2026-06-01T00:00:00Z";@@ -943,7 +1194,8 @@ describe("PluginContributionsPanel single uninstall outcomes", () => {expect(mocks.listPlugins).toHaveBeenCalledOnce();expect(state.installedPlugins.map((plugin) => `${plugin.manifest.id}@${plugin.manifest.version}`)).toEqual(["[email protected]", "[email protected]"]);expect(changed).toHaveBeenCalledOnce();- expect(state.error).toBe("");+ expect(state.errorBannerText).toBe("");+ expect(state.loadError).toBe("");});it("keeps the uninstall failure visible when the follow-up refresh also fails", async () => {@@ -953,7 +1205,8 @@ describe("PluginContributionsPanel single uninstall outcomes", () => {await state.uninstallSelectedPlugin();expect(mocks.toast).toHaveBeenLastCalledWith("denied", 5000);- expect(state.error).toBe('pluginPlatform.batchRefreshFailed:{"error":"refresh offline"}');+ expect(state.errorBannerText).toBe('pluginPlatform.batchRefreshFailed:{"error":"refresh offline"}');+ expect(state.loadError).toBe('pluginPlatform.batchRefreshFailed:{"error":"refresh offline"}');});});diff --git a/apps/desktop/src/lib/plugins/__tests__/pluginBatch.spec.ts b/apps/desktop/src/lib/plugins/__tests__/pluginBatch.spec.tsindex 65e17a2ede..bfc7dd008c 100644--- a/apps/desktop/src/lib/plugins/__tests__/pluginBatch.spec.ts+++ b/apps/desktop/src/lib/plugins/__tests__/pluginBatch.spec.ts@@ -10,6 +10,7 @@ describe("runBatch", () => {async (item) => {order.push(item.id);},+ (item) => item.id,);expect(order).toEqual(["a", "b", "c"]);expect(outcome.succeeded).toEqual(["a", "b", "c"]);@@ -25,15 +26,48 @@ describe("runBatch", () => {ran.push(item.id);if (item.id === "b") throw new Error("boom");},+ (item) => item.id,);expect(ran).toEqual(["a", "b", "c"]);expect(outcome.succeeded).toEqual(["a", "c"]);- expect(outcome.failed).toEqual([{ name: "b", error: "boom" }]);+ expect(outcome.failed).toEqual([{ id: "b", name: "b", error: "boom" }]);+ });++ it("records the item identity for a non-Error rejection too", async () => {+ const outcome = await runBatch(+ [{ id: "a" }, { id: "b" }],+ (item) => item.id,+ async (item) => {+ if (item.id === "b") throw "denied";+ },+ (item) => item.id,+ );+ expect(outcome.failed).toEqual([{ id: "b", name: "b", error: "denied" }]);+ });++ it("reads identity and label before the action can destroy them", async () => {+ // A failed action may leave the item unusable (see the plugin store leaving a half-replaced+ // version dir behind), so the failure has to carry the identity captured up front.+ const outcome = await runBatch(+ [{ id: "a" }],+ (item) => item.id,+ async (item) => {+ item.id = "";+ throw new Error("boom");+ },+ (item) => item.id,+ );+ expect(outcome.failed).toEqual([{ id: "a", name: "a", error: "boom" }]);});it("returns an empty outcome for empty input", async () => {const action = vi.fn();- const outcome = await runBatch([], (item: { id: string }) => item.id, action);+ const outcome = await runBatch(+ [],+ (item: { id: string }) => item.id,+ action,+ (item: { id: string }) => item.id,+ );expect(action).not.toHaveBeenCalled();expect(outcome.succeeded).toEqual([]);expect(outcome.failed).toEqual([]);diff --git a/apps/desktop/src/lib/plugins/pluginBatch.ts b/apps/desktop/src/lib/plugins/pluginBatch.tsindex 4beaa5e1e3..e4f73700e7 100644--- a/apps/desktop/src/lib/plugins/pluginBatch.ts+++ b/apps/desktop/src/lib/plugins/pluginBatch.ts@@ -3,6 +3,9 @@// and result aggregation so partial failures can be reported without aborting the batch.export interface BatchItemOutcome {+ // Item identity, kept alongside the label so a caller can map a failure back to the item it came+ // from (retire a stale per-item banner, for instance) instead of string-matching the name.+ id: string;name: string;ok: boolean;error?: string;@@ -11,25 +14,29 @@ export interface BatchItemOutcome {export interface BatchOutcome {results: BatchItemOutcome[];succeeded: string[];- failed: { name: string; error: string }[];+ failed: { id: string; name: string; error: string }[];}/*** Run `action` over `items` sequentially, recording per-item success/failure. A failing item is* captured and the batch continues; nothing is rolled back. `nameOf` supplies a human label used- * in the summary. `onProgress` fires after every item (success or failure) so callers can render- * live "(current/total)" progress. Empty input yields an empty outcome.+ * in the summary and `idOf` the machine identity of the item. `onProgress` fires after every item+ * (success or failure) so callers can render live "(current/total)" progress. Empty input yields+ * an empty outcome.*/-export async function runBatch<T>(items: readonly T[], nameOf: (item: T) => string, action: (item: T) => Promise<void>, onProgress?: (completed: number, total: number) => void): Promise<BatchOutcome> {+export async function runBatch<T>(items: readonly T[], nameOf: (item: T) => string, action: (item: T) => Promise<void>, idOf: (item: T) => string, onProgress?: (completed: number, total: number) => void): Promise<BatchOutcome> {const results: BatchItemOutcome[] = [];let completed = 0;for (const item of items) {+ // Identity (and label) are read before the action runs: a failed action may leave the item in a+ // state it can no longer be identified from, and the failure still has to name its own item.+ const id = idOf(item);const name = nameOf(item);try {await action(item);- results.push({ name, ok: true });+ results.push({ id, name, ok: true });} catch (cause) {- results.push({ name, ok: false, error: cause instanceof Error ? cause.message : String(cause) });+ results.push({ id, name, ok: false, error: cause instanceof Error ? cause.message : String(cause) });}completed += 1;onProgress?.(completed, items.length);@@ -37,7 +44,7 @@ export async function runBatch<T>(items: readonly T[], nameOf: (item: T) => strireturn {results,succeeded: results.filter((result) => result.ok).map((result) => result.name),- failed: results.filter((result) => !result.ok).map((result) => ({ name: result.name, error: result.error ?? "" })),+ failed: results.filter((result) => !result.ok).map((result) => ({ id: result.id, name: result.name, error: result.error ?? "" })),};}