plugin-cdn-zip-marketplace-install.test.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { existsSync, readFileSync } from "node:fs";
  2. import { join } from "node:path";
  3. import type { ZCodePluginInfo } from "@zcode/shared";
  4. import { clearAppData, getE2EAppDataPaths } from "../helpers/desktop-app.js";
  5. import {
  6. PLUGIN_CDN_ZIP_ARCHIVE_PATH,
  7. PLUGIN_CDN_ZIP_ID,
  8. PLUGIN_CDN_ZIP_MARKETPLACE_ID,
  9. PLUGIN_CDN_ZIP_NAME,
  10. PLUGIN_CDN_ZIP_VERSION,
  11. } from "../helpers/plugin-cdn-zip-marketplace.js";
  12. import {
  13. capturePluginManualReview,
  14. getPluginList,
  15. getPluginOverview,
  16. installPluginThroughUi,
  17. openPluginCard,
  18. openPluginSettings,
  19. requirePluginManualReview,
  20. waitForPluginCard,
  21. } from "../helpers/plugin-management-lifecycle.js";
  22. const ZIP_PLUGIN_INSTALL_TIMEOUT_MS = 180000;
  23. describe("PLM-LC-007 Desktop official CDN ZIP plugin UI lifecycle", () => {
  24. after(async () => {
  25. await browser.electron.restoreAllMocks();
  26. await clearAppData();
  27. });
  28. it("从 Public 卡片和详情入口安装本地确定性 official CDN ZIP", async function () {
  29. this.timeout(ZIP_PLUGIN_INSTALL_TIMEOUT_MS);
  30. requirePluginManualReview();
  31. await openPluginSettings();
  32. await waitForPluginCard(PLUGIN_CDN_ZIP_ID, 60000);
  33. const before = await getPluginOverview();
  34. expect(
  35. before.marketplaces.filter((item) => item.id === PLUGIN_CDN_ZIP_MARKETPLACE_ID),
  36. ).toHaveLength(1);
  37. expect(before.availablePlugins.find((plugin) => plugin.id === PLUGIN_CDN_ZIP_ID)).toMatchObject(
  38. {
  39. installed: false,
  40. marketplace: PLUGIN_CDN_ZIP_MARKETPLACE_ID,
  41. name: PLUGIN_CDN_ZIP_NAME,
  42. version: PLUGIN_CDN_ZIP_VERSION,
  43. },
  44. );
  45. await openPluginCard(PLUGIN_CDN_ZIP_ID);
  46. await capturePluginManualReview("PLM-LC-007", "official-cdn-local-detail");
  47. await installPluginThroughUi(PLUGIN_CDN_ZIP_ID);
  48. const paths = getE2EAppDataPaths();
  49. const pluginStorageRoot = join(paths.homeDir, ".zcode", "cli", "plugins");
  50. const cacheRoot = join(
  51. pluginStorageRoot,
  52. "cache",
  53. PLUGIN_CDN_ZIP_MARKETPLACE_ID,
  54. PLUGIN_CDN_ZIP_NAME,
  55. PLUGIN_CDN_ZIP_VERSION,
  56. );
  57. assertCacheMaterialized(cacheRoot);
  58. assertInstalledRecord(pluginStorageRoot, cacheRoot);
  59. const plugin = (await getPluginList()).plugins.find((item) => item.id === PLUGIN_CDN_ZIP_ID);
  60. expect(plugin).toMatchObject({
  61. commandRootCount: 1,
  62. enabled: true,
  63. rootPath: cacheRoot,
  64. skillRootCount: 1,
  65. version: PLUGIN_CDN_ZIP_VERSION,
  66. });
  67. expect(componentNames(plugin, "skill")).toContain("zip-skill");
  68. expect(componentNames(plugin, "command")).toContain("zip-command");
  69. });
  70. });
  71. function assertCacheMaterialized(cacheRoot: string): void {
  72. expect(existsSync(join(cacheRoot, ".claude-plugin", "plugin.json"))).toBe(true);
  73. expect(existsSync(join(cacheRoot, "skills", "zip-skill", "SKILL.md"))).toBe(true);
  74. expect(existsSync(join(cacheRoot, "commands", "zip-command.md"))).toBe(true);
  75. }
  76. function assertInstalledRecord(pluginStorageRoot: string, cacheRoot: string): void {
  77. const state = JSON.parse(
  78. readFileSync(join(pluginStorageRoot, "installed_plugins.json"), "utf-8"),
  79. ) as {
  80. plugins?: Array<{
  81. id?: string;
  82. installPath?: string;
  83. source?: { sha256?: string; source?: string; type?: string; url?: string };
  84. version?: string;
  85. }>;
  86. };
  87. const record = state.plugins?.find((plugin) => plugin.id === PLUGIN_CDN_ZIP_ID);
  88. expect(record).toMatchObject({
  89. id: PLUGIN_CDN_ZIP_ID,
  90. installPath: cacheRoot,
  91. version: PLUGIN_CDN_ZIP_VERSION,
  92. });
  93. expect(record?.source).toMatchObject({ source: "url", type: "zip" });
  94. expect(record?.source?.url ?? "").toContain(PLUGIN_CDN_ZIP_ARCHIVE_PATH);
  95. expect(record?.source?.sha256 ?? "").toMatch(/^[a-f0-9]{64}$/u);
  96. }
  97. function componentNames(plugin: ZCodePluginInfo | undefined, kind: "command" | "skill"): string[] {
  98. return (
  99. plugin?.components?.find((group) => group.kind === kind)?.items.map((item) => item.name) ?? []
  100. );
  101. }