fix(plugins): retire plugin batch failure banner on state change
This commit is contained in:
1 parent
e96d8890bc
commit
092a562ebf
4 files changed
+484
-43
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, defineComponent, h, onBeforeUnmount, onMounted, ref, watch, TransitionGroup } from "vue";
|
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 { Badge } from "@/components/ui/badge";
|
||||||
import { isSensitivePluginPermission } from "@/lib/plugins/pluginPermissions";
|
import { isSensitivePluginPermission } from "@/lib/plugins/pluginPermissions";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
@@ -37,7 +37,7 @@ import {
|
|||||||
type MarketplacePluginSortMode,
|
type MarketplacePluginSortMode,
|
||||||
type PluginSourceChange,
|
type PluginSourceChange,
|
||||||
} from "@/lib/plugins/pluginMarketplace";
|
} 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 { COMPONENT_PLUGINS_UPDATED_EVENT, notifyComponentPluginsUpdated, notifyComponentUpdatesChanged } 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";
|
||||||
@@ -97,7 +97,24 @@ const marketplaceInstallingKey = ref("");
|
|||||||
const marketplaceUnavailable = ref(false);
|
const marketplaceUnavailable = ref(false);
|
||||||
const installedUpdateProgress = ref<{ current: number; total: number } | null>(null);
|
const installedUpdateProgress = ref<{ current: number; total: number } | null>(null);
|
||||||
const operating = ref(false);
|
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 selectedPluginId = ref("");
|
||||||
const selectedContributionId = ref("");
|
const selectedContributionId = ref("");
|
||||||
const selectedConnectionId = ref("");
|
const selectedConnectionId = ref("");
|
||||||
@@ -233,6 +250,70 @@ function markRecentlyCompleted(key: string) {
|
|||||||
}, 900);
|
}, 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) {
|
function openExternal(url?: string) {
|
||||||
const target = url?.trim();
|
const target = url?.trim();
|
||||||
if (!target) return;
|
if (!target) return;
|
||||||
@@ -248,16 +329,19 @@ function openExternal(url?: string) {
|
|||||||
|
|
||||||
async function refresh(preferredPluginId = props.focusTarget?.pluginId || selectedPluginId.value) {
|
async function refresh(preferredPluginId = props.focusTarget?.pluginId || selectedPluginId.value) {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
error.value = "";
|
loadError.value = "";
|
||||||
try {
|
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();
|
await refreshMarketplace();
|
||||||
// Settings navigation is handled immediately by the watcher; replaying it
|
// Settings navigation is handled immediately by the watcher; replaying it
|
||||||
// after loading would overwrite any subsequent navigation by the user.
|
// after loading would overwrite any subsequent navigation by the user.
|
||||||
if (props.focusTarget && props.focusTarget.section !== "settings") applyFocusTarget(props.focusTarget);
|
if (props.focusTarget && props.focusTarget.section !== "settings") applyFocusTarget(props.focusTarget);
|
||||||
else selectFirstProvider(preferredPluginId);
|
else selectFirstProvider(preferredPluginId);
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
error.value = cause instanceof Error ? cause.message : String(cause);
|
loadError.value = cause instanceof Error ? cause.message : String(cause);
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
@@ -265,9 +349,11 @@ async function refresh(preferredPluginId = props.focusTarget?.pluginId || select
|
|||||||
|
|
||||||
async function refreshMarketplace() {
|
async function refreshMarketplace() {
|
||||||
marketplaceLoading.value = true;
|
marketplaceLoading.value = true;
|
||||||
|
let loaded = false;
|
||||||
try {
|
try {
|
||||||
catalogResults.value = await api.fetchPluginMarketplaceCatalogs();
|
catalogResults.value = await api.fetchPluginMarketplaceCatalogs();
|
||||||
marketplaceUnavailable.value = false;
|
marketplaceUnavailable.value = false;
|
||||||
|
loaded = true;
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
catalogResults.value = [];
|
catalogResults.value = [];
|
||||||
// Track total failure separately: catalogErrors is derived from catalogResults, which is
|
// Track total failure separately: catalogErrors is derived from catalogResults, which is
|
||||||
@@ -277,6 +363,9 @@ async function refreshMarketplace() {
|
|||||||
} finally {
|
} finally {
|
||||||
marketplaceLoading.value = false;
|
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) {
|
function applyFocusTarget(focus: PluginCenterFocus) {
|
||||||
@@ -336,6 +425,9 @@ async function installMarketplaceListing(listing: MarketplacePluginListing, opti
|
|||||||
marketplaceInstallingKey.value = listing.key;
|
marketplaceInstallingKey.value = listing.key;
|
||||||
try {
|
try {
|
||||||
const result = await installListing(listing, options.allowSourceChange === true);
|
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);
|
markRecentlyCompleted(listing.key);
|
||||||
toast(t(listing.status === "update" ? "pluginPlatform.updateSuccess" : "pluginPlatform.installSuccess", { name: result.plugin.manifest.name, version: result.plugin.manifest.version }));
|
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 +
|
// The COMPONENT_PLUGINS_UPDATED_EVENT handler does the panel-side refresh (icon cache +
|
||||||
@@ -348,8 +440,8 @@ async function installMarketplaceListing(listing: MarketplacePluginListing, opti
|
|||||||
toast(translateBackendError(t, cause), 8000);
|
toast(translateBackendError(t, cause), 8000);
|
||||||
// A failed install can still have mutated the store (a partially replaced version directory, for
|
// 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
|
// instance), so re-read the installed list instead of leaving the card on state it may no longer
|
||||||
// describe.
|
// describe. The fallback keeps the previous list when the re-read itself fails.
|
||||||
installedPlugins.value = await api.listPlugins().catch(() => installedPlugins.value);
|
applyInstalledPlugins(await api.listPlugins().catch(() => installedPlugins.value));
|
||||||
notifyComponentUpdatesChanged();
|
notifyComponentUpdatesChanged();
|
||||||
} finally {
|
} finally {
|
||||||
marketplaceInstallingKey.value = "";
|
marketplaceInstallingKey.value = "";
|
||||||
@@ -360,18 +452,47 @@ function batchSummaryKey(outcome: { succeeded: unknown[]; failed: { name: string
|
|||||||
return outcome.failed.length ? "pluginPlatform.batchSummaryWithFailures" : "pluginPlatform.batchSummary";
|
return 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("、");
|
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);
|
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() {
|
async function refreshAfterBatch() {
|
||||||
try {
|
try {
|
||||||
installedPlugins.value = await api.listPlugins();
|
await reloadInstalledPlugins();
|
||||||
window.dispatchEvent(new CustomEvent("dbx:plugins-changed"));
|
window.dispatchEvent(new CustomEvent("dbx:plugins-changed"));
|
||||||
} catch (cause) {
|
} 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 (sourceChanged.length) toast(t("pluginPlatform.batchSourceChangeSkipped", { names: sourceChanged.map((entry) => entry.listing.name).join("、") }), 8000);
|
||||||
if (!entries.length || mutationRunning.value) return;
|
if (!entries.length || mutationRunning.value) return;
|
||||||
batchRunning.value = true;
|
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 };
|
installedUpdateProgress.value = { current: 0, total: entries.length };
|
||||||
try {
|
try {
|
||||||
const outcome = await runBatch(
|
const outcome = await runBatch(
|
||||||
@@ -396,6 +520,7 @@ async function runUpdateAllInstalled() {
|
|||||||
async (entry) => {
|
async (entry) => {
|
||||||
await installListing(entry.listing);
|
await installListing(entry.listing);
|
||||||
},
|
},
|
||||||
|
(entry) => entry.listing.plugin.id,
|
||||||
(current, total) => {
|
(current, total) => {
|
||||||
installedUpdateProgress.value = { current, total };
|
installedUpdateProgress.value = { current, total };
|
||||||
},
|
},
|
||||||
@@ -405,7 +530,8 @@ async function runUpdateAllInstalled() {
|
|||||||
notifyComponentPluginsUpdated();
|
notifyComponentPluginsUpdated();
|
||||||
notifyComponentUpdatesChanged();
|
notifyComponentUpdatesChanged();
|
||||||
}
|
}
|
||||||
reportBatchSummary(outcome);
|
reportBatchSummary(outcome, descriptors);
|
||||||
|
retireBatchFailures(succeededIds(outcome));
|
||||||
await refreshAfterBatch();
|
await refreshAfterBatch();
|
||||||
} finally {
|
} finally {
|
||||||
batchRunning.value = false;
|
batchRunning.value = false;
|
||||||
@@ -416,9 +542,9 @@ async function runUpdateAllInstalled() {
|
|||||||
async function refreshAfterExternalPluginUpdate() {
|
async function refreshAfterExternalPluginUpdate() {
|
||||||
clearPluginIconCache();
|
clearPluginIconCache();
|
||||||
try {
|
try {
|
||||||
installedPlugins.value = await api.listPlugins();
|
await reloadInstalledPlugins();
|
||||||
} catch (cause) {
|
} 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));
|
const sourceChangedListings = targets.filter((listing) => pluginSourceChange(listing));
|
||||||
if (sourceChangedListings.length) return toast(t("pluginPlatform.batchSourceChangeSkipped", { names: sourceChangedListings.map((listing) => listing.name).join("、") }), 8000);
|
if (sourceChangedListings.length) return toast(t("pluginPlatform.batchSourceChangeSkipped", { names: sourceChangedListings.map((listing) => listing.name).join("、") }), 8000);
|
||||||
batchRunning.value = true;
|
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 {
|
try {
|
||||||
const outcome = await runBatch(
|
const outcome = await runBatch(
|
||||||
targets,
|
targets,
|
||||||
@@ -490,9 +619,11 @@ async function runBatchInstallUpdate() {
|
|||||||
async (listing) => {
|
async (listing) => {
|
||||||
await installListing(listing);
|
await installListing(listing);
|
||||||
},
|
},
|
||||||
|
(listing) => listing.plugin.id,
|
||||||
);
|
);
|
||||||
clearBatchSelection();
|
clearBatchSelection();
|
||||||
reportBatchSummary(outcome);
|
reportBatchSummary(outcome, descriptors);
|
||||||
|
retireBatchFailures(succeededIds(outcome));
|
||||||
await refreshAfterBatch();
|
await refreshAfterBatch();
|
||||||
notifyComponentUpdatesChanged();
|
notifyComponentUpdatesChanged();
|
||||||
} finally {
|
} finally {
|
||||||
@@ -506,7 +637,8 @@ async function runBatchUninstall() {
|
|||||||
const names = targets.map((definition) => definition.plugin.manifest.name).join("、");
|
const names = targets.map((definition) => definition.plugin.manifest.name).join("、");
|
||||||
if (!window.confirm(t("pluginPlatform.batchUninstallConfirm", { count: targets.length, names }))) return;
|
if (!window.confirm(t("pluginPlatform.batchUninstallConfirm", { count: targets.length, names }))) return;
|
||||||
batchRunning.value = true;
|
batchRunning.value = true;
|
||||||
error.value = "";
|
loadError.value = "";
|
||||||
|
const descriptors: BatchFailureDescriptor[] = targets.map((definition) => ({ pluginId: definition.plugin.manifest.id, kind: "uninstall" }));
|
||||||
try {
|
try {
|
||||||
const outcome = await runBatch(
|
const outcome = await runBatch(
|
||||||
targets,
|
targets,
|
||||||
@@ -514,9 +646,11 @@ async function runBatchUninstall() {
|
|||||||
async (definition) => {
|
async (definition) => {
|
||||||
await api.uninstallPlugin(definition.plugin.manifest.id);
|
await api.uninstallPlugin(definition.plugin.manifest.id);
|
||||||
},
|
},
|
||||||
|
(definition) => definition.plugin.manifest.id,
|
||||||
);
|
);
|
||||||
clearBatchSelection();
|
clearBatchSelection();
|
||||||
reportBatchSummary(outcome);
|
reportBatchSummary(outcome, descriptors);
|
||||||
|
retireBatchFailures(succeededIds(outcome));
|
||||||
await refreshAfterBatch();
|
await refreshAfterBatch();
|
||||||
notifyComponentUpdatesChanged();
|
notifyComponentUpdatesChanged();
|
||||||
} finally {
|
} finally {
|
||||||
@@ -722,7 +856,10 @@ async function finishInstall(result: PluginInstallResult) {
|
|||||||
toast(t("pluginPlatform.installSuccess", { name: result.plugin.manifest.name, version: result.plugin.manifest.version }));
|
toast(t("pluginPlatform.installSuccess", { name: result.plugin.manifest.name, version: result.plugin.manifest.version }));
|
||||||
clearPluginIconCache();
|
clearPluginIconCache();
|
||||||
notifyComponentPluginsUpdated();
|
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();
|
notifyComponentUpdatesChanged();
|
||||||
window.dispatchEvent(new CustomEvent("dbx:plugins-changed"));
|
window.dispatchEvent(new CustomEvent("dbx:plugins-changed"));
|
||||||
selectPlugin(result.plugin.manifest.id);
|
selectPlugin(result.plugin.manifest.id);
|
||||||
@@ -870,7 +1007,9 @@ async function rollbackSelectedPlugin() {
|
|||||||
notifyPluginRuntimeReplaced(result.plugin.manifest.id);
|
notifyPluginRuntimeReplaced(result.plugin.manifest.id);
|
||||||
toast(t("pluginPlatform.rollbackSuccess", { version: result.plugin.manifest.version }));
|
toast(t("pluginPlatform.rollbackSuccess", { version: result.plugin.manifest.version }));
|
||||||
clearPluginIconCache();
|
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();
|
notifyComponentUpdatesChanged();
|
||||||
window.dispatchEvent(new CustomEvent("dbx:plugins-changed"));
|
window.dispatchEvent(new CustomEvent("dbx:plugins-changed"));
|
||||||
selectPlugin(result.plugin.manifest.id);
|
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;
|
if (mutationRunning.value || !definition || !window.confirm(t("pluginPlatform.uninstallConfirm", { name: definition.plugin.manifest.name }))) return;
|
||||||
operating.value = true;
|
operating.value = true;
|
||||||
try {
|
try {
|
||||||
installedPlugins.value = await api.uninstallPlugin(definition.plugin.manifest.id);
|
applyInstalledPlugins(await api.uninstallPlugin(definition.plugin.manifest.id));
|
||||||
|
retireBatchFailure(definition.plugin.manifest.id);
|
||||||
notifyComponentUpdatesChanged();
|
notifyComponentUpdatesChanged();
|
||||||
window.dispatchEvent(new CustomEvent("dbx:plugins-changed"));
|
window.dispatchEvent(new CustomEvent("dbx:plugins-changed"));
|
||||||
clearPluginIconCache();
|
clearPluginIconCache();
|
||||||
@@ -956,7 +1096,14 @@ onBeforeUnmount(() => {
|
|||||||
<template>
|
<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">
|
<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" />
|
<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">
|
<Tabs v-model="activeSection" class="min-h-0 flex-1 gap-3">
|
||||||
<TabsList class="grid h-9 w-full grid-cols-3">
|
<TabsList class="grid h-9 w-full grid-cols-3">
|
||||||
|
|||||||
+263
-10
@@ -84,7 +84,12 @@ type PanelState = {
|
|||||||
repositoryCatalogUrl: string;
|
repositoryCatalogUrl: string;
|
||||||
trustedKeyId: string;
|
trustedKeyId: string;
|
||||||
trustedPublicKey: 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;
|
toggleListingSelection: (listing: MarketplacePluginListing) => void;
|
||||||
selectAllUpdatable: () => void;
|
selectAllUpdatable: () => void;
|
||||||
runBatchInstallUpdate: () => Promise<void>;
|
runBatchInstallUpdate: () => Promise<void>;
|
||||||
@@ -389,7 +394,7 @@ describe("PluginContributionsPanel installed-tab updates", () => {
|
|||||||
mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("update denied"));
|
mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("update denied"));
|
||||||
await state.runUpdateAllInstalled();
|
await state.runUpdateAllInstalled();
|
||||||
expect(mocks.installMarketplacePlugin).toHaveBeenCalledTimes(3);
|
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.installedUpdateProgress).toBeNull();
|
||||||
expect(state.batchRunning).toBe(false);
|
expect(state.batchRunning).toBe(false);
|
||||||
});
|
});
|
||||||
@@ -576,7 +581,7 @@ describe("PluginContributionsPanel workbench refresh", () => {
|
|||||||
await running;
|
await running;
|
||||||
}
|
}
|
||||||
expect(mocks.refreshPluginWorkbenches.mock.calls).toEqual([["a"], ["c"]]);
|
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 () => {
|
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"));
|
mocks.installMarketplacePlugin.mockRejectedValueOnce(new Error("Plugin update blocked by active connections: Production S3"));
|
||||||
await state.runBatchInstallUpdate();
|
await state.runBatchInstallUpdate();
|
||||||
expect(mocks.installMarketplacePlugin).toHaveBeenCalledTimes(3);
|
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();
|
await nextTick();
|
||||||
expect(host.textContent).toContain("Production S3");
|
expect(host.textContent).toContain("Production S3");
|
||||||
});
|
});
|
||||||
@@ -748,13 +753,18 @@ describe("PluginContributionsPanel completed batch outcomes", () => {
|
|||||||
expect(mutation).toHaveBeenCalledTimes(3);
|
expect(mutation).toHaveBeenCalledTimes(3);
|
||||||
expect(mocks.toast).toHaveBeenCalledTimes(1);
|
expect(mocks.toast).toHaveBeenCalledTimes(1);
|
||||||
expect(mocks.toast).toHaveBeenLastCalledWith(summary, failures ? 8000 : 4000);
|
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();
|
await nextTick();
|
||||||
expect(host.textContent).toContain(state.error);
|
expect(host.textContent).toContain(state.errorBannerText);
|
||||||
expect(state.batchRunning).toBe(false);
|
expect(state.batchRunning).toBe(false);
|
||||||
state.selectedListingKeys = new Set(["first:a"]);
|
state.selectedListingKeys = new Set(["first:a"]);
|
||||||
await state.runBatchInstallUpdate();
|
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) => {
|
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(mutation.mock.calls.map(([request]) => (batch === "install" ? request.pluginId : request))).toEqual(["a", "b", "c"]);
|
||||||
expect(mocks.listPlugins).toHaveBeenCalledTimes(1);
|
expect(mocks.listPlugins).toHaveBeenCalledTimes(1);
|
||||||
expect(mocks.toast).toHaveBeenLastCalledWith('pluginPlatform.batchSummaryWithFailures:{"success":2,"failed":1,"names":"b"}', 8000);
|
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.batchRunning).toBe(false);
|
||||||
expect(state.selectedListingKeys.size).toBe(0);
|
expect(state.selectedListingKeys.size).toBe(0);
|
||||||
expect(state.selectedInstalledIds.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", () => {
|
describe("PluginContributionsPanel marketplace sort", () => {
|
||||||
const OLDEST = "2025-01-01T00:00:00Z";
|
const OLDEST = "2025-01-01T00:00:00Z";
|
||||||
const NEWEST = "2026-06-01T00:00:00Z";
|
const NEWEST = "2026-06-01T00:00:00Z";
|
||||||
@@ -943,7 +1194,8 @@ describe("PluginContributionsPanel single uninstall outcomes", () => {
|
|||||||
expect(mocks.listPlugins).toHaveBeenCalledOnce();
|
expect(mocks.listPlugins).toHaveBeenCalledOnce();
|
||||||
expect(state.installedPlugins.map((plugin) => `${plugin.manifest.id}@${plugin.manifest.version}`)).toEqual(["a@1.0.0", "b@9.9.9"]);
|
expect(state.installedPlugins.map((plugin) => `${plugin.manifest.id}@${plugin.manifest.version}`)).toEqual(["a@1.0.0", "b@9.9.9"]);
|
||||||
expect(changed).toHaveBeenCalledOnce();
|
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 () => {
|
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();
|
await state.uninstallSelectedPlugin();
|
||||||
|
|
||||||
expect(mocks.toast).toHaveBeenLastCalledWith("denied", 5000);
|
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"}');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+36
-2
@@ -10,6 +10,7 @@ describe("runBatch", () => {
|
|||||||
async (item) => {
|
async (item) => {
|
||||||
order.push(item.id);
|
order.push(item.id);
|
||||||
},
|
},
|
||||||
|
(item) => item.id,
|
||||||
);
|
);
|
||||||
expect(order).toEqual(["a", "b", "c"]);
|
expect(order).toEqual(["a", "b", "c"]);
|
||||||
expect(outcome.succeeded).toEqual(["a", "b", "c"]);
|
expect(outcome.succeeded).toEqual(["a", "b", "c"]);
|
||||||
@@ -25,15 +26,48 @@ describe("runBatch", () => {
|
|||||||
ran.push(item.id);
|
ran.push(item.id);
|
||||||
if (item.id === "b") throw new Error("boom");
|
if (item.id === "b") throw new Error("boom");
|
||||||
},
|
},
|
||||||
|
(item) => item.id,
|
||||||
);
|
);
|
||||||
expect(ran).toEqual(["a", "b", "c"]);
|
expect(ran).toEqual(["a", "b", "c"]);
|
||||||
expect(outcome.succeeded).toEqual(["a", "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 () => {
|
it("returns an empty outcome for empty input", async () => {
|
||||||
const action = vi.fn();
|
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(action).not.toHaveBeenCalled();
|
||||||
expect(outcome.succeeded).toEqual([]);
|
expect(outcome.succeeded).toEqual([]);
|
||||||
expect(outcome.failed).toEqual([]);
|
expect(outcome.failed).toEqual([]);
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
// and result aggregation so partial failures can be reported without aborting the batch.
|
// and result aggregation so partial failures can be reported without aborting the batch.
|
||||||
|
|
||||||
export interface BatchItemOutcome {
|
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;
|
name: string;
|
||||||
ok: boolean;
|
ok: boolean;
|
||||||
error?: string;
|
error?: string;
|
||||||
@@ -11,25 +14,29 @@ export interface BatchItemOutcome {
|
|||||||
export interface BatchOutcome {
|
export interface BatchOutcome {
|
||||||
results: BatchItemOutcome[];
|
results: BatchItemOutcome[];
|
||||||
succeeded: string[];
|
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
|
* 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
|
* 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
|
* in the summary and `idOf` the machine identity of the item. `onProgress` fires after every item
|
||||||
* live "(current/total)" progress. Empty input yields an empty outcome.
|
* (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[] = [];
|
const results: BatchItemOutcome[] = [];
|
||||||
let completed = 0;
|
let completed = 0;
|
||||||
for (const item of items) {
|
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);
|
const name = nameOf(item);
|
||||||
try {
|
try {
|
||||||
await action(item);
|
await action(item);
|
||||||
results.push({ name, ok: true });
|
results.push({ id, name, ok: true });
|
||||||
} catch (cause) {
|
} 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;
|
completed += 1;
|
||||||
onProgress?.(completed, items.length);
|
onProgress?.(completed, items.length);
|
||||||
@@ -37,7 +44,7 @@ export async function runBatch<T>(items: readonly T[], nameOf: (item: T) => stri
|
|||||||
return {
|
return {
|
||||||
results,
|
results,
|
||||||
succeeded: results.filter((result) => result.ok).map((result) => result.name),
|
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 ?? "" })),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user