fix(confidence-engine): sanitize reasoning error responses
This commit is contained in:
@@ -13,6 +13,10 @@ vi.mock("@/lib/llm/provider.js", () => ({
|
||||
getProviderModelName: () => "gpt-5.6-terra",
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/supabase/api-auth.js", () => ({
|
||||
withAuthenticatedApi: (handler) => handler,
|
||||
}));
|
||||
|
||||
// ── Helpers ─────────────────────────────────────────────────
|
||||
|
||||
function makeValidGraph() {
|
||||
@@ -110,10 +114,13 @@ describe("POST /api/cases/synthesis — error cases", () => {
|
||||
});
|
||||
|
||||
it("domain seam throws with statusCode → mapped status", async () => {
|
||||
mockSynthesize.mockRejectedValue(new Error("Provider failed"));
|
||||
// Add statusCode property to the error object after creation
|
||||
const err = Object.assign(new Error("Provider failed"), { statusCode: 502 });
|
||||
mockSynthesize.mockRejectedValue(err);
|
||||
const err = Object.assign(
|
||||
new Error("Ollama /api/generate returned 500 from private host"),
|
||||
{ statusCode: 502 },
|
||||
);
|
||||
mockSynthesize.mockImplementationOnce(async () => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
const { POST } = await import("@/app/api/cases/synthesis/route.js");
|
||||
const res = await POST(makeRequest({ situationGraph: makeValidGraph() }));
|
||||
@@ -122,10 +129,17 @@ describe("POST /api/cases/synthesis — error cases", () => {
|
||||
const data = await res.json();
|
||||
expect(data.success).toBe(false);
|
||||
expect(data.stage).toBe("provider");
|
||||
expect(data).toEqual({
|
||||
success: false,
|
||||
stage: "provider",
|
||||
error: "Reasoning request could not be completed.",
|
||||
});
|
||||
});
|
||||
|
||||
it("domain seam throws without statusCode → 500", async () => {
|
||||
mockSynthesize.mockRejectedValue(new Error("unknown error"));
|
||||
mockSynthesize.mockImplementationOnce(async () => {
|
||||
throw new Error("unknown error");
|
||||
});
|
||||
|
||||
const { POST } = await import("@/app/api/cases/synthesis/route.js");
|
||||
const res = await POST(makeRequest({ situationGraph: makeValidGraph() }));
|
||||
@@ -138,7 +152,9 @@ describe("POST /api/cases/synthesis — error cases", () => {
|
||||
|
||||
it("domain seam throws 400 → mapped to 400", async () => {
|
||||
const err = Object.assign(new Error("Invalid input"), { statusCode: 400 });
|
||||
mockSynthesize.mockRejectedValue(err);
|
||||
mockSynthesize.mockImplementationOnce(async () => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
const { POST } = await import("@/app/api/cases/synthesis/route.js");
|
||||
const res = await POST(makeRequest({ situationGraph: makeValidGraph() }));
|
||||
|
||||
Reference in New Issue
Block a user