executeToolCallBlock.test.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 { ExecuteToolCallBlock } from "../src/ToolCallBlocks/renderers/execute.js";
  6. describe("ExecuteToolCallBlock", () => {
  7. it("renders execution results from structured output instead of raw JSON", () => {
  8. const html = renderToStaticMarkup(
  9. createElement(
  10. ZCodeIntlProvider,
  11. { initialLocale: "zh-CN" },
  12. createElement(ExecuteToolCallBlock, {
  13. toolCallNode: {
  14. toolCall: {
  15. toolId: "tool-execute",
  16. kind: "execute",
  17. title: "运行 npm install",
  18. input: {
  19. command: "npm install",
  20. },
  21. output: {
  22. stdout: "packages installed successfully",
  23. exitCode: 0,
  24. },
  25. status: "completed",
  26. raw: {
  27. rawOutput: {
  28. stdout: "packages installed successfully",
  29. exitCode: 0,
  30. },
  31. },
  32. },
  33. childToolCalls: [],
  34. },
  35. workspacePath: "/workspace",
  36. displayModel: {
  37. inlinePreview: { type: "none" },
  38. planResult: null,
  39. viewerSource: null,
  40. viewerLabelId: "codeViewer.viewCode",
  41. showSummaryFileLink: true,
  42. showInput: false,
  43. showOutput: true,
  44. showKind: false,
  45. },
  46. viewerSource: null,
  47. rawFileSummaries: [],
  48. isRunning: false,
  49. statusLabel: "Completed",
  50. childToolList: null,
  51. forceOpen: true,
  52. canToggle: true,
  53. showIcon: true,
  54. }),
  55. ),
  56. );
  57. expect(html).toContain("输出结果");
  58. expect(html).toContain("packages installed successfully");
  59. expect(html).not.toContain(""stdout"");
  60. expect(html).not.toContain(""exitCode"");
  61. });
  62. });