fix(confidence-engine): sanitize reasoning error responses
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mockSynthesize = vi.fn();
|
||||
|
||||
@@ -11,6 +11,10 @@ vi.mock("@/lib/llm/provider.js", () => ({
|
||||
getProviderModelName: () => "gpt-5.6-terra",
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/supabase/api-auth.js", () => ({
|
||||
withAuthenticatedApi: (handler) => handler,
|
||||
}));
|
||||
|
||||
describe("POST /api/cases/overview provider routing", () => {
|
||||
beforeEach(() => mockSynthesize.mockClear());
|
||||
|
||||
@@ -26,4 +30,36 @@ describe("POST /api/cases/overview provider routing", () => {
|
||||
expect(response.status).toBe(200);
|
||||
expect(mockSynthesize.mock.calls[0][1]).toMatchObject({ modelName: "gpt-5.6-terra" });
|
||||
});
|
||||
|
||||
it("sanitizes provider failure details", async () => {
|
||||
const error = Object.assign(
|
||||
new Error("Ollama /api/generate returned 500 from private host"),
|
||||
{ statusCode: 502 },
|
||||
);
|
||||
mockSynthesize.mockImplementationOnce(async () => {
|
||||
throw error;
|
||||
});
|
||||
|
||||
const { POST } = await import("@/app/api/cases/overview/route.js");
|
||||
const response = await POST(new Request("http://localhost/api/cases/overview", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ situationGraph: { nodes: [], edges: [] } }),
|
||||
}));
|
||||
|
||||
expect(response.status).toBe(502);
|
||||
const rawData = await response.text();
|
||||
const data = JSON.parse(rawData);
|
||||
|
||||
expect(data.success).toBe(false);
|
||||
expect(data.stage).toBe("provider");
|
||||
expect(data).toEqual({
|
||||
success: false,
|
||||
stage: "provider",
|
||||
error: "Reasoning request could not be completed.",
|
||||
});
|
||||
|
||||
// Prove raw provider diagnostics are NOT exposed at the route boundary
|
||||
expect(rawData).not.toContain(error.message);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user