planToolCall.test.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { describe, expect, it } from "vitest";
  2. import { extractPlanToolCallContent, getPlanDirectoryTitle } from "../src/lib/planToolCall.js";
  3. describe("planToolCall", () => {
  4. it("prefers the streaming input plan and resolves a relative plan file", () => {
  5. expect(
  6. extractPlanToolCallContent(
  7. {
  8. input: {
  9. plan: "# 计划\n\n- 第一步",
  10. planFilePath: ".zcode/plans/demo.md",
  11. },
  12. output: "fallback",
  13. },
  14. "/workspace",
  15. ),
  16. ).toEqual({
  17. markdown: "# 计划\n\n- 第一步",
  18. planFilePath: "/workspace/.zcode/plans/demo.md",
  19. });
  20. });
  21. it("extracts a directory title from H1 before falling back to the first text line", () => {
  22. expect(getPlanDirectoryTitle("\n## 摘要\n\n# 最终实施计划\n")).toBe("最终实施计划");
  23. expect(getPlanDirectoryTitle("\n> 只有一行摘要\n\n- 细节")).toBe("只有一行摘要");
  24. expect(getPlanDirectoryTitle(" \n\t")).toBeUndefined();
  25. });
  26. it("reads a completed plan from serialized tool input text", () => {
  27. expect(
  28. extractPlanToolCallContent(
  29. {
  30. inputText: JSON.stringify({ plan: "# 冷恢复计划" }),
  31. output: { content: "tool finished" },
  32. },
  33. "/workspace",
  34. ),
  35. ).toEqual({ markdown: "# 冷恢复计划" });
  36. });
  37. });