fix(webui): cache tool catalogs across settings navigation (#6552)
* fix(webui): cache tool catalogs across settings navigation * refactor(webui): remove unreachable catalog invalidation condition
This commit is contained in:
1 parent
62c2ed4e7e
commit
8632940a99
15 files changed
+424
-31
No files matched your search
@@ -19,6 +19,7 @@ import { initializeI18n, setAppLanguage } from "@/i18n";
|
||||
import { normalizeLocale } from "@/i18n/config";
|
||||
import type { McpPresetInfo, UIMessage } from "@/lib/types";
|
||||
import { SkeletonFixture } from "./skeleton-fixture";
|
||||
import { installToolsCatalogPreviewApi, ToolsCatalogFixture } from "./tools-catalog-fixture";
|
||||
import { installSkeletonPreviewApi, SkeletonAdditionsFixture } from "./skeleton-additions-fixture";
|
||||
import { NewChatSkeletonFixture } from "./new-chat-skeleton-fixture";
|
||||
import "../src/globals.css";
|
||||
@@ -215,6 +216,7 @@ function AppsFixture() {
|
||||
/>{managing && <output data-testid="mcp-actions">{JSON.stringify(actions)}</output>}</main>;
|
||||
}
|
||||
if (parameters.get("case") === "skeleton-additions") installSkeletonPreviewApi();
|
||||
if (parameters.get("case") === "tools-catalog") installToolsCatalogPreviewApi();
|
||||
if (parameters.get("case") === "idle-compaction") installIdleCompactionApi();
|
||||
if (parameters.get("case") === "subagent-dock") installSubagentDockApi();
|
||||
await initializeI18n();
|
||||
@@ -274,6 +276,8 @@ createRoot(document.getElementById("root")!).render(<TooltipProvider>
|
||||
? <ClientProvider client={railClient} token="fixture"><SkeletonAdditionsFixture /></ClientProvider>
|
||||
: parameters.get("case") === "skeleton"
|
||||
? <ClientProvider client={railClient} token="fixture"><SkeletonFixture surface={parameters.get("surface") ?? "skills"} loading={parameters.has("loading")} /></ClientProvider>
|
||||
: parameters.get("case") === "tools-catalog"
|
||||
? <ClientProvider client={railClient} token="fixture"><ToolsCatalogFixture /></ClientProvider>
|
||||
: parameters.get("case") === "apps"
|
||||
? <ClientProvider client={railClient} token="fixture"><AppsFixture /></ClientProvider>
|
||||
: parameters.get("case") === "rail"
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import { SettingsView } from "@/components/settings/SettingsView";
|
||||
import { settings } from "@/dev/gallery/settings";
|
||||
|
||||
export function installToolsCatalogPreviewApi() {
|
||||
const fetch = window.fetch.bind(window);
|
||||
window.fetch = (input, init) => String(input) === "/api/settings"
|
||||
? Promise.resolve(Response.json(settings))
|
||||
: fetch(input, init);
|
||||
}
|
||||
|
||||
export function ToolsCatalogFixture() {
|
||||
const [open, setOpen] = useState(true);
|
||||
return <main>
|
||||
<button onClick={() => setOpen(value => !value)}>{open ? "Leave settings" : "Open settings"}</button>
|
||||
{open && <SettingsView
|
||||
initialSection="apps"
|
||||
initialSettings={settings}
|
||||
themePreference="light"
|
||||
onChangeTheme={() => {}}
|
||||
onModelNameChange={() => {}}
|
||||
onBackToChat={() => setOpen(false)}
|
||||
/>}
|
||||
</main>;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test("settings reentry reuses tools immediately and refreshes expired catalogs without hiding rows", async ({ page }) => {
|
||||
const counts = { cli: 0, mcp: 0 };
|
||||
let refresh = false;
|
||||
let release!: () => void;
|
||||
const gate = new Promise<void>(resolve => { release = resolve; });
|
||||
await page.route("**/api/settings/cli-apps", async route => {
|
||||
counts.cli++;
|
||||
if (refresh) await gate;
|
||||
await route.fulfill({ json: { apps: [{
|
||||
name: "fixture-cli", display_name: refresh ? "Updated CLI" : "Fixture CLI", category: "tools",
|
||||
description: "Fixture app", requires: "", source: "catalog", entry_point: "fixture-cli",
|
||||
install_supported: true, installed: true, available: true, status: "installed", skill_installed: false,
|
||||
}], installed_count: 1 } });
|
||||
});
|
||||
await page.route("**/api/settings/mcp-presets", async route => {
|
||||
counts.mcp++;
|
||||
if (refresh) await gate;
|
||||
await route.fulfill({ json: { presets: [{
|
||||
name: "fixture-plugin", display_name: refresh ? "Updated plugin" : "Fixture plugin", category: "Plugin",
|
||||
description: "Fixture plugin", requires: "", transport: "stdio", source: "agent-plugin",
|
||||
install_supported: false, installed: true, configured: true, enabled: false, available: false,
|
||||
status: "disabled", required_fields: [], docs_url: "", note: "", connection_summary: "",
|
||||
}], installed_count: 1 } });
|
||||
});
|
||||
await page.goto("/browser/fixture.html?case=tools-catalog");
|
||||
await expect(page.getByRole("heading", { name: "Fixture CLI", exact: true })).toBeVisible();
|
||||
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 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 });
|
||||
await page.getByRole("button", { name: "Leave settings", exact: true }).click();
|
||||
refresh = true;
|
||||
await page.clock.setFixedTime(new Date(Date.now() + 31_000));
|
||||
await page.getByRole("button", { name: "Open settings", 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();
|
||||
await expect(page.getByRole("status", { name: "Loading apps…", exact: true })).toHaveCount(0);
|
||||
release();
|
||||
await expect(page.getByRole("heading", { name: "Updated CLI", exact: true })).toBeVisible();
|
||||
await expect(page.getByRole("heading", { name: "Updated plugin", exact: true })).toBeVisible();
|
||||
});
|
||||
Reference in new issue
Block a user