fix(confidence-engine): log case-start failures
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mockStartCase = vi.fn();
|
||||
let warnSpy;
|
||||
let errorSpy;
|
||||
|
||||
vi.mock("@/lib/graph/orchestrator.js", () => ({
|
||||
startCase: (...args) => mockStartCase(...args),
|
||||
@@ -10,6 +12,13 @@ describe("app/api/cases/start route", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
vi.clearAllMocks();
|
||||
warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
warnSpy.mockRestore();
|
||||
errorSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("delegates request body to the orchestrator", async () => {
|
||||
@@ -78,6 +87,8 @@ describe("app/api/cases/start route", () => {
|
||||
success: true,
|
||||
reconstruction,
|
||||
});
|
||||
expect(warnSpy).not.toHaveBeenCalled();
|
||||
expect(errorSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns 400 for invalid request input", async () => {
|
||||
@@ -102,6 +113,12 @@ describe("app/api/cases/start route", () => {
|
||||
success: false,
|
||||
error: "Invalid start-case request",
|
||||
});
|
||||
expect(warnSpy).toHaveBeenCalledTimes(1);
|
||||
expect(warnSpy).toHaveBeenCalledWith(
|
||||
"[api/cases/start] error response",
|
||||
expect.objectContaining({ status: 400, error: "Invalid start-case request" }),
|
||||
);
|
||||
expect(errorSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns provider/internal failures as 5xx without stack traces", async () => {
|
||||
@@ -148,6 +165,18 @@ describe("app/api/cases/start route", () => {
|
||||
received: "undefined",
|
||||
}),
|
||||
]);
|
||||
expect(errorSpy).toHaveBeenCalledTimes(1);
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
"[api/cases/start] error response",
|
||||
expect.objectContaining({
|
||||
status: 502,
|
||||
error: "Provider unavailable",
|
||||
analysisErrors: ["reconstruction: Required"],
|
||||
validationIssues: expect.any(Array),
|
||||
rawResponse,
|
||||
}),
|
||||
);
|
||||
expect(warnSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns structured 500 on malformed JSON", async () => {
|
||||
@@ -163,5 +192,13 @@ describe("app/api/cases/start route", () => {
|
||||
success: false,
|
||||
error: "Internal server error",
|
||||
});
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
"[api/cases/start] unhandled exception",
|
||||
expect.objectContaining({
|
||||
message: "Unexpected token",
|
||||
stack: expect.any(String),
|
||||
error: expect.any(Error),
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user