fix(confidence-engine): sanitize focused reasoning outage
This commit is contained in:
@@ -9,6 +9,10 @@
|
||||
import { afterEach, beforeEach, describe, it, expect, vi } from "vitest";
|
||||
import { focusedDeconstructJsonSchema, validateFocusedDeconstructSchema } from "@/lib/graph/focused-investigation";
|
||||
|
||||
vi.mock("@/lib/supabase/api-auth.js", () => ({
|
||||
withAuthenticatedApi: (handler) => handler,
|
||||
}));
|
||||
|
||||
// ── helpers ──────────────────────────────────────────────────────────────
|
||||
|
||||
function makeMockProvider(inventedTargetNodeId) {
|
||||
@@ -389,6 +393,36 @@ describe("focused-deconstruct targetNodeId identity boundary", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("returns a sanitized 503 when the provider is unavailable", async () => {
|
||||
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
vi.doMock("@/lib/llm/provider", () => ({
|
||||
getProvider: () => ({
|
||||
generateReconstruction: vi.fn().mockRejectedValue(Object.assign(new Error(
|
||||
"Ollama /api/generate request timed out after 5 minutes",
|
||||
), { code: "PROVIDER_UNAVAILABLE", providerApiPath: "/api/generate" })),
|
||||
}),
|
||||
getProviderModelName: () => "configured-model",
|
||||
}));
|
||||
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(503);
|
||||
const json = await response.json();
|
||||
expect(json).toEqual({ error: "Reasoning service is temporarily unavailable." });
|
||||
expect(JSON.stringify(json)).not.toMatch(/ollama|generate|timed out/i);
|
||||
} finally {
|
||||
errorSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves the 502 validation-failure contract with diagnostics", async () => {
|
||||
vi.doMock("@/lib/llm/provider", () => ({
|
||||
getProvider: () => ({
|
||||
|
||||
Reference in New Issue
Block a user