chore(confidence-engine): expose reconstruction fallback path
This commit is contained in:
@@ -139,6 +139,12 @@ describe("app/api/cases/start route", () => {
|
||||
},
|
||||
],
|
||||
providerApiPath: "/api/generate",
|
||||
providerExecution: {
|
||||
chatCapabilityDetected: false,
|
||||
chatRequestAttempted: false,
|
||||
chatRequestSucceeded: false,
|
||||
generateRequestAttempted: true,
|
||||
},
|
||||
rawResponse,
|
||||
});
|
||||
|
||||
@@ -167,6 +173,12 @@ describe("app/api/cases/start route", () => {
|
||||
}),
|
||||
]);
|
||||
expect(body.providerApiPath).toBe("/api/generate");
|
||||
expect(body.providerExecution).toEqual({
|
||||
chatCapabilityDetected: false,
|
||||
chatRequestAttempted: false,
|
||||
chatRequestSucceeded: false,
|
||||
generateRequestAttempted: true,
|
||||
});
|
||||
expect(errorSpy).toHaveBeenCalledTimes(1);
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
"[api/cases/start] error response",
|
||||
@@ -176,6 +188,12 @@ describe("app/api/cases/start route", () => {
|
||||
analysisErrors: ["reconstruction: Required"],
|
||||
validationIssues: expect.any(Array),
|
||||
providerApiPath: "/api/generate",
|
||||
providerExecution: {
|
||||
chatCapabilityDetected: false,
|
||||
chatRequestAttempted: false,
|
||||
chatRequestSucceeded: false,
|
||||
generateRequestAttempted: true,
|
||||
},
|
||||
rawResponse,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -567,10 +567,17 @@ describe("lib/graph/orchestrator startCase", () => {
|
||||
});
|
||||
|
||||
it("preserves an attempted provider API path on analysis failure", async () => {
|
||||
const providerExecution = {
|
||||
chatCapabilityDetected: true,
|
||||
chatRequestAttempted: true,
|
||||
chatRequestSucceeded: false,
|
||||
generateRequestAttempted: true,
|
||||
};
|
||||
mockAnalyseScenario.mockResolvedValue({
|
||||
success: false,
|
||||
error: "Provider failed",
|
||||
providerApiPath: "/api/chat",
|
||||
providerExecution,
|
||||
});
|
||||
const { startCase } = await import("@/lib/graph/orchestrator.js");
|
||||
|
||||
@@ -580,6 +587,7 @@ describe("lib/graph/orchestrator startCase", () => {
|
||||
success: false,
|
||||
statusCode: 502,
|
||||
providerApiPath: "/api/chat",
|
||||
providerExecution,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { __resetChatSupportForTests, getProvider } from "@/lib/llm/provider.js";
|
||||
|
||||
describe("OllamaLlmProvider chat capability detection", () => {
|
||||
it("uses the configured model for the chat probe and keeps the chat path", async () => {
|
||||
@@ -13,7 +14,7 @@ describe("OllamaLlmProvider chat capability detection", () => {
|
||||
process.env.OLLAMA_BASE_URL = "http://ollama.test";
|
||||
|
||||
try {
|
||||
const { getProvider } = await import("@/lib/llm/provider.js");
|
||||
__resetChatSupportForTests();
|
||||
const result = await getProvider().generateReconstruction("prompt", "configured-model");
|
||||
|
||||
expect(JSON.parse(fetchSpy.mock.calls[0][1].body)).toMatchObject({
|
||||
@@ -37,6 +38,12 @@ describe("OllamaLlmProvider chat capability detection", () => {
|
||||
expect(result).toMatchObject({
|
||||
response: {},
|
||||
providerApiPath: "/api/chat",
|
||||
providerExecution: {
|
||||
chatCapabilityDetected: true,
|
||||
chatRequestAttempted: true,
|
||||
chatRequestSucceeded: true,
|
||||
generateRequestAttempted: false,
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
vi.unstubAllGlobals();
|
||||
@@ -45,7 +52,7 @@ describe("OllamaLlmProvider chat capability detection", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("reports the actually attempted generate path when generation fails", async () => {
|
||||
it("reports chat-skipped generate fallback execution", async () => {
|
||||
const originalBaseUrl = process.env.OLLAMA_BASE_URL;
|
||||
const fetchSpy = vi.fn()
|
||||
.mockResolvedValueOnce({ ok: false, status: 501, body: { consume: vi.fn() } })
|
||||
@@ -54,10 +61,18 @@ describe("OllamaLlmProvider chat capability detection", () => {
|
||||
process.env.OLLAMA_BASE_URL = "http://ollama.test";
|
||||
|
||||
try {
|
||||
const { getProvider } = await import("@/lib/llm/provider.js");
|
||||
__resetChatSupportForTests();
|
||||
await expect(
|
||||
getProvider().generateReconstruction("prompt", "configured-model"),
|
||||
).rejects.toMatchObject({ providerApiPath: "/api/generate" });
|
||||
).rejects.toMatchObject({
|
||||
providerApiPath: "/api/generate",
|
||||
providerExecution: {
|
||||
chatCapabilityDetected: false,
|
||||
chatRequestAttempted: false,
|
||||
chatRequestSucceeded: false,
|
||||
generateRequestAttempted: true,
|
||||
},
|
||||
});
|
||||
expect(fetchSpy.mock.calls[1][0]).toBe("http://ollama.test/api/generate");
|
||||
} finally {
|
||||
vi.unstubAllGlobals();
|
||||
@@ -65,4 +80,35 @@ describe("OllamaLlmProvider chat capability detection", () => {
|
||||
else process.env.OLLAMA_BASE_URL = originalBaseUrl;
|
||||
}
|
||||
});
|
||||
|
||||
it("reports chat-attempt-failed generate fallback execution", async () => {
|
||||
const originalBaseUrl = process.env.OLLAMA_BASE_URL;
|
||||
const fetchSpy = vi.fn()
|
||||
.mockResolvedValueOnce({ ok: true, body: { consume: vi.fn() } })
|
||||
.mockResolvedValueOnce({ ok: false, 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 {
|
||||
__resetChatSupportForTests();
|
||||
await expect(
|
||||
getProvider().generateReconstruction("prompt", "configured-model"),
|
||||
).rejects.toMatchObject({
|
||||
providerApiPath: "/api/generate",
|
||||
providerExecution: {
|
||||
chatCapabilityDetected: true,
|
||||
chatRequestAttempted: true,
|
||||
chatRequestSucceeded: false,
|
||||
generateRequestAttempted: true,
|
||||
},
|
||||
});
|
||||
expect(fetchSpy.mock.calls[1][0]).toBe("http://ollama.test/api/chat");
|
||||
expect(fetchSpy.mock.calls[2][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;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -115,6 +115,12 @@ describe("analyseScenario compatibility", () => {
|
||||
it("preserves an attempted provider API path on provider failure", async () => {
|
||||
const providerError = new Error("Provider failed");
|
||||
providerError.providerApiPath = "/api/chat";
|
||||
providerError.providerExecution = {
|
||||
chatCapabilityDetected: true,
|
||||
chatRequestAttempted: true,
|
||||
chatRequestSucceeded: false,
|
||||
generateRequestAttempted: true,
|
||||
};
|
||||
mockGenerateReconstruction.mockRejectedValue(providerError);
|
||||
|
||||
const { analyseScenario } = await import("@/lib/analysis.js");
|
||||
@@ -125,6 +131,7 @@ describe("analyseScenario compatibility", () => {
|
||||
expect(result).toMatchObject({
|
||||
success: false,
|
||||
providerApiPath: "/api/chat",
|
||||
providerExecution: providerError.providerExecution,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user