From 446052c949aa6a26ebfbfd39f2dcf27039e07fed Mon Sep 17 00:00:00 2001 From: d-robotics Date: Wed, 14 Oct 2026 04:44:16 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20acceptance-fixes=203=20(Lane=20A?= =?UTF-8?q?=20follow-up):=20drop=20immortal=20pending=20after=20server=20d?= =?UTF-8?q?raft=20reset=20on=20result-version=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useReviewDraft.ts | 11 +++++++++++ tests/frontend/acceptance-legacy-compat.test.mjs | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/hooks/useReviewDraft.ts b/src/hooks/useReviewDraft.ts index 79f56623..ab3f193c 100644 --- a/src/hooks/useReviewDraft.ts +++ b/src/hooks/useReviewDraft.ts @@ -300,6 +300,17 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean, cause.status !== 408 && cause.code !== "review_write_in_progress"; if (conflict || definitive) m.pending = null; + // The server resets the draft when the reviewed result moves on + // (loadCurrentReviewDraft keys it by resultVersion): the immutable + // pending operation can never apply there, and every retry would + // throw the same 标注内容已更新 error again. Drop the pending and + // keep the text in edits so save/discard and canLeave() recover — + // otherwise guardDiscard refuses forever while m.pending is set + // (acceptance-fixes 缺陷 3 的第二死锁). + if (p && cause instanceof Error && cause.message.startsWith("标注内容已更新")) { + if (!p.confirmationsOnly) m.edits.set(opinionKey(p.editor), p.editor); + m.pending = null; + } m.blocked = true; m.error = cause instanceof Error ? cause.message : "保存失败,文字仍保留"; m.message = "未保存"; diff --git a/tests/frontend/acceptance-legacy-compat.test.mjs b/tests/frontend/acceptance-legacy-compat.test.mjs index bd8f91fc..4f3dad33 100644 --- a/tests/frontend/acceptance-legacy-compat.test.mjs +++ b/tests/frontend/acceptance-legacy-compat.test.mjs @@ -84,3 +84,19 @@ test("review draft flush always releases the busy flag when its run ends (defect const finallyIndex = hook.indexOf("m.busy = false"); assert.ok(finallyIndex > 0, "busy reset must exist"); }); + +test("a result-version reset drops the immortal pending write instead of retrying forever (defect 3)", () => { + // When the server resets the draft because the reviewed result moved on, the + // immutable pending operation can never apply. Retrying it throws the same + // 标注内容已更新 error forever, and guardDiscard refuses while m.pending is + // set — the reviewer could never leave the task. The flush catch must drop + // the pending (keeping the text in edits) so save/discard recover. + const hook = readFileSync(new URL("../../src/hooks/useReviewDraft.ts", import.meta.url), "utf8"); + assert.match(hook, /cause\.message\.startsWith\("标注内容已更新"\)/); + assert.match(hook, /m\.pending = null;/); + const dropBlock = hook.slice( + hook.indexOf('startsWith("标注内容已更新")'), + hook.indexOf("m.pending = null;", hook.indexOf('startsWith("标注内容已更新")')) + 40, + ); + assert.match(dropBlock, /m\.edits\.set\(opinionKey\(p\.editor\), p\.editor\)/, "text must survive in edits"); +});