From 18992eb42a7ec7b4e7ed8d9e2eb98d645f6250dc Mon Sep 17 00:00:00 2001 From: Jesse_Chen Date: Sun, 19 Jul 2026 19:10:19 +0800 Subject: [PATCH] fix: accept rectifying low-confidence terminal results --- .../lib/birth-time-candidate-completion.ts | 9 +++- .../birth-time-candidate-completion.test.ts | 41 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/birth-time-candidate-completion.ts b/frontend/src/lib/birth-time-candidate-completion.ts index dca767a1..e13b54e5 100644 --- a/frontend/src/lib/birth-time-candidate-completion.ts +++ b/frontend/src/lib/birth-time-candidate-completion.ts @@ -23,10 +23,15 @@ export function candidateWorkingTime( const terminal = actionKind === "present_low_result" || actionKind === "present_medium_result" || actionKind === "candidate_saved"; + const terminalStatusMatches = actionKind === "present_low_result" + ? assessment?.status === "rectifying" + : (actionKind === "present_medium_result" || actionKind === "candidate_saved") + && assessment?.status === "candidate"; return assessment?.id === request.caseId - && assessment.user_id - && assessment.status === "candidate" + && typeof assessment?.user_id === "string" + && assessment.user_id.length > 0 + && terminalStatusMatches && assessment.candidate_result_id === request.resultId && action?.resultId === request.resultId && terminal diff --git a/frontend/tests/birth-time-candidate-completion.test.ts b/frontend/tests/birth-time-candidate-completion.test.ts index 3955e82c..c8a17661 100644 --- a/frontend/tests/birth-time-candidate-completion.test.ts +++ b/frontend/tests/birth-time-candidate-completion.test.ts @@ -19,6 +19,22 @@ const terminalCase = { }, }; +const lowTerminalCase = { + ...terminalCase, + status: "rectifying", + candidate_result: { + ...terminalCase.candidate_result, + confidence: "low", + }, + turn_state: { + ...terminalCase.turn_state, + nextAction: { + kind: "present_low_result", + resultId: terminalCase.candidate_result_id, + }, + }, +}; + test("candidate completion only accepts the persisted terminal representative time", () => { assert.equal(candidateWorkingTime(terminalCase, { caseId: terminalCase.id, @@ -33,6 +49,31 @@ test("candidate completion only accepts the persisted terminal representative ti }), null); }); +test("accepts a matching low-confidence result from the rectifying state", () => { + assert.equal(candidateWorkingTime(lowTerminalCase, { + caseId: terminalCase.id, + resultId: terminalCase.candidate_result_id, + time: "04:53", + }), "04:53"); +}); + +test("does not accept a medium terminal action from the rectifying state", () => { + assert.equal(candidateWorkingTime({ + ...lowTerminalCase, + turn_state: { + ...lowTerminalCase.turn_state, + nextAction: { + kind: "present_medium_result", + resultId: terminalCase.candidate_result_id, + }, + }, + }, { + caseId: terminalCase.id, + resultId: terminalCase.candidate_result_id, + time: "04:53", + }), null); +}); + test("non-terminal cases cannot be adopted for consultation", () => { assert.equal(candidateWorkingTime({ ...terminalCase,