plugin-manifest-isolation.test.ts 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { readFile, writeFile } from "node:fs/promises";
  2. import { join } from "node:path";
  3. import { clearAppData } from "#e2e/helpers/desktop-app";
  4. import {
  5. PLUGIN_LIFECYCLE_ID,
  6. PLUGIN_LIFECYCLE_EXTRA_ID,
  7. PLUGIN_LIFECYCLE_NAME,
  8. PLUGIN_LIFECYCLE_MARKETPLACE_ID,
  9. addLifecycleMarketplaceThroughUi,
  10. capturePluginManualReview,
  11. clickPluginControl,
  12. createPluginLifecycleFixture,
  13. getPluginList,
  14. getPluginOverview,
  15. hasPluginControl,
  16. installPluginThroughUi,
  17. openPluginSettings,
  18. requirePluginManualReview,
  19. setPluginPresentation,
  20. setPluginEnabledThroughUi,
  21. waitForPluginCard,
  22. } from "#e2e/helpers/plugin-management-lifecycle";
  23. describe("PLM-MANIFEST-ISOLATION 插件清单兼容候选 E2E", () => {
  24. after(async () => {
  25. await clearAppData();
  26. });
  27. it("未知配置字段不阻断列表及其他插件安装,坏字段只隔离自身", async function () {
  28. this.timeout(180000);
  29. requirePluginManualReview();
  30. const fixture = await createPluginLifecycleFixture("1.0.0");
  31. const path = join(fixture.pluginRoot, ".zcode-plugin", "plugin.json");
  32. const manifest = JSON.parse(await readFile(path, "utf8"));
  33. manifest.userConfig.track = { type: "string", default: "auto", options: ["auto", "transform"] };
  34. manifest.userConfig.panel = { type: "string", default: "auto", options: ["auto", "off"] };
  35. await writeFile(path, JSON.stringify(manifest));
  36. await openPluginSettings();
  37. await addLifecycleMarketplaceThroughUi(fixture);
  38. await clickPluginControl("plugin-store-segment-personal");
  39. await installPluginThroughUi(PLUGIN_LIFECYCLE_ID);
  40. await setPluginEnabledThroughUi(PLUGIN_LIFECYCLE_ID, false, "market");
  41. await setPluginEnabledThroughUi(PLUGIN_LIFECYCLE_ID, true, "market");
  42. const list = await getPluginList();
  43. const plugin = list.plugins.find((item) => item.id === PLUGIN_LIFECYCLE_ID)!;
  44. expect(plugin.userConfig?.track).toEqual({ type: "string", default: "auto" });
  45. expect(plugin.userConfig?.panel).toEqual({ type: "string", default: "auto" });
  46. expect(plugin.skillRootCount).toBeGreaterThan(0);
  47. expect(
  48. JSON.parse(await readFile(join(plugin.rootPath, ".zcode-plugin", "plugin.json"), "utf8"))
  49. .userConfig.track.options,
  50. ).toEqual(["auto", "transform"]);
  51. await installPluginThroughUi(PLUGIN_LIFECYCLE_EXTRA_ID);
  52. await clickPluginControl("plugin-store-refresh");
  53. await waitForPluginCard(PLUGIN_LIFECYCLE_EXTRA_ID);
  54. expect(await hasPluginControl("plugin-store-error")).toBe(false);
  55. expect(
  56. (await getPluginOverview()).installedPlugins.some(
  57. (item) => item.id === PLUGIN_LIFECYCLE_EXTRA_ID,
  58. ),
  59. ).toBe(true);
  60. for (const theme of ["zai-dark", "zai-light"] as const) {
  61. await setPluginPresentation({
  62. locale: theme === "zai-dark" ? "zh-CN" : "en-US",
  63. theme,
  64. width: 1200,
  65. height: 900,
  66. });
  67. await capturePluginManualReview("PLM-MANIFEST-ISOLATION", `compatible-${theme}`);
  68. }
  69. const installedPath = join(plugin.rootPath, ".zcode-plugin", "plugin.json");
  70. manifest.userConfig.track.type = "invalid";
  71. await writeFile(installedPath, JSON.stringify(manifest));
  72. const invalid = await getPluginList();
  73. expect(invalid.diagnostics).toContainEqual(
  74. expect.objectContaining({
  75. code: "plugin_manifest_invalid",
  76. pluginId: `${PLUGIN_LIFECYCLE_NAME}@${PLUGIN_LIFECYCLE_MARKETPLACE_ID}`,
  77. }),
  78. );
  79. expect(invalid.plugins.some((item) => item.id === PLUGIN_LIFECYCLE_EXTRA_ID)).toBe(true);
  80. });
  81. });