mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-03 09:20:08 +08:00
Merge pull request #1872 from dajiaohuang/fix/composer-empty-mcp-scope
fix(web): distinguish inherited and empty MCP selections
This commit is contained in:
@@ -40,14 +40,15 @@ export function useComposerResources(
|
||||
// Depend on the contents rather than the array identity: `workspaces` is
|
||||
// refetched on every session change, and re-running on a new array of the
|
||||
// same rows would refetch the catalog with it.
|
||||
const allowedKey = allowedMcp ? allowedMcp.join("\u0000") : "";
|
||||
const allowedKey = JSON.stringify(allowedMcp);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
void getWorkspaceResources(workspaceId ?? "")
|
||||
.then((remote) => {
|
||||
if (!alive) return;
|
||||
const allowed = allowedKey ? new Set(allowedKey.split("\u0000")) : null;
|
||||
const selected = JSON.parse(allowedKey) as string[] | null;
|
||||
const allowed = selected === null ? null : new Set(selected);
|
||||
setCatalog({
|
||||
skills: remote.skills ?? [],
|
||||
mcp: (remote.mcp ?? []).filter(
|
||||
|
||||
47
web/tests/composer-empty-mcp-scope.spec.tsx
Normal file
47
web/tests/composer-empty-mcp-scope.spec.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import { renderHook, waitFor } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { useComposerResources } from "@/hooks/useComposerResources";
|
||||
import type { ChatWorkspaceRegistration } from "@/lib/workspaces-api";
|
||||
|
||||
const api = vi.hoisted(() => ({ fetch: vi.fn() }));
|
||||
vi.mock("@/lib/api", () => ({ apiFetch: api.fetch, apiUrl: (url: string) => url }));
|
||||
|
||||
function workspace(mcp: string[] | null): ChatWorkspaceRegistration {
|
||||
return {
|
||||
workspace_id: "workspace-a", kind: "workspace", follows_root: true,
|
||||
display_name: "Workspace A", path: "/workspace-a", archived: false,
|
||||
created_at: "2026-10-05T00:00:00Z", status: "ready", error: "",
|
||||
resources: { skills: null, mcp, knowledge_bases: null },
|
||||
};
|
||||
}
|
||||
|
||||
function catalog() {
|
||||
api.fetch.mockImplementation(() => Promise.resolve(new Response(JSON.stringify({
|
||||
skills: [{ id: "skill-a", name: "Skill A" }],
|
||||
mcp: [{ id: "server-a", name: "Server A" }, { id: "server-b", name: "Server B" }],
|
||||
knowledge_bases: [],
|
||||
}))));
|
||||
}
|
||||
|
||||
describe("composer MCP workspace selection", () => {
|
||||
it.each([
|
||||
[null, ["server-a", "server-b"]],
|
||||
[["server-a"], ["server-a"]],
|
||||
[[], []],
|
||||
] as const)("respects configured MCP selection %j", async (mcp, expected) => {
|
||||
catalog();
|
||||
const { result } = renderHook(() => useComposerResources("workspace-a", [workspace(mcp ? [...mcp] : null)]));
|
||||
await waitFor(() => expect(result.current.skills).toHaveLength(1));
|
||||
expect(result.current.mcp.map(option => option.id)).toEqual(expected);
|
||||
});
|
||||
|
||||
it("refreshes when an inherited selection becomes explicitly empty", async () => {
|
||||
catalog();
|
||||
const { result, rerender } = renderHook(({ mcp }: { mcp: string[] | null }) =>
|
||||
useComposerResources("workspace-a", [workspace(mcp)]),
|
||||
{ initialProps: { mcp: null } as { mcp: string[] | null } });
|
||||
await waitFor(() => expect(result.current.mcp).toHaveLength(2));
|
||||
rerender({ mcp: [] });
|
||||
await waitFor(() => expect(result.current.mcp).toHaveLength(0));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user