fix(confidence-engine): supply focused deconstruction schema

This commit is contained in:
2026-09-06 16:21:26 +01:00
parent 188dd04ab9
commit a93b6798cc
6 changed files with 110 additions and 17 deletions
+26 -5
View File
@@ -5,6 +5,7 @@ import {
createOpenAIReconstructionProvider,
getProvider,
normaliseOpenAITransportResponse,
reconstructionJsonSchema,
} from "@/lib/llm/provider.js";
import { reconstructionV2Schema } from "@/lib/reconstruction/schema.js";
import { z } from "zod";
@@ -40,11 +41,7 @@ describe("OllamaLlmProvider chat capability detection", () => {
messages: [{ role: "user", content: "prompt" }],
stream: false,
});
expect(chatRequest.format).toBeTypeOf("object");
expect(chatRequest.format).not.toBe("json");
const formatText = JSON.stringify(chatRequest.format);
expect(formatText).toContain("relationship");
expect(formatText).toContain("evidenceType");
expect(chatRequest.format).toEqual(reconstructionJsonSchema);
expect(result).toMatchObject({
response: {},
providerApiPath: "/api/chat",
@@ -63,6 +60,30 @@ describe("OllamaLlmProvider chat capability detection", () => {
}
});
it("uses a supplied structured-output schema for the chat request", async () => {
const originalBaseUrl = process.env.OLLAMA_BASE_URL;
const outputSchema = {
type: "object",
properties: { focused: { type: "string" } },
required: ["focused"],
};
const fetchSpy = vi.fn()
.mockResolvedValueOnce({ ok: true, text: async () => "" })
.mockResolvedValueOnce({ ok: true, json: async () => ({ message: { content: "{}" } }) });
vi.stubGlobal("fetch", fetchSpy);
process.env.OLLAMA_BASE_URL = "http://ollama.test";
try {
__resetChatSupportForTests();
await getProvider().generateReconstruction("prompt", "configured-model", outputSchema);
expect(JSON.parse(fetchSpy.mock.calls[1][1].body).format).toEqual(outputSchema);
} finally {
vi.unstubAllGlobals();
if (originalBaseUrl === undefined) delete process.env.OLLAMA_BASE_URL;
else process.env.OLLAMA_BASE_URL = originalBaseUrl;
}
});
it("reports chat-skipped generate fallback execution", async () => {
const originalBaseUrl = process.env.OLLAMA_BASE_URL;
const fetchSpy = vi.fn()