30 lines
1.3 KiB
TypeScript
30 lines
1.3 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { presentToolDefinitions, withStructuredContent } from "./tool-presentation";
|
|
|
|
describe("LLM tool presentation", () => {
|
|
test("marks read-only, destructive and open-world tools accurately", () => {
|
|
const input = ["get_product_detail", "delete_category", "upload_product_image_from_url"].map((name) => ({
|
|
name,
|
|
inputSchema: { type: "object" as const },
|
|
}));
|
|
const tools = presentToolDefinitions(input);
|
|
|
|
expect(tools[0]?.annotations).toMatchObject({ readOnlyHint: true, idempotentHint: true, destructiveHint: false });
|
|
expect(tools[1]?.annotations).toMatchObject({ readOnlyHint: false, destructiveHint: true });
|
|
expect(tools[2]?.annotations).toMatchObject({ readOnlyHint: false, openWorldHint: true });
|
|
});
|
|
|
|
test("adds structured JSON without removing the existing text content", () => {
|
|
const result = { content: [{ type: "text" as const, text: '{"success":true,"count":2}' }] };
|
|
expect(withStructuredContent(result)).toEqual({
|
|
...result,
|
|
structuredContent: { success: true, count: 2 },
|
|
});
|
|
});
|
|
|
|
test("leaves plain text responses untouched", () => {
|
|
const result = { content: [{ type: "text" as const, text: "Connection successful!" }] };
|
|
expect(withStructuredContent(result)).toEqual(result);
|
|
});
|
|
});
|