experiment(confidence-engine): trace focused deconstruction failures
This commit is contained in:
@@ -328,4 +328,64 @@ describe("focused-deconstruct targetNodeId identity boundary", () => {
|
||||
expect(json.providerApiPath).toBeUndefined();
|
||||
expect(json.providerExecution).toBeUndefined();
|
||||
});
|
||||
|
||||
it("preserves the 500 provider-failure contract while logging structural diagnostics", async () => {
|
||||
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
vi.doMock("@/lib/llm/provider", () => ({
|
||||
getProvider: () => ({
|
||||
generateReconstruction: vi.fn().mockRejectedValue(Object.assign(new Error("provider failed"), {
|
||||
providerApiPath: "/v1/responses",
|
||||
statusCode: 400,
|
||||
})),
|
||||
}),
|
||||
getProviderModelName: () => "gpt-5.6-terra",
|
||||
}));
|
||||
const { POST } = await import("../app/api/focused-investigation/deconstruct/route.js");
|
||||
|
||||
try {
|
||||
const response = await POST(new Request("http://localhost/api/focused-investigation/deconstruct", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
targetNodeId: "node-id", targetLabel: "label", targetDescription: "description",
|
||||
centralStatement: "central", question: "question?", answer: "answer.",
|
||||
}),
|
||||
}));
|
||||
expect(response.status).toBe(500);
|
||||
await expect(response.json()).resolves.toEqual({ error: "provider failed" });
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
"[api/focused-investigation/deconstruct] provider failure",
|
||||
expect.objectContaining({ targetNodeId: "node-id", providerApiPath: "/v1/responses" }),
|
||||
);
|
||||
} finally {
|
||||
errorSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves the 502 validation-failure contract with diagnostics", async () => {
|
||||
vi.doMock("@/lib/llm/provider", () => ({
|
||||
getProvider: () => ({
|
||||
generateReconstruction: vi.fn().mockResolvedValue({
|
||||
response: {}, providerApiPath: "/v1/responses",
|
||||
}),
|
||||
}),
|
||||
getProviderModelName: () => "gpt-5.6-terra",
|
||||
}));
|
||||
const { POST } = await import("../app/api/focused-investigation/deconstruct/route.js");
|
||||
const response = await POST(new Request("http://localhost/api/focused-investigation/deconstruct", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
targetNodeId: "node-id", targetLabel: "label", targetDescription: "description",
|
||||
centralStatement: "central", question: "question?", answer: "answer.",
|
||||
}),
|
||||
}));
|
||||
|
||||
expect(response.status).toBe(502);
|
||||
await expect(response.json()).resolves.toMatchObject({
|
||||
success: false,
|
||||
error: "Focused deconstruction result did not match expected schema",
|
||||
targetNodeId: "node-id",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user