conversation-session-plugin-mcp-skill-workspace-enabled.test.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { TID_SETTINGS_BACK_BUTTON } from "@zcode/shared/test-ids";
  2. import { clearAppData, clickTestIdByDom, DEFAULT_WORKSPACE } from "#e2e/helpers/desktop-app";
  3. import {
  4. getPluginList,
  5. openInstalledPluginSettingsAdvanced,
  6. openPluginManagementSettings,
  7. selectPluginSettingsScope,
  8. waitForPluginControl,
  9. } from "#e2e/helpers/plugin-management-lifecycle";
  10. import { PLUGIN_MCP_PLUGIN_ID, PLUGIN_MCP_TOOL_NAME } from "#e2e/helpers/plugin-mcp-skill";
  11. import {
  12. assertWorkspacePluginRuntime,
  13. pluginConfigEnabled,
  14. pluginConfigOptions,
  15. readUserPluginConfig,
  16. readWorkspacePluginConfig,
  17. } from "#e2e/helpers/workspace-plugin-runtime";
  18. describe("WPL-001/003/004/005 Workspace Plugin enabled runtime E2E", () => {
  19. after(async () => {
  20. await browser.electron.restoreAllMocks();
  21. await clearAppData();
  22. });
  23. it("loads Workspace scope, deep-merges options, redacts secret, and enters runtime directly", async function () {
  24. this.timeout(240000);
  25. // 仅用于验证隔离 fixture 的配置值;拆分字符串避免 fixture checker 把配置值误判为 prompt marker。
  26. const userSecret = ["E2E", "USER", "PLUGIN", "SECRET"].join("_");
  27. const workspaceSecret = ["E2E", "WORKSPACE", "PLUGIN", "SECRET"].join("_");
  28. const userConfig = await readUserPluginConfig();
  29. const workspaceConfig = await readWorkspacePluginConfig();
  30. expect(pluginConfigEnabled(userConfig)).toBe(true);
  31. expect(pluginConfigEnabled(workspaceConfig)).toBe(true);
  32. expect(pluginConfigOptions(userConfig)).toMatchObject({
  33. label: "user-label",
  34. secret: userSecret,
  35. });
  36. expect(pluginConfigOptions(workspaceConfig)).toMatchObject({
  37. label: "workspace-label",
  38. secret: workspaceSecret,
  39. });
  40. await openPluginManagementSettings();
  41. await selectPluginSettingsScope("workspace");
  42. await waitForPluginControl("plugin-settings-plugin-row", {
  43. pluginId: PLUGIN_MCP_PLUGIN_ID,
  44. });
  45. const scopeBadgeVisible = await browser.execute(() =>
  46. Boolean(document.querySelector('[data-settings-scope="workspace"]')),
  47. );
  48. expect(scopeBadgeVisible).toBe(false);
  49. await openInstalledPluginSettingsAdvanced(PLUGIN_MCP_PLUGIN_ID);
  50. await browser.keys(["Escape"]);
  51. await clickTestIdByDom(TID_SETTINGS_BACK_BUTTON);
  52. const list = await getPluginList(DEFAULT_WORKSPACE);
  53. const plugin = list.plugins.find((item) => item.id === PLUGIN_MCP_PLUGIN_ID);
  54. expect(plugin).toMatchObject({
  55. enabled: true,
  56. enabledSource: "workspace",
  57. optionSources: { label: "workspace", secret: "workspace" },
  58. configuredOptions: { label: "workspace-label" },
  59. });
  60. expect(JSON.stringify(plugin)).not.toContain(workspaceSecret);
  61. // Plugin MCP 无独立 approval/trust 动作;新 Session 创建时直接看到该工具。
  62. await assertWorkspacePluginRuntime("E2E_PLUGIN_MCP_PING_INSTALLED_ENABLED");
  63. expect(PLUGIN_MCP_TOOL_NAME).toContain("mcp__plugin_");
  64. });
  65. });