🐛 acceptance-fixes 3 (Lane A follow-up): drop immortal pending after server draft reset on result-version change

This commit is contained in:
d-robotics 2026-10-14 04:44:16 +08:00
parent 4d182c8cc5
commit 446052c949
2 changed files with 27 additions and 0 deletions

View File

@ -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 = "未保存";

View File

@ -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");
});