diff --git a/lib/graph/current-understanding-synthesis.js b/lib/graph/current-understanding-synthesis.js index 6a6cd24..3af75c6 100644 --- a/lib/graph/current-understanding-synthesis.js +++ b/lib/graph/current-understanding-synthesis.js @@ -279,9 +279,9 @@ export async function synthesizeCurrentUnderstanding( modelName = process.env.OLLAMA_MODEL ?? null; } - let rawResponse; + let providerResult; try { - rawResponse = await provider.generateReconstruction( + providerResult = await provider.generateReconstruction( prompt, modelName, synthesisOutputSchema, @@ -293,7 +293,7 @@ export async function synthesizeCurrentUnderstanding( } // 5. Validate response - const validated = validateSynthesisResponse(rawResponse); + const validated = validateSynthesisResponse(providerResult.response); if (!validated.valid) { const err = new Error(`Synthesis validation failed: ${validated.error}`); err.statusCode = 502; diff --git a/tests/graph/current-understanding-synthesis.test.js b/tests/graph/current-understanding-synthesis.test.js index 36e3cdb..e538e64 100644 --- a/tests/graph/current-understanding-synthesis.test.js +++ b/tests/graph/current-understanding-synthesis.test.js @@ -56,9 +56,10 @@ const agreedFinding = () => ({ /** Fake provider factory for tests */ const makeFakeProvider = (defaultResponse) => ({ generateReconstruction: vi.fn(async () => { - return typeof defaultResponse === "function" - ? defaultResponse() + const response = typeof defaultResponse === "function" + ? await defaultResponse() : 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 () => { const fake = makeFakeProvider(); await synthesizeCurrentUnderstanding(