import { describe, expect, it } from "vitest"; import { AppError } from "../src/lib/errors.js"; import { parseExampleEchoToolInput, parseExampleSummaryPromptInput, renderExampleSummaryPrompt, runExampleEchoTool, } from "../src/capabilities/index.js"; describe("example capability contracts", () => { it("accepts valid tool input and applies uppercase transform", () => { expect( parseExampleEchoToolInput({ message: " hello team ", uppercase: true }), ).toEqual({ message: "hello team", uppercase: true, }); expect(runExampleEchoTool({ message: "hello", uppercase: true })).toEqual({ output: "HELLO", }); }); it("rejects invalid tool input shapes", () => { expect(() => parseExampleEchoToolInput("bad-input")).toThrow(AppError); expect(() => parseExampleEchoToolInput({ message: "" })).toThrow( "message must not be empty", ); expect(() => parseExampleEchoToolInput({ message: "valid", uppercase: "yes" }), ).toThrow("uppercase must be a boolean when provided"); }); it("accepts valid prompt input and renders generic prompt text", () => { expect( parseExampleSummaryPromptInput({ topic: "event-driven systems", audience: "new contributors", }), ).toEqual({ topic: "event-driven systems", audience: "new contributors", }); expect( renderExampleSummaryPrompt({ topic: "API design", }), ).toBe("Write a concise summary about API design."); }); it("rejects invalid prompt input shapes", () => { expect(() => parseExampleSummaryPromptInput(null)).toThrow(AppError); expect(() => parseExampleSummaryPromptInput({ topic: 42 })).toThrow( "topic must be a string", ); expect(() => parseExampleSummaryPromptInput({ topic: "valid topic", audience: " ", }), ).toThrow("audience must not be empty"); }); });