forked from longtao.wu/droboticflow
325 lines
15 KiB
JavaScript
325 lines
15 KiB
JavaScript
// Real local UI/API acceptance: lost fixed editing geometry, remounted media,
|
||
// implicit saving or broken history must fail user-visible assertions here.
|
||
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 task = process.env.ANNOTATION_TASK_ID || "annotation-task-workspace-layout-acceptance-annotate-primary";
|
||
assert.match(task, /^annotation-task-workspace-layout-acceptance-(annotate-primary|slice-primary|annotate-delayed)$/);
|
||
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 reachable = async (locator, label) =>
|
||
assert.ok(
|
||
await locator.evaluate((e) => {
|
||
const r = e.getBoundingClientRect();
|
||
return (
|
||
r.x >= 0 &&
|
||
r.y >= 0 &&
|
||
r.right <= innerWidth &&
|
||
r.bottom <= innerHeight &&
|
||
e.contains(document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2))
|
||
);
|
||
}),
|
||
`${label} is visible and reachable without scrolling`,
|
||
);
|
||
const geometry = async () =>
|
||
page.evaluate(() => ({
|
||
videos: [...document.querySelectorAll("video")].map((v) => {
|
||
const r = v.getBoundingClientRect(),
|
||
s = Math.min(r.width / v.videoWidth, r.height / v.videoHeight);
|
||
return {
|
||
width: v.videoWidth * s,
|
||
height: v.videoHeight * s,
|
||
x: r.x,
|
||
y: r.y,
|
||
right: r.right,
|
||
bottom: r.bottom,
|
||
fit: getComputedStyle(v).objectFit,
|
||
};
|
||
}),
|
||
scrollers: [
|
||
document.documentElement,
|
||
...document.querySelectorAll("main, main > div,.annotation-operations-page,.capture-workbench-body"),
|
||
]
|
||
.filter((e) => e.scrollHeight > e.clientHeight + 1 && getComputedStyle(e).overflowY !== "visible")
|
||
.map((e) => e.className),
|
||
}));
|
||
let releaseStatus = () => {};
|
||
try {
|
||
if (process.env.ANNOTATION_VERIFY_SUBMITTED === "1") {
|
||
const item = await readItem();
|
||
assert.equal(item.currentStageId, "quality_review");
|
||
assert.ok(!item.pendingCombinedSubmissionId);
|
||
assert.ok(item.currentRevision > 0);
|
||
console.log(
|
||
"PASS completed handoff public readback",
|
||
JSON.stringify({
|
||
version: item.version,
|
||
currentStageId: item.currentStageId,
|
||
currentRevision: item.currentRevision,
|
||
status: item.status,
|
||
}),
|
||
);
|
||
} else {
|
||
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();
|
||
const workbench = page.getByTestId("capture-annotation-workbench");
|
||
await workbench.waitFor();
|
||
await page.waitForFunction(
|
||
() =>
|
||
document.querySelectorAll("video").length === 2 &&
|
||
[...document.querySelectorAll("video")].every((v) => v.readyState >= 2),
|
||
null,
|
||
{ timeout: 60000 },
|
||
);
|
||
await page.getByTestId("annotation-description-block").first().click();
|
||
const input = page.getByRole("textbox", { name: "动作描述", exact: true });
|
||
const original = await input.inputValue();
|
||
const value = `Task03 saved description ${Date.now()}`;
|
||
await input.fill(value);
|
||
const videos = await page.locator("video").elementHandles();
|
||
const editor = await input.elementHandle();
|
||
let previous = 0;
|
||
for (const [width, height] of [
|
||
[1280, 640],
|
||
[1366, 680],
|
||
[1440, 800],
|
||
[1920, 980],
|
||
[2560, 1320],
|
||
]) {
|
||
await page.setViewportSize({ width, height });
|
||
const g = await geometry();
|
||
console.log(JSON.stringify({ viewport: [width, height], ...g }));
|
||
for (const v of g.videos) {
|
||
assert.ok(v.width >= 400 && v.height >= 325, "each effective image meets 400×325 floor");
|
||
assert.equal(v.fit, "contain");
|
||
assert.ok(v.x >= 0 && v.y >= 0 && v.right <= width && v.bottom <= height);
|
||
}
|
||
assert.ok(g.videos[0].width >= previous);
|
||
previous = g.videos[0].width;
|
||
assert.deepEqual(g.scrollers, [], "no page/workbench scrolling");
|
||
await reachable(input, "description");
|
||
for (const name of [
|
||
"确认保存描述",
|
||
"调整结束点",
|
||
"删除此动作(保留空白)",
|
||
"取消编辑",
|
||
"完成任务并提交质检",
|
||
"撤销",
|
||
"重做",
|
||
"切回原布局",
|
||
"快捷键帮助",
|
||
"上一帧",
|
||
"下一帧",
|
||
])
|
||
await reachable(button(name), name);
|
||
const ed = await page.locator(".capture-description-actions").boundingBox();
|
||
const disposition = await page.getByTestId("slice-disposition-panel").boundingBox();
|
||
assert.ok(ed.y + ed.height <= disposition.y, "editor including save actions stays above disposition");
|
||
const r = await input.boundingBox();
|
||
assert.ok(r.x > g.videos[1].right, "editor remains right of both videos");
|
||
}
|
||
console.log("PASS five-size fixed annotation geometry");
|
||
await page.setViewportSize({ width: 1280, height: 640 });
|
||
await page.screenshot({ path: "local-data/verification/annotation-workspace-layout/task03-focused.png" });
|
||
const beforeConflict = await readItem();
|
||
const saveURL = `**/tasks/${task}/annotation-confirmations`;
|
||
await page.route(saveURL, async (route) => {
|
||
const payload = route.request().postDataJSON();
|
||
const response = await route.fetch({ postData: JSON.stringify({ ...payload, version: payload.version - 1 }) });
|
||
assert.equal(response.status(), 409, "real API rejects stale version");
|
||
await route.fulfill({ response });
|
||
});
|
||
await button("确认保存描述").click();
|
||
await page.getByTestId("annotation-description-editor").getByRole("alert").waitFor();
|
||
assert.equal(await input.inputValue(), value, "failed save retains text");
|
||
assert.equal((await readItem()).version, beforeConflict.version);
|
||
await reachable(button("确认保存描述"), "failed save retry");
|
||
await reachable(button("调整结束点"), "failed save boundary");
|
||
assert.deepEqual((await geometry()).scrollers, []);
|
||
await page.unroute(saveURL);
|
||
console.log("PASS real stale-version failure preserves draft and visible retry");
|
||
const before = await readItem();
|
||
const writes = [];
|
||
page.on("request", (r) => {
|
||
if (r.method() !== "GET" && /\/tasks\/|random-claims/.test(r.url())) writes.push(r.url());
|
||
});
|
||
for (const name of ["切回原布局", "进入专注视图"]) {
|
||
await button(name).click();
|
||
assert.equal(await input.inputValue(), value);
|
||
assert.ok(await editor.evaluate((e) => e.isConnected));
|
||
for (const v of videos) assert.ok(await v.evaluate((e) => e.isConnected));
|
||
}
|
||
assert.equal(writes.length, 0);
|
||
await input.press("Control+Enter");
|
||
await input.waitFor({ state: "detached" });
|
||
assert.equal((await readItem()).version, before.version + 1);
|
||
assert.ok((await readItem()).subject.payload.annotationWorkspace.segments.some((s) => s.description === value));
|
||
const mutation = () =>
|
||
page.waitForResponse((r) => r.url().endsWith("annotation-confirmations") && r.request().method() === "POST");
|
||
let response = mutation();
|
||
await button("撤销").click();
|
||
assert.ok((await response).ok());
|
||
assert.ok((await readItem()).subject.payload.annotationWorkspace.segments.some((s) => s.description === original));
|
||
await page.waitForTimeout(1100);
|
||
response = mutation();
|
||
await button("重做").click();
|
||
assert.ok((await response).ok());
|
||
assert.ok((await readItem()).subject.payload.annotationWorkspace.segments.some((s) => s.description === value));
|
||
assert.equal(writes.length, 3);
|
||
console.log("PASS exact public saved/undo/redo readback and stable media/editor");
|
||
const persistedBeforeCancel = await readItem();
|
||
await page.getByTestId("annotation-description-block").first().click();
|
||
await input.fill("应取消的未保存修改");
|
||
await button("取消编辑").click();
|
||
await input.waitFor({ state: "detached" });
|
||
assert.equal((await readItem()).version, persistedBeforeCancel.version);
|
||
await page.getByTestId("annotation-description-block").first().click();
|
||
assert.equal(await input.inputValue(), value, "cancel restores persisted text");
|
||
await button("取消编辑").click();
|
||
assert.equal(writes.length, 3, "cancel never saves");
|
||
console.log("PASS visible existing-edit cancel discards only the current buffer");
|
||
// Park a new draft in the second slice, then navigate and toggle with no implicit save.
|
||
await workbench.focus();
|
||
await page.keyboard.press("Control+ArrowRight");
|
||
await page.keyboard.press("n");
|
||
await button("确认结束点").waitFor();
|
||
for (let i = 0; i < 6; i++) await page.keyboard.press("ArrowRight");
|
||
await page.keyboard.press("n");
|
||
assert.ok(
|
||
await page.getByTestId("annotation-description-editor").evaluate((e) => e === document.activeElement),
|
||
"N ends at a frame and focuses the existing editor",
|
||
);
|
||
await page.keyboard.press("Enter");
|
||
assert.ok(await input.evaluate((e) => e === document.activeElement), "Enter enters text from the editor");
|
||
await input.fill("第二片未保存动作");
|
||
await reachable(button("取消新增"), "cancel");
|
||
await reachable(button("确认保存描述"), "save");
|
||
const start = await page.getByRole("spinbutton", { name: "动作开始时间(秒)" }).inputValue();
|
||
const end = await page.getByRole("spinbutton", { name: "动作结束时间(秒)" }).inputValue();
|
||
assert.ok(Number(end) > Number(start));
|
||
await workbench.focus();
|
||
await page.keyboard.press("Control+ArrowLeft");
|
||
await button("切回原布局").click();
|
||
await workbench.focus();
|
||
await page.keyboard.press("Control+ArrowRight");
|
||
await button("进入专注视图").click();
|
||
assert.equal(await input.inputValue(), "第二片未保存动作");
|
||
await button("完成任务并提交质检").click();
|
||
await page.getByRole("dialog", { name: "请先处理未保存草稿", exact: true }).waitFor();
|
||
await reachable(button("返回编辑"), "draft confirmation return");
|
||
await button("返回编辑").click();
|
||
assert.equal(writes.length, 3, "parked draft blocks stage writes");
|
||
await button("取消新增").click();
|
||
await workbench.focus();
|
||
await page.keyboard.press("Control+Enter");
|
||
const dialog = page.getByRole("dialog", { name: "确认提交质检", exact: true });
|
||
await dialog.waitFor();
|
||
await reachable(button("返回编辑"), "stage confirmation return");
|
||
await reachable(button("确认送检"), "stage confirmation");
|
||
assert.equal(writes.length, 3, "first confirmation does not submit");
|
||
await button("返回编辑").click();
|
||
console.log("PASS N/end/focus, per-slice draft, cancel and two-step submission guards");
|
||
if (process.env.ANNOTATION_SUBMIT === "1") {
|
||
assert.equal(
|
||
task,
|
||
"annotation-task-workspace-layout-acceptance-annotate-delayed",
|
||
"only consume the designated submission fixture",
|
||
);
|
||
const beforeSubmit = await readItem();
|
||
const statusGate = new Promise((r) => (releaseStatus = r));
|
||
const statusURL = `**/tasks/${task}/status`;
|
||
await page.route(statusURL, async (route) => {
|
||
await statusGate;
|
||
await route.continue();
|
||
});
|
||
await button("完成任务并提交质检").click();
|
||
await reachable(button("确认送检"), "actual send confirmation");
|
||
const submitted = page.waitForResponse(
|
||
(r) => r.url().endsWith("/combined-submissions") && r.request().method() === "POST",
|
||
);
|
||
await button("确认送检").click();
|
||
const submittedResponse = await submitted;
|
||
assert.ok(submittedResponse.ok());
|
||
const accepted = await submittedResponse.json();
|
||
console.log(
|
||
"Real submission accepted",
|
||
JSON.stringify({
|
||
beforeVersion: beforeSubmit.version,
|
||
acceptedVersion: accepted.item?.version,
|
||
status: accepted.status,
|
||
}),
|
||
);
|
||
assert.equal(accepted.status, "processing", "actual asynchronous preparation stays processing");
|
||
assert.equal(accepted.item.currentStageId, "annotation_combined");
|
||
assert.ok(accepted.item.pendingCombinedSubmissionId);
|
||
await page.getByTestId("combined-submission-status").waitFor();
|
||
assert.match(await page.getByTestId("combined-submission-status").innerText(), /送检处理中/);
|
||
assert.ok(
|
||
(await button("完成任务并提交质检").count()) === 0 || (await button("完成任务并提交质检").isDisabled()),
|
||
"processing cannot be submitted again",
|
||
);
|
||
assert.deepEqual((await geometry()).scrollers, []);
|
||
assert.equal(
|
||
writes.filter((u) => u.includes("random-claims")).length,
|
||
0,
|
||
"processing does not acquire another task",
|
||
);
|
||
await page.screenshot({ path: "local-data/verification/annotation-workspace-layout/task03-processing.png" });
|
||
releaseStatus();
|
||
await page.waitForFunction(() => document.body.innerText.includes("已提交质检"), null, { timeout: 120000 });
|
||
const completed = await readItem();
|
||
assert.equal(completed.currentStageId, "quality_review");
|
||
assert.ok(!completed.pendingCombinedSubmissionId);
|
||
assert.ok(completed.currentRevision > 0);
|
||
assert.equal(writes.filter((u) => u.endsWith("/combined-submissions")).length, 1);
|
||
assert.equal(
|
||
writes.filter((u) => u.includes("random-claims")).length,
|
||
0,
|
||
"stopped work stays stopped after real handoff",
|
||
);
|
||
console.log(
|
||
"PASS actual submission public readback",
|
||
JSON.stringify({
|
||
beforeVersion: beforeSubmit.version,
|
||
acceptedVersion: accepted.item.version,
|
||
completedVersion: completed.version,
|
||
currentStageId: completed.currentStageId,
|
||
currentRevision: completed.currentRevision,
|
||
}),
|
||
);
|
||
}
|
||
}
|
||
} catch (e) {
|
||
await page.screenshot({ path: "local-data/verification/annotation-workspace-layout/task03-error.png" });
|
||
console.log(await page.locator("body").innerText());
|
||
console.log(
|
||
await page
|
||
.locator(".capture-workbench, .annotation-task-workspace, .annotation-task-detail, .capture-workbench-host")
|
||
.evaluateAll((es) => es.map((e) => ({ class: e.className, rect: e.getBoundingClientRect().toJSON() }))),
|
||
);
|
||
throw e;
|
||
} finally {
|
||
releaseStatus();
|
||
await context.close();
|
||
await browser.close();
|
||
}
|