Файли
openidea/e2e/agentMcp.spec.ts
T
l0ng-ai d8e58296be feat(agents): redesign Settings > Agents pages (#7825)
Reorganize Settings > Agents into General, Coding Agents, Permissions, Rules & Memory, Skills, MCP (External Servers, IDE Server), Agent Plugins and Automations, with redirects from the old MCP page ids. List pages share a master-detail layout and form pages align their fields. The IDE Server options stay in the settings search, and the docs use the new page names.
2026-12-03 22:32:31 +08:00

694 рядки
24 KiB
TypeScript
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
import type {
AgentEntry,
AgentProvider,
AgentTask,
McpExternalSource,
McpProbeResult,
McpRegistryPage,
McpServer,
McpServerInput,
} from "../src/bindings";
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
const copilotProvider: AgentProvider = {
id: "copilot",
name: "GitHub Copilot",
command: "copilot",
program: "copilot",
args: [],
defaultProgram: "copilot",
defaultArgs: [],
loginHint: null,
commandOverridden: false,
commandEditable: true,
commandReadOnlyReason: null,
installed: true,
env: {},
commands: [],
source: { kind: "builtin" },
config: [
{
id: "model",
category: "model",
name: "Model",
description: null,
current: "claude-sonnet-4.6",
via: "option",
values: [{ value: "claude-sonnet-4.6", name: "Claude Sonnet 4.6", description: null }],
},
{
id: "mode",
category: "mode",
name: "Mode",
description: null,
current: "agent",
via: "option",
values: [
{ value: "agent", name: "Agent", description: null },
{ value: "plan", name: "Plan", description: null },
],
},
],
thoughtLevels: {},
};
const sampleTask: AgentTask = {
id: "mcp-session-1",
title: "Investigate authentication service latency",
provider: "copilot",
status: "ready",
isolation: "local",
model: "claude-sonnet-4.6",
cwd: "/dev/acme-api",
branch: "main",
base: null,
baseCommit: null,
error: null,
createdMs: 0,
updatedMs: 0,
config: copilotProvider.config,
commands: [],
usage: null,
queue: [],
mcpOverrides: {},
};
const initialServers: McpServer[] = [
{
id: "user::github-mcp-server",
name: "github-mcp-server",
scope: "user",
transport: "http",
enabled: true,
command: null,
args: [],
env: [],
url: "https://api.githubcopilot.com/mcp/",
headers: [{ name: "Authorization", value: "Bearer ***" }],
agents: [],
unapproved: false,
},
{
id: "user::slack-official",
name: "slack-official",
scope: "user",
transport: "stdio",
enabled: true,
command: "npx",
args: ["-y", "mcp-remote", "https://mcp.slack.com/mcp"],
env: [],
url: null,
headers: [],
agents: [],
unapproved: false,
},
{
id: "workspace::postgres-local",
name: "postgres-local",
scope: "workspace",
transport: "stdio",
enabled: true,
command: "npx",
args: ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/acme"],
env: [{ name: "PGPASSWORD", value: "***" }],
url: null,
headers: [],
agents: [],
unapproved: false,
},
];
const discoveredSources: McpExternalSource[] = [
{
id: "copilot-cli",
label: "GitHub Copilot CLI",
path: "/Users/dev/.copilot/mcp-config.json",
suggestedScope: "user",
nativeProvider: "copilot",
servers: [
{
name: "playwright",
transport: "stdio",
enabled: true,
command: "npx",
args: ["-y", "@playwright/mcp@latest"],
url: null,
envKeys: [],
headerKeys: [],
},
{
name: "datadog",
transport: "http",
enabled: true,
command: null,
args: [],
url: "https://mcp.datadoghq.com/api/unstable/mcp-server/mcp",
envKeys: [],
headerKeys: ["DD-API-KEY"],
},
],
},
{
id: "jetbrains-air",
label: "JetBrains Air",
path: "/Users/dev/.jetbrains/mcp/mcp.json",
suggestedScope: "user",
nativeProvider: null,
servers: [
{
name: "linear",
transport: "stdio",
enabled: true,
command: "npx",
args: ["-y", "mcp-remote", "https://mcp.linear.app/mcp"],
url: null,
envKeys: [],
headerKeys: [],
},
],
},
];
const probeResult: McpProbeResult = {
ok: true,
serverName: "github-mcp-server",
serverVersion: "0.18.2",
protocolVersion: "2024-11-05",
durationMs: 68,
error: null,
tools: [
{ name: "search_issues", description: "Search issues across GitHub repositories using semantic matching" },
{ name: "pull_request_read", description: "Read pull request details, diff, reviews, and CI check runs" },
{ name: "list_commits", description: "List commits on a branch in a GitHub repository" },
],
};
test("manages multi-level MCP servers in Settings and per-session overrides via Composer /mcp", async ({
workbench: page,
}) => {
await page.setViewportSize({ width: 1280, height: 840 });
await stubDesktop(page);
await page.evaluate(
async ({ copilotProvider, sampleTask, initialServers, discoveredSources, probeResult }) => {
const storeModule = "/src/features/agents/store.ts";
const store = await import(/* @vite-ignore */ storeModule);
const projectModule = "/src/platform/project.ts";
const { useProject } = await import(/* @vite-ignore */ projectModule);
const prevSettings = useProject.getState().settings ?? {};
useProject.setState({
settings: {
...prevSettings,
mcpServer: { ...(prevSettings as { mcpServer?: object }).mcpServer, enabled: true },
} as never,
});
let servers = structuredClone(initialServers);
let currentTask = structuredClone(sampleTask);
const entries: AgentEntry[] = [
{ type: "user", text: "Can you check why p95 latency spiked on /v1/token?", attachments: [] },
{
type: "agent",
text: "I inspected the token endpoint traces and local Postgres pool configuration. Ready for follow-up.",
},
];
const handlers = window.__ipc.handlers;
handlers.agent_subscribe = () => [currentTask];
handlers.agent_providers = () => [copilotProvider];
handlers.agent_refresh_models = () => ({
provider: copilotProvider.id,
config: copilotProvider.config,
thoughtLevels: {},
refreshing: false,
refreshedAtMs: Date.now(),
retryAtMs: null,
error: null,
});
handlers.agent_probe = () => null;
handlers.agent_commands = () => [];
handlers.agent_entries = () => entries;
handlers.agent_changes = () => [];
handlers.agent_grouped_changes = () => ({ uncommitted: [], commits: [] });
handlers.vcs_branch_info = () => ({ head: "main" });
handlers.vcs_branches = () => [];
handlers.agent_mcp_list = () => servers;
handlers.agent_mcp_discover_sources = () => discoveredSources;
handlers.agent_mcp_test = () => probeResult;
handlers.mcp_server_tools = () => ({
ok: true,
serverName: "OpenIDEA",
serverVersion: "0.1.55",
protocolVersion: "2025-06-18",
durationMs: 1,
error: null,
tools: [
{ name: "check_files", description: "Checks files with the language servers and returns their problems" },
{ name: "search_text", description: "Searches for a text substring within project files" },
],
});
handlers.mcp_server_status = () => ({
running: true,
error: null,
address: "127.0.0.1",
port: 26371,
portUnavailable: null,
project: "/dev/acme-api",
url: "http://127.0.0.1:26371/mcp?project=%2Fdev%2Facme-api",
token: "test-token",
stdioCommand: [
"/Applications/OpenIDEA.app/Contents/MacOS/openidea",
"--mcp-stdio",
"--project",
"/dev/acme-api",
],
});
handlers.agent_mcp_set_enabled = ({ id, enabled }) => {
servers = servers.map((s) => (s.id === id ? { ...s, enabled: Boolean(enabled) } : s));
return servers;
};
handlers.agent_mcp_import_selected = ({ scope, selections }) => {
for (const sel of selections as Array<{ sourceId: string; name: string }>) {
const src = discoveredSources.find((d) => d.id === sel.sourceId);
const srv = src?.servers.find((d) => d.name === sel.name);
if (!srv) continue;
const id = `${String(scope)}::${srv.name}`;
if (!servers.some((s) => s.id === id)) {
servers = [
...servers,
{
id,
name: srv.name,
scope: scope as "user" | "workspace",
transport: srv.transport,
enabled: true,
command: srv.command,
args: srv.args,
env: [],
url: srv.url,
headers: [],
agents: [],
unapproved: false,
},
];
}
}
return servers;
};
handlers.agent_set_mcp_overrides = ({ overrides }) => {
currentTask = { ...currentTask, mcpOverrides: overrides as Record<string, boolean> };
return currentTask;
};
await store.connect();
store.openTask(currentTask.id);
},
{ copilotProvider, sampleTask, initialServers, discoveredSources, probeResult },
);
// 1. Open per-session MCP picker via `/mcp` in the active session composer.
const composerBox = page.getByRole("textbox", { name: "Message" });
await expect(composerBox).toBeVisible();
await composerBox.click();
await page.keyboard.type("/mc");
await expect(page.getByRole("listbox", { name: "Commands" })).toContainText("/mcp");
await page.keyboard.press("Enter");
const sessionPopup = page.getByRole("dialog", { name: "Session MCP Servers" });
await expect(sessionPopup).toBeVisible();
await expect(sessionPopup).toContainText("openidea");
await expect(sessionPopup).toContainText("postgres-local");
await expect(sessionPopup).toContainText("github-mcp-server");
await expect(sessionPopup).toContainText("playwright");
// Disable `slack-official` (Global) and `playwright` (Agent Config) for this session only.
await sessionPopup.getByRole("switch", { name: "Enable slack-official for this session" }).click();
await sessionPopup.getByRole("switch", { name: "Enable playwright for this session" }).click();
await expect(sessionPopup).toContainText("Disabled for this session (GitHub Copilot CLI)");
const overrideCalls = await ipcCalls(page, "agent_set_mcp_overrides");
expect(overrideCalls.at(-1)?.overrides).toEqual({ "slack-official": false, playwright: false });
const screenshotDir = process.env.CAPTURE_MCP_SCREENSHOTS;
if (screenshotDir) {
await page.waitForTimeout(250);
await page.screenshot({ path: `${screenshotDir}/mcp-session-picker.png` });
}
await sessionPopup.getByRole("button", { name: "Reset" }).click();
await expect(sessionPopup.getByRole("button", { name: "Reset" })).toHaveCount(0);
// 2. Jump directly from the session MCP popover's gear button to Settings › Agents › MCP › External Servers.
await sessionPopup.getByRole("button", { name: "MCP Connections…", exact: true }).click();
const settingsDialog = page.getByRole("dialog", { name: "Settings", exact: true });
await expect(settingsDialog).toBeVisible();
await expect(settingsDialog.getByRole("treeitem", { name: "External Servers", exact: true })).toHaveAttribute(
"aria-selected",
"true",
);
// Probe `github-mcp-server` and inspect discovered tools inside the detail pane.
await settingsDialog
.getByRole("button", { name: /github-mcp-server/ })
.first()
.click();
await settingsDialog.getByRole("button", { name: "Test Connection" }).click();
await expect(settingsDialog.getByText("Tools (3)")).toBeVisible();
await expect(settingsDialog.getByText("pull_request_read")).toBeVisible();
if (screenshotDir) {
await settingsDialog.screenshot({ path: `${screenshotDir}/mcp-hub-levels.png` });
await settingsDialog.getByRole("button", { name: "More Actions", exact: true }).click();
await page.getByRole("menuitem", { name: "Add from JSON…" }).click();
const addDialog = page.getByRole("dialog", { name: "Add MCP Server" });
await expect(addDialog).toBeVisible();
await addDialog.screenshot({ path: `${screenshotDir}/mcp-hub-add-json.png` });
await addDialog.getByRole("button", { name: "Cancel" }).click();
}
// Select a detected external server from Detected from Agents and import it.
const detectedRegion = settingsDialog.getByRole("region", { name: "Detected from Agents" });
await detectedRegion.getByRole("button", { name: /linear/ }).click();
await expect(settingsDialog.getByText("JetBrains Air").first()).toBeVisible();
if (screenshotDir) {
await settingsDialog.screenshot({ path: `${screenshotDir}/mcp-hub-agent-configs.png` });
}
await settingsDialog.getByRole("button", { name: "Import to Global" }).click();
await expect(settingsDialog.getByText("Imported linear.")).toBeVisible();
// Switch to the sibling IDE Server sub-page and inspect exposed IDE tools.
await settingsDialog.getByRole("treeitem", { name: "IDE Server", exact: true }).click();
await expect(settingsDialog.getByText("Running on port 26371")).toBeVisible();
await settingsDialog.getByRole("button", { name: "Inspect Tools" }).click();
await expect(settingsDialog.getByText("Tools (2)")).toBeVisible();
await expect(settingsDialog.getByText("check_files")).toBeVisible();
});
const svgDataIcon = (bg: string, label: string) =>
`data:image/svg+xml,${encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="6" fill="${bg}"/><text x="16" y="21" text-anchor="middle" fill="#fff" font-family="system-ui,sans-serif" font-size="14" font-weight="700">${label}</text></svg>`,
)}`;
const registryPage: McpRegistryPage = {
registryUrl: "https://api.mcp.github.com",
total: 981,
nextCursor: "cursor-page-2",
servers: [
{
name: "microsoft/playwright-mcp",
displayName: "Playwright MCP",
suggestedName: "playwright-mcp",
description: "Automate web browsers using accessibility trees for testing and data extraction.",
version: "0.0.1-seed",
publisher: "microsoft",
iconUrl: svgDataIcon("#2EAD33", "PW"),
iconDarkUrl: null,
repositoryUrl: "https://github.com/microsoft/playwright-mcp",
websiteUrl: null,
license: "Apache-2.0",
stars: 40441,
installOptions: [
{
id: "pkg:0",
label: "npm (npx)",
transport: "stdio",
registryType: "npm",
packageIdentifier: "@playwright/mcp",
command: "npx",
args: ["-y", "@playwright/mcp"],
url: null,
headers: [],
inputs: [],
runtimeAvailable: true,
},
],
},
{
name: "io.github.netdata/mcp-server",
displayName: "Netdata",
suggestedName: "netdata",
description: "Real-time infrastructure monitoring with metrics, logs, alerts, and ML-based anomaly detection.",
version: "2.13.0",
publisher: "netdata",
iconUrl: svgDataIcon("#00AB44", "ND"),
iconDarkUrl: null,
repositoryUrl: "https://github.com/netdata/netdata",
websiteUrl: "https://www.netdata.cloud",
license: "GPL-3.0",
stars: 74200,
installOptions: [
{
id: "remote:0",
label: "Streamable HTTP",
transport: "http",
registryType: "streamable-http",
packageIdentifier: null,
command: null,
args: [],
url: "https://app.netdata.cloud/api/v1/mcp",
headers: [{ name: "Authorization", value: "Bearer {NETDATA_CLOUD_API_TOKEN}" }],
inputs: [
{
key: "header:Authorization:NETDATA_CLOUD_API_TOKEN",
label: "NETDATA_CLOUD_API_TOKEN",
kind: "header",
description: "Netdata Cloud API token with scope:mcp",
required: true,
secret: true,
defaultValue: null,
placeholder: null,
choices: [],
headerName: "Authorization",
flag: null,
templateToken: "{NETDATA_CLOUD_API_TOKEN}",
},
],
runtimeAvailable: true,
},
],
},
{
name: "microsoft/markitdown",
displayName: "MarkItDown",
suggestedName: "markitdown",
description: "Convert various file formats (PDF, Word, Excel, images, audio) to Markdown.",
version: "1.0.0",
publisher: "microsoft",
iconUrl: svgDataIcon("#0078D4", "MD"),
iconDarkUrl: null,
repositoryUrl: "https://github.com/microsoft/markitdown",
websiteUrl: null,
license: "MIT License",
stars: 199509,
installOptions: [
{
id: "pkg:0",
label: "PyPI (uvx)",
transport: "stdio",
registryType: "pypi",
packageIdentifier: "markitdown-mcp",
command: "uvx",
args: ["markitdown-mcp==0.0.1a4"],
url: null,
headers: [],
inputs: [],
runtimeAvailable: false,
},
],
},
...Array.from({ length: 10 }, (_, idx) => ({
name: `io.example/demo-server-${idx + 1}`,
displayName: `Demo Server ${idx + 1}`,
suggestedName: `demo-server-${idx + 1}`,
description: `Sample MCP server ${idx + 1} for scrollable registry listing.`,
version: "1.0.0",
publisher: "example",
iconUrl: idx % 2 === 0 ? svgDataIcon("#5B6AE0", `S${idx + 1}`) : null,
iconDarkUrl: null,
repositoryUrl: null,
websiteUrl: null,
license: "MIT",
stars: 100 - idx,
installOptions: [
{
id: "remote:0",
label: "Streamable HTTP",
transport: "http" as const,
registryType: "streamable-http",
packageIdentifier: null,
command: null,
args: [],
url: `https://demo-${idx + 1}.example.com/mcp`,
headers: [],
inputs: [],
runtimeAvailable: true,
},
],
})),
],
};
const registryPage2: McpRegistryPage = {
registryUrl: "https://api.mcp.github.com",
total: 981,
nextCursor: null,
servers: [
{
name: "upstash/context7",
displayName: "Context7 MCP",
suggestedName: "context7",
description: "Up-to-date documentation and code examples for any library.",
version: "1.0.12",
publisher: "upstash",
iconUrl: svgDataIcon("#00B87C", "C7"),
iconDarkUrl: null,
repositoryUrl: "https://github.com/upstash/context7",
websiteUrl: null,
license: "MIT",
stars: 35200,
installOptions: [
{
id: "pkg:0",
label: "npm (npx)",
transport: "stdio",
registryType: "npm",
packageIdentifier: "@upstash/context7-mcp",
command: "npx",
args: ["-y", "@upstash/context7-mcp"],
url: null,
headers: [],
inputs: [],
runtimeAvailable: true,
},
],
},
],
};
test("browses the MCP Registry with infinite scroll and performs one-click install and uninstall", async ({
workbench: page,
}) => {
await page.setViewportSize({ width: 1180, height: 800 });
await stubDesktop(page);
await page.evaluate(
async ({ initialServers, registryPage, registryPage2 }) => {
let servers = structuredClone(initialServers);
const handlers = window.__ipc.handlers;
handlers.window_open_settings = () => {
throw { kind: "unavailable", message: "separate settings window disabled in browser test", detail: null };
};
handlers.agent_mcp_list = () => servers;
handlers.agent_mcp_discover_sources = () => [];
handlers.agent_mcp_registry_search = ({ query, cursor }) => {
if (cursor === "cursor-page-2") {
return registryPage2;
}
const q = String(query ?? "")
.trim()
.toLowerCase();
return {
...registryPage,
servers: q
? registryPage.servers.filter(
(s) => s.displayName.toLowerCase().includes(q) || s.name.toLowerCase().includes(q),
)
: registryPage.servers,
nextCursor: q ? null : registryPage.nextCursor,
};
};
handlers.agent_mcp_save = ({ input }) => {
const req = input as McpServerInput;
const id = `${req.scope}::${req.name}`;
servers = [
...servers.filter((s) => s.id !== id),
{
id,
name: req.name,
scope: req.scope,
transport: req.transport,
enabled: req.enabled ?? true,
command: req.command ?? null,
args: req.args ?? [],
env: req.env ?? [],
url: req.url ?? null,
headers: req.headers ?? [],
agents: req.agents ?? [],
unapproved: false,
registryName: req.registryName ?? null,
registryUrl: req.registryUrl ?? null,
},
];
return servers;
};
handlers.agent_mcp_remove = ({ id }) => {
servers = servers.filter((s) => s.id !== id);
return servers;
};
const actionsModule = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
await executeAction("file.settings", "agents.mcpServers");
},
{ initialServers, registryPage, registryPage2 },
);
const settingsDialog = page.getByRole("dialog", { name: "Settings", exact: true });
await expect(settingsDialog).toBeVisible();
await settingsDialog.getByRole("tab", { name: "Registry", exact: true }).click();
const registryView = settingsDialog.getByTestId("mcp-registry-tab");
await expect(registryView).toBeVisible();
await expect(registryView.getByText("Playwright MCP", { exact: true })).toBeVisible();
await expect(registryView.getByText("Netdata", { exact: true })).toBeVisible();
await expect(registryView.getByText("Needs uvx", { exact: true })).toBeVisible();
await expect(registryView.getByRole("button", { name: "Load More" })).toHaveCount(0);
await expect(registryView.getByText("Context7 MCP", { exact: true })).toHaveCount(0);
const screenshotDir = process.env.CAPTURE_MCP_SCREENSHOTS;
if (screenshotDir) {
await settingsDialog.screenshot({ path: `${screenshotDir}/mcp-browse-light.png`, animations: "disabled" });
}
// One-click install Playwright MCP.
const pwRow = registryView.getByRole("listitem").filter({ hasText: "Playwright MCP" });
await pwRow.getByRole("button", { name: "Install", exact: true }).click();
await expect(pwRow.getByText("Installed")).toBeVisible();
await expect(pwRow.getByRole("button", { name: "Uninstall", exact: true })).toBeVisible();
if (screenshotDir) {
await settingsDialog.screenshot({
path: `${screenshotDir}/mcp-browse-installed-light.png`,
animations: "disabled",
});
// Open Install dialog for Netdata (required secret header).
const ndRow = registryView.getByRole("listitem").filter({ hasText: "Netdata" });
await ndRow.getByRole("button", { name: "Install…" }).click();
const installDlg = page.getByRole("dialog", { name: "Install MCP Server — Netdata" });
await expect(installDlg).toBeVisible();
await installDlg.screenshot({
path: `${screenshotDir}/mcp-browse-install-dialog-light.png`,
animations: "disabled",
});
await installDlg.getByRole("button", { name: "Cancel" }).click();
// Dark theme screenshot.
await page.evaluate(async () => {
const themePath = "/src/workbench/theme.ts";
const { setTheme } = await import(/* @vite-ignore */ themePath);
await setTheme("dark");
});
await settingsDialog.screenshot({ path: `${screenshotDir}/mcp-browse-dark.png`, animations: "disabled" });
}
// One-click uninstall Playwright MCP.
await pwRow.getByRole("button", { name: "Uninstall", exact: true }).click();
await expect(pwRow.getByRole("button", { name: "Install", exact: true })).toBeVisible();
// Scroll to the bottom to trigger pageless infinite scroll automatically.
await registryView.getByTestId("mcp-registry-sentinel").scrollIntoViewIfNeeded();
await expect(registryView.getByText("Context7 MCP", { exact: true })).toBeVisible();
await expect(registryView.getByTestId("mcp-registry-sentinel")).toHaveCount(0);
});