🐛 Preserve cross-slice history reveal and stable page-edge drags

This commit is contained in:
d-robotics 2026-09-18 04:00:16 +08:00
parent 94b238d575
commit e95adca8bb
5 changed files with 216 additions and 26 deletions

View File

@ -31,3 +31,5 @@
描述阶段浏览器验收为 `tests/browser/annotation-workspace-annotation.mjs`:默认使用 annotate-primary 检查五档内容区、固定编辑、过期版本真实拒绝、保存/撤销/重做回读和草稿拦截。`ANNOTATION_SUBMIT=1` 仅允许 annotate-delayed 专用任务执行真实送检,推进后不应重跑或重置;`ANNOTATION_VERIFY_SUBMITTED=1` 配合该任务 ID 只回读已完成送检。shell 回归以 `ANNOTATION_SLICE_TASK_ID` 指定仍处于切片阶段的 pool fixture,默认 pool-01,避免误用已生成的 slice-primary。
大量条目的浏览器验收为 `tests/browser/annotation-workspace-navigation.mjs`,使用独立的 many-annotate-04 与 many-slice-04 任务(后者传入 `NAVIGATION_PHASE=slice`)。两者均有 13 个切片,描述任务首片有 13 条描述。脚本检查五档尺寸、全局导航、草稿与布局切换、尾页删除、跨页历史、单帧描述查找及公共 API 回读;仅显式保存与历史恢复写入本地描述任务,不生成切片或送检。禁止通过重置已有任务重跑验收;任务 ID 可指定该命名前缀下的新增隔离任务。
分页边界拖动验收为 `tests/browser/annotation-workspace-boundaries.mjs`,默认检查切片,传入 `NAVIGATION_PHASE=annotate` 检查描述。它使用真实鼠标手势将页尾边界向两侧移动,并检查同一横坐标不会重复改变边界;描述模式通过现有编辑、确认结束点和保存建立相邻区间,再以公共 API 核对共享精确帧。历史验收还覆盖从另一切片重做已保存描述时,关闭编辑器并显示目标页。

View File

@ -61,6 +61,7 @@ import { useCaptureVideoTransport } from "../hooks/useCaptureVideoTransport";
type Phase = "slice" | "materializing" | "annotate";
type Boundary = { index: number; field: "end" } | null;
type PointerPoint = { x: number; time: number };
type BoundaryGesture = { x: number; time: number; secondsPerPixel: number };
type SplitPreview = { sliceIndex: number; time: number } | null;
type EndSelection = { id: string; start: number; end: number; limit: number; confirmed: boolean; isNew: boolean };
export type SliceEditor = { annotation: AnnotationSegment; endSelection: EndSelection | null };
@ -295,10 +296,11 @@ export function CaptureAnnotationWorkbench({
const rightVideoRef = useRef<HTMLVideoElement>(null);
const sliceTrackRef = useRef<HTMLDivElement>(null);
const annotationTrackRef = useRef<HTMLDivElement>(null);
const sliceDragRef = useRef<{ index: number } | null>(null);
const sliceDragRef = useRef<{ index: number; gesture: BoundaryGesture } | null>(null);
const annotationBoundaryDragRef = useRef<{
index: number;
before: AnnotationEditState;
gesture: BoundaryGesture;
after?: AnnotationEditState;
} | null>(null);
const [selectedAnnotationBoundary, setSelectedAnnotationBoundary] = useState<{ index: number } | null>(null);
@ -420,7 +422,20 @@ export function CaptureAnnotationWorkbench({
const upperAnnotation = selectedSlice?.end ?? clipEnd;
const slicePage = useTimelinePage(slices, selectedSlice.id, taskId, historyReveal?.revision);
const descriptionPage = useTimelinePage(annotationForRender, editingAnnotation?.id, `${taskId}:${selectedSlice.id}`);
const descriptionPage = useTimelinePage(
annotationForRender,
editingAnnotation?.id,
`${taskId}:${selectedSlice.id}`,
undefined,
historyReveal
? {
scope: `${taskId}:${historyReveal.sliceId}`,
revision: historyReveal.revision,
id: historyReveal.editor?.annotation.id ?? historyReveal.revealAnnotation?.id,
start: historyReveal.editor?.annotation.start ?? historyReveal.revealAnnotation?.start ?? historyReveal.time,
}
: undefined,
);
const visibleSlices = focusedLayout ? slicePage.items : slices;
const visibleDescriptions = focusedLayout ? descriptionPage.items : annotationForRender;
const sliceTimelineStart = focusedLayout ? (slicePage.start ?? clipStart) : clipStart;
@ -761,15 +776,6 @@ export function CaptureAnnotationWorkbench({
if (historyReveal.editor && historyReveal.editor.endSelection?.confirmed !== false)
requestAnimationFrame(focusDescriptionEditor);
}
const restoredDescriptions = annotationSegmentsForSlice(affected, segments).sort((a, b) => a.start - b.start);
const revealTime = historyReveal.revealAnnotation?.start ?? historyReveal.time;
const target =
historyReveal.editor?.annotation ??
restoredDescriptions.find((segment) => segment.id === historyReveal.revealAnnotation?.id) ??
restoredDescriptions.find((segment) => segment.start <= revealTime && segment.end > revealTime) ??
restoredDescriptions.find((segment) => segment.start >= revealTime) ??
restoredDescriptions.at(-1);
descriptionPage.setPage(pageContaining(restoredDescriptions, target?.id, 4) ?? 0);
setSplitPreview(null);
setAnnotationSplitPreview(null);
}, [historyReveal, slices]);
@ -872,10 +878,18 @@ export function CaptureAnnotationWorkbench({
};
const beginSliceBoundaryDrag = (event: ReactPointerEvent<HTMLButtonElement>, index: number) => {
if (readOnly || saving || phase !== "slice") return;
if (readOnly || saving || phase !== "slice" || !sliceTrackRef.current) return;
event.preventDefault();
event.stopPropagation();
sliceDragRef.current = { index };
sliceDragRef.current = {
index,
gesture: {
x: event.clientX,
time: slices[index].end,
secondsPerPixel:
(sliceTimelineEnd - sliceTimelineStart) / Math.max(sliceTrackRef.current.getBoundingClientRect().width, 1),
},
};
onSliceBoundaryEditStart?.(slices[index].id);
transport.beginScrub();
setSelectedBoundary({ index, field: "end" });
@ -884,8 +898,11 @@ export function CaptureAnnotationWorkbench({
const updateSliceDrag = (event: ReactPointerEvent<HTMLDivElement>) => {
if (!sliceDragRef.current || !sliceTrackRef.current) return;
const point = pointForEvent(event, sliceTrackRef.current, sliceTimelineStart, sliceTimelineEnd);
updateSliceBoundaryAt(sliceDragRef.current.index, point.time, true);
const { index, gesture } = sliceDragRef.current;
// Keep the gesture scale fixed as the edge changes the visible page range.
// Global adjacent-frame limits below permit motion past the visible edge.
const time = gesture.time + (event.clientX - gesture.x) * gesture.secondsPerPixel;
updateSliceBoundaryAt(index, time, true);
};
const releaseSliceDrag = () => {
@ -1262,14 +1279,24 @@ export function CaptureAnnotationWorkbench({
};
const beginAnnotationBoundaryDrag = (event: ReactPointerEvent<HTMLButtonElement>, index: number) => {
if (readOnly || saving || phase !== "annotate" || selectingEnd) return;
if (readOnly || saving || phase !== "annotate" || selectingEnd || !annotationTrackRef.current) return;
if (Math.abs(annotationSegments[index]?.end - annotationSegments[index + 1]?.start) > 0.000001) {
setError("这两段之间有未标注区间,请先补标,不会自动拉伸描述填空。");
return;
}
event.preventDefault();
event.stopPropagation();
annotationBoundaryDragRef.current = { index, before: annotationEditState() };
annotationBoundaryDragRef.current = {
index,
before: annotationEditState(),
gesture: {
x: event.clientX,
time: annotationSegments[index].end,
secondsPerPixel:
(descriptionTimelineEnd - descriptionTimelineStart) /
Math.max(annotationTrackRef.current.getBoundingClientRect().width, 1),
},
};
transport.beginScrub();
setSelectedAnnotationBoundary({ index });
event.currentTarget.setPointerCapture(event.pointerId);
@ -1295,15 +1322,15 @@ export function CaptureAnnotationWorkbench({
return;
}
if (!annotationTrackRef.current || !selectedSlice) return;
const point = pointForEvent(event, annotationTrackRef.current, descriptionTimelineStart, descriptionTimelineEnd);
const index = annotationBoundaryDragRef.current.index;
const { index, gesture } = annotationBoundaryDragRef.current;
const time = gesture.time + (event.clientX - gesture.x) * gesture.secondsPerPixel;
const current = annotationSegments[index];
const following = annotationSegments[index + 1];
if (!current || !following) return;
const minimum = exactFrames ? stepFrameBoundary(frameBoundaries, current.start, 1) : current.start + 0.033;
const maximum = exactFrames ? stepFrameBoundary(frameBoundaries, following.end, -1) : following.end - 0.033;
const nextTime = clamp(snap(point.time), minimum, maximum);
const nextTime = clamp(snap(time), minimum, maximum);
const updated = segments.map((seg) => {
if (seg.id === current.id) return { ...seg, end: nextTime };

View File

@ -9,19 +9,32 @@ export function useTimelinePage<T extends Entry>(
selectedId: string | undefined,
scope: string,
revealRevision?: number,
target?: { scope: string; revision: number; id?: string; start: number },
) {
const selectedPage = pageContaining(items, selectedId, pageSize);
const selectionKey = `${scope}:${selectedId}:${selectedPage}:${revealRevision}`;
const [state, setState] = useState({ page: selectedPage ?? 0, scope, selectionKey });
const [state, setState] = useState({ page: selectedPage ?? 0, scope, selectionKey, revealedTarget: "" });
// Derive a new window before rendering its entries. Separate selection and
// clamping effects can race when a parked editor moves between long/short lists.
const requestedPage =
state.selectionKey !== selectionKey ? (selectedPage ?? (state.scope === scope ? state.page : 0)) : state.page;
const targetKey = target ? `${target.scope}:${target.revision}` : "";
const revealTarget = target?.scope === scope && targetKey !== state.revealedTarget;
const targetItem = revealTarget
? (items.find((item) => item.id === target.id) ??
items.find((item) => item.start <= target.start && item.end > target.start) ??
items.find((item) => item.start >= target.start) ??
items.at(-1))
: undefined;
const requestedPage = revealTarget
? (pageContaining(items, targetItem?.id, pageSize) ?? 0)
: state.selectionKey !== selectionKey
? (selectedPage ?? (state.scope === scope ? state.page : 0))
: state.page;
const window = timelinePage(items, requestedPage, pageSize);
if (state.selectionKey !== selectionKey || state.page !== window.page) {
setState({ page: window.page, scope, selectionKey });
const revealedTarget = revealTarget ? targetKey : state.revealedTarget;
if (state.selectionKey !== selectionKey || state.page !== window.page || revealTarget) {
setState({ page: window.page, scope, selectionKey, revealedTarget });
}
const setPage = (page: number) => setState({ page, scope, selectionKey });
const setPage = (page: number) => setState({ page, scope, selectionKey, revealedTarget });
return { ...window, setPage, reveal: () => setPage(selectedPage ?? window.page) };
}

View File

@ -0,0 +1,145 @@
// Page-edge drags must use the global adjacent intervals and a stable gesture
// scale. Exercise actual pointer events, visible boundaries and saved API data.
import assert from "node:assert/strict";
import { chromium } from "playwright";
const browser = await chromium.launch({
executablePath: "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
headless: true,
args: ["--no-proxy-server"],
});
const context = await browser.newContext({
storageState: "local-data/verification/annotation-workspace-layout/auth.json",
viewport: { width: 1280, height: 640 },
});
const page = await context.newPage();
page.setDefaultTimeout(12000);
const phase = process.env.NAVIGATION_PHASE || "slice";
const task = `annotation-task-workspace-layout-acceptance-many-${phase}-04`;
const button = (name) => page.getByRole("button", { name, exact: true });
const readItem = async () => {
const r = await context.request.get(
`http://127.0.0.1:5173/api/human-items/${task.replace("annotation-task-", "human-item-")}`,
);
assert.ok(r.ok());
return (await r.json()).item;
};
const mutation = () =>
page.waitForResponse((r) => r.url().endsWith("annotation-confirmations") && r.request().method() === "POST");
const search = async (label, ordinal) => {
await page.getByLabel(`查找${label}`, { exact: true }).fill(`#${ordinal}`);
await button(`查找下一${label}`).click();
};
try {
await page.goto(
`http://127.0.0.1:5173/plugins/annotation-qa/workflows/all/work?projectId=project-workspace-layout-acceptance&taskId=${task}`,
);
await button("继续工作").click();
if (await button("进入专注视图").count()) await button("进入专注视图").click();
await page.waitForFunction(
() =>
document.querySelectorAll("video").length === 2 &&
[...document.querySelectorAll("video")].every((v) => v.readyState >= 2),
null,
{ timeout: 60000 },
);
const before = await readItem();
const workspace = before.subject.payload.annotationWorkspace;
workspace.segments.sort((a, b) => a.start - b.start);
await search("切片", phase === "slice" ? 4 : 1);
let original, field;
if (phase === "annotate") {
// Make the existing fourth/fifth intervals contiguous through normal editing.
await search("描述", 4);
field = page.getByRole("spinbutton", { name: "动作结束时间(秒)" });
original = workspace.segments[4].start;
await field.fill(String(original));
await field.blur();
let response = mutation();
if (await button("确认结束点").count()) await button("确认结束点").click();
await button("确认保存描述").click();
assert.ok((await response).ok());
await search("描述", 4);
} else {
original = workspace.sliceSegments[3].end;
field = page.getByRole("spinbutton", { name: "切片结束时间" });
}
// The slice interval is displayed in the fixed editor; annotation uses its
// accessible boundary field. Record the shared edge from the list when slicing.
const sliceEnd = async () => {
const text = await page.locator(".capture-slice-name-editor").innerText();
const m = text.match(/(\d+):(\d+)\.(\d+)\s*~/);
assert.ok(m);
const end = text.match(/~\s*(\d+):(\d+)\.(\d+)/);
assert.ok(end);
return Number(end[1]) * 60 + Number(end[2]) + Number(end[3]) / 1000;
};
const readBoundary = phase === "slice" ? sliceEnd : async () => Number(await field.inputValue());
const handle = () =>
page.getByRole("button", { name: phase === "slice" ? "拖动切片边界" : "拖动动作分界", exact: true }).last();
const drag = async (delta) => {
const r = await handle().boundingBox();
assert.ok(r);
const track = await page
.getByTestId(phase === "slice" ? "capture-slice-timeline" : "slice-annotation-timeline")
.boundingBox();
// Grab the visible left half of the page-edge handle before crossing the
// track edge. Pointer capture must keep the gesture active outside it.
const x = Math.min(r.x + 3, track.x + track.width - 3),
y = r.y + Math.min(r.height / 2, 15);
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x + delta, y, { steps: 3 });
const once = await readBoundary();
await page.mouse.move(x + delta, y + 1);
await page.mouse.move(x + delta, y);
const repeated = await readBoundary();
assert.equal(repeated, once, "the same horizontal coordinate cannot move a boundary twice");
await page.mouse.up();
return once;
};
const later = await drag(12);
assert.ok(later > original, `page-edge drag must extend later: ${later} > ${original}`);
const earlier = await drag(-24);
assert.ok(earlier < later, `page-edge drag must move earlier: ${earlier} < ${later}`);
console.log("PASS stable bidirectional page-edge pointer drag", JSON.stringify({ phase, original, later, earlier }));
if (phase === "annotate") {
let response = mutation();
if (await button("确认结束点").count()) await button("确认结束点").click();
await button("确认保存描述").click();
assert.ok((await response).ok());
const saved = await readItem();
const ss = saved.subject.payload.annotationWorkspace.segments;
assert.equal(ss[3].end, ss[4].start);
assert.ok(Math.abs(ss[3].end - earlier) < 0.0011);
console.log(
"PASS exact shared boundary API readback",
JSON.stringify({ version: saved.version, end: ss[3].end, nextStart: ss[4].start }),
);
// Restore only these two intervals through the same public UI save, so the
// established fixture remains repeatable and all original gaps survive.
await search("描述", 4);
await field.fill(String(workspace.segments[3].end));
await field.blur();
response = mutation();
if (await button("确认结束点").count()) await button("确认结束点").click();
await button("确认保存描述").click();
assert.ok((await response).ok());
await search("描述", 5);
await page.getByRole("spinbutton", { name: "动作开始时间(秒)" }).fill(String(workspace.segments[4].start));
await page.getByRole("spinbutton", { name: "动作开始时间(秒)" }).blur();
response = mutation();
if (await button("确认结束点").count()) await button("确认结束点").click();
await button("确认保存描述").click();
assert.ok((await response).ok());
} else assert.equal((await readItem()).version, before.version, "local slice drag never implicitly saves");
await page.screenshot({ path: `local-data/verification/annotation-workspace-layout/task04-boundary-${phase}.png` });
} catch (e) {
await page.screenshot({
path: `local-data/verification/annotation-workspace-layout/task04-boundary-${phase}-error.png`,
});
console.log(await page.locator("body").innerText());
throw e;
} finally {
await context.close();
await browser.close();
}

View File

@ -193,9 +193,12 @@ try {
assert.ok((await readItem()).subject.payload.annotationWorkspace.segments.some((x) => x.description === original));
await page.waitForTimeout(1100);
await button("描述上一页").click();
await workbench.focus();
await page.keyboard.press("Control+ArrowRight");
response = mutation();
await button("重做").click();
assert.ok((await response).ok());
await input.waitFor({ state: "detached" });
await matchPage("描述", /^4\/4/, "redo reveals the saved item even without an open editor");
await page.getByTestId("annotation-description-block").last().click();
response = mutation();