import { afterEach, describe, expect, it, vi } from "vitest"; import { generateLlmText } from "./llm-client"; afterEach(() => { vi.restoreAllMocks(); }); describe("generateLlmText", () => { it("requests JSON object responses from OpenAI-compatible providers when asked", async () => { const fetchMock = vi.spyOn(globalThis, "fetch").mockResolvedValueOnce( new Response( JSON.stringify({ choices: [ { message: { content: '{"assistantMessage":"Connected","boardAction":{"type":"none","workPackageId":null}}', }, }, ], }), { status: 200, headers: { "content-type": "application/json" }, }, ), ); await generateLlmText({ config: { apiKey: "key", baseUrl: "https://api.example.com/v1", model: "gpt-test", }, systemPrompt: "Return JSON only.", userPrompt: "Say hello.", responseFormat: "json_object", }); const [, init] = fetchMock.mock.calls[0] ?? []; const body = JSON.parse(String(init?.body ?? "{}")) as { response_format?: { type?: string }; }; expect(body.response_format?.type).toBe("json_object"); }); });