fix: stabilise multi-turn question progression

This commit is contained in:
2026-08-03 13:55:39 +01:00
parent 34c25fcb43
commit fe6a9925cb
4 changed files with 452 additions and 16 deletions
+71
View File
@@ -1083,6 +1083,77 @@ describe("lib/graph/orchestrator startCase", () => {
expect(result.selectedQuestion?.nodeId).toBe("n-value");
});
it("keeps a follow-up question when a resolved child still has an eligible sibling", async () => {
const { updateCase } = await import("@/lib/graph/orchestrator.js");
const initialGraph = makeCommercialUpdateGraph();
const firstPass = applyValidatedProposal({
situationGraph: initialGraph,
proposal: {
addedNodes: [
makeNode({
id: "n-anchor",
label: "Update anchor",
description:
"Anchor state introduced by the answer because the update must contain a meaningful change.",
kind: "state",
status: "known",
confidence: "low",
}),
],
updatedNodes: [],
addedEdges: [],
removedEdgeIds: [],
resolvedUnknownNodeIds: [],
affectedNodeIds: [],
selectedQuestion: null,
},
});
expect(firstPass.success).toBe(true);
const provider = {
generateReconstruction: vi.fn().mockResolvedValue({
addedNodes: [],
updatedNodes: [
{
nodeId: firstPass.selectedQuestion.nodeId,
previousStatus: "unknown",
newStatus: "resolved",
previousValue: null,
newValue:
"I experience it myself when deciding whether a project or investment is justified.",
reason: "The answer resolves the first child.",
},
],
addedEdges: [],
removedEdgeIds: [],
resolvedUnknownNodeIds: [firstPass.selectedQuestion.nodeId],
affectedNodeIds: [],
selectedQuestion: null,
}),
};
const result = await updateCase(
{
situationGraph: firstPass.updatedSituationGraph,
previousQuestion: firstPass.selectedQuestion.question,
answer:
"I experience it myself when deciding whether a project or investment is justified.",
promptVersion: "v0.4",
},
{
provider,
config: MOCK_CONFIG,
applyProposal: true,
},
);
expect(result.success).toBe(true);
expect(result.selectedQuestion).toBeTruthy();
expect(result.newActiveUnknownNodeId).toBe(result.selectedQuestion?.nodeId);
expect(result.diagnostics.noQuestionReason).toBeNull();
});
it("defaults to proposal-only mode", async () => {
const { updateCase } = await import("@/lib/graph/orchestrator.js");
const applyValidatedProposal = vi.fn();