plugin-store-auto-refresh-throttled.test.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {
  2. clearAppData,
  3. clickTestIdByDom,
  4. waitForDefaultWorkspaceReady,
  5. } from "#e2e/helpers/desktop-app";
  6. import {
  7. PLUGIN_CDN_ZIP_ID,
  8. PLUGIN_CDN_ZIP_MARKETPLACE_ID,
  9. PLUGIN_CDN_ZIP_OFFLINE_LAST_UPDATED,
  10. } from "#e2e/helpers/plugin-cdn-zip-marketplace";
  11. import {
  12. capturePluginManualReview,
  13. getPluginOverview,
  14. hasPluginControl,
  15. openPluginSettings,
  16. requirePluginManualReview,
  17. waitForPluginCard,
  18. waitForPluginControl,
  19. } from "#e2e/helpers/plugin-management-lifecycle";
  20. const THROTTLED_TIMEOUT_MS = 120000;
  21. // 自动刷新若被误触发,operationId 会立刻置为 marketplace:update:*;等一个远大于 UI 调度延迟
  22. // 的窗口再取 overview,确认 lastUpdated 与 seed 值一致即证明没有发起刷新。
  23. const NO_REFRESH_SETTLE_MS = 5000;
  24. function readOfficialLastUpdated(
  25. overview: Awaited<ReturnType<typeof getPluginOverview>>,
  26. ): string | undefined {
  27. return overview.marketplaces.find((item) => item.id === PLUGIN_CDN_ZIP_MARKETPLACE_ID)
  28. ?.lastUpdated;
  29. }
  30. describe("PLM-LC-018 Desktop plugin store auto refresh throttled", () => {
  31. after(async () => {
  32. await browser.electron.restoreAllMocks();
  33. await clearAppData();
  34. });
  35. it("官方市场 1 分钟前刷新过,进入与重进商店页都不再刷新", async function () {
  36. this.timeout(THROTTLED_TIMEOUT_MS);
  37. requirePluginManualReview();
  38. await waitForDefaultWorkspaceReady();
  39. // wdio seed 把官方市场 lastUpdated 写成启动前 1 分钟(命中 10 分钟节流窗口)。
  40. const seeded = await getPluginOverview();
  41. const seededLastUpdated = readOfficialLastUpdated(seeded);
  42. if (!seededLastUpdated) throw new Error("Seeded official marketplace has no lastUpdated");
  43. expect(Date.now() - Date.parse(seededLastUpdated)).toBeLessThan(10 * 60_000);
  44. await openPluginSettings();
  45. await waitForPluginCard(PLUGIN_CDN_ZIP_ID, 60000);
  46. await browser.pause(NO_REFRESH_SETTLE_MS);
  47. expect(readOfficialLastUpdated(await getPluginOverview())).toBe(seededLastUpdated);
  48. expect(await hasPluginControl("plugin-store-error")).toBe(false);
  49. // 离开商店页再重进(重新挂载),仍在窗口内,同样不刷新。
  50. // 商店顶栏返回聊天,再从侧栏进入,保证 PluginStorePage 真正重新挂载。
  51. await clickTestIdByDom("desktop-top-nav-back");
  52. await clickTestIdByDom("plugin-store-sidebar-open");
  53. await waitForPluginControl("plugin-store-root", {}, 30000);
  54. await waitForPluginCard(PLUGIN_CDN_ZIP_ID, 60000);
  55. await browser.pause(NO_REFRESH_SETTLE_MS);
  56. const after = await getPluginOverview();
  57. expect(readOfficialLastUpdated(after)).toBe(seededLastUpdated);
  58. expect(
  59. after.marketplaces.find((item) => item.id === PLUGIN_CDN_ZIP_MARKETPLACE_ID)?.refreshFailure,
  60. ).toBeUndefined();
  61. // claude-plugins-official 不是强依赖:进入商店页不得对它发起任何拉取(无失败痕迹、时间戳不变)。
  62. const claude = after.marketplaces.find((item) => item.id === "claude-plugins-official");
  63. expect(claude?.refreshFailure).toBeUndefined();
  64. expect(claude?.lastUpdated).toBe(PLUGIN_CDN_ZIP_OFFLINE_LAST_UPDATED);
  65. expect(await hasPluginControl("plugin-store-error")).toBe(false);
  66. await capturePluginManualReview("PLM-LC-018", "throttled-reenter");
  67. });
  68. });