修复换人接手返工时加载旧切片的问题 #78
@ -509,6 +509,22 @@ export function annotationRecoverableWorkspaceFromHumanItem(item) {
|
||||
return annotationSavedDraftFromHumanItem(item) || annotationDraftFromHumanItem(item);
|
||||
}
|
||||
|
||||
export function annotationWorkspaceForAssignee(item, userId) {
|
||||
if (!userId || item?.assignedUserId !== userId || !["claimed", "in_progress"].includes(item.status)) return null;
|
||||
const workspace = annotationRecoverableWorkspaceFromHumanItem(item);
|
||||
if (workspace?.userId === userId) return workspace;
|
||||
// A confirmed rework workspace follows the task when the assignee changes.
|
||||
// The historical fallback to annotationDraft still requires the draft owner.
|
||||
if (
|
||||
item.currentStageId === "annotation_combined" &&
|
||||
item.reviewRound > 0 &&
|
||||
item.subject?.payload?.annotationWorkspace != null
|
||||
) {
|
||||
return workspace;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function validateSliceFullCoverage(slice, segments = [], tolerance = 0.005) {
|
||||
if (!slice) return { complete: false, reason: "slice_missing" };
|
||||
const sliceSegments = annotationSegmentsForSlice(slice, segments).sort(
|
||||
|
||||
@ -156,7 +156,7 @@ import {
|
||||
} from "../lib/annotation-operations.js";
|
||||
import {
|
||||
annotationDraftFromHumanItem,
|
||||
annotationRecoverableWorkspaceFromHumanItem,
|
||||
annotationWorkspaceForAssignee,
|
||||
annotationOrphanSegments,
|
||||
applySliceStatuses,
|
||||
deriveSliceStatuses,
|
||||
@ -1848,37 +1848,30 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
next.humanItem.version < detailRef.current.humanItem.version
|
||||
)
|
||||
return;
|
||||
const storedDraft = annotationRecoverableWorkspaceFromHumanItem(next.humanItem);
|
||||
const savedWorkspace = annotationWorkspaceForAssignee(next.humanItem, currentUser?.id);
|
||||
const discardedWorkspace = Boolean(
|
||||
(next.humanItem?.subject?.payload?.sliceWorkflow as { discardedWorkspace?: boolean } | undefined)
|
||||
?.discardedWorkspace,
|
||||
);
|
||||
const restoreDraft = Boolean(
|
||||
storedDraft &&
|
||||
storedDraft.userId === currentUser?.id &&
|
||||
next.humanItem?.assignedUserId === currentUser?.id &&
|
||||
["claimed", "in_progress"].includes(next.humanItem.status),
|
||||
);
|
||||
let nextAnnotations = restoreDraft
|
||||
? storedDraft.segments
|
||||
let nextAnnotations = savedWorkspace
|
||||
? savedWorkspace.segments
|
||||
: discardedWorkspace
|
||||
? []
|
||||
: humanEditableAnnotationSegments(next.revisions);
|
||||
const nextSlices = initialCaptureSlices(
|
||||
next.task,
|
||||
discardedWorkspace ? [] : next.sliceRevisions,
|
||||
restoreDraft ? storedDraft.sliceSegments : undefined,
|
||||
savedWorkspace?.sliceSegments,
|
||||
).map((slice) => ({
|
||||
...slice,
|
||||
name: slice.deliveryDisposition === "discard" ? "" : slice.name?.trim() || "",
|
||||
...(next.task.templateVersion >= 6 ? { taskLabelId: undefined, taskLabel: undefined } : {}),
|
||||
}));
|
||||
const nextOperations = restoreDraft ? storedDraft.operations : [];
|
||||
let nextStatuses = deriveSliceStatuses(
|
||||
nextSlices,
|
||||
nextAnnotations,
|
||||
restoreDraft ? storedDraft.statuses : {},
|
||||
) as Record<string, NonNullable<SliceSegment["annotationStatus"]>>;
|
||||
const nextOperations = savedWorkspace?.operations ?? [];
|
||||
let nextStatuses = deriveSliceStatuses(nextSlices, nextAnnotations, savedWorkspace?.statuses ?? {}) as Record<
|
||||
string,
|
||||
NonNullable<SliceSegment["annotationStatus"]>
|
||||
>;
|
||||
const sliceWorkflow = next.humanItem?.subject?.payload?.sliceWorkflow as
|
||||
| { status?: string; phase?: string; error?: string }
|
||||
| undefined;
|
||||
@ -1964,7 +1957,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
void loadFrameTimeline(
|
||||
next.task,
|
||||
nextSlices,
|
||||
!restoreDraft &&
|
||||
!savedWorkspace &&
|
||||
!next.sliceRevisions.some(
|
||||
(revision) =>
|
||||
revision.segments?.length && !(revision.revision === 0 && revision.authorUserId === "system"),
|
||||
|
||||
@ -31,6 +31,41 @@ test("valid newer autosave restores without replacing confirmed baseline", () =>
|
||||
draft.savedAt = "2026-10-15T01:00:00Z";
|
||||
assert.equal(workbench.annotationSavedDraftFromHumanItem(item), null);
|
||||
});
|
||||
|
||||
test("the current rework assignee resumes confirmed progress from the former assignee", () => {
|
||||
const annotationWorkspace = {
|
||||
sliceSegments: [{ id: "merged", start: 0, end: 3 }],
|
||||
segments: [{ id: "a", start: 0, end: 3, description: "confirmed rework" }],
|
||||
userId: "former",
|
||||
confirmedAt: "2026-10-16T01:00:00Z",
|
||||
};
|
||||
const annotationDraft = {
|
||||
...annotationWorkspace,
|
||||
segments: [{ id: "a", start: 0, end: 3, description: "private draft" }],
|
||||
savedAt: "2026-10-16T02:00:00Z",
|
||||
};
|
||||
const item = {
|
||||
assignedUserId: "current",
|
||||
currentStageId: "annotation_combined",
|
||||
status: "claimed",
|
||||
reviewRound: 1,
|
||||
subject: { payload: { annotationWorkspace, annotationDraft } },
|
||||
};
|
||||
const restored = workbench.annotationWorkspaceForAssignee(item, "current");
|
||||
assert.deepEqual(restored.sliceSegments, annotationWorkspace.sliceSegments);
|
||||
assert.deepEqual(restored.segments, annotationWorkspace.segments);
|
||||
assert.equal(restored.userId, "former");
|
||||
assert.equal(workbench.annotationWorkspaceForAssignee(item, "former"), null);
|
||||
assert.equal(workbench.annotationWorkspaceForAssignee({ ...item, reviewRound: 0 }, "current"), null);
|
||||
assert.equal(workbench.annotationWorkspaceForAssignee({ ...item, status: "ready" }, "current"), null);
|
||||
assert.equal(
|
||||
workbench.annotationWorkspaceForAssignee({ ...item, subject: { payload: { annotationDraft } } }, "current"),
|
||||
null,
|
||||
);
|
||||
annotationDraft.userId = "current";
|
||||
assert.equal(workbench.annotationWorkspaceForAssignee(item, "current").segments[0].description, "private draft");
|
||||
});
|
||||
|
||||
test("semantic reconciliation tolerates compressed proof but still detects content changes", () => {
|
||||
const original = {
|
||||
sliceSegments: [{ id: "a", start: 0, end: 1 }],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user