fix(confidence-engine): extract raw openai response text
This commit is contained in:
@@ -239,6 +239,65 @@ describe("OpenAI reconstruction provider experiment seam", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("extracts ordered output_text parts from raw Responses output", async () => {
|
||||
const provider = createOpenAIReconstructionProvider({
|
||||
apiKey: "test-key",
|
||||
fetchImpl: vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
output: [
|
||||
{ type: "reasoning", content: [] },
|
||||
{
|
||||
type: "message",
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "output_text", text: '{"reconstruction":' },
|
||||
{ type: "output_text", text: '"result"}' },
|
||||
],
|
||||
},
|
||||
],
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
await expect(provider.generateReconstruction("prompt")).resolves.toEqual({
|
||||
response: { reconstruction: "result" },
|
||||
providerApiPath: "/v1/responses",
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves output_text convenience responses", async () => {
|
||||
const provider = createOpenAIReconstructionProvider({
|
||||
apiKey: "test-key",
|
||||
fetchImpl: vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ output_text: '{"reconstruction":"result"}' }),
|
||||
}),
|
||||
});
|
||||
|
||||
await expect(provider.generateReconstruction("prompt")).resolves.toEqual({
|
||||
response: { reconstruction: "result" },
|
||||
providerApiPath: "/v1/responses",
|
||||
});
|
||||
});
|
||||
|
||||
it("fails safely when a raw Responses result has no output text", async () => {
|
||||
const provider = createOpenAIReconstructionProvider({
|
||||
apiKey: "test-key",
|
||||
fetchImpl: vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
output: [{ type: "message", content: [{ type: "refusal" }] }],
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
await expect(provider.generateReconstruction("prompt")).rejects.toMatchObject({
|
||||
providerApiPath: "/v1/responses",
|
||||
message: expect.stringContaining("refusal: true"),
|
||||
});
|
||||
});
|
||||
|
||||
it("surfaces Responses API failures without inventing reconstruction content", async () => {
|
||||
const provider = createOpenAIReconstructionProvider({
|
||||
apiKey: "test-key",
|
||||
|
||||
Reference in New Issue
Block a user