plugin-localization-creator.test.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import { clearAppData, setInputValueByTestIdDom } from "../../../helpers/desktop-app.js";
  2. import { resolveE2EToolPath } from "../../../helpers/e2e-runtime-paths.js";
  3. import {
  4. getV4ComposerText,
  5. isV4ComposerFocused,
  6. waitForV4Pane,
  7. } from "../../../helpers/v4-conversation.js";
  8. import {
  9. PLUGIN_LIFECYCLE_ID,
  10. PLUGIN_LIFECYCLE_MARKETPLACE_ID,
  11. addLifecycleMarketplaceThroughUi,
  12. assertPluginStoreFitsViewport,
  13. capturePluginManualReview,
  14. clickPluginControl,
  15. createPluginLifecycleFixture,
  16. getPluginControlText,
  17. installPluginThroughUi,
  18. openPluginManagementSettings,
  19. openPluginSettings,
  20. requirePluginManualReview,
  21. setPluginPresentation,
  22. waitForPluginControl,
  23. } from "../../../helpers/plugin-management-lifecycle.js";
  24. describe("PLM-LC-018/019/020 本地化与插件创建入口", () => {
  25. after(async () => {
  26. await browser.electron.restoreAllMocks();
  27. await clearAppData();
  28. });
  29. it("两处添加菜单分别创建真实 skill 草稿并保留来源添加与中文管理搜索", async function () {
  30. this.timeout(300000);
  31. requirePluginManualReview();
  32. const fixture = await createPluginLifecycleFixture();
  33. await openPluginSettings();
  34. await setPluginPresentation({ locale: "zh-CN", theme: "zai-light", width: 1440, height: 1000 });
  35. await addLifecycleMarketplaceThroughUi(fixture);
  36. const countMarketCards = () =>
  37. browser.execute(
  38. (marketplace) =>
  39. [...document.querySelectorAll<HTMLElement>('[data-testid="plugin-store-card"]')].filter(
  40. (card) => card.dataset.pluginId?.endsWith(`@${marketplace}`),
  41. ).length,
  42. PLUGIN_LIFECYCLE_MARKETPLACE_ID,
  43. );
  44. expect(await countMarketCards()).toBe(8);
  45. await capturePluginManualReview("PLM-LC-001", "all-plugins-expanded");
  46. const groupKey = `marketplace:${PLUGIN_LIFECYCLE_MARKETPLACE_ID}`;
  47. await clickPluginControl("plugin-store-group-toggle", { groupKey });
  48. expect(await countMarketCards()).toBe(6);
  49. await clickPluginControl("plugin-store-group-toggle", { groupKey });
  50. expect(await countMarketCards()).toBe(8);
  51. await installPluginThroughUi(PLUGIN_LIFECYCLE_ID);
  52. for (const query of ["shengmingzhouqi", "SMZQ"]) {
  53. await setInputValueByTestIdDom("plugin-store-search", query);
  54. await waitForPluginControl("plugin-store-card", { pluginId: PLUGIN_LIFECYCLE_ID });
  55. }
  56. await setInputValueByTestIdDom("plugin-store-search", "");
  57. await openAddMenu("plugin-store-create");
  58. expect(await getPluginControlText("plugin-add-menu")).toContain("创建插件");
  59. expect(await getPluginControlText("plugin-add-menu")).not.toContain("录制");
  60. await clickPluginControl("plugin-create-menu-item");
  61. await expectCreatorDraft();
  62. await capturePluginManualReview("PLM-LC-019", "store-creator-draft");
  63. await openPluginManagementSettings();
  64. await clickPluginControl("settings-back-button");
  65. await expectCreatorDraft(false);
  66. await openPluginManagementSettings();
  67. await waitForPluginControl("plugin-settings-plugin-row", { pluginId: PLUGIN_LIFECYCLE_ID });
  68. expect(
  69. await getPluginControlText("plugin-settings-plugin-row", { pluginId: PLUGIN_LIFECYCLE_ID }),
  70. ).toContain("生命周期测试插件");
  71. for (const query of ["生命周期测试插件", "shengmingzhouqi", "smzq"]) {
  72. await setInputValueByTestIdDom("plugin-settings-search", query);
  73. await waitForPluginControl("plugin-settings-plugin-row", { pluginId: PLUGIN_LIFECYCLE_ID });
  74. }
  75. await setInputValueByTestIdDom("plugin-settings-search", "");
  76. await openAddMenu("plugin-settings-add");
  77. await clickPluginControl("plugin-create-menu-item");
  78. await expectCreatorDraft();
  79. await openPluginManagementSettings();
  80. await openAddMenu("plugin-settings-add");
  81. await clickPluginControl("plugin-store-add-source-menu-item");
  82. await waitForPluginControl("plugin-store-add-source-dialog");
  83. expect(
  84. await browser.execute(() => document.querySelector('[data-testid="settings-page"]') === null),
  85. ).toBe(true);
  86. const invalidSource = resolveE2EToolPath("plugin-creator", "missing-marketplace");
  87. await setInputValueByTestIdDom("plugin-store-add-source-input", invalidSource);
  88. await clickPluginControl("plugin-store-add-source-submit");
  89. await waitForPluginControl("plugin-store-add-source-error");
  90. expect(
  91. await browser.execute(
  92. () =>
  93. document.querySelector<HTMLInputElement>('[data-testid="plugin-store-add-source-input"]')
  94. ?.value,
  95. ),
  96. ).toBe(invalidSource);
  97. await browser.keys("Escape");
  98. // Electron 窗口最小宽度为 480;该宽度仍进入共享 UI 的手机断点。
  99. await setPluginPresentation({ locale: "en-US", theme: "zai-dark", width: 480, height: 844 });
  100. await setInputValueByTestIdDom("plugin-store-search", "smzq");
  101. await waitForPluginControl("plugin-store-card", { pluginId: PLUGIN_LIFECYCLE_ID });
  102. await openAddMenu("plugin-store-create");
  103. const text = await getPluginControlText("plugin-add-menu");
  104. expect(text).toContain("Create plugin");
  105. expect(text).toContain("Add plugin marketplace");
  106. await capturePluginManualReview("PLM-LC-020", "en-dark-narrow-add-menu");
  107. await assertPluginStoreFitsViewport();
  108. });
  109. });
  110. async function openAddMenu(testId: string) {
  111. await waitForPluginControl(testId);
  112. await browser.execute((id) => {
  113. document
  114. .querySelector<HTMLElement>(`[data-testid="${id}"]`)
  115. ?.dispatchEvent(
  116. new PointerEvent("pointerdown", { bubbles: true, button: 0, pointerType: "mouse" }),
  117. );
  118. }, testId);
  119. await waitForPluginControl("plugin-add-menu");
  120. expect(
  121. await browser.execute(
  122. () => document.querySelectorAll('[data-testid="plugin-add-menu"] [role="menuitem"]').length,
  123. ),
  124. ).toBe(2);
  125. }
  126. async function expectCreatorDraft(checkFocus = true) {
  127. // 旧草稿仍挂载在设置页背后,必须先等创建请求真正关闭设置,避免读到上次草稿。
  128. await browser.waitUntil(
  129. async () => browser.execute(() => !document.querySelector('[data-testid="settings-page"]')),
  130. { timeout: 30000 },
  131. );
  132. await waitForV4Pane((s) => s.sessionId === "draft", "创建插件未进入新草稿");
  133. await browser.waitUntil(
  134. async () => (await getV4ComposerText())?.includes("$plugin-creator") === true,
  135. { timeout: 30000 },
  136. );
  137. const text = await getV4ComposerText();
  138. expect(text).toContain("/SKILL.md)");
  139. expect(text?.endsWith(" ")).toBe(true);
  140. if (checkFocus)
  141. await browser.waitUntil(isV4ComposerFocused, {
  142. timeout: 15000,
  143. timeoutMsg: "创建插件后输入框未获得焦点",
  144. });
  145. await waitForV4Pane(
  146. (snapshot) => snapshot.sessionId === "draft" && snapshot.rowCount === 0 && !snapshot.canStop,
  147. "创建入口自动发送了任务",
  148. );
  149. }