conversationShareToolPresentation.test.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. conversationShareContentBlockSchema,
  4. decodeConversationShareContentBlocks,
  5. } from "../src/conversation-share-content.js";
  6. const block = {
  7. id: "share-content-1",
  8. type: "tool-presentation",
  9. version: 1,
  10. product_turn_id: "share-product-turn-1",
  11. fallback_row_id: 2,
  12. captured_at: 1,
  13. resource_ids: [],
  14. payload: { display: { kind: "bash_output", output: "hello", truncated: false } },
  15. };
  16. describe("share tool presentation contract", () => {
  17. it("accepts a typed tool snapshot and leaves the V1 row independent", () =>
  18. expect(conversationShareContentBlockSchema.safeParse(block).success).toBe(true));
  19. it("rejects runtime output paths, plugin UI and raw metadata", () => {
  20. for (const payload of [
  21. {
  22. display: {
  23. kind: "bash_output",
  24. output: "hello",
  25. truncated: false,
  26. outputPath: "/Users/dev/log",
  27. },
  28. },
  29. { raw: {} },
  30. {
  31. display: {
  32. kind: "mcp_tool",
  33. serverName: "example",
  34. toolName: "test",
  35. ui: { resourceUri: "ui://app" },
  36. },
  37. },
  38. ])
  39. expect(conversationShareContentBlockSchema.safeParse({ ...block, payload }).success).toBe(
  40. false,
  41. );
  42. });
  43. it("rejects unclosed image references and falls back on unknown versions", () => {
  44. expect(
  45. conversationShareContentBlockSchema.safeParse({
  46. ...block,
  47. payload: { images: [{ resource_id: "share-artifact-1", mime_type: "image/png" }] },
  48. }).success,
  49. ).toBe(false);
  50. expect(decodeConversationShareContentBlocks([{ ...block, version: 99 }])).toEqual([]);
  51. });
  52. });