goalToolCallBlock.test.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it } from "vitest";
  4. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  5. import { GoalToolCallBlock } from "../src/ToolCallBlocks/renderers/goal.js";
  6. const displayModel = {
  7. inlinePreview: { type: "none" as const },
  8. planResult: null,
  9. viewerSource: null,
  10. viewerLabelId: "codeViewer.viewCode" as const,
  11. showSummaryFileLink: false,
  12. showInput: false,
  13. showOutput: true,
  14. showKind: false,
  15. };
  16. describe("GoalToolCallBlock", () => {
  17. it("renders only goal result details without parameters or raw tool payload", () => {
  18. const html = renderToStaticMarkup(
  19. createElement(
  20. ZCodeIntlProvider,
  21. { initialLocale: "zh-CN" },
  22. createElement(GoalToolCallBlock, {
  23. toolCallNode: {
  24. toolCall: {
  25. toolId: "tool-goal-update",
  26. toolName: "GoalUpdate",
  27. kind: "GoalUpdate",
  28. title: "GoalUpdate",
  29. input: {
  30. completionEvidence: "测试已通过,文档已更新。",
  31. status: "complete",
  32. },
  33. output: JSON.stringify({
  34. goal: {
  35. sessionID: "sess_1",
  36. targetID: "target_1",
  37. objective: "完成 goal UI",
  38. summaryTitle: "完成 goal UI",
  39. status: "complete",
  40. },
  41. verification: {
  42. passed: true,
  43. reason: "所有验收项都有证据。",
  44. },
  45. }),
  46. content: "模型额外返回的 content",
  47. status: "completed",
  48. raw: {
  49. result: {
  50. content: "raw result content should be deduped",
  51. display: {
  52. summary: "raw display content",
  53. },
  54. },
  55. parentToolUseId: null,
  56. rawDebug: "raw debug payload",
  57. },
  58. },
  59. childToolCalls: [],
  60. },
  61. workspacePath: "/workspace",
  62. displayModel,
  63. viewerSource: null,
  64. rawFileSummaries: [],
  65. isRunning: false,
  66. statusLabel: "已执行",
  67. childToolList: null,
  68. forceOpen: true,
  69. canToggle: true,
  70. showIcon: true,
  71. }),
  72. ),
  73. );
  74. expect(html).toContain("GoalUpdate");
  75. expect(html).toContain("结果");
  76. expect(html).toContain("completed");
  77. expect(html).toContain("complete");
  78. expect(html).toContain("模型额外返回的 content");
  79. expect(html).toContain("所有验收项都有证据");
  80. expect(html).not.toContain("Parameters");
  81. expect(html).not.toContain("completionEvidence");
  82. expect(html).not.toContain("parentToolUseId");
  83. expect(html).not.toContain("raw debug payload");
  84. });
  85. });