|
| 1 | +import { describe, it, expect } from "vitest" |
| 2 | +import { formatContentBlockToMarkdown, ExtendedContentBlock } from "../export-markdown" |
| 3 | + |
| 4 | +describe("export-markdown", () => { |
| 5 | + describe("formatContentBlockToMarkdown", () => { |
| 6 | + it("should format text blocks", () => { |
| 7 | + const block = { type: "text", text: "Hello, world!" } as ExtendedContentBlock |
| 8 | + expect(formatContentBlockToMarkdown(block)).toBe("Hello, world!") |
| 9 | + }) |
| 10 | + |
| 11 | + it("should format image blocks", () => { |
| 12 | + const block = { |
| 13 | + type: "image", |
| 14 | + source: { type: "base64", media_type: "image/png", data: "data" }, |
| 15 | + } as ExtendedContentBlock |
| 16 | + expect(formatContentBlockToMarkdown(block)).toBe("[Image]") |
| 17 | + }) |
| 18 | + |
| 19 | + it("should format tool_use blocks with string input", () => { |
| 20 | + const block = { type: "tool_use", name: "read_file", id: "123", input: "file.txt" } as ExtendedContentBlock |
| 21 | + expect(formatContentBlockToMarkdown(block)).toBe("[Tool Use: read_file]\nfile.txt") |
| 22 | + }) |
| 23 | + |
| 24 | + it("should format tool_use blocks with object input", () => { |
| 25 | + const block = { |
| 26 | + type: "tool_use", |
| 27 | + name: "read_file", |
| 28 | + id: "123", |
| 29 | + input: { path: "file.txt", line_count: 10 }, |
| 30 | + } as ExtendedContentBlock |
| 31 | + expect(formatContentBlockToMarkdown(block)).toBe("[Tool Use: read_file]\nPath: file.txt\nLine_count: 10") |
| 32 | + }) |
| 33 | + |
| 34 | + it("should format tool_result blocks with string content", () => { |
| 35 | + const block = { type: "tool_result", tool_use_id: "123", content: "File content" } as ExtendedContentBlock |
| 36 | + expect(formatContentBlockToMarkdown(block)).toBe("[Tool]\nFile content") |
| 37 | + }) |
| 38 | + |
| 39 | + it("should format tool_result blocks with error", () => { |
| 40 | + const block = { |
| 41 | + type: "tool_result", |
| 42 | + tool_use_id: "123", |
| 43 | + content: "Error message", |
| 44 | + is_error: true, |
| 45 | + } as ExtendedContentBlock |
| 46 | + expect(formatContentBlockToMarkdown(block)).toBe("[Tool (Error)]\nError message") |
| 47 | + }) |
| 48 | + |
| 49 | + it("should format tool_result blocks with array content", () => { |
| 50 | + const block = { |
| 51 | + type: "tool_result", |
| 52 | + tool_use_id: "123", |
| 53 | + content: [ |
| 54 | + { type: "text", text: "Line 1" }, |
| 55 | + { type: "text", text: "Line 2" }, |
| 56 | + ], |
| 57 | + } as ExtendedContentBlock |
| 58 | + expect(formatContentBlockToMarkdown(block)).toBe("[Tool]\nLine 1\nLine 2") |
| 59 | + }) |
| 60 | + |
| 61 | + it("should format reasoning blocks", () => { |
| 62 | + const block = { type: "reasoning", text: "Let me think about this..." } as ExtendedContentBlock |
| 63 | + expect(formatContentBlockToMarkdown(block)).toBe("[Reasoning]\nLet me think about this...") |
| 64 | + }) |
| 65 | + |
| 66 | + it("should skip thoughtSignature blocks", () => { |
| 67 | + const block = { type: "thoughtSignature" } as ExtendedContentBlock |
| 68 | + expect(formatContentBlockToMarkdown(block)).toBe("") |
| 69 | + }) |
| 70 | + |
| 71 | + it("should handle unexpected content types", () => { |
| 72 | + const block = { type: "unknown_type" as const } as any |
| 73 | + expect(formatContentBlockToMarkdown(block)).toBe("[Unexpected content type: unknown_type]") |
| 74 | + }) |
| 75 | + }) |
| 76 | +}) |
0 commit comments