Skip to content

Commit f9b5693

Browse files
steipeteampagent
andauthored
1 parent 0a861b4 commit f9b5693

3 files changed

Lines changed: 104 additions & 12 deletions

File tree

‎ui/src/pages/plugins/plugins-page.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,57 @@ describe("PluginsPage", () => {
760760
expect(calls).toContainEqual(["plugins.list", {}]);
761761
});
762762

763+
it("does not let an older uninstall republish its page notice after a newer row action", async () => {
764+
const uninstallResult = deferred<unknown>();
765+
const enabledPlugin = createPlugin({ enabled: true, state: "enabled" });
766+
const removable = createPlugin({
767+
id: "community-thing",
768+
name: "Community Thing",
769+
origin: "global",
770+
removable: true,
771+
featured: false,
772+
});
773+
const { client, request } = createClient(async (method) => {
774+
if (method === "plugins.uninstall") {
775+
return uninstallResult.promise;
776+
}
777+
if (method === "plugins.setEnabled") {
778+
return { ok: true, plugin: enabledPlugin, restartRequired: false };
779+
}
780+
if (method === "plugins.list") {
781+
return createResult(enabledPlugin);
782+
}
783+
throw new Error(`Unexpected method ${method}`);
784+
});
785+
const harness = createGateway(client);
786+
const { page } = await mountPage(
787+
createContext(harness.gateway),
788+
createPluginsRouteData(harness.gateway, {
789+
plugins: [createPlugin(), removable],
790+
diagnostics: [],
791+
mutationAllowed: true,
792+
}),
793+
);
794+
795+
const uninstall = page.uninstall("community-thing", "plugin:community-thing");
796+
await waitForFast(() =>
797+
expect(request).toHaveBeenCalledWith("plugins.uninstall", { pluginId: "community-thing" }),
798+
);
799+
await page.updateEnabled("workboard", true);
800+
801+
uninstallResult.resolve({
802+
ok: true,
803+
pluginId: "community-thing",
804+
restartRequired: true,
805+
removed: ["config entry", "install record", "directory"],
806+
});
807+
await uninstall;
808+
await page.updateComplete;
809+
810+
expect(page.querySelector(".plugins-page-notice")).toBeNull();
811+
expect(page.messages["plugin:workboard"]?.text).toContain("Enabled Workboard");
812+
});
813+
763814
it("adds an MCP server through the shared config seam", async () => {
764815
const { client } = createClient(async (method) => {
765816
if (method === "plugins.list") {

‎ui/src/pages/plugins/plugins-page.ts‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ class PluginsPage extends OpenClawLightDomElement {
717717
refreshError: string | null,
718718
client: GatewayBrowserClient,
719719
isCurrent: () => boolean,
720+
isLatest: () => boolean,
720721
) => Promise<void>,
721722
onError: (error: unknown) => void = (error) => {
722723
this.setMessage(rowKey, {
@@ -730,10 +731,12 @@ class PluginsPage extends OpenClawLightDomElement {
730731
if (!scope || !this.canMutate() || this.busy[rowKey]) {
731732
return;
732733
}
734+
this.pageNotice = null;
733735
const mutationToken = ++this.mutationToken;
734736
this.mutationTokens.set(rowKey, mutationToken);
735737
const isCurrent = () =>
736738
this.gateway.isCurrent(scope) && this.mutationTokens.get(rowKey) === mutationToken;
739+
const isLatest = () => isCurrent() && this.mutationToken === mutationToken;
737740
this.setBusy(rowKey, true);
738741
if (!options.preserveMessageWhilePending) {
739742
this.setMessage(rowKey, null);
@@ -747,7 +750,7 @@ class PluginsPage extends OpenClawLightDomElement {
747750
if (!isCurrent()) {
748751
return;
749752
}
750-
await onSuccess(mutation.value, mutation.refreshError, scope.client, isCurrent);
753+
await onSuccess(mutation.value, mutation.refreshError, scope.client, isCurrent, isLatest);
751754
} catch (error) {
752755
if (isCurrent()) {
753756
onError(error);
@@ -840,19 +843,21 @@ class PluginsPage extends OpenClawLightDomElement {
840843
await this.runPluginMutation(
841844
rowKey,
842845
(client) => uninstallPlugin(client, pluginId),
843-
async (result, refreshError, client) => {
846+
async (result, refreshError, client, _isCurrent, isLatest) => {
844847
this.setPendingRemoval(rowKey, false);
845848
// Removal hides its row, so keep the restart reminder on the page.
846-
this.pageNotice = {
847-
kind: "success",
848-
text: [
849-
t("pluginsPage.removedRestart", { name: result.pluginId }),
850-
...(result.warnings ?? []).map((warning) => formatUiExternalText(warning)),
851-
refreshError ? t("pluginsPage.configRefreshFailed", { error: refreshError }) : null,
852-
]
853-
.filter(Boolean)
854-
.join("\n"),
855-
};
849+
if (isLatest()) {
850+
this.pageNotice = {
851+
kind: "success",
852+
text: [
853+
t("pluginsPage.removedRestart", { name: result.pluginId }),
854+
...(result.warnings ?? []).map((warning) => formatUiExternalText(warning)),
855+
refreshError ? t("pluginsPage.configRefreshFailed", { error: refreshError }) : null,
856+
]
857+
.filter(Boolean)
858+
.join("\n"),
859+
};
860+
}
856861
await this.refreshCatalogAfterMutation(client);
857862
},
858863
);

‎ui/src/pages/plugins/plugins.e2e.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,42 @@ describeControlUiE2e("Control UI Plugins mocked Gateway E2E", () => {
676676
"Removed calendar-plus",
677677
);
678678

679+
await gateway.setMethodResponse("plugins.list", uninstalledInventory);
680+
await page.getByRole("tab", { name: /^Discover/u }).click();
681+
const searchCountBeforeReinstall = (await gateway.getRequests("plugins.search")).length;
682+
await page.getByRole("searchbox", { name: "Search plugins" }).fill("calendar");
683+
await waitForNextRequest(gateway, "plugins.search", searchCountBeforeReinstall);
684+
const reinstallRow = page.locator(
685+
'[data-package-name="calendar-plus"][data-plugin-status="not-installed"]',
686+
);
687+
await reinstallRow.waitFor({ state: "visible" });
688+
await gateway.setMethodResponse("plugins.install", installResult);
689+
await gateway.setMethodResponse("plugins.list", finalInventory);
690+
const installCountBeforeReinstall = (await gateway.getRequests("plugins.install")).length;
691+
await reinstallRow
692+
.getByRole("button", { name: "Install Calendar Plus", exact: true })
693+
.click();
694+
const reinstallRequest = await waitForNextRequest(
695+
gateway,
696+
"plugins.install",
697+
installCountBeforeReinstall,
698+
);
699+
expect(requestParams(reinstallRequest)).toEqual({
700+
source: "clawhub",
701+
packageName: "calendar-plus",
702+
});
703+
const reinstalledRow = page.locator(
704+
'[data-package-name="calendar-plus"][data-plugin-status="enabled"]',
705+
);
706+
await reinstalledRow.waitFor({ state: "attached" });
707+
await captureScreenshot(page, "11-reinstalled-feedback-desktop.png");
708+
expect(await page.locator(".plugins-page-notice").count()).toBe(0);
709+
expect(await reinstalledRow.getByRole("status").textContent()).toContain(
710+
"Installed Calendar Plus",
711+
);
712+
713+
await page.getByRole("tab", { name: /^Installed/u }).click();
714+
await page.getByRole("searchbox", { name: "Search plugins" }).fill("");
679715
await page.setViewportSize(mobileViewport);
680716
await expect
681717
.poll(() =>

0 commit comments

Comments
 (0)