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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. waitForPluginCard,
  25. waitUntilPluginOverview,
  26. } from "#e2e/helpers/plugin-management-lifecycle";
  27. describe("WPL-009 Global Plugin Marketplace install E2E", () => {
  28. after(async () => {
  29. await browser.electron.restoreAllMocks();
  30. await clearAppData();
  31. });
  32. it("keeps marketplace and installation in User inventory while Workspace stays config-only", async function () {
  33. this.timeout(300000);
  34. const fixture = await createPluginLifecycleFixture("1.0.0");
  35. const { storageRoot, workspace } = getE2EAppDataPaths();
  36. const workspaceConfigPath = join(workspace, ".zcode", "config.json");
  37. const userConfigPath = join(storageRoot, "cli", "config.json");
  38. const knownMarketplacesPath = pluginStoragePath("known_marketplaces.json");
  39. const marketplaceCachePath = pluginStoragePath("marketplaces", PLUGIN_LIFECYCLE_MARKETPLACE_ID);
  40. await waitForDefaultWorkspaceReady();
  41. // 插件 bridge 由 workspace App 注册,不能在全局未归类草稿等待它出现。
  42. await waitForWorkspaceApp(workspace, 45000);
  43. await startDraftFromProject(workspace);
  44. await addMarketplaceSourceThroughAgent(fixture.marketplaceRoot);
  45. await waitUntilPluginOverview(
  46. (overview) => overview.availablePlugins.some((plugin) => plugin.id === PLUGIN_LIFECYCLE_ID),
  47. "Global marketplace fixture did not become available",
  48. 60000,
  49. );
  50. expect(await readFile(knownMarketplacesPath, "utf8")).toContain(
  51. PLUGIN_LIFECYCLE_MARKETPLACE_ID,
  52. );
  53. expect(existsSync(marketplaceCachePath)).toBe(true);
  54. expect((await getPluginOverview(workspace, "user")).marketplaces).toEqual(
  55. expect.arrayContaining([expect.objectContaining({ id: PLUGIN_LIFECYCLE_MARKETPLACE_ID })]),
  56. );
  57. // Marketplace 只从全局入口打开;页面本身没有 scope 或 options 配置控件;未安装项不显示启停开关。
  58. await openPluginSettings();
  59. expect(await hasPluginControl("plugin-store-scope-trigger")).toBe(false);
  60. expect(await hasPluginControl("plugin-store-config")).toBe(false);
  61. await clickPluginControl("plugin-store-segment-personal");
  62. await waitForPluginCard(PLUGIN_LIFECYCLE_ID);
  63. expect(
  64. await hasPluginControl("plugin-store-enabled-switch", { pluginId: PLUGIN_LIFECYCLE_ID }),
  65. ).toBe(false);
  66. await openPluginCard(PLUGIN_LIFECYCLE_ID);
  67. await installPluginThroughUi(PLUGIN_LIFECYCLE_ID);
  68. const userConfig = JSON.parse(await readFile(userConfigPath, "utf8")) as {
  69. plugins?: {
  70. enabledPlugins?: Record<string, boolean>;
  71. options?: Record<string, Record<string, unknown>>;
  72. };
  73. };
  74. expect(userConfig.plugins?.enabledPlugins?.[PLUGIN_LIFECYCLE_ID]).toBe(true);
  75. expect(userConfig.plugins?.options?.[PLUGIN_LIFECYCLE_ID]).toBeUndefined();
  76. const workspaceConfig = existsSync(workspaceConfigPath)
  77. ? (JSON.parse(await readFile(workspaceConfigPath, "utf8")) as {
  78. plugins?: {
  79. extraKnownMarketplaces?: Record<string, unknown>;
  80. enabledPlugins?: Record<string, boolean>;
  81. options?: Record<string, Record<string, unknown>>;
  82. };
  83. })
  84. : {};
  85. expect(workspaceConfig.plugins?.extraKnownMarketplaces).toBeUndefined();
  86. expect(workspaceConfig.plugins?.enabledPlugins?.[PLUGIN_LIFECYCLE_ID]).toBeUndefined();
  87. expect(workspaceConfig.plugins?.options?.[PLUGIN_LIFECYCLE_ID]).toBeUndefined();
  88. const workspaceProjection = (
  89. await getPluginList(workspace, undefined, "workspace")
  90. ).plugins.find((plugin) => plugin.id === PLUGIN_LIFECYCLE_ID);
  91. const userProjection = (await getPluginList(workspace, undefined, "user")).plugins.find(
  92. (plugin) => plugin.id === PLUGIN_LIFECYCLE_ID,
  93. );
  94. expect(workspaceProjection).toMatchObject({ enabled: true, enabledSource: "user" });
  95. expect(userProjection).toMatchObject({ enabled: true, enabledSource: "user" });
  96. });
  97. });