Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

test: 补充 MCP 导入和编辑归属的交互验证

geng yue9ec4a942d24f
diff --git a/apps/desktop/test/mcp-market-owner-user-path.test.mjs b/apps/desktop/test/mcp-market-owner-user-path.test.mjs
index dd55dfd0d..75d144c80 100644
--- a/apps/desktop/test/mcp-market-owner-user-path.test.mjs
+++ b/apps/desktop/test/mcp-market-owner-user-path.test.mjs
@@ -23,9 +23,10 @@ import { ToastHost } from "../../apps/desktop/src/components/Toast";
import { useAppStore } from "../../apps/desktop/src/stores/app-store";
const projectPath = "/projects/market-owner-a";
+const otherProjectPath = "/projects/market-owner-b";
const entry = BUILTIN_MCP_CATALOG.servers.find((item) => !item.requiredEnv?.length);
const settings = { defaultMode: "agent", theme: "light", language: "en" };
-let records = [], writes = [], hasProject = true;
+let records = [], writes = [], imports = [], hasProject = true;
Object.defineProperty(window, "AudioContext", { configurable: true, value: undefined });
window.piDesktop = {
platform: "darwin",
@@ -34,7 +35,7 @@ window.piDesktop = {
let data;
switch (channel) {
case IPC.invoke.projectList:
- data = { projects: hasProject ? [{ id: 1, path: projectPath, name: "Market Project" }] : [] };
+ data = { projects: hasProject ? [{ id: 1, path: projectPath, name: "Market Project" }, { id: 2, path: otherProjectPath, name: "Other Project" }] : [] };
break;
case IPC.invoke.mcpList:
data = { servers: records.filter((record) => record.level === input.level &&
@@ -51,6 +52,13 @@ window.piDesktop = {
data = { server: { ...input, enabled: true } };
records.push(data.server);
break;
+ case IPC.invoke.mcpImportScan:
+ data = { candidates: [{ source: "codex", sourcePath: "/fixture/config.toml", id: "imported", rawKey: "imported", label: "Imported fixture", transport: "stdio", command: "fixture-server", warnings: [] }], sources: [] };
+ break;
+ case IPC.invoke.mcpImportRun:
+ imports.push(input);
+ data = { imported: input.items.map(item => ({ item, server: { ...item, level: input.level, projectPath: input.projectPath } })), skipped: [], failed: [] };
+ break;
default:
throw new Error("Unexpected fixture IPC: " + channel);
}
@@ -90,6 +98,12 @@ async function install() {
click(document.querySelector('[role="dialog"] .ext-sheet-actions button.mcpm-install:not(.is-ghost)'));
await until(() => !document.querySelector(".mcpm"), "Install did not return to MCP settings");
}
+async function selectOtherProject() {
+ click(document.querySelector('.agent-capability-project-select .settings-menu-select-trigger'));
+ await until(() => document.querySelector('[role="option"]'), "Project options missing");
+ click([...document.querySelectorAll('[role="option"]')].find(node => node.textContent.trim() === "Other Project"));
+ await until(() => document.querySelector('.agent-capability-project-select').textContent.includes("Other Project"), "Project did not change");
+}
window.mcpMarketOwnerProbe = async () => {
const results = [];
for (const [filter, project, otherOwner] of [
@@ -100,6 +114,7 @@ window.mcpMarketOwnerProbe = async () => {
flushSync(() => root.render(null));
hasProject = Boolean(project);
writes = [];
+ imports = [];
const level = filter === "project" || (filter === "all" && project) ? "project" : "global";
records = otherOwner ? [{ ...entry, label: entry.name, enabled: true,
level: level === "global" ? "project" : "global", projectPath }] : [];
@@ -116,6 +131,13 @@ window.mcpMarketOwnerProbe = async () => {
assert(writes[0].level === level, "Creation wrote to wrong level");
assert(writes[0].projectPath === (level === "project" ? project : undefined), "Creation wrote to wrong project");
await until(() => !document.querySelector('[role="dialog"]'), "Editor did not close");
+ click(document.querySelector('[aria-controls="agent-mcp-import-panel"]'));
+ click(button(i18n.t("settings.importScan")));
+ await until(() => document.querySelector('.import-select-all input'), "Imported candidates missing");
+ click(document.querySelector('.import-select-all input'));
+ click(button(i18n.t("settings.importSelected", { count: 1 })));
+ await until(() => imports.length === 1, "Import did not save");
+ assert(imports[0].level === level && imports[0].projectPath === (level === "project" ? project : undefined), "Import wrote to wrong owner");
writes = [];
await openMarket();
await install();
@@ -128,6 +150,23 @@ window.mcpMarketOwnerProbe = async () => {
await until(() => marketAction()?.disabled, "Installed state must follow the destination owner");
results.push({ filter, project, otherOwner, level: writes[0].level });
}
+ // An existing global or project record retains its owner after the page's
+ // selected project changes while the editor is open.
+ for (const level of ["global", "project"]) {
+ flushSync(() => root.render(null));
+ hasProject = true;
+ writes = [];
+ records = [{ id: "existing", label: "Existing fixture", command: "fixture-server", transport: "stdio", enabled: true, level,
+ ...(level === "project" ? { projectPath } : {}) }];
+ useAppStore.setState({ settings, workspace: { path: projectPath, name: "Market Project" } });
+ flushSync(() => root.render(<AgentMcpPage />));
+ await until(() => document.querySelector('.agent-capability-row'), "Existing record missing");
+ click(document.querySelector('[aria-label="' + i18n.t("settings.editMcpOf", { name: "Existing fixture" }) + '"]'));
+ await selectOtherProject();
+ click(button(i18n.t("common.save")));
+ await until(() => writes.length === 1, "Edit did not save");
+ assert(writes[0].level === level && writes[0].projectPath === (level === "project" ? projectPath : undefined), "Edit moved the existing owner");
+ }
flushSync(() => root.render(null));
hasProject = false;
writes = [];