plugin-creator.test.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { describe, expect, it } from "vitest";
  2. import { access, readFile } from "node:fs/promises";
  3. import { fileURLToPath } from "node:url";
  4. import { join } from "node:path";
  5. import {
  6. OFFICIAL_NODE_REPL_HOST_PLUGIN_NAME,
  7. OFFICIAL_PLUGIN_DEFINITIONS,
  8. } from "../src/app/official-plugin-definitions.js";
  9. // 不面向用户、不进市场的 seed 单元:只携带共用运行时产物,因此没有 listing。
  10. // 白名单之外的条目一律必须带中文描述,漏配 listing 仍然会红。
  11. const SEED_ONLY_PLUGIN_NAMES = new Set<string>([OFFICIAL_NODE_REPL_HOST_PLUGIN_NAME]);
  12. describe("bundled Plugin Creator", () => {
  13. it("ships a default-enabled creator with every referenced resource and localized description", async () => {
  14. const definition = OFFICIAL_PLUGIN_DEFINITIONS.find((item) => item.name === "plugin-creator");
  15. expect(definition).toMatchObject({
  16. defaultEnabled: true,
  17. version: "0.1.1",
  18. listing: { displayName_i18n: { "zh-CN": "插件创建器" } },
  19. });
  20. const root = fileURLToPath(new URL("../../plugin-creator-plugin/", import.meta.url));
  21. const manifest = JSON.parse(await readFile(join(root, ".zcode-plugin/plugin.json"), "utf8"));
  22. expect(manifest.version).toBe(definition?.version);
  23. for (const path of definition?.requiredSeedPaths ?? []) await access(join(root, path));
  24. const skill = await readFile(join(root, "skills/plugin-creator/SKILL.md"), "utf8");
  25. expect(skill).toContain("name: plugin-creator");
  26. expect(skill).toContain("zcode plugins validate");
  27. });
  28. it("provides Chinese descriptions for all bundled entries", () => {
  29. for (const definition of OFFICIAL_PLUGIN_DEFINITIONS) {
  30. if (SEED_ONLY_PLUGIN_NAMES.has(definition.name)) {
  31. // 反向钉住 seed 单元的设计:它必须始终不进市场,一旦有人给它配了 listing
  32. // 就说明归属变了,应当先决定它是否面向用户,而不是让本用例静默放过。
  33. expect(definition.listing, definition.name).toBeUndefined();
  34. continue;
  35. }
  36. expect(definition.listing?.description_i18n?.["zh-CN"], definition.name).toBeTruthy();
  37. }
  38. });
  39. });