|
| 1 | +import { describe, expect, test } from "bun:test" |
| 2 | + |
| 3 | +import { toolOutputText } from "./serialize" |
| 4 | + |
| 5 | +describe("toolOutputText", () => { |
| 6 | + test("text + error-text pass through", () => { |
| 7 | + expect(toolOutputText({ type: "text", value: "plain" })).toBe("plain") |
| 8 | + expect(toolOutputText({ type: "error-text", value: "boom" })).toBe("boom") |
| 9 | + }) |
| 10 | + |
| 11 | + test("json + error-json stringify", () => { |
| 12 | + expect(toolOutputText({ type: "json", value: { a: 1 } })).toBe('{"a":1}') |
| 13 | + expect(toolOutputText({ type: "error-json", value: { err: true } })).toBe( |
| 14 | + '{"err":true}', |
| 15 | + ) |
| 16 | + }) |
| 17 | + |
| 18 | + test("execution-denied uses the reason, with a fallback", () => { |
| 19 | + expect(toolOutputText({ type: "execution-denied", reason: "nope" })).toBe("nope") |
| 20 | + expect(toolOutputText({ type: "execution-denied" })).toBe("(execution denied)") |
| 21 | + }) |
| 22 | + |
| 23 | + test("content arrays join text items and label non-text ones", () => { |
| 24 | + expect( |
| 25 | + toolOutputText({ |
| 26 | + type: "content", |
| 27 | + value: [ |
| 28 | + { type: "text", text: "first" }, |
| 29 | + { type: "media", data: "AAAA", mediaType: "image/png" }, |
| 30 | + { type: "text", text: "last" }, |
| 31 | + ], |
| 32 | + }), |
| 33 | + ).toBe("first\n[media]\nlast") |
| 34 | + }) |
| 35 | +}) |
0 commit comments