fix(confidence-engine): expose failed provider path

This commit is contained in:
2026-09-05 17:00:33 +01:00
parent 677f5e5757
commit dabd9e2245
9 changed files with 81 additions and 6 deletions
+3
View File
@@ -138,6 +138,7 @@ describe("app/api/cases/start route", () => {
received: "undefined",
},
],
providerApiPath: "/api/generate",
rawResponse,
});
@@ -165,6 +166,7 @@ describe("app/api/cases/start route", () => {
received: "undefined",
}),
]);
expect(body.providerApiPath).toBe("/api/generate");
expect(errorSpy).toHaveBeenCalledTimes(1);
expect(errorSpy).toHaveBeenCalledWith(
"[api/cases/start] error response",
@@ -173,6 +175,7 @@ describe("app/api/cases/start route", () => {
error: "Provider unavailable",
analysisErrors: ["reconstruction: Required"],
validationIssues: expect.any(Array),
providerApiPath: "/api/generate",
rawResponse,
}),
);
+17
View File
@@ -566,6 +566,23 @@ describe("lib/graph/orchestrator startCase", () => {
expect(result.rawResponse).toHaveLength(2501);
});
it("preserves an attempted provider API path on analysis failure", async () => {
mockAnalyseScenario.mockResolvedValue({
success: false,
error: "Provider failed",
providerApiPath: "/api/chat",
});
const { startCase } = await import("@/lib/graph/orchestrator.js");
const result = await startCase({ scenario: "Scenario text" });
expect(result).toMatchObject({
success: false,
statusCode: 502,
providerApiPath: "/api/chat",
});
});
it("returns null selectedQuestion when neither analysis nor graph path yields a question", async () => {
mockAnalyseScenario.mockResolvedValue(
makeAnalysisResult({
+21
View File
@@ -29,4 +29,25 @@ describe("OllamaLlmProvider chat capability detection", () => {
else process.env.OLLAMA_BASE_URL = originalBaseUrl;
}
});
it("reports the actually attempted generate path when generation fails", async () => {
const originalBaseUrl = process.env.OLLAMA_BASE_URL;
const fetchSpy = vi.fn()
.mockResolvedValueOnce({ ok: false, status: 501, body: { consume: vi.fn() } })
.mockResolvedValueOnce({ ok: false, status: 500, text: async () => "failure" });
vi.stubGlobal("fetch", fetchSpy);
process.env.OLLAMA_BASE_URL = "http://ollama.test";
try {
const { getProvider } = await import("@/lib/llm/provider.js");
await expect(
getProvider().generateReconstruction("prompt", "configured-model"),
).rejects.toMatchObject({ providerApiPath: "/api/generate" });
expect(fetchSpy.mock.calls[1][0]).toBe("http://ollama.test/api/generate");
} finally {
vi.unstubAllGlobals();
if (originalBaseUrl === undefined) delete process.env.OLLAMA_BASE_URL;
else process.env.OLLAMA_BASE_URL = originalBaseUrl;
}
});
});
@@ -112,6 +112,22 @@ describe("normaliseAnalysisResponse", () => {
});
describe("analyseScenario compatibility", () => {
it("preserves an attempted provider API path on provider failure", async () => {
const providerError = new Error("Provider failed");
providerError.providerApiPath = "/api/chat";
mockGenerateReconstruction.mockRejectedValue(providerError);
const { analyseScenario } = await import("@/lib/analysis.js");
const result = await analyseScenario("Scenario text", {
promptVersion: "v0.3",
});
expect(result).toMatchObject({
success: false,
providerApiPath: "/api/chat",
});
});
it("succeeds when the only mismatch is null evidence source", async () => {
mockGenerateReconstruction.mockResolvedValue({
inputClassification: {