diff --git a/frontend/src/lib/birth-time-dynamic-preview.ts b/frontend/src/lib/birth-time-dynamic-preview.ts index e7d5acfd..2249a559 100644 --- a/frontend/src/lib/birth-time-dynamic-preview.ts +++ b/frontend/src/lib/birth-time-dynamic-preview.ts @@ -198,13 +198,26 @@ export function advanceDynamicBirthTimePreview( } } } - case "reframe": return response({ - nextAction: { kind: "ask_dynamic_choice", question: questions[1] }, - phase: "question", - answeredCount: turn.progress.answeredCount, - effectiveAnswerCount: turn.progress.effectiveAnswerCount, - turnVersion: turn.turnVersion + 1, - }); + case "reframe": { + if (turn.nextAction.kind === "clarify_unmatched_answer" + && turn.nextAction.questionId === questions[1].questionId) { + return response({ + nextAction: { kind: "present_low_result", resultId: null }, + phase: "result", + answeredCount: turn.progress.answeredCount, + effectiveAnswerCount: turn.progress.effectiveAnswerCount, + snapshotState: "candidate", + turnVersion: turn.turnVersion + 1, + }); + } + return response({ + nextAction: { kind: "ask_dynamic_choice", question: questions[1] }, + phase: "question", + answeredCount: turn.progress.answeredCount, + effectiveAnswerCount: turn.progress.effectiveAnswerCount, + turnVersion: turn.turnVersion + 1, + }); + } case "finish": return response({ nextAction: { kind: "present_low_result", resultId: null }, phase: "result", diff --git a/frontend/tests/birth-time-choice-question.test.ts b/frontend/tests/birth-time-choice-question.test.ts index d6a9090f..7a86b2f6 100644 --- a/frontend/tests/birth-time-choice-question.test.ts +++ b/frontend/tests/birth-time-choice-question.test.ts @@ -70,6 +70,20 @@ test("preview unknown answers terminate instead of repeating the same question", assert.equal(terminal.progress.answeredCount, 2); }); +test("preview unmatched reframing terminates when no different question remains", () => { + const start = dynamicBirthTimePreview(); + const secondQuestion = advanceDynamicBirthTimePreview(start, { kind: "select", optionId: "earlier" }); + const secondClarification = advanceDynamicBirthTimePreview(secondQuestion, { + kind: "select", + optionId: "unmatched-2", + }); + const terminal = advanceDynamicBirthTimePreview(secondClarification, { kind: "reframe" }); + + assert.equal(secondClarification.nextAction.kind, "clarify_unmatched_answer"); + assert.equal(terminal.nextAction.kind, "present_low_result"); + assert.equal(terminal.progress.answeredCount, 2); +}); + test("dynamic previews cover every visible result and recovery state", () => { const expected = new Map([ ["generating", "generate_dynamic_question"],