forked from longtao.wu/droboticflow
⏸️ Suspend focused annotation safely below the viewport minimum
This commit is contained in:
parent
39bed0fc11
commit
cb74444e0d
@ -108,6 +108,7 @@ type Props = {
|
||||
phase: Phase;
|
||||
adaptiveLayout?: boolean;
|
||||
focusedLayout?: boolean;
|
||||
viewportSuspended?: boolean;
|
||||
frameBoundaries?: number[];
|
||||
frameTimelineStatus?: "loading" | "ready" | "error";
|
||||
onRetryFrameTimeline?: () => void;
|
||||
@ -216,6 +217,7 @@ export function CaptureAnnotationWorkbench({
|
||||
phase,
|
||||
adaptiveLayout = false,
|
||||
focusedLayout = false,
|
||||
viewportSuspended = false,
|
||||
frameBoundaries = [],
|
||||
frameTimelineStatus = "ready",
|
||||
onRetryFrameTimeline,
|
||||
@ -269,6 +271,7 @@ export function CaptureAnnotationWorkbench({
|
||||
const timelineReady = frameTimelineStatus === "ready";
|
||||
const readOnly = providedReadOnly || !timelineReady;
|
||||
const workbenchRef = useRef<HTMLElement>(null);
|
||||
const suspendedDialogsRef = useRef<HTMLDialogElement[] | null>(null);
|
||||
const descriptionInputRef = useRef<HTMLTextAreaElement>(null);
|
||||
const descriptionEditorRef = useRef<HTMLDivElement>(null);
|
||||
const sliceDictionaryTriggerRef = useRef<HTMLButtonElement>(null);
|
||||
@ -689,6 +692,24 @@ export function CaptureAnnotationWorkbench({
|
||||
[publishSeekTarget],
|
||||
);
|
||||
const pausePlayback = useCallback(() => transportRef.current.pause(), []);
|
||||
useEffect(() => {
|
||||
if (viewportSuspended) {
|
||||
pausePlayback();
|
||||
// Native modal dialogs occupy the browser top layer and escape ancestor
|
||||
// inertness. Temporarily close them so viewport recovery stays reachable.
|
||||
suspendedDialogsRef.current = Array.from(
|
||||
workbenchRef.current?.querySelectorAll<HTMLDialogElement>("dialog[open]") || [],
|
||||
);
|
||||
suspendedDialogsRef.current.forEach((dialog) => dialog.close());
|
||||
} else if (suspendedDialogsRef.current) {
|
||||
const dialogs = suspendedDialogsRef.current;
|
||||
dialogs.forEach((dialog) => {
|
||||
if (dialog.isConnected) dialog.showModal();
|
||||
});
|
||||
if (!dialogs.some((dialog) => dialog.isConnected)) workbenchRef.current?.focus({ preventScroll: true });
|
||||
suspendedDialogsRef.current = null;
|
||||
}
|
||||
}, [viewportSuspended, pausePlayback]);
|
||||
const previewSeek = (time: number) => transport.preview(publishSeekTarget(time));
|
||||
const sliderDragging = useRef(false);
|
||||
const sliderEvents = {
|
||||
@ -1622,6 +1643,7 @@ export function CaptureAnnotationWorkbench({
|
||||
closeStageConfirmation();
|
||||
}}
|
||||
onClose={() => {
|
||||
if (viewportSuspended) return;
|
||||
setStageConfirmation(null);
|
||||
focusWorkbench();
|
||||
}}
|
||||
|
||||
@ -34,6 +34,10 @@ export function useAnnotationWorkSession(userId: string, projectId: string, work
|
||||
const identityRef = useRef({ scope });
|
||||
if (identityRef.current.scope !== scope) identityRef.current = { scope };
|
||||
const [, render] = useState(0);
|
||||
// A failed initial claim releases its inactive owner, but must not dismiss
|
||||
// viewport recovery. The latch belongs to this page/scope, not the lock.
|
||||
const viewportRef = useRef({ scope, suspended: false });
|
||||
if (viewportRef.current.scope !== scope) viewportRef.current = { scope, suspended: false };
|
||||
const [observation, setObservation] = useState({ scope: "", blocked: false, unavailable: false });
|
||||
const channelRef = useRef<BroadcastChannel | null>(null);
|
||||
|
||||
@ -187,9 +191,27 @@ export function useAnnotationWorkSession(userId: string, projectId: string, work
|
||||
},
|
||||
[owns],
|
||||
);
|
||||
const isContinuous = useCallback(() => owns() && Boolean(ownedSession?.active && ownedSession.continuous), [owns]);
|
||||
// Viewport suspension never changes user intent or clears a hard pause reason.
|
||||
const setViewportSuspended = useCallback((suspended: boolean) => {
|
||||
if (viewportRef.current.suspended === suspended) return;
|
||||
viewportRef.current.suspended = suspended;
|
||||
render((version) => version + 1);
|
||||
}, []);
|
||||
const hasContinuousIntent = useCallback(
|
||||
() => owns() && Boolean(ownedSession?.active && ownedSession.continuous),
|
||||
[owns],
|
||||
);
|
||||
const isViewportSuspended = useCallback(() => viewportRef.current.suspended, []);
|
||||
const isContinuous = useCallback(
|
||||
() => hasContinuousIntent() && !isViewportSuspended(),
|
||||
[hasContinuousIntent, isViewportSuspended],
|
||||
);
|
||||
|
||||
return {
|
||||
viewportSuspended: isViewportSuspended(),
|
||||
setViewportSuspended,
|
||||
isViewportSuspended,
|
||||
hasContinuousIntent,
|
||||
continuous: owns() && Boolean(ownedSession?.continuous),
|
||||
pauseReason: owns() ? ownedSession?.pauseReason || "" : "",
|
||||
setContinuous,
|
||||
|
||||
@ -517,6 +517,26 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
const [workflows, setWorkflows] = useState<Workflow[]>([]);
|
||||
const [projectId, setProjectId] = useState("");
|
||||
const workSession = useAnnotationWorkSession(currentUser?.id || "", projectId || requestedProjectId, workPage);
|
||||
const [viewportSize, setViewportSize] = useState(() => ({ width: window.innerWidth, height: window.innerHeight }));
|
||||
const viewportTooSmall =
|
||||
workPage && workspaceLayout === "focused" && (viewportSize.width < 1280 || viewportSize.height < 640);
|
||||
const viewportPaused = viewportTooSmall || (workPage && workSession.viewportSuspended);
|
||||
// Read the actual content area at dispatch boundaries too, before React's
|
||||
// resize render. Existing request/session fences deliberately ignore this latch.
|
||||
const viewportBlocksDispatch = () =>
|
||||
workPage &&
|
||||
(workSession.isViewportSuspended() ||
|
||||
(workspaceLayout === "focused" && (window.innerWidth < 1280 || window.innerHeight < 640)));
|
||||
useEffect(() => {
|
||||
const measure = () => {
|
||||
setViewportSize({ width: window.innerWidth, height: window.innerHeight });
|
||||
if (workPage && workspaceLayout === "focused" && (window.innerWidth < 1280 || window.innerHeight < 640))
|
||||
workSession.setViewportSuspended(true);
|
||||
};
|
||||
measure();
|
||||
window.addEventListener("resize", measure);
|
||||
return () => window.removeEventListener("resize", measure);
|
||||
}, [workPage, workspaceLayout, workSession.active, workSession.setViewportSuspended]);
|
||||
const [projectMembers, setProjectMembers] = useState<ProjectMember[]>([]);
|
||||
const [templates, setTemplates] = useState<AnnotationTemplate[]>([]);
|
||||
const [tasks, setTasks] = useState<AnnotationTaskRecord[]>([]);
|
||||
@ -3145,7 +3165,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
setWorkbenchDrafts([]);
|
||||
clearEditHistory();
|
||||
setCombinedSubmissionNotice("审核数据已生成,任务已提交质检。");
|
||||
if (workSession.isContinuous()) setNextAfterHandoff(next.task.id);
|
||||
if (workSession.hasContinuousIntent()) setNextAfterHandoff(next.task.id);
|
||||
};
|
||||
|
||||
const selectTask = (taskId: string) => {
|
||||
@ -3179,6 +3199,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
entryStillCurrent?: () => boolean,
|
||||
session?: AnnotationWorkSession,
|
||||
) => {
|
||||
if (viewportBlocksDispatch()) return;
|
||||
const origin = claimContextRef.current;
|
||||
const taskOrigin = annotationMutationContextRef.current.current();
|
||||
let requestSession = session;
|
||||
@ -3204,6 +3225,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
if (!requestSession || !canContinue()) return;
|
||||
}
|
||||
requestId = pendingClaimRequest(key);
|
||||
if (viewportBlocksDispatch()) return;
|
||||
if (!requestId) requestId = newAnnotationClaimRequestID();
|
||||
// Fail closed if persistence is unavailable: a closed tab must never lose
|
||||
// the logical request and allocate a second task when it is reopened.
|
||||
@ -3275,6 +3297,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
};
|
||||
|
||||
const startWork = async (resumeOnly = false) => {
|
||||
if (viewportBlocksDispatch()) return;
|
||||
if (
|
||||
!blindAnnotator ||
|
||||
!canAccessWorkspace ||
|
||||
@ -3362,7 +3385,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
// handoff queues one entry; owned-first entry and its origin/session fences
|
||||
// remain responsible for choosing or claiming the next task.
|
||||
useEffect(() => {
|
||||
if (!nextAfterHandoff || saving || loading || workEntryBusy || randomClaimBusy) return;
|
||||
if (!nextAfterHandoff || saving || loading || workEntryBusy || randomClaimBusy || viewportBlocksDispatch()) return;
|
||||
setNextAfterHandoff("");
|
||||
if (selectedTaskId !== nextAfterHandoff || !workSession.isContinuous()) return;
|
||||
if (!blindAnnotator || !canAccessWorkspace || projectLoadError) {
|
||||
@ -3370,7 +3393,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
return;
|
||||
}
|
||||
void startWork();
|
||||
}, [nextAfterHandoff, saving, loading, workEntryBusy, randomClaimBusy]);
|
||||
}, [nextAfterHandoff, saving, loading, workEntryBusy, randomClaimBusy, viewportPaused]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
@ -3382,6 +3405,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
}, [workPage, workSession.continuous, blindAnnotator, canAccessWorkspace, projectLoadError, loading]);
|
||||
|
||||
const resumeContinuousWork = async () => {
|
||||
if (viewportBlocksDispatch()) return;
|
||||
if (
|
||||
!workSession.active ||
|
||||
!workSession.owns() ||
|
||||
@ -3457,8 +3481,12 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
isOwnedRecoverableAnnotationItem(item, projectId, currentUser?.id),
|
||||
);
|
||||
|
||||
return (
|
||||
const showViewportPrompt = viewportPaused && pendingTaskId === null && leaveBlocker.state !== "blocked";
|
||||
|
||||
const workspaceContent = (
|
||||
<div
|
||||
inert={showViewportPrompt || undefined}
|
||||
aria-hidden={showViewportPrompt || undefined}
|
||||
className="annotation-operations-page space-y-4"
|
||||
data-adaptive-slice={adaptiveSliceLayout || undefined}
|
||||
data-work-page={workPage || undefined}
|
||||
@ -4463,6 +4491,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
onAnnotationDraftEdit={() => editHistoryRef.current.invalidateRedo()}
|
||||
adaptiveLayout={adaptiveSliceLayout}
|
||||
focusedLayout={focusedStageLayout}
|
||||
viewportSuspended={viewportPaused}
|
||||
taskId={detail.task.id}
|
||||
frameTimelineStatus={frameTimelineStatus}
|
||||
onRetryFrameTimeline={() =>
|
||||
@ -4751,4 +4780,51 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
{showViewportPrompt && (
|
||||
<div className="fixed inset-0 z-[90] flex items-center justify-center bg-black/80 p-4">
|
||||
<section
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label="工作区已暂停"
|
||||
className="w-full max-w-lg rounded-xl border bg-[color:var(--app-panel)] p-5 shadow-2xl"
|
||||
>
|
||||
<h2 className="text-lg font-semibold">工作区已暂停</h2>
|
||||
<p className="my-3 text-sm">
|
||||
专注视图需要至少 1280 × 640 CSS
|
||||
像素。请扩大窗口或降低浏览器缩放,然后主动继续。当前任务与草稿已保留,已发出的请求仍在核对。
|
||||
</p>
|
||||
<p className="mb-4 text-sm">
|
||||
当前内容区:{viewportSize.width} × {viewportSize.height}。继续后视频仍保持暂停。
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
disabled={viewportTooSmall}
|
||||
onClick={() => {
|
||||
workSession.setViewportSuspended(false);
|
||||
// Entry may have been suspended while reading the owned pool,
|
||||
// before it could dispatch a claim. Requeue that handoff only.
|
||||
if (workSession.hasContinuousIntent() && detail && combinedSubmissionFinished(detail))
|
||||
setNextAfterHandoff(detail.task.id);
|
||||
}}
|
||||
className="rounded-lg bg-blue-600 px-3 py-2 text-white disabled:opacity-40"
|
||||
>
|
||||
继续当前工作
|
||||
</button>
|
||||
<button type="button" onClick={toggleLayout} className="rounded-lg border px-3 py-2">
|
||||
{workspaceLayout === "focused" ? "切回原布局" : "进入专注视图"}
|
||||
</button>
|
||||
<Link to={workPoolPath} className="rounded-lg border px-3 py-2">
|
||||
返回任务池
|
||||
</Link>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
)}
|
||||
{workspaceContent}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
322
tests/browser/annotation-workspace-viewport-requests.mjs
Normal file
322
tests/browser/annotation-workspace-viewport-requests.mjs
Normal file
@ -0,0 +1,322 @@
|
||||
// All operations reach the real localhost API. Gates delay/drop only delivery
|
||||
// after route.fetch completes, preserving authoritative effects and receipts.
|
||||
import assert from "node:assert/strict";
|
||||
import { chromium } from "playwright";
|
||||
const base = "http://127.0.0.1:5173";
|
||||
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(20000);
|
||||
const button = (name) => page.getByRole("button", { name, exact: true });
|
||||
const prompt = page.getByRole("dialog", { name: "工作区已暂停" });
|
||||
const writes = [];
|
||||
page.on("request", (r) => {
|
||||
if (r.method() === "POST") writes.push({ url: r.url(), body: r.postDataJSON() });
|
||||
});
|
||||
const read = async (task) => {
|
||||
const r = await context.request.get(`${base}/api/human-items/${task.replace("annotation-task-", "human-item-")}`);
|
||||
assert.ok(r.ok());
|
||||
return (await r.json()).item;
|
||||
};
|
||||
const open = async (prefix, slug) => {
|
||||
const task = `annotation-task-${prefix}-${slug}`;
|
||||
await page.goto(`${base}/plugins/annotation-qa/workflows/all/work?projectId=project-${prefix}&taskId=${task}`);
|
||||
const row = page.getByRole("button").filter({ hasText: task });
|
||||
await row.waitFor();
|
||||
await row.click();
|
||||
await button("继续工作").click();
|
||||
await page.getByTestId("capture-annotation-workbench").waitFor();
|
||||
if (await button("进入专注视图").count()) await button("进入专注视图").click();
|
||||
return task;
|
||||
};
|
||||
const gate = async (url, drop = false) => {
|
||||
let release, done, finish;
|
||||
const held = new Promise((r) => (release = r)),
|
||||
server = new Promise((r) => (done = r)),
|
||||
settled = new Promise((r) => (finish = r));
|
||||
await page.route(url, async (route) => {
|
||||
const response = await route.fetch();
|
||||
assert.ok(response.ok(), `real API success ${url}`);
|
||||
const body = await response.json();
|
||||
done(body);
|
||||
await held;
|
||||
if (drop) await route.abort("failed");
|
||||
else await route.fulfill({ response });
|
||||
finish();
|
||||
});
|
||||
return {
|
||||
server,
|
||||
release,
|
||||
remove: async () => {
|
||||
await settled;
|
||||
await page.unroute(url);
|
||||
},
|
||||
};
|
||||
};
|
||||
const shrink = async () => {
|
||||
await page.setViewportSize({ width: 1279, height: 640 });
|
||||
await prompt.waitFor();
|
||||
};
|
||||
const grow = async () => {
|
||||
await page.setViewportSize({ width: 1280, height: 640 });
|
||||
await page.waitForTimeout(250);
|
||||
assert.ok(await prompt.isVisible());
|
||||
};
|
||||
const continueWork = async () => {
|
||||
await grow();
|
||||
await button("继续当前工作").click();
|
||||
};
|
||||
const mode = process.env.VIEWPORT_CASE || "save";
|
||||
try {
|
||||
if (mode === "save") {
|
||||
const task = await open("workspace-layout-acceptance", "annotate-primary");
|
||||
const before = await read(task);
|
||||
await page.getByTestId("annotation-description-block").first().click();
|
||||
const input = page.getByRole("textbox", { name: "动作描述", exact: true });
|
||||
const old = await input.inputValue();
|
||||
const text = `viewport save ${Date.now()}`;
|
||||
await input.fill(text);
|
||||
const pending = await gate(`**/tasks/${task}/annotation-confirmations`);
|
||||
await button("确认保存描述").click();
|
||||
await pending.server;
|
||||
await shrink();
|
||||
assert.equal((await read(task)).version, before.version + 1);
|
||||
await button("切回原布局").click();
|
||||
await button("继续当前工作").click();
|
||||
assert.ok(await button("确认保存描述").isDisabled(), "viewport Continue never clears pending save");
|
||||
await button("进入专注视图").click();
|
||||
await prompt.waitFor();
|
||||
pending.release();
|
||||
await pending.remove();
|
||||
await page.waitForFunction(() => !document.querySelector('[aria-label="动作描述"]'));
|
||||
await continueWork();
|
||||
assert.ok((await read(task)).subject.payload.annotationWorkspace.segments.some((s) => s.description === text));
|
||||
const response = page.waitForResponse(
|
||||
(r) => r.url().endsWith("/annotation-confirmations") && r.request().method() === "POST",
|
||||
);
|
||||
await button("撤销").click();
|
||||
assert.ok((await response).ok());
|
||||
assert.ok(
|
||||
(await read(task)).subject.payload.annotationWorkspace.segments.some((s) => s.description === old),
|
||||
"history survives pending save/viewport/original transitions",
|
||||
);
|
||||
await page.waitForTimeout(1100);
|
||||
const redo = page.waitForResponse(
|
||||
(r) => r.url().endsWith("/annotation-confirmations") && r.request().method() === "POST",
|
||||
);
|
||||
await button("重做").click();
|
||||
assert.ok((await redo).ok());
|
||||
assert.ok((await read(task)).subject.payload.annotationWorkspace.segments.some((s) => s.description === text));
|
||||
console.log(
|
||||
"PASS delayed save, pending restriction and persisted undo/redo",
|
||||
JSON.stringify({
|
||||
before: before.version,
|
||||
after: (await read(task)).version,
|
||||
writes: writes.map((w) => ({ path: new URL(w.url).pathname, version: w.body.version })),
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (mode === "claim" || mode === "unknown") {
|
||||
const prefix =
|
||||
mode === "claim"
|
||||
? "workspace-viewport-claim"
|
||||
: process.env.VIEWPORT_UNKNOWN_PREFIX || "workspace-viewport-unknown2";
|
||||
await page.goto(`${base}/plugins/annotation-qa/workflows/all/work?projectId=project-${prefix}`);
|
||||
await page.getByText("当前没有可继续的已领取任务。", { exact: true }).waitFor();
|
||||
const pending = await gate("**/random-claims", mode === "unknown");
|
||||
await button("核对领取结果并开始连续工作").click();
|
||||
const result = await pending.server;
|
||||
await shrink();
|
||||
pending.release();
|
||||
await pending.remove();
|
||||
if (mode === "unknown") {
|
||||
await page.waitForTimeout(1200);
|
||||
await grow();
|
||||
assert.ok(await prompt.isVisible(), "unknown claim retains viewport latch after inactive-session release");
|
||||
await button("继续当前工作").click();
|
||||
assert.equal(
|
||||
writes.filter((w) => w.url.endsWith("/random-claims")).length,
|
||||
1,
|
||||
"viewport Continue does not retry an unknown claim",
|
||||
);
|
||||
await button("核对领取结果并开始连续工作").click();
|
||||
}
|
||||
await page.waitForURL(new RegExp(`taskId=${result.task.id}`));
|
||||
if (mode === "claim") {
|
||||
await grow();
|
||||
assert.equal(writes.filter((w) => w.url.endsWith("/random-claims")).length, 1);
|
||||
await button("继续当前工作").click();
|
||||
}
|
||||
await page.getByTestId("capture-annotation-workbench").waitFor();
|
||||
const claims = writes.filter((w) => w.url.endsWith("/random-claims"));
|
||||
assert.equal(claims.length, mode === "unknown" ? 2 : 1);
|
||||
if (mode === "unknown")
|
||||
assert.equal(claims[0].body.requestId, claims[1].body.requestId, "unknown replay uses same receipt");
|
||||
const item = await read(result.task.id);
|
||||
assert.equal(item.assignedUserId, result.item.assignedUserId);
|
||||
console.log(
|
||||
"PASS in-flight claim " + mode,
|
||||
JSON.stringify({ task: result.task.id, version: item.version, requests: claims.map((w) => w.body) }),
|
||||
);
|
||||
}
|
||||
if (mode === "hard") {
|
||||
const task = await open("workspace-viewport-claim", "pool-02");
|
||||
const before = await read(task);
|
||||
await button("开始连续工作").click();
|
||||
const secondary = await browser.newContext({
|
||||
storageState: "local-data/verification/annotation-workspace-layout/secondary-auth.json",
|
||||
});
|
||||
const csrf = (await secondary.cookies(base)).find((c) => c.name === "droboticflow_csrf")?.value;
|
||||
assert.ok(csrf);
|
||||
const url = `**/tasks/${task}/slice-confirmations`;
|
||||
let delivered, release;
|
||||
const done = new Promise((r) => (delivered = r)),
|
||||
hold = new Promise((r) => (release = r));
|
||||
let settled;
|
||||
const finished = new Promise((r) => (settled = r));
|
||||
await page.route(url, async (route) => {
|
||||
const response = await secondary.request.post(route.request().url(), {
|
||||
data: route.request().postDataJSON(),
|
||||
headers: { "X-Droboticflow-CSRF-Token": decodeURIComponent(csrf) },
|
||||
});
|
||||
assert.equal(response.status(), 403, "actual other-account permission/ownership rejection");
|
||||
delivered();
|
||||
await hold;
|
||||
await route.fulfill({ response });
|
||||
settled();
|
||||
});
|
||||
await button("确认全部切片").click();
|
||||
await button("确认生成").click();
|
||||
await done;
|
||||
await shrink();
|
||||
release();
|
||||
await finished;
|
||||
await page.unroute(url);
|
||||
await secondary.close();
|
||||
await page.waitForTimeout(1000);
|
||||
await continueWork();
|
||||
assert.equal(
|
||||
await button("完成当前任务后停止").count(),
|
||||
0,
|
||||
"viewport Continue does not clear permission-induced continuous pause",
|
||||
);
|
||||
assert.ok(await button("恢复连续工作").isVisible());
|
||||
assert.equal((await read(task)).version, before.version, "denied request never changes authoritative task");
|
||||
const pending = await gate(url, true);
|
||||
const detailURL = `**/api/plugins/annotation-qa/tasks/${task}`;
|
||||
await page.route(detailURL, async (route) => {
|
||||
await route.fetch();
|
||||
await route.abort("failed");
|
||||
});
|
||||
await button("确认全部切片").click();
|
||||
await button("确认生成").click();
|
||||
await pending.server;
|
||||
await shrink();
|
||||
pending.release();
|
||||
await pending.remove();
|
||||
await page.waitForTimeout(5000);
|
||||
await continueWork();
|
||||
await page.locator(".workspace-status-details > summary").click();
|
||||
await button("核对阶段结果").waitFor();
|
||||
assert.ok(
|
||||
await button("恢复连续工作").isDisabled(),
|
||||
"unknown result remains a hard restriction after viewport Continue",
|
||||
);
|
||||
assert.ok(await button("确认全部切片").isDisabled(), "unknown generation cannot be repeated");
|
||||
await page.unroute(detailURL);
|
||||
await button("核对阶段结果").click();
|
||||
await button("新增动作描述").waitFor({ timeout: 180000 });
|
||||
const after = await read(task);
|
||||
assert.equal(after.subject.payload.sliceWorkflow.phase, "annotate");
|
||||
assert.equal(
|
||||
writes.filter((w) => w.url.endsWith("/slice-confirmations")).length,
|
||||
2,
|
||||
"one real denied attempt and one real successful generation",
|
||||
);
|
||||
assert.equal(writes.filter((w) => w.url.endsWith("/random-claims")).length, 0);
|
||||
console.log(
|
||||
"PASS real403 restriction and unknown-stage reconciliation survive viewport Continue",
|
||||
JSON.stringify({ before: before.version, after: after.version }),
|
||||
);
|
||||
}
|
||||
if (mode === "generation") {
|
||||
const task = await open("workspace-viewport-generation", "slice-primary");
|
||||
const before = await read(task);
|
||||
const pending = await gate(`**/tasks/${task}/slice-confirmations`);
|
||||
await button("确认全部切片").click();
|
||||
await button("确认生成").click();
|
||||
const accepted = await pending.server;
|
||||
await shrink();
|
||||
pending.release();
|
||||
await pending.remove();
|
||||
await continueWork();
|
||||
if ((await button("新增动作描述").count()) === 0) {
|
||||
assert.equal(
|
||||
await button("恢复连续工作")
|
||||
.isEnabled()
|
||||
.catch(() => false),
|
||||
false,
|
||||
"generation processing cannot resume continuous work",
|
||||
);
|
||||
}
|
||||
await button("新增动作描述").waitFor({ timeout: 180000 });
|
||||
const after = await read(task);
|
||||
assert.equal(after.subject.payload.sliceWorkflow.phase, "annotate");
|
||||
assert.equal(after.subject.payload.sliceWorkflow.status, "completed");
|
||||
assert.equal(writes.filter((w) => w.url.endsWith("/slice-confirmations")).length, 1);
|
||||
assert.equal(writes.filter((w) => w.url.endsWith("/random-claims")).length, 0);
|
||||
console.log(
|
||||
"PASS real generation reconciles through viewport latch",
|
||||
JSON.stringify({ before: before.version, after: after.version, status: accepted.sliceWorkflow?.status }),
|
||||
);
|
||||
}
|
||||
if (mode === "submit") {
|
||||
const task = await open("workspace-viewport-submit", "annotate-primary");
|
||||
const before = await read(task);
|
||||
await button("开始连续工作").click();
|
||||
await button("完成当前任务后停止").waitFor();
|
||||
const pending = await gate(`**/tasks/${task}/combined-submissions`);
|
||||
await button("完成任务并提交质检").click();
|
||||
await button("确认送检").click();
|
||||
const accepted = await pending.server;
|
||||
await shrink();
|
||||
pending.release();
|
||||
await pending.remove();
|
||||
for (let i = 0; i < 150; i++) {
|
||||
if ((await read(task)).currentStageId === "quality_review") break;
|
||||
await page.waitForTimeout(1000);
|
||||
}
|
||||
const after = await read(task);
|
||||
assert.equal(after.currentStageId, "quality_review");
|
||||
await page.waitForTimeout(3500);
|
||||
assert.equal(writes.filter((w) => w.url.endsWith("/random-claims")).length, 0, "handoff while paused never claims");
|
||||
await grow();
|
||||
assert.equal(writes.filter((w) => w.url.endsWith("/random-claims")).length, 0, "growing alone never claims");
|
||||
await button("继续当前工作").click();
|
||||
await page.waitForURL(/taskId=annotation-task-workspace-viewport-submit-pool-01/);
|
||||
assert.equal(writes.filter((w) => w.url.endsWith("/combined-submissions")).length, 1);
|
||||
assert.equal(writes.filter((w) => w.url.endsWith("/random-claims")).length, 1);
|
||||
console.log(
|
||||
"PASS real submission defers next claim until explicit Continue",
|
||||
JSON.stringify({
|
||||
before: before.version,
|
||||
accepted: accepted.item?.version,
|
||||
after: after.version,
|
||||
claims: writes.filter((w) => w.url.endsWith("/random-claims")).map((w) => w.body),
|
||||
}),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
await page.screenshot({ path: `local-data/verification/annotation-workspace-layout/task07-${mode}-error.png` });
|
||||
throw error;
|
||||
} finally {
|
||||
await context.close();
|
||||
await browser.close();
|
||||
}
|
||||
73
tests/browser/annotation-workspace-viewport-zoom.mjs
Normal file
73
tests/browser/annotation-workspace-viewport-zoom.mjs
Normal file
@ -0,0 +1,73 @@
|
||||
// Actual browser-engine zoom on an isolated persistent Edge profile; no reload,
|
||||
// CSS zoom or deviceScaleFactor substitution. OS/native monitor coverage is separate.
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync, mkdtempSync } from "node:fs";
|
||||
import { chromium } from "playwright";
|
||||
const dir = mkdtempSync("local-data/verification/annotation-workspace-layout/task07-zoom-");
|
||||
const context = await chromium.launchPersistentContext(dir, {
|
||||
executablePath: "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
||||
headless: true,
|
||||
viewport: null,
|
||||
args: ["--no-proxy-server", "--window-size=1366,768"],
|
||||
});
|
||||
const auth = JSON.parse(readFileSync("local-data/verification/annotation-workspace-layout/auth.json", "utf8"));
|
||||
await context.addCookies(auth.cookies);
|
||||
const settings = await context.newPage();
|
||||
await settings.goto("edge://settings/appearance");
|
||||
const zoom = async (factor) =>
|
||||
settings.evaluate(
|
||||
(f) =>
|
||||
new Promise((resolve, reject) =>
|
||||
chrome.settingsPrivate.setDefaultZoom(f, () =>
|
||||
chrome.runtime.lastError ? reject(new Error(chrome.runtime.lastError.message)) : resolve(),
|
||||
),
|
||||
),
|
||||
factor,
|
||||
);
|
||||
const page = await context.newPage();
|
||||
const button = (name) => page.getByRole("button", { name, exact: true });
|
||||
try {
|
||||
await zoom(1);
|
||||
const task = "annotation-task-workspace-layout-acceptance-annotate-primary";
|
||||
await page.goto(
|
||||
`http://127.0.0.1:5173/plugins/annotation-qa/workflows/all/work?projectId=project-workspace-layout-acceptance&taskId=${task}`,
|
||||
);
|
||||
const row = page.getByRole("button").filter({ hasText: task });
|
||||
await row.waitFor();
|
||||
await row.click();
|
||||
await button("继续工作").click();
|
||||
await page.getByTestId("capture-annotation-workbench").waitFor();
|
||||
if (await button("进入专注视图").count()) await button("进入专注视图").click();
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.querySelectorAll("video").length === 2 &&
|
||||
[...document.querySelectorAll("video")].every((v) => v.readyState >= 2),
|
||||
);
|
||||
await page.getByTestId("annotation-description-block").first().click();
|
||||
const input = page.getByRole("textbox", { name: "动作描述", exact: true });
|
||||
await input.fill("Actual zoom preserves unsaved draft");
|
||||
await button("播放").click();
|
||||
await page.waitForFunction(() => [...document.querySelectorAll("video")].every((v) => !v.paused));
|
||||
const measurements = [];
|
||||
measurements.push(
|
||||
await page.evaluate(() => ({ innerWidth, innerHeight, outerWidth, outerHeight, dpr: devicePixelRatio })),
|
||||
);
|
||||
await zoom(1.25);
|
||||
await page.getByRole("dialog", { name: "工作区已暂停" }).waitFor();
|
||||
measurements.push(
|
||||
await page.evaluate(() => ({ innerWidth, innerHeight, outerWidth, outerHeight, dpr: devicePixelRatio })),
|
||||
);
|
||||
assert.ok(measurements[1].innerWidth < 1280 || measurements[1].innerHeight < 640);
|
||||
assert.ok(await page.locator("video").evaluateAll((vs) => vs.every((v) => v.paused)));
|
||||
await zoom(1);
|
||||
await page.waitForTimeout(300);
|
||||
assert.ok(await page.getByRole("dialog", { name: "工作区已暂停" }).isVisible());
|
||||
await button("继续当前工作").click();
|
||||
assert.equal(await input.inputValue(), "Actual zoom preserves unsaved draft");
|
||||
assert.ok(await page.locator("video").evaluateAll((vs) => vs.every((v) => v.paused)));
|
||||
await button("取消编辑").click();
|
||||
console.log("PASS actual 100→125→100% browser zoom", JSON.stringify(measurements));
|
||||
} finally {
|
||||
await zoom(1);
|
||||
await context.close();
|
||||
}
|
||||
158
tests/browser/annotation-workspace-viewport.mjs
Normal file
158
tests/browser/annotation-workspace-viewport.mjs
Normal file
@ -0,0 +1,158 @@
|
||||
// Real API/browser acceptance. Resize must freeze media and preserve the editor;
|
||||
// restoring space or changing layout must never silently dismiss the latch.
|
||||
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(15000);
|
||||
const button = (name) => page.getByRole("button", { name, exact: true });
|
||||
const task = "annotation-task-workspace-layout-acceptance-annotate-primary";
|
||||
const base = "http://127.0.0.1:5173";
|
||||
const read = async () =>
|
||||
(
|
||||
await (
|
||||
await context.request.get(`${base}/api/human-items/${task.replace("annotation-task-", "human-item-")}`)
|
||||
).json()
|
||||
).item;
|
||||
const videosPaused = () => page.locator("video").evaluateAll((videos) => videos.every((v) => v.paused));
|
||||
const writes = [];
|
||||
page.on("request", (r) => {
|
||||
if (r.method() !== "GET" && /\/tasks\/|random-claims/.test(r.url())) writes.push(r.url());
|
||||
});
|
||||
try {
|
||||
const before = await read();
|
||||
await page.goto(
|
||||
`${base}/plugins/annotation-qa/workflows/all/work?projectId=project-workspace-layout-acceptance&taskId=${task}`,
|
||||
);
|
||||
const row = page.getByRole("button").filter({ hasText: task });
|
||||
await row.waitFor();
|
||||
await row.click();
|
||||
await button("继续工作").click();
|
||||
await page.getByTestId("capture-annotation-workbench").waitFor();
|
||||
if (await button("进入专注视图").count()) await button("进入专注视图").click();
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.querySelectorAll("video").length === 2 &&
|
||||
[...document.querySelectorAll("video")].every((v) => v.readyState >= 2),
|
||||
);
|
||||
await button("开始连续工作").click();
|
||||
await button("完成当前任务后停止").click();
|
||||
await page.getByTestId("annotation-description-block").first().click();
|
||||
const input = page.getByRole("textbox", { name: "动作描述", exact: true });
|
||||
const draft = `viewport unsaved ${Date.now()}`;
|
||||
await input.fill(draft);
|
||||
const workbench = page.getByTestId("capture-annotation-workbench");
|
||||
await workbench.focus();
|
||||
await page.keyboard.press("Control+ArrowRight");
|
||||
await button("新增动作描述").click();
|
||||
await workbench.focus();
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await button("确认结束点").click();
|
||||
await input.fill("Viewport parked second slice draft");
|
||||
await workbench.focus();
|
||||
await page.keyboard.press("Control+ArrowLeft");
|
||||
assert.equal(await input.inputValue(), draft);
|
||||
const handles = await page.locator("video").elementHandles();
|
||||
await button("播放").click();
|
||||
await page.waitForFunction(() => [...document.querySelectorAll("video")].every((v) => !v.paused));
|
||||
await page.setViewportSize({ width: 1279, height: 640 });
|
||||
await page.waitForTimeout(300);
|
||||
assert.ok(await videosPaused(), "below-width boundary pauses both playing videos");
|
||||
const prompt = page.getByRole("dialog", { name: "工作区已暂停" });
|
||||
await prompt.waitFor();
|
||||
await prompt.getByRole("link", { name: "返回任务池", exact: true }).click();
|
||||
const leave = page.getByRole("dialog", { name: "离开未保存修改确认" });
|
||||
await leave.waitFor();
|
||||
await leave.getByRole("button", { name: "继续编辑", exact: true }).click();
|
||||
await prompt.waitFor();
|
||||
const held = await page
|
||||
.locator("video")
|
||||
.first()
|
||||
.evaluate((v) => v.currentTime);
|
||||
await page.setViewportSize({ width: 1280, height: 640 });
|
||||
await page.waitForTimeout(400);
|
||||
assert.ok(await prompt.isVisible(), "size restoration keeps explicit recovery latch");
|
||||
assert.equal(
|
||||
await page
|
||||
.locator("video")
|
||||
.first()
|
||||
.evaluate((v) => v.currentTime),
|
||||
held,
|
||||
);
|
||||
await button("继续当前工作").click();
|
||||
assert.equal(await input.inputValue(), draft);
|
||||
assert.ok(await videosPaused(), "explicit Continue does not play");
|
||||
await page.keyboard.press("Space");
|
||||
await page.waitForTimeout(300);
|
||||
assert.equal(await videosPaused(), false, "Space explicitly resumes playback after viewport Continue");
|
||||
await page.keyboard.press("Space");
|
||||
assert.equal(await button("完成当前任务后停止").count(), 0, "Continue preserves stop-after-current intent");
|
||||
assert.ok(await button("恢复连续工作").isVisible());
|
||||
await workbench.focus();
|
||||
await page.keyboard.press("Control+ArrowRight");
|
||||
assert.equal(await input.inputValue(), "Viewport parked second slice draft");
|
||||
await button("取消新增").click();
|
||||
await workbench.focus();
|
||||
await page.keyboard.press("Control+ArrowLeft");
|
||||
assert.equal(await input.inputValue(), draft);
|
||||
await page.setViewportSize({ width: 1280, height: 639 });
|
||||
await prompt.waitFor();
|
||||
await button("切回原布局").click();
|
||||
assert.ok(await prompt.isVisible(), "fallback keeps latch until Continue");
|
||||
await button("继续当前工作").click();
|
||||
assert.equal(await input.inputValue(), draft);
|
||||
await page.setViewportSize({ width: 1100, height: 600 });
|
||||
await page.waitForTimeout(300);
|
||||
assert.equal(await prompt.count(), 0, "original layout does not initiate viewport suspension");
|
||||
await button("进入专注视图").click();
|
||||
await prompt.waitFor();
|
||||
await page.setViewportSize({ width: 1280, height: 640 });
|
||||
await button("继续当前工作").click();
|
||||
for (const handle of handles) assert.ok(await handle.evaluate((v) => v.isConnected), "video DOM remains mounted");
|
||||
assert.equal(await input.inputValue(), draft);
|
||||
await button("取消编辑").click();
|
||||
await button("完成任务并提交质检").click();
|
||||
await page.getByRole("dialog", { name: "确认提交质检", exact: true }).waitFor();
|
||||
await page.setViewportSize({ width: 1279, height: 640 });
|
||||
await prompt.waitFor();
|
||||
assert.ok(
|
||||
await prompt.getByRole("button", { name: "切回原布局", exact: true }).evaluate((b) => {
|
||||
const r = b.getBoundingClientRect();
|
||||
return b.contains(document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2));
|
||||
}),
|
||||
"viewport fallback remains reachable above an open native stage confirmation",
|
||||
);
|
||||
await page.setViewportSize({ width: 1280, height: 640 });
|
||||
await button("继续当前工作").click();
|
||||
await page.getByRole("dialog", { name: "确认提交质检", exact: true }).waitFor();
|
||||
await button("返回编辑").click();
|
||||
const other = await context.newPage();
|
||||
await other.goto(page.url());
|
||||
await other.getByRole("button", { name: "返回活动工作页", exact: true }).waitFor();
|
||||
await other.setViewportSize({ width: 1279, height: 640 });
|
||||
await other.getByRole("dialog", { name: "工作区已暂停" }).waitFor();
|
||||
await other.setViewportSize({ width: 1280, height: 640 });
|
||||
await other.getByRole("button", { name: "继续当前工作", exact: true }).click();
|
||||
assert.ok(
|
||||
await other.getByRole("button", { name: "继续工作", exact: true }).isDisabled(),
|
||||
"viewport Continue cannot acquire another page's session",
|
||||
);
|
||||
await other.close();
|
||||
assert.equal(writes.length, 0);
|
||||
assert.equal((await read()).version, before.version);
|
||||
console.log(
|
||||
"PASS viewport width/height boundaries, latch/fallback, media freeze, draft/DOM continuity; version",
|
||||
before.version,
|
||||
);
|
||||
} finally {
|
||||
await context.close();
|
||||
await browser.close();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user