fix(plugins): make plugin uninstall state consistent on failure

This commit is contained in:
jearhe authored and GitHub committed 2026-09-26 06:07:31 +08:00
1 parent 88dccd7cde
commit 8be259be5f
7 files changed
+430 -33

No files matched your search

@@ -867,6 +867,10 @@ async function uninstallSelectedPlugin() {
selectFirstProvider();
} catch (cause) {
toast(cause instanceof Error ? cause.message : String(cause), 5000);
// A failed uninstall can still have changed the store (the container is renamed out of the
// plugin store before its physical delete, for instance), so re-read the installed list
// instead of leaving the panel on state it may no longer describe.
await refreshAfterBatch();
} finally {
operating.value = false;
}
@@ -854,3 +854,37 @@ describe("PluginContributionsPanel marketplace sort", () => {
expect(renderedOrder()).toEqual(["a.older", "b.newer"]);
});
});
describe("PluginContributionsPanel single uninstall outcomes", () => {
it("re-reads the installed list and notifies listeners when a single uninstall fails", async () => {
const changed = vi.fn();
window.addEventListener("dbx:plugins-changed", changed);
const failure = "The process cannot access the file because it is being used by another process. (os error 32)";
mocks.uninstallPlugin.mockRejectedValueOnce(new Error(failure));
// The backend kept the plugin installed (the uninstall never committed), and the panel has to
// show exactly that instead of the state it guessed before the call.
mocks.listPlugins.mockResolvedValueOnce([installed("a"), installed("b", "9.9.9")]);
try {
await state.uninstallSelectedPlugin();
} finally {
window.removeEventListener("dbx:plugins-changed", changed);
}
expect(mocks.toast).toHaveBeenLastCalledWith(failure, 5000);
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(changed).toHaveBeenCalledOnce();
expect(state.error).toBe("");
});
it("keeps the uninstall failure visible when the follow-up refresh also fails", async () => {
mocks.uninstallPlugin.mockRejectedValueOnce(new Error("denied"));
mocks.listPlugins.mockRejectedValueOnce(new Error("refresh offline"));
await state.uninstallSelectedPlugin();
expect(mocks.toast).toHaveBeenLastCalledWith("denied", 5000);
expect(state.error).toBe('pluginPlatform.batchRefreshFailed:{"error":"refresh offline"}');
});
});