fix(webui): open ready apps by default (#6685)

* fix(webui): open ready apps by default

* test(webui): select apps when checking catalog cache
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-17 11:21:26 +08:00
1 parent 7782095a85
commit e767174450
7 files changed
+130 -14

No files matched your search

+5
View File
@@ -26,9 +26,13 @@ test("settings reentry reuses tools immediately and refreshes expired catalogs w
});
await page.goto("/browser/fixture.html?case=tools-catalog");
await expect(page.getByRole("heading", { name: "Fixture CLI", exact: true })).toBeVisible();
await expect(page.getByRole("button", { name: "Ready", exact: true })).toHaveAttribute("aria-pressed", "true");
await expect(page.getByRole("heading", { name: "Fixture plugin", exact: true })).toHaveCount(0);
await page.getByRole("button", { name: "Apps", exact: true }).click();
await expect(page.getByRole("heading", { name: "Fixture plugin", exact: true })).toBeVisible();
await page.getByRole("button", { name: "Leave settings", exact: true }).click();
await page.getByRole("button", { name: "Open settings", exact: true }).click();
await page.getByRole("button", { name: "Apps", exact: true }).click();
await expect(page.getByRole("heading", { name: "Fixture CLI", exact: true })).toBeVisible();
await expect(page.getByRole("heading", { name: "Fixture plugin", exact: true })).toBeVisible();
expect(counts).toEqual({ cli: 1, mcp: 1 });
@@ -36,6 +40,7 @@ test("settings reentry reuses tools immediately and refreshes expired catalogs w
refresh = true;
await page.clock.setFixedTime(new Date(Date.now() + 31_000));
await page.getByRole("button", { name: "Open settings", exact: true }).click();
await page.getByRole("button", { name: "Apps", exact: true }).click();
await expect.poll(() => counts).toEqual({ cli: 2, mcp: 2 });
await expect(page.getByRole("heading", { name: "Fixture CLI", exact: true })).toBeVisible();
await expect(page.getByRole("heading", { name: "Fixture plugin", exact: true })).toBeVisible();
@@ -35,7 +35,7 @@ import {
SettingsSectionTitle,
RestartRequiredNotice,
} from "@/components/settings/shared/SettingsControls";
import { AppsCatalogSettings } from "@/components/settings/system/AppsSettings";
import { AppsCatalogPage } from "@/components/settings/system/AppsSettings";
import {
AutomationDeleteDialog,
AutomationEditDialog,
@@ -497,7 +497,6 @@ export function SettingsPage({
onBeforeCloseChange={registerChannelCompletion}
onConfigureMcp={(name) => {
setMcpSetupName(name);
systemState.setAppsKindFilter("mcp");
systemState.setAppsQuery(name);
selectSection("apps");
}}
@@ -521,7 +520,7 @@ export function SettingsPage({
case "apps":
return (
<div className="settings-stack">
<AppsCatalogSettings
<AppsCatalogPage
onConfigureProxy={configureProxy}
setupName={mcpSetupName}
onSetupOpened={() => setMcpSetupName(null)}
@@ -530,7 +529,6 @@ export function SettingsPage({
cliAppsLoading={systemState.cliAppsLoading}
mcpPresetsLoading={systemState.mcpPresetsLoading}
query={systemState.appsQuery}
filter={systemState.appsKindFilter}
cliActionKey={systemState.cliAppsAction}
mcpActionKey={systemState.mcpPresetAction}
mcpOAuthFlow={systemState.mcpOAuthFlow}
@@ -549,7 +547,6 @@ export function SettingsPage({
showBrandLogos={localPrefs.brandLogos}
requiresRestartPending={pendingRestartSections.runtime}
onQueryChange={systemState.setAppsQuery}
onFilterChange={systemState.setAppsKindFilter}
onCliAction={systemActions.handleCliAppAction}
onMcpAction={systemActions.handleMcpPresetAction}
onMcpOAuthConnect={systemActions.handleMcpOAuthConnect}
@@ -10,6 +10,7 @@ import {
useId,
useMemo,
useState,
type ComponentProps,
type ComponentPropsWithoutRef,
type Dispatch,
type ReactNode,
@@ -101,6 +102,23 @@ export const DEFAULT_CUSTOM_MCP_FORM: CustomMcpForm = {
useProxy: false,
};
export function AppsCatalogPage(props: Omit<ComponentProps<typeof AppsCatalogSettings>, "filter" | "onFilterChange">) {
const [selection, setSelection] = useState<AppsKindFilter | null>(() => props.setupName ? "mcp" : null);
const hasReady = Boolean(
props.cliApps?.apps.some((app) => app.installed) || props.mcpPresets?.presets.some(mcpPresetReady),
);
const waiting = (props.cliAppsLoading && !props.cliApps) || (props.mcpPresetsLoading && !props.mcpPresets);
const filter = selection ?? (hasReady || waiting ? "ready" : "cli");
useEffect(() => {
if (selection === null && (hasReady || (props.cliApps && props.mcpPresets))) {
setSelection(hasReady ? "ready" : "cli");
}
}, [selection, hasReady, props.cliApps, props.mcpPresets]);
return <AppsCatalogSettings {...props} filter={filter} onFilterChange={setSelection} />;
}
export function AppsCatalogSettings({
setupName,
onSetupOpened,
@@ -962,12 +980,13 @@ function appsTitle(item: AppsCatalogItem): string {
return item.kind === "cli" ? item.app.display_name : item.preset.display_name;
}
function mcpPresetReady(preset: McpPresetInfo): boolean {
if (preset.enabled !== undefined) return preset.enabled;
return preset.installed && preset.configured && preset.runtime_status === "connected";
}
function appsReady(item: AppsCatalogItem): boolean {
if (item.kind === "cli") return item.app.installed;
if (item.preset.enabled !== undefined) return item.preset.enabled;
return item.preset.installed &&
item.preset.configured &&
item.preset.runtime_status === "connected";
return item.kind === "cli" ? item.app.installed : mcpPresetReady(item.preset);
}
function appsSearchText(item: AppsCatalogItem): string {
@@ -5,7 +5,6 @@ import type { ToolsCatalog } from "@/lib/tools-catalog-cache";
import type { AutomationFilter } from "@/components/settings/system/AutomationsSettings";
import {
DEFAULT_CUSTOM_MCP_FORM,
type AppsKindFilter,
type CustomMcpForm,
} from "@/components/settings/system/AppsSettings";
import type {
@@ -50,7 +49,6 @@ export function useSystemSettingsState(toolsCatalog: ToolsCatalog) {
const [cliAppsError, setCliAppsError] = useState<string | null>(null);
const [nanobotFeaturesError, setNanobotFeaturesError] = useState<string | null>(null);
const [cliAppsFocusName, setCliAppsFocusName] = useState<string | null>(null);
const [appsKindFilter, setAppsKindFilter] = useState<AppsKindFilter>("cli");
const [mcpMessage, setMcpMessage] = useState<string | null>(null);
const [mcpError, setMcpError] = useState<string | null>(null);
const [automationsError, setAutomationsError] = useState<string | null>(null);
@@ -66,7 +64,6 @@ export function useSystemSettingsState(toolsCatalog: ToolsCatalog) {
return {
toolsCatalog,
toolsCatalogInvalidation,
appsKindFilter,
appsQuery,
automationAction,
automationPendingDelete,
@@ -103,7 +100,6 @@ export function useSystemSettingsState(toolsCatalog: ToolsCatalog) {
nanobotFeatures,
nanobotFeaturesError,
nanobotFeaturesLoading,
setAppsKindFilter,
setAppsQuery,
setAutomationAction,
setAutomationPendingDelete,
+27
View File
@@ -3533,6 +3533,33 @@ describe("App layout", () => {
expect(settingsHighlight).toHaveAttribute("data-active-id", "capabilities");
});
it("defaults to Ready again when returning to Apps from another sidebar page", async () => {
const app = {
name: "example", display_name: "Example App", category: "productivity", description: "Example",
requires: "", source: "catalog", entry_point: "example", install_supported: true,
installed: true, available: true, status: "installed", skill_installed: false,
};
mockFetchRoutes({
"/api/settings": baseSettingsPayload(),
"/api/settings/cli-apps": { apps: [app], installed_count: 1 },
"/api/settings/mcp-presets": { presets: [], installed_count: 0 },
"/api/webui/skills": { skills: [] },
});
render(<App />);
await waitFor(() => expect(connectSpy).toHaveBeenCalled());
const sidebar = screen.getByRole("navigation", { name: "Sidebar navigation" });
fireEvent.click(within(sidebar).getByRole("button", { name: "Apps" }));
await act(async () => { await import("@/components/settings/SettingsView"); });
expect(await screen.findByRole("heading", { name: "Example App" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Ready" })).toHaveAttribute("aria-pressed", "true");
fireEvent.click(screen.getByRole("button", { name: "MCP" }));
fireEvent.click(within(sidebar).getByRole("button", { name: "Skills" }));
expect(await screen.findByRole("heading", { name: "Skills" })).toBeInTheDocument();
fireEvent.click(within(sidebar).getByRole("button", { name: "Apps" }));
expect(await screen.findByRole("heading", { name: "Example App" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Ready" })).toHaveAttribute("aria-pressed", "true");
});
it("transitions between Apps and Skills without replacing the sidebar", async () => {
mockFetchRoutes({
"/api/settings": baseSettingsPayload(),
+3
View File
@@ -57,6 +57,7 @@ describe("catalog loading", () => {
cleanup();
fetch.mockClear();
renderSettingsView({ client, initialSettings: settingsPayload() });
fireEvent.click(screen.getByRole("button", { name: "Apps" }));
expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Computer Use" })).toBeInTheDocument();
expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument();
@@ -66,6 +67,7 @@ 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" }));
expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Computer Use" })).toBeInTheDocument();
expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument();
@@ -134,6 +136,7 @@ describe("catalog loading", () => {
return Promise.resolve(jsonResponse(settingsPayload()));
}));
renderSettingsView({ initialSettings: settingsPayload() });
fireEvent.click(screen.getByRole("button", { name: "Apps" }));
expect(screen.getByRole("status", { name: "Loading apps…" })).toHaveAttribute("aria-busy", "true");
await act(async () => { cli.resolve(jsonResponse({ apps: [app], installed_count: 1 })); });
@@ -0,0 +1,69 @@
import { act, cleanup, fireEvent, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import type { NanobotClient } from "@/lib/nanobot-client";
import {
installSettingsViewTestHooks,
jsonResponse,
renderSettingsView,
settingsPayload,
} from "@/tests/settings-test-utils";
const app = {
name: "example", display_name: "Example App", category: "productivity", description: "Example app",
requires: "", source: "catalog", entry_point: "example", install_supported: true,
installed: false, available: false, status: "not_installed", skill_installed: false,
};
const mcp = {
name: "docs", display_name: "Docs MCP", category: "productivity", description: "Example MCP",
docs_url: "", transport: "stdio", requires: "", note: "", install_supported: true,
installed: true, configured: true, available: true, status: "configured", required_fields: [],
connection_summary: "", source: "preset", runtime_status: "connected",
};
const plugin = { ...mcp, name: "plugin", display_name: "Example Plugin", source: "agent-plugin", enabled: true };
function deferred<T>() {
let resolve!: (value: T) => void;
const promise = new Promise<T>((done) => { resolve = done; });
return { promise, resolve };
}
describe("Apps default filter", () => {
installSettingsViewTestHooks();
it("opens Apps when nothing is ready, including disconnected MCP and disabled plugins", async () => {
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
if (String(input) === "/api/settings/cli-apps") return jsonResponse({ apps: [app], installed_count: 0 });
if (String(input) === "/api/settings/mcp-presets") return jsonResponse({
presets: [{ ...mcp, runtime_status: "disconnected" }, { ...plugin, enabled: false }], installed_count: 2,
});
return jsonResponse(settingsPayload());
}));
renderSettingsView({ initialSettings: settingsPayload() });
expect(await screen.findByRole("heading", { name: "Example App" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Apps" })).toHaveAttribute("aria-pressed", "true");
});
it("preserves a manual choice while MCP loads, then defaults to the cached Ready items on re-entry", async () => {
const client = { status: "open", onStatus: () => () => {} } as unknown as NanobotClient;
const pending = deferred<Response>();
vi.stubGlobal("fetch", vi.fn((input: RequestInfo | URL) => {
if (String(input) === "/api/settings/cli-apps") return Promise.resolve(jsonResponse({ apps: [app], installed_count: 0 }));
if (String(input) === "/api/settings/mcp-presets") return pending.promise;
return Promise.resolve(jsonResponse(settingsPayload()));
}));
renderSettingsView({ client, initialSettings: settingsPayload() });
await act(async () => {});
expect(screen.queryByRole("heading", { name: "Example App" })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "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("heading", { name: "Example App" })).toBeInTheDocument();
cleanup();
renderSettingsView({ client, initialSettings: settingsPayload() });
expect(screen.getByRole("button", { name: "Ready" })).toHaveAttribute("aria-pressed", "true");
expect(screen.getByRole("heading", { name: "Docs MCP" })).toBeInTheDocument();
});
});