fix(webui): separate agent plugins from CLI apps (#6687)

* fix(webui): separate agent plugins from CLI apps

* fix(webui): preserve plugin payload row typing
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-17 15:20:55 +08:00
1 parent e767174450
commit b77e9592af
26 files changed
+485 -116

No files matched your search

+12 -7
View File
@@ -57,8 +57,9 @@ describe("catalog loading", () => {
cleanup();
fetch.mockClear();
renderSettingsView({ client, initialSettings: settingsPayload() });
fireEvent.click(screen.getByRole("button", { name: "Apps" }));
fireEvent.click(screen.getByRole("button", { name: "CLI Apps" }));
expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Agent Plugins" }));
expect(screen.getByRole("heading", { name: "Computer Use" })).toBeInTheDocument();
expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument();
expect(fetch.mock.calls.filter(([url]) => String(url).match(/cli-apps|mcp-presets/))).toHaveLength(0);
@@ -67,8 +68,9 @@ describe("catalog loading", () => {
const now = vi.spyOn(Date, "now").mockReturnValue(Date.now() + TOOLS_CATALOG_TTL_MS + 1);
try {
renderSettingsView({ client, initialSettings: settingsPayload() });
fireEvent.click(screen.getByRole("button", { name: "Apps" }));
fireEvent.click(screen.getByRole("button", { name: "CLI Apps" }));
expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Agent Plugins" }));
expect(screen.getByRole("heading", { name: "Computer Use" })).toBeInTheDocument();
expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument();
expect(fetch.mock.calls.filter(([url]) => String(url).match(/cli-apps|mcp-presets/))).toHaveLength(2);
@@ -76,8 +78,9 @@ describe("catalog loading", () => {
cli.resolve(jsonResponse({ apps: [{ ...app, display_name: "Updated app" }], installed_count: 1 }));
mcp.resolve(jsonResponse({ presets: [{ ...plugin, display_name: "Updated plugin" }], installed_count: 1 }));
});
expect(screen.getByRole("heading", { name: "Updated app" })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Updated plugin" })).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "CLI Apps" }));
expect(screen.getByRole("heading", { name: "Updated app" })).toBeInTheDocument();
} finally {
now.mockRestore();
}
@@ -136,13 +139,15 @@ describe("catalog loading", () => {
return Promise.resolve(jsonResponse(settingsPayload()));
}));
renderSettingsView({ initialSettings: settingsPayload() });
fireEvent.click(screen.getByRole("button", { name: "Apps" }));
fireEvent.click(screen.getByRole("button", { name: "CLI Apps" }));
expect(screen.getByRole("status", { name: "Loading apps…" })).toHaveAttribute("aria-busy", "true");
await act(async () => { cli.resolve(jsonResponse({ apps: [app], installed_count: 1 })); });
expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument();
expect(screen.getByRole("status", { name: "Loading apps…" })).toBeInTheDocument();
await act(async () => { mcp.resolve(jsonResponse({ presets: [plugin], installed_count: 1 })); });
expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Agent Plugins" }));
expect(screen.getByRole("heading", { name: "Computer Use" })).toBeInTheDocument();
expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument();
});
@@ -160,7 +165,7 @@ describe("catalog loading", () => {
renderSettingsView({ initialSettings: settingsPayload() });
await act(async () => {});
expect(screen.getByRole("status", { name: "Loading apps…" })).toBeInTheDocument();
expect(screen.queryByText("No apps available.")).not.toBeInTheDocument();
expect(screen.queryByText("No CLI Apps available.")).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "MCP" }));
expect(screen.getByText("No MCP tools available.")).toBeInTheDocument();
@@ -168,7 +173,7 @@ describe("catalog loading", () => {
fireEvent.change(screen.getByPlaceholderText("Search tools"), { target: { value: "AnyGen" } });
expect(screen.getByText("No tools match your search.")).toBeInTheDocument();
expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Apps" }));
fireEvent.click(screen.getByRole("button", { name: "CLI Apps" }));
expect(screen.getByRole("status", { name: "Loading apps…" })).toBeInTheDocument();
expect(screen.queryByText("No tools match your search.")).not.toBeInTheDocument();
await act(async () => { cli.resolve(jsonResponse({ apps: [app], installed_count: 1 })); });
@@ -186,7 +191,7 @@ describe("catalog loading", () => {
renderSettingsView({ initialSection: section, initialSettings: settingsPayload() });
expect(await screen.findByText("Catalog offline")).toBeInTheDocument();
expect(screen.queryByRole("status", { name: /Loading (apps|channels)/ })).not.toBeInTheDocument();
expect(screen.queryByText("No apps available.")).not.toBeInTheDocument();
expect(screen.queryByText("No CLI Apps available.")).not.toBeInTheDocument();
expect(screen.queryByText("No channels match this filter.")).not.toBeInTheDocument();
});
@@ -42,7 +42,7 @@ describe("Apps default filter", () => {
renderSettingsView({ initialSettings: settingsPayload() });
expect(await screen.findByRole("heading", { name: "Example App" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Apps" })).toHaveAttribute("aria-pressed", "true");
expect(screen.getByRole("button", { name: "CLI Apps" })).toHaveAttribute("aria-pressed", "true");
});
it("preserves a manual choice while MCP loads, then defaults to the cached Ready items on re-entry", async () => {
@@ -56,9 +56,9 @@ describe("Apps default filter", () => {
renderSettingsView({ client, initialSettings: settingsPayload() });
await act(async () => {});
expect(screen.queryByRole("heading", { name: "Example App" })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Apps" }));
fireEvent.click(screen.getByRole("button", { name: "CLI Apps" }));
await act(async () => { pending.resolve(jsonResponse({ presets: [mcp], installed_count: 1 })); });
expect(screen.getByRole("button", { name: "Apps" })).toHaveAttribute("aria-pressed", "true");
expect(screen.getByRole("button", { name: "CLI Apps" })).toHaveAttribute("aria-pressed", "true");
expect(screen.getByRole("heading", { name: "Example App" })).toBeInTheDocument();
cleanup();
+1 -1
View File
@@ -83,7 +83,7 @@ describe("SettingsView Apps catalog", () => {
expect(screen.getByRole("heading", { name: "Figma local" })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Figma connected" })).toBeInTheDocument();
expect(screen.queryByRole("heading", { name: "Figma CLI" })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Apps" }));
fireEvent.click(screen.getByRole("button", { name: "CLI Apps" }));
expect(screen.getByRole("heading", { name: "Figma pending" })).toBeInTheDocument();
expect(screen.queryByRole("heading", { name: "Figma local" })).not.toBeInTheDocument();
expect(screen.queryByRole("heading", { name: "Photoshop CLI" })).not.toBeInTheDocument();
+1 -1
View File
@@ -348,7 +348,7 @@ describe("Settings overview and appearance", () => {
renderSettingsView();
expect(await screen.findByText("No apps available.")).toBeInTheDocument();
expect(await screen.findByText("No CLI Apps available.")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Browse MCP tools" }));
expect(await screen.findByText("Add MCP")).toBeInTheDocument();
});
+85 -4
View File
@@ -138,11 +138,16 @@ describe("Settings system domains", () => {
renderSettingsView();
fireEvent.click(await screen.findByRole("button", { name: "Agent Plugins" }));
expect(await screen.findByText("Computer Use")).toBeInTheDocument();
expect(screen.getByText("Plugins")).toBeInTheDocument();
expect(screen.getByText(/Control the desktop/)).toBeInTheDocument();
expect(screen.getByText("screen-recording, accessibility")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Enable" }));
fireEvent.click(screen.getByRole("button", { name: "Computer Use" }));
const dialog = screen.getByRole("dialog", { name: "Computer Use" });
expect(within(dialog).getByText("Declared permissions")).toBeVisible();
expect(within(dialog).getByText("screen-recording, accessibility")).toBeVisible();
expect(within(dialog).queryByRole("tab", { name: "Tools" })).not.toBeInTheDocument();
expect(requestMutationMock).not.toHaveBeenCalled();
fireEvent.click(within(dialog).getByRole("button", { name: "Enable" }));
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
"settings.mcp.enable", { name: "plugin-computer-use" }, 20_000,
@@ -159,6 +164,52 @@ describe("Settings system domains", () => {
});
it("groups a CLI-managed plugin under its app while keeping other plugins independent", async () => {
const managed = { ...agentPlugin, name: "plugin-cli-app-anygen", display_name: "Managed plugin", managed_by_cli: "anygen" };
const separate = { ...agentPlugin, name: "plugin-cli-app-other", display_name: "Separate plugin", managed_by_cli: null };
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
const url = String(input);
if (url === "/api/settings/cli-apps") return jsonResponse({ apps: [installedAnyGen], installed_count: 1 });
if (url === "/api/settings/mcp-presets") return jsonResponse({ presets: [managed, separate], installed_count: 1 });
return jsonResponse(settingsPayload());
}));
requestMutationMock.mockResolvedValue({
presets: [{ ...managed, enabled: true, status: "enabled" }, separate], installed_count: 2,
});
renderSettingsView({ initialSection: "apps" });
expect(await screen.findByRole("heading", { name: "AnyGen" })).toBeVisible();
expect(screen.queryByRole("heading", { name: "Managed plugin" })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Agent Plugins" }));
expect(screen.getByRole("heading", { name: "Separate plugin" })).toBeVisible();
expect(screen.queryByRole("heading", { name: "Managed plugin" })).not.toBeInTheDocument();
fireEvent.change(screen.getByPlaceholderText("Search tools"), { target: { value: "separate" } });
expect(screen.getByRole("heading", { name: "Separate plugin" })).toBeVisible();
fireEvent.click(screen.getByRole("button", { name: "CLI Apps" }));
expect(screen.queryByRole("heading", { name: "AnyGen" })).not.toBeInTheDocument();
fireEvent.change(screen.getByPlaceholderText("Search tools"), { target: { value: "" } });
fireEvent.click(screen.getByRole("button", { name: "Agent Plugin disabled" }));
fireEvent.click(within(screen.getByRole("dialog", { name: "Managed plugin" })).getByRole("button", { name: "Enable" }));
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
"settings.mcp.enable", { name: "plugin-cli-app-anygen" }, 20_000,
));
await waitFor(() => expect(screen.queryByRole("button", { name: "Agent Plugin disabled" })).not.toBeInTheDocument());
});
it("keeps a managed plugin accessible when its owning app is missing from the loaded catalog", async () => {
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
const url = String(input);
if (url === "/api/settings/cli-apps") return jsonResponse({ apps: [], installed_count: 1 });
if (url === "/api/settings/mcp-presets") return jsonResponse({
presets: [{ ...agentPlugin, managed_by_cli: "missing-app" }], installed_count: 0,
});
return jsonResponse(settingsPayload());
}));
renderSettingsView({ initialSection: "apps" });
fireEvent.click(await screen.findByRole("button", { name: "Agent Plugins" }));
expect(await screen.findByRole("heading", { name: "Computer Use" })).toBeVisible();
});
it.each(["apps", "skills", "automations", "channels"] as const)(
"uses the conversation-width content frame for the standalone %s page",
(initialSection) => {
@@ -487,6 +538,35 @@ describe("Settings system domains", () => {
});
});
it("refreshes plugin ownership after installing a CLI app without replacing its mutation result", async () => {
let installed = false;
const managed = { ...agentPlugin, name: "plugin-cli-app-anygen", display_name: "Managed plugin", enabled: true, managed_by_cli: "anygen" };
const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
const url = String(input);
if (url === "/api/settings/cli-apps") return jsonResponse({
apps: [{ ...installedAnyGen, installed: false }], installed_count: 0,
});
if (url === "/api/settings/mcp-presets") return jsonResponse({
presets: installed ? [managed] : [], installed_count: Number(installed),
});
return jsonResponse(settingsPayload());
});
vi.stubGlobal("fetch", fetchMock);
requestMutationMock.mockImplementation(async () => {
installed = true;
return { apps: [installedAnyGen], installed_count: 1 };
});
renderSettingsView({ initialSection: "apps" });
fireEvent.click(await screen.findByRole("button", { name: "Install app" }));
await waitFor(() => expect(fetchMock.mock.calls.filter(([url]) => String(url) === "/api/settings/mcp-presets")).toHaveLength(2));
const appAction = await screen.findByRole("button", { name: "App ready" });
fireEvent.pointerDown(appAction, { button: 0, ctrlKey: false });
fireEvent.click(await screen.findByRole("menuitem", { name: "Agent Plugin" }));
expect(screen.getByRole("dialog", { name: "Managed plugin" })).toBeVisible();
expect(fetchMock.mock.calls.filter(([url]) => String(url) === "/api/settings/cli-apps")).toHaveLength(1);
});
it("shows a visible uninstall button for installed CLI apps and calls uninstall", async () => {
const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
const url = String(input);
@@ -581,7 +661,8 @@ describe("Settings system domains", () => {
expect(await screen.findByText("AnyGen")).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Ready" })).toHaveAttribute("aria-pressed", "false");
expect(screen.getByRole("button", { name: "Apps" })).toHaveAttribute("aria-pressed", "true");
expect(screen.getByRole("button", { name: "CLI Apps" })).toHaveAttribute("aria-pressed", "true");
expect(screen.getByRole("button", { name: "Agent Plugins" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "MCP" })).toBeInTheDocument();
});