plugin-store-auto-refresh-on-enter.test.ts 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import {
  2. clearAppData,
  3. clickTestIdByDom,
  4. waitForDefaultWorkspaceReady,
  5. } from "#e2e/helpers/desktop-app";
  6. import {
  7. PLUGIN_CDN_ZIP_MARKETPLACE_ID,
  8. PLUGIN_STORE_AUTO_REFRESH_STALE_LAST_UPDATED,
  9. } from "#e2e/helpers/plugin-cdn-zip-marketplace";
  10. import {
  11. capturePluginManualReview,
  12. getPluginOverview,
  13. hasPluginControl,
  14. openPluginSettings,
  15. requirePluginManualReview,
  16. waitForPluginControl,
  17. } from "#e2e/helpers/plugin-management-lifecycle";
  18. // 本例验证真实官方市场刷新,需要可访问公网 CDN;模型 replay 不替代市场 HTTP 请求。
  19. // 已迁入正式目录,直接按本文件运行,不再依赖 manual-review 的 capture 或 HOLD_MS 配置。
  20. const CDN_REFRESH_TIMEOUT_MS = 180000;
  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-019 Desktop plugin store auto refresh on enter (real official CDN)", () => {
  29. after(async () => {
  30. await browser.electron.restoreAllMocks();
  31. await clearAppData();
  32. });
  33. it("官方市场刷新时间过期时,进入商店页不点刷新也会自动刷新,重进则命中节流", async function () {
  34. requirePluginManualReview();
  35. await waitForDefaultWorkspaceReady();
  36. // wdio seed 把官方市场 lastUpdated 写成远古时间且 pluginCount>0,必然落在节流窗口外。
  37. expect(readOfficialLastUpdated(await getPluginOverview())).toBe(
  38. PLUGIN_STORE_AUTO_REFRESH_STALE_LAST_UPDATED,
  39. );
  40. const enteredAt = Date.now();
  41. await openPluginSettings();
  42. let refreshedLastUpdated: string | undefined;
  43. let official: Awaited<ReturnType<typeof getPluginOverview>>["marketplaces"][number] | undefined;
  44. await browser
  45. .waitUntil(
  46. async () => {
  47. official = (await getPluginOverview()).marketplaces.find(
  48. (item) => item.id === PLUGIN_CDN_ZIP_MARKETPLACE_ID,
  49. );
  50. // 刷新失败会被持久化成 refreshFailure;直接带着诊断失败,不要空等到超时。
  51. if (official?.refreshFailure) {
  52. throw new Error(
  53. `Official marketplace auto refresh failed: ${JSON.stringify(official.refreshFailure)}`,
  54. );
  55. }
  56. refreshedLastUpdated = official?.lastUpdated;
  57. return (
  58. refreshedLastUpdated !== undefined &&
  59. refreshedLastUpdated !== PLUGIN_STORE_AUTO_REFRESH_STALE_LAST_UPDATED
  60. );
  61. },
  62. {
  63. timeout: CDN_REFRESH_TIMEOUT_MS,
  64. interval: 2000,
  65. timeoutMsg: "Entering the plugin store did not auto refresh the official marketplace",
  66. },
  67. )
  68. .catch((error: unknown) => {
  69. // 超时时把官方市场记录一并带出,便于区分「没触发」与「触发了但落盘异常」。
  70. throw new Error(
  71. `${error instanceof Error ? error.message : String(error)}; official=${JSON.stringify(official)}`,
  72. );
  73. });
  74. if (!refreshedLastUpdated) throw new Error("Official marketplace lastUpdated missing");
  75. // 允许 agent/renderer 时钟有秒级偏差。
  76. expect(Date.parse(refreshedLastUpdated)).toBeGreaterThanOrEqual(enteredAt - 60_000);
  77. expect(await hasPluginControl("plugin-store-error")).toBe(false);
  78. await capturePluginManualReview("PLM-LC-019", "auto-refreshed-on-enter");
  79. // 刚刷新过:离开再重进商店页命中 10 分钟窗口,不再刷新。
  80. // 商店顶栏返回聊天,再从侧栏进入,保证 PluginStorePage 真正重新挂载。
  81. await clickTestIdByDom("desktop-top-nav-back");
  82. await clickTestIdByDom("plugin-store-sidebar-open");
  83. await waitForPluginControl("plugin-store-root", {}, 30000);
  84. await browser.pause(NO_REFRESH_SETTLE_MS);
  85. expect(readOfficialLastUpdated(await getPluginOverview())).toBe(refreshedLastUpdated);
  86. });
  87. });