sea-official-plugin-assets.test.mjs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import assert from "node:assert/strict";
  2. import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
  3. import { tmpdir } from "node:os";
  4. import { dirname, join } from "node:path";
  5. import test from "node:test";
  6. import {
  7. collectSeaOfficialPluginAssets,
  8. officialSeaPlugins,
  9. } from "../scripts/sea-official-plugin-assets.mjs";
  10. test("includes the document judge agent in official SEA assets", async () => {
  11. const stagingDirectory = await mkdtemp(join(tmpdir(), "zcode-sea-document-agent-"));
  12. const root = join(import.meta.dirname, "../../..");
  13. try {
  14. const { manifest } = await collectSeaOfficialPluginAssets({
  15. root,
  16. stagingDirectory,
  17. });
  18. assert.equal(
  19. manifest.plugins.some((plugin) => plugin.name === "document-skills"),
  20. false,
  21. );
  22. for (const [name, skill] of [
  23. ["documents", "docx"],
  24. ["pdf", "pdf"],
  25. ["presentations", "pptx"],
  26. ["spreadsheets", "xlsx"],
  27. ]) {
  28. const plugin = manifest.plugins.find((plugin) => plugin.name === name);
  29. assert.ok(plugin, `missing ${name} SEA manifest entry`);
  30. for (const path of ["agents/visual-judge.md", `skills/${skill}/SKILL.md`])
  31. assert.ok(
  32. plugin.files.some((file) => file.path === path),
  33. `${name}: ${path}`,
  34. );
  35. }
  36. const creator = manifest.plugins.find((plugin) => plugin.name === "plugin-creator");
  37. assert.ok(creator, "missing plugin-creator SEA manifest entry");
  38. for (const path of [
  39. ".zcode-plugin/plugin.json",
  40. "skills/plugin-creator/SKILL.md",
  41. "skills/plugin-creator/scripts/create-basic-plugin.mjs",
  42. "skills/plugin-creator/scripts/marketplace-files.mjs",
  43. "skills/plugin-creator/scripts/upsert-dev-marketplace.mjs",
  44. "skills/plugin-creator/scripts/scaffold-files.mjs",
  45. "skills/plugin-creator/scripts/validate-plugin.mjs",
  46. "skills/plugin-creator/references/plugin-json-spec.md",
  47. "skills/plugin-creator/references/installing-and-updating.md",
  48. ])
  49. assert.ok(
  50. creator.files.some((file) => file.path === path),
  51. `missing ${path}`,
  52. );
  53. // SEA 清单版本必须与包 package.json 一致:runtime 按 (name, version) 精确匹配
  54. // SEA 资产,清单落后会让整个插件在 SEA 下不 seed。此前断言硬编码 "0.1.6",
  55. // 版本演进后过期红掉且无人修;改为从包内动态读取,让漂移本身成为唯一失败原因。
  56. for (const entry of officialSeaPlugins) {
  57. const manifestPlugin = manifest.plugins.find((plugin) => plugin.name === entry.name);
  58. assert.ok(manifestPlugin, `missing ${entry.name} SEA manifest entry`);
  59. const packageVersion = JSON.parse(
  60. await readFile(join(root, entry.rootPath, "package.json"), "utf8"),
  61. ).version;
  62. assert.equal(
  63. manifestPlugin.version,
  64. packageVersion,
  65. `${entry.name}: SEA manifest version drifted from package.json`,
  66. );
  67. }
  68. } finally {
  69. await rm(stagingDirectory, { force: true, recursive: true });
  70. }
  71. });
  72. test("rejects an incomplete documents SEA seed", async () => {
  73. const directory = await mkdtemp(join(tmpdir(), "zcode-sea-document-agent-missing-"));
  74. const root = join(directory, "root");
  75. const stagingDirectory = join(directory, "staging");
  76. try {
  77. // 夹具必须覆盖清单里除 documents 之外的所有条目:collect 按清单顺序对每个
  78. // 条目先校验 manifest 与 seed 资产,任何先于 documents 的条目缺资产都会
  79. // 以别的错误先抛,让本测试想覆盖的 documents 拒绝路径永远走不到(历史上
  80. // visualize 排到首位后该测试就一直红在 visualize manifest 缺失上)。
  81. for (const entry of officialSeaPlugins) {
  82. if (entry.name === "documents") {
  83. await writeTestFile(root, join(entry.rootPath, ".zcode-plugin/plugin.json"), "{}");
  84. continue;
  85. }
  86. await writeTestFile(root, join(entry.rootPath, ".zcode-plugin/plugin.json"), "{}");
  87. for (const seedPath of entry.requiredSeedPaths ?? [])
  88. await writeTestFile(root, join(entry.rootPath, seedPath), "");
  89. }
  90. await assert.rejects(
  91. collectSeaOfficialPluginAssets({ root, stagingDirectory }),
  92. /Missing documents required seed asset.*agents[/\\]visual-judge\.md/u,
  93. );
  94. } finally {
  95. await rm(directory, { force: true, recursive: true });
  96. }
  97. });
  98. async function writeTestFile(root, relativePath, content) {
  99. const filePath = join(root, ...String(relativePath).split("/"));
  100. await mkdir(dirname(filePath), { recursive: true });
  101. await writeFile(filePath, content, "utf8");
  102. }