import { describe, expect, test } from "vitest"; import { repairCustomWidgetToolInput } from "./assistant-tool-input-repair"; describe("repairCustomWidgetToolInput", () => { test("repairs literal newlines generated inside a multiline Custom JSX template", () => { const input = `{"definition":{"template":" {data.fixtures?.length} fixtures "}}`; const repaired = repairCustomWidgetToolInput({ toolName: "customWidget_previewCreate", input }); expect(repaired).not.toBeNull(); expect(JSON.parse(repaired?.input ?? "")).toEqual({ definition: { template: "\n {data.fixtures?.length} fixtures\n" }, }); }); test("does not alter unrelated tools or guess at truncated JSON", () => { expect(repairCustomWidgetToolInput({ toolName: "app_create", input: '{"name":"Wiki\npedia"}' })).toBeNull(); expect( repairCustomWidgetToolInput({ toolName: "customWidget_create", input: '{"template":"broken' }), ).toBeNull(); }); });