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

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import assert from "node:assert/strict";
  2. import { mkdir, mkdtemp, 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("rejects an incomplete documents SEA seed", async () => {
  11. const directory = await mkdtemp(join(tmpdir(), "zcode-sea-document-agent-missing-"));
  12. const root = join(directory, "root");
  13. const stagingDirectory = join(directory, "staging");
  14. try {
  15. // 夹具必须覆盖清单里除 documents 之外的所有条目:collect 按清单顺序对每个
  16. // 条目先校验 manifest 与 seed 资产,任何先于 documents 的条目缺资产都会
  17. // 以别的错误先抛,让本测试想覆盖的 documents 拒绝路径永远走不到(历史上
  18. // visualize 排到首位后该测试就一直红在 visualize manifest 缺失上)。
  19. for (const entry of officialSeaPlugins) {
  20. if (entry.name === "documents") {
  21. await writeTestFile(root, join(entry.rootPath, ".zcode-plugin/plugin.json"), "{}");
  22. continue;
  23. }
  24. await writeTestFile(root, join(entry.rootPath, ".zcode-plugin/plugin.json"), "{}");
  25. for (const seedPath of entry.requiredSeedPaths ?? [])
  26. await writeTestFile(root, join(entry.rootPath, seedPath), "");
  27. }
  28. await assert.rejects(
  29. collectSeaOfficialPluginAssets({ root, stagingDirectory }),
  30. /Missing documents required seed asset.*agents[/\\]visual-judge\.md/u,
  31. );
  32. } finally {
  33. await rm(directory, { force: true, recursive: true });
  34. }
  35. });
  36. async function writeTestFile(root, relativePath, content) {
  37. const filePath = join(root, ...String(relativePath).split("/"));
  38. await mkdir(dirname(filePath), { recursive: true });
  39. await writeFile(filePath, content, "utf8");
  40. }