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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { clearAppData, clickTestIdByDom } from "../../../helpers/desktop-app.js";
  2. import { TID_SETTINGS_BACK_BUTTON } from "@zcode/shared";
  3. import {
  4. PLUGIN_CDN_ZIP_ID,
  5. PLUGIN_CDN_ZIP_MARKETPLACE_ID,
  6. PLUGIN_CDN_ZIP_OFFLINE_LAST_UPDATED,
  7. } from "../../../helpers/plugin-cdn-zip-marketplace.js";
  8. import {
  9. capturePluginManualReview,
  10. getPluginOverview,
  11. hasPluginControl,
  12. openPluginSettings,
  13. requirePluginManualReview,
  14. waitForPluginCard,
  15. waitForPluginControl,
  16. waitForPluginSettingsScope,
  17. } from "../../../helpers/plugin-management-lifecycle.js";
  18. const THROTTLED_TIMEOUT_MS = 120000;
  19. // 自动刷新若被误触发,operationId 会立刻置为 marketplace:update:*;等一个远大于 UI 调度延迟
  20. // 的窗口再取 overview,确认 lastUpdated 与 seed 值一致即证明没有发起刷新。
  21. const NO_REFRESH_SETTLE_MS = 5000;
  22. function readOfficialLastUpdated(
  23. overview: Awaited<ReturnType<typeof getPluginOverview>>,
  24. ): string | undefined {
  25. return overview.marketplaces.find((item) => item.id === PLUGIN_CDN_ZIP_MARKETPLACE_ID)
  26. ?.lastUpdated;
  27. }
  28. describe("PLM-LC-018 Desktop plugin store auto refresh throttled", () => {
  29. after(async () => {
  30. await browser.electron.restoreAllMocks();
  31. await clearAppData();
  32. });
  33. it("官方市场 1 分钟前刷新过,进入与重进商店页都不再刷新", async function () {
  34. this.timeout(THROTTLED_TIMEOUT_MS);
  35. requirePluginManualReview();
  36. // wdio seed 把官方市场 lastUpdated 写成启动前 1 分钟(命中 10 分钟节流窗口)。
  37. const seeded = await getPluginOverview();
  38. const seededLastUpdated = readOfficialLastUpdated(seeded);
  39. if (!seededLastUpdated) throw new Error("Seeded official marketplace has no lastUpdated");
  40. expect(Date.now() - Date.parse(seededLastUpdated)).toBeLessThan(10 * 60_000);
  41. await openPluginSettings();
  42. await waitForPluginCard(PLUGIN_CDN_ZIP_ID, 60000);
  43. await browser.pause(NO_REFRESH_SETTLE_MS);
  44. expect(readOfficialLastUpdated(await getPluginOverview())).toBe(seededLastUpdated);
  45. expect(await hasPluginControl("plugin-store-error")).toBe(false);
  46. // 离开商店页再重进(重新挂载),仍在窗口内,同样不刷新。
  47. // 重进路径与 conversation-session-plugin-marketplace-installed-roundtrip 一致:商店顶栏返回
  48. // 到设置页 → 退出设置 → 侧栏「插件市场」重新进入,保证 PluginStorePage 真正重新挂载。
  49. await clickTestIdByDom("desktop-top-nav-back");
  50. await waitForPluginSettingsScope("user");
  51. await clickTestIdByDom(TID_SETTINGS_BACK_BUTTON);
  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. });