plugin-management-persistence-source.test.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { mkdir } from "node:fs/promises";
  2. import { join } from "node:path";
  3. import { TID_SETTINGS_BACK_BUTTON } from "@zcode/shared";
  4. import {
  5. clearAppData,
  6. clickTestIdByDom,
  7. getE2EAppDataPaths,
  8. } from "../../../helpers/desktop-app.js";
  9. import { waitForUpstreamRequestContaining } from "../../../helpers/conversation-session.js";
  10. import { findUpstreamRequestContaining } from "../../../helpers/plugin-mcp-skill.js";
  11. import { prepareV4ConversationE2E, sendV4Prompt } from "../../../helpers/v4-conversation.js";
  12. import {
  13. PLUGIN_LIFECYCLE_CONFIG_VALUE,
  14. PLUGIN_LIFECYCLE_ID,
  15. PLUGIN_LIFECYCLE_MARKETPLACE_ID,
  16. PLUGIN_LIFECYCLE_RUNTIME_MARKER,
  17. addLifecycleMarketplaceThroughUi,
  18. capturePluginManualReview,
  19. clickPluginControl,
  20. configureLifecyclePluginThroughUi,
  21. createPluginLifecycleFixture,
  22. getPluginList,
  23. getPluginOverview,
  24. hasPluginControl,
  25. installPluginThroughUi,
  26. openManageView,
  27. openPluginCard,
  28. openPluginSettings,
  29. readPluginConfigOptions,
  30. removeMarketplaceSourceThroughUi,
  31. requirePluginManualReview,
  32. restartPluginLifecycleApp,
  33. setPluginEnabledThroughUi,
  34. uninstallPluginThroughUi,
  35. waitForPluginCard,
  36. waitForPluginControl,
  37. } from "../../../helpers/plugin-management-lifecycle.js";
  38. const PERSISTENCE_TIMEOUT_MS = 240000;
  39. describe("PLM-LC-004/005 插件持久化、跨本地 workspace 与来源孤立 E2E", () => {
  40. after(async () => {
  41. await browser.electron.restoreAllMocks();
  42. await clearAppData();
  43. });
  44. it("重启保留 user-scope 状态,删除来源后保留安装并可重新关联", async function () {
  45. this.timeout(PERSISTENCE_TIMEOUT_MS);
  46. requirePluginManualReview();
  47. const fixture = await createPluginLifecycleFixture();
  48. await openPluginSettings();
  49. await addLifecycleMarketplaceThroughUi(fixture);
  50. await clickPluginControl("plugin-store-segment-personal");
  51. await openPluginCard(PLUGIN_LIFECYCLE_ID);
  52. await installPluginThroughUi(PLUGIN_LIFECYCLE_ID);
  53. await configureLifecyclePluginThroughUi(PLUGIN_LIFECYCLE_CONFIG_VALUE);
  54. await setPluginEnabledThroughUi(PLUGIN_LIFECYCLE_ID, false, "detail");
  55. await restartPluginLifecycleApp();
  56. await openPluginSettings();
  57. expect(
  58. (await getPluginOverview()).installedPlugins.find(
  59. (plugin) => plugin.id === PLUGIN_LIFECYCLE_ID,
  60. )?.enabled,
  61. ).toBe(false);
  62. expect((await readPluginConfigOptions()).display_label).toBe(PLUGIN_LIFECYCLE_CONFIG_VALUE);
  63. const workspaceB = join(getE2EAppDataPaths().homeDir, "ZCodeProjectB");
  64. await mkdir(workspaceB, { recursive: true });
  65. expect(
  66. (await getPluginOverview(workspaceB)).installedPlugins.some(
  67. (plugin) => plugin.id === PLUGIN_LIFECYCLE_ID,
  68. ),
  69. ).toBe(true);
  70. await removeMarketplaceSourceThroughUi(PLUGIN_LIFECYCLE_MARKETPLACE_ID);
  71. expect(
  72. (await getPluginOverview()).marketplaces.some(
  73. (marketplace) => marketplace.id === PLUGIN_LIFECYCLE_MARKETPLACE_ID,
  74. ),
  75. ).toBe(false);
  76. expect(
  77. (await getPluginList()).plugins.some((plugin) => plugin.id === PLUGIN_LIFECYCLE_ID),
  78. ).toBe(true);
  79. await openManageView();
  80. await waitForPluginControl("plugin-store-installed-row", { pluginId: PLUGIN_LIFECYCLE_ID });
  81. await clickPluginControl("plugin-store-installed-row", { pluginId: PLUGIN_LIFECYCLE_ID });
  82. await waitForPluginControl("plugin-store-source-degraded", {
  83. pluginId: PLUGIN_LIFECYCLE_ID,
  84. });
  85. await configureLifecyclePluginThroughUi(`${PLUGIN_LIFECYCLE_CONFIG_VALUE}-orphaned`);
  86. await setPluginEnabledThroughUi(PLUGIN_LIFECYCLE_ID, true, "detail");
  87. expect(
  88. await hasPluginControl("plugin-store-menu-update", { pluginId: PLUGIN_LIFECYCLE_ID }),
  89. ).toBe(false);
  90. expect(await hasPluginControl("plugin-store-detail-update")).toBe(false);
  91. // 孤立插件的 updateStatus 可能残留删除来源前的值:角标、行内更新按钮、已安装条更新入口
  92. // 与菜单/详情入口一样,都必须以 canUpdatePluginItem(含 orphaned 排除)为准而不出现。
  93. for (const control of [
  94. "plugin-store-update-badge",
  95. "plugin-store-card-update",
  96. "plugin-store-installed-item-update",
  97. ]) {
  98. expect(await hasPluginControl(control, { pluginId: PLUGIN_LIFECYCLE_ID })).toBe(false);
  99. }
  100. await capturePluginManualReview("PLM-LC-005", "orphaned-installed-detail");
  101. await clickTestIdByDom(TID_SETTINGS_BACK_BUTTON);
  102. await prepareV4ConversationE2E();
  103. const orphanedRuntimeRequest = `E2E_PLUGIN_LIFECYCLE_ORPHANED_REQUEST_${Date.now()}`;
  104. await sendV4Prompt(`${orphanedRuntimeRequest}: reply with exactly upstream-e2e-ok.`);
  105. await waitForUpstreamRequestContaining(orphanedRuntimeRequest, 60000);
  106. const orphanedRequest = await findUpstreamRequestContaining(orphanedRuntimeRequest, 60000);
  107. expect(JSON.stringify(orphanedRequest?.requestJson)).toContain(
  108. `${PLUGIN_LIFECYCLE_RUNTIME_MARKER}_1.0.0`,
  109. );
  110. await openPluginSettings();
  111. await addLifecycleMarketplaceThroughUi(fixture);
  112. expect(
  113. (await getPluginOverview()).marketplaces.some(
  114. (marketplace) => marketplace.id === PLUGIN_LIFECYCLE_MARKETPLACE_ID,
  115. ),
  116. ).toBe(true);
  117. await clickPluginControl("plugin-store-segment-personal");
  118. await waitForPluginCard(PLUGIN_LIFECYCLE_ID);
  119. await openPluginCard(PLUGIN_LIFECYCLE_ID);
  120. await uninstallPluginThroughUi(PLUGIN_LIFECYCLE_ID, true);
  121. });
  122. });