toolPresentationParity.test.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it } from "vitest";
  4. import { ToolPresentation } from "@/ToolCallBlocks/ToolPresentation.js";
  5. import { ToolCallBlock } from "@/ToolCallBlocks.js";
  6. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  7. import { toolCallRowToLegacyNode } from "@/v4/toolCallRowAdapter.js";
  8. import type { ToolCallRow } from "@zcode/shared/zcode-protocol-v4";
  9. const cases = [
  10. ["WebFetch", { url: "https://example.com/paper", prompt: "hidden extraction" }, "Fetch"],
  11. ["WebSearch", { query: "test query" }, "Search"],
  12. ["Read", { file_path: "/Users/dev/example.ts" }, "Read"],
  13. ["Bash", { command: "echo hello" }, "Terminal"],
  14. ["Skill", { skill: "test-skill" }, "Skill"],
  15. ["Agent", { subagent_type: "researcher", description: "Investigate" }, "researcher"],
  16. ] as const;
  17. describe("common readonly tool renderer", () => {
  18. for (const [toolName, input, label] of cases)
  19. it(`matches App ${toolName} summary`, () => {
  20. const row: ToolCallRow = {
  21. kind: "toolCall",
  22. rowId: 1,
  23. turnId: "t",
  24. toolCallId: "tool",
  25. toolName,
  26. status: "success",
  27. inputText: JSON.stringify(input),
  28. input,
  29. createdAt: 1,
  30. createdAtSeq: 1,
  31. };
  32. const node = toolCallRowToLegacyNode(row);
  33. const render = (component: typeof ToolPresentation | typeof ToolCallBlock) =>
  34. renderToStaticMarkup(
  35. createElement(
  36. ZCodeIntlProvider,
  37. { initialLocale: "en-US" },
  38. createElement(component, {
  39. toolCallNode: node,
  40. workspacePath: "",
  41. showTodoToolCalls: false,
  42. }),
  43. ),
  44. );
  45. const app = render(ToolCallBlock);
  46. const share = render(ToolPresentation);
  47. expect(app).toContain(label);
  48. expect(share).toContain(label);
  49. if (toolName === "WebFetch") {
  50. expect(share).toContain("https://example.com/paper");
  51. expect(share).not.toContain("hidden extraction");
  52. expect(share).not.toContain("aria-expanded");
  53. }
  54. });
  55. });