fix(confidence-engine): unwrap synthesis provider response

This commit is contained in:
2026-09-07 15:50:50 +01:00
parent 7548a6af59
commit ae00e70ced
2 changed files with 14 additions and 5 deletions
+3 -3
View File
@@ -279,9 +279,9 @@ export async function synthesizeCurrentUnderstanding(
modelName = process.env.OLLAMA_MODEL ?? null; modelName = process.env.OLLAMA_MODEL ?? null;
} }
let rawResponse; let providerResult;
try { try {
rawResponse = await provider.generateReconstruction( providerResult = await provider.generateReconstruction(
prompt, prompt,
modelName, modelName,
synthesisOutputSchema, synthesisOutputSchema,
@@ -293,7 +293,7 @@ export async function synthesizeCurrentUnderstanding(
} }
// 5. Validate response // 5. Validate response
const validated = validateSynthesisResponse(rawResponse); const validated = validateSynthesisResponse(providerResult.response);
if (!validated.valid) { if (!validated.valid) {
const err = new Error(`Synthesis validation failed: ${validated.error}`); const err = new Error(`Synthesis validation failed: ${validated.error}`);
err.statusCode = 502; err.statusCode = 502;
@@ -56,9 +56,10 @@ const agreedFinding = () => ({
/** Fake provider factory for tests */ /** Fake provider factory for tests */
const makeFakeProvider = (defaultResponse) => ({ const makeFakeProvider = (defaultResponse) => ({
generateReconstruction: vi.fn(async () => { generateReconstruction: vi.fn(async () => {
return typeof defaultResponse === "function" const response = typeof defaultResponse === "function"
? defaultResponse() ? await defaultResponse()
: JSON.stringify({ currentUnderstanding: "Synthesized output" }); : JSON.stringify({ currentUnderstanding: "Synthesized output" });
return { response, providerApiPath: "/test-provider" };
}), }),
}); });
@@ -383,6 +384,14 @@ describe("synthesizeCurrentUnderstanding — full seam", () => {
}); });
}); });
it("unwraps the provider response before validating the synthesis narrative", async () => {
const fake = makeFakeProvider(() => ({ currentUnderstanding: "Wrapped narrative" }));
await expect(synthesizeCurrentUnderstanding(
{ situationGraph: fullScenario, findings: [] },
{ provider: fake },
)).resolves.toEqual({ currentUnderstanding: "Wrapped narrative" });
});
it("supported node content flows to provider via synthesis prompt", async () => { it("supported node content flows to provider via synthesis prompt", async () => {
const fake = makeFakeProvider(); const fake = makeFakeProvider();
await synthesizeCurrentUnderstanding( await synthesizeCurrentUnderstanding(