conversationShareToolSnapshot.test.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { describe, expect, it } from "vitest";
  2. import { buildConversationSharePublicProjection } from "../src/conversation-share/conversationSharePublicProjection.js";
  3. import type { ConversationRow } from "@zcode/shared/zcode-protocol-v4";
  4. const rows: ConversationRow[] = [
  5. {
  6. kind: "turnHeader",
  7. rowId: 1,
  8. turnId: "t",
  9. productTurnId: "p",
  10. createdAt: 1,
  11. createdAtSeq: 1,
  12. origin: "userInput",
  13. state: "completedSuccess",
  14. startedAt: 1,
  15. },
  16. {
  17. kind: "toolCall",
  18. rowId: 2,
  19. turnId: "t",
  20. entityId: "e",
  21. productTurnId: "p",
  22. createdAt: 2,
  23. createdAtSeq: 2,
  24. toolCallId: "tool",
  25. toolName: "Bash",
  26. status: "success",
  27. inputText: "{}",
  28. input: { command: "echo hello" },
  29. output: {
  30. text: "hello",
  31. display: {
  32. kind: "bash_output",
  33. output: "hello",
  34. truncated: false,
  35. outputPath: "/Users/dev/private.log",
  36. },
  37. },
  38. },
  39. ];
  40. describe("public tool snapshots", () => {
  41. it("keeps typed result facts outside the legacy row and strips local output paths", () => {
  42. const result = buildConversationSharePublicProjection({
  43. rows,
  44. selectedProductTurnIds: ["p"],
  45. toolPresentation: true,
  46. });
  47. expect(result.contentBlocks?.[0]).toMatchObject({
  48. type: "tool-presentation",
  49. fallback_row_id: 2,
  50. payload: { display: { kind: "bash_output", output: "hello", truncated: false } },
  51. });
  52. expect(JSON.stringify(result)).not.toContain("private.log");
  53. });
  54. it("does not change old-server payloads", () =>
  55. expect(
  56. buildConversationSharePublicProjection({ rows, selectedProductTurnIds: ["p"] }).contentBlocks,
  57. ).toBeUndefined());
  58. });