conversation-session-plugin-workspace-marketplace.test.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import { startDraftFromProject } from "#e2e/helpers/project-sidebar";
  2. import { existsSync } from "node:fs";
  3. import { readFile } from "node:fs/promises";
  4. import { join } from "node:path";
  5. import {
  6. clearAppData,
  7. getE2EAppDataPaths,
  8. waitForDefaultWorkspaceReady,
  9. waitForWorkspaceApp,
  10. } from "#e2e/helpers/desktop-app";
  11. import {
  12. addMarketplaceSourceThroughAgent,
  13. clickPluginControl,
  14. createPluginLifecycleFixture,
  15. getPluginList,
  16. getPluginOverview,
  17. hasPluginControl,
  18. installPluginThroughUi,
  19. openPluginCard,
  20. openPluginSettings,
  21. PLUGIN_LIFECYCLE_ID,
  22. PLUGIN_LIFECYCLE_MARKETPLACE_ID,
  23. pluginStoragePath,
  24. setPluginEnabledThroughUi,
  25. waitForPluginCard,
  26. waitForPluginControl,
  27. waitUntilPluginOverview,
  28. } from "#e2e/helpers/plugin-management-lifecycle";
  29. describe("WPL-009 Global Plugin Marketplace install E2E", () => {
  30. after(async () => {
  31. await browser.electron.restoreAllMocks();
  32. await clearAppData();
  33. });
  34. it("keeps marketplace and installation in User inventory while Workspace stays config-only", async function () {
  35. this.timeout(300000);
  36. const fixture = await createPluginLifecycleFixture("1.0.0");
  37. const { storageRoot, workspace } = getE2EAppDataPaths();
  38. const workspaceConfigPath = join(workspace, ".zcode", "config.json");
  39. const userConfigPath = join(storageRoot, "cli", "config.json");
  40. const knownMarketplacesPath = pluginStoragePath("known_marketplaces.json");
  41. const marketplaceCachePath = pluginStoragePath("marketplaces", PLUGIN_LIFECYCLE_MARKETPLACE_ID);
  42. await waitForDefaultWorkspaceReady();
  43. // 插件 bridge 由 workspace App 注册,不能在全局未归类草稿等待它出现。
  44. await waitForWorkspaceApp(workspace, 45000);
  45. await startDraftFromProject(workspace);
  46. await addMarketplaceSourceThroughAgent(fixture.marketplaceRoot);
  47. await waitUntilPluginOverview(
  48. (overview) => overview.availablePlugins.some((plugin) => plugin.id === PLUGIN_LIFECYCLE_ID),
  49. "Global marketplace fixture did not become available",
  50. 60000,
  51. );
  52. expect(await readFile(knownMarketplacesPath, "utf8")).toContain(
  53. PLUGIN_LIFECYCLE_MARKETPLACE_ID,
  54. );
  55. expect(existsSync(marketplaceCachePath)).toBe(true);
  56. expect((await getPluginOverview(workspace, "user")).marketplaces).toEqual(
  57. expect.arrayContaining([expect.objectContaining({ id: PLUGIN_LIFECYCLE_MARKETPLACE_ID })]),
  58. );
  59. // Marketplace 只从全局入口打开;页面本身没有 scope 或 options 配置控件;未安装项不显示启停开关。
  60. await openPluginSettings();
  61. expect(await hasPluginControl("plugin-store-scope-trigger")).toBe(false);
  62. expect(await hasPluginControl("plugin-store-config")).toBe(false);
  63. await clickPluginControl("plugin-store-segment-personal");
  64. await waitForPluginCard(PLUGIN_LIFECYCLE_ID);
  65. expect(
  66. await hasPluginControl("plugin-store-enabled-switch", { pluginId: PLUGIN_LIFECYCLE_ID }),
  67. ).toBe(false);
  68. await openPluginCard(PLUGIN_LIFECYCLE_ID);
  69. await installPluginThroughUi(PLUGIN_LIFECYCLE_ID);
  70. // 回归:项目上下文的市场开关曾写 Workspace 覆盖,“不指定项目”的新草稿目录不继承该覆盖。
  71. // 市场启停必须写 User;重新开启后,下方断言要求 Workspace 无 enabled 条目、来源为 user。
  72. await clickPluginControl("plugin-store-detail-back");
  73. await waitForPluginControl("plugin-store-enabled-switch", { pluginId: PLUGIN_LIFECYCLE_ID });
  74. await setPluginEnabledThroughUi(PLUGIN_LIFECYCLE_ID, false, "market", workspace);
  75. const disabledUserConfig = JSON.parse(await readFile(userConfigPath, "utf8")) as {
  76. plugins?: { enabledPlugins?: Record<string, boolean> };
  77. };
  78. expect(disabledUserConfig.plugins?.enabledPlugins?.[PLUGIN_LIFECYCLE_ID]).toBe(false);
  79. await setPluginEnabledThroughUi(PLUGIN_LIFECYCLE_ID, true, "market", workspace);
  80. const userConfig = JSON.parse(await readFile(userConfigPath, "utf8")) as {
  81. plugins?: {
  82. enabledPlugins?: Record<string, boolean>;
  83. options?: Record<string, Record<string, unknown>>;
  84. };
  85. };
  86. expect(userConfig.plugins?.enabledPlugins?.[PLUGIN_LIFECYCLE_ID]).toBe(true);
  87. expect(userConfig.plugins?.options?.[PLUGIN_LIFECYCLE_ID]).toBeUndefined();
  88. const workspaceConfig = existsSync(workspaceConfigPath)
  89. ? (JSON.parse(await readFile(workspaceConfigPath, "utf8")) as {
  90. plugins?: {
  91. extraKnownMarketplaces?: Record<string, unknown>;
  92. enabledPlugins?: Record<string, boolean>;
  93. options?: Record<string, Record<string, unknown>>;
  94. };
  95. })
  96. : {};
  97. expect(workspaceConfig.plugins?.extraKnownMarketplaces).toBeUndefined();
  98. expect(workspaceConfig.plugins?.enabledPlugins?.[PLUGIN_LIFECYCLE_ID]).toBeUndefined();
  99. expect(workspaceConfig.plugins?.options?.[PLUGIN_LIFECYCLE_ID]).toBeUndefined();
  100. const workspaceProjection = (
  101. await getPluginList(workspace, undefined, "workspace")
  102. ).plugins.find((plugin) => plugin.id === PLUGIN_LIFECYCLE_ID);
  103. const userProjection = (await getPluginList(workspace, undefined, "user")).plugins.find(
  104. (plugin) => plugin.id === PLUGIN_LIFECYCLE_ID,
  105. );
  106. expect(workspaceProjection).toMatchObject({ enabled: true, enabledSource: "user" });
  107. expect(userProjection).toMatchObject({ enabled: true, enabledSource: "user" });
  108. });
  109. });