conversation-session-plugin-mcp-skill-workspace-disabled.test.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { readFile } from "node:fs/promises";
  2. import { join } from "node:path";
  3. import { TID_SETTINGS_BACK_BUTTON } from "@zcode/shared/test-ids";
  4. import { clearAppData, clickTestIdByDom, getE2EAppDataPaths } from "#e2e/helpers/desktop-app";
  5. import {
  6. getPluginList,
  7. openPluginManagementSettings,
  8. selectPluginSettingsScope,
  9. waitUntilPluginList,
  10. waitForPluginControl,
  11. } from "#e2e/helpers/plugin-management-lifecycle";
  12. import { PLUGIN_MCP_PLUGIN_ID } from "#e2e/helpers/plugin-mcp-skill";
  13. import {
  14. assertWorkspacePluginUnavailable,
  15. pluginConfigEnabled,
  16. readUserPluginConfig,
  17. readWorkspacePluginConfig,
  18. } from "#e2e/helpers/workspace-plugin-runtime";
  19. describe("WPL-002 Workspace Plugin explicit false precedence E2E", () => {
  20. after(async () => {
  21. await browser.electron.restoreAllMocks();
  22. await clearAppData();
  23. });
  24. it("lets Workspace false override User true and keeps the package installed", async function () {
  25. this.timeout(180000);
  26. expect(pluginConfigEnabled(await readUserPluginConfig())).toBe(true);
  27. expect(pluginConfigEnabled(await readWorkspacePluginConfig())).toBe(false);
  28. const plugin = (await getPluginList()).plugins.find((item) => item.id === PLUGIN_MCP_PLUGIN_ID);
  29. expect(plugin).toMatchObject({ enabled: false, enabledSource: "workspace" });
  30. expect(plugin?.rootPath).toBeTruthy();
  31. const { storageRoot } = getE2EAppDataPaths();
  32. const installedPluginsPath = join(storageRoot, "cli", "plugins", "installed_plugins.json");
  33. const installedBefore = await readFile(installedPluginsPath, "utf8");
  34. // resident App 的 Plugin catalog 在创建时冻结;先用 seed 的显式 false 验证新 Session
  35. // 不广告工具,再切换配置验证 package/config 解耦,避免把 WPL-008 的热更新语义混入本 case。
  36. await assertWorkspacePluginUnavailable("E2E_PLUGIN_MCP_PING_DISABLED");
  37. await openPluginManagementSettings();
  38. await selectPluginSettingsScope("workspace");
  39. await waitForPluginControl("plugin-settings-enabled-switch", {
  40. pluginId: PLUGIN_MCP_PLUGIN_ID,
  41. });
  42. await clickTestIdByDom("plugin-settings-enabled-switch");
  43. await waitUntilPluginList(
  44. (list) => list.plugins.some((item) => item.id === PLUGIN_MCP_PLUGIN_ID && item.enabled),
  45. "Workspace enable did not update the effective Plugin state",
  46. );
  47. await clickTestIdByDom("plugin-settings-enabled-switch");
  48. await waitUntilPluginList(
  49. (list) => list.plugins.some((item) => item.id === PLUGIN_MCP_PLUGIN_ID && !item.enabled),
  50. "Workspace disable did not update the effective Plugin state",
  51. );
  52. expect(await readFile(installedPluginsPath, "utf8")).toBe(installedBefore);
  53. expect(pluginConfigEnabled(await readWorkspacePluginConfig())).toBe(false);
  54. await clickTestIdByDom(TID_SETTINGS_BACK_BUTTON);
  55. });
  56. });