fix(confidence-engine): honor openai alternate output schema

This commit is contained in:
2026-09-07 10:18:41 +01:00
parent bb3082d633
commit 0eadef6e3b
3 changed files with 66 additions and 6 deletions
+47
View File
@@ -9,6 +9,7 @@ import {
reconstructionJsonSchema,
} from "@/lib/llm/provider.js";
import { reconstructionV2Schema } from "@/lib/reconstruction/schema.js";
import { focusedDeconstructJsonSchema } from "@/lib/graph/focused-investigation.js";
import { z } from "zod";
describe("OllamaLlmProvider chat capability detection", () => {
@@ -303,6 +304,52 @@ describe("OpenAI reconstruction provider experiment seam", () => {
});
});
it("projects a caller-supplied focused schema for OpenAI structured output", async () => {
const fetchSpy = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({
output_text: JSON.stringify({
targetNodeId: "target",
observations: [],
uncertainties: [],
assumptions: [],
relationships: [],
possibleFollowUpQuestions: [],
}),
}),
});
const provider = createOpenAIReconstructionProvider({ apiKey: "test-key", fetchImpl: fetchSpy });
const result = await provider.generateReconstruction(
"focused prompt",
"gpt-5.6-terra",
focusedDeconstructJsonSchema,
);
const request = JSON.parse(fetchSpy.mock.calls[0][1].body);
const schema = request.text.format.schema;
expect(schema.required).toEqual([
"targetNodeId",
"observations",
"uncertainties",
"assumptions",
"relationships",
"possibleFollowUpQuestions",
]);
expect(Object.keys(schema.properties)).toEqual(schema.required);
expect(schema.properties).toHaveProperty("targetNodeId");
expect(schema.properties).not.toHaveProperty("reconstruction");
expect(schema.properties).not.toHaveProperty("inputClassification");
expect(result.response).toEqual({
targetNodeId: "target",
observations: [],
uncertainties: [],
assumptions: [],
relationships: [],
possibleFollowUpQuestions: [],
});
});
it("extracts ordered output_text parts from raw Responses output", async () => {
const provider = createOpenAIReconstructionProvider({
apiKey: "test-key",